| Carsten 的个人资料Microsoft Dynamics CRM &...日志列表 | 帮助 |
|
|
Microsoft Dynamics CRM 4.0 | Sicherheit für Grid-Buttons
Folgendes Szenario: Ihr habt in einer Datensatzübersicht(Grid)-Ansicht einen Button hinzugefügt, der ein Ereignis auslöst. Nun habt Ihr jedoch die Anforderung, dass dieses Ereignis nur ein bestimmter Personenkreis ausführen darf. Hier hilft uns ein kleines, feines Script weiter: function DoSomething() { // Define the role names you wish to allow var allowedRoles = [ "Planer", "Systemadministrator" ]; // Check to see if the user's role matches one of the defined allowed roles var roleAllowed = IsRoleAllowed(allowedRoles); // If the role is not allowed, then alert if (! roleAllowed) { alert('Sie sind nicht berechtigt, die Funktion auszuführen.' return; } // Here comes the code which should fire, if the user is allowed } function IsRoleAllowed(allowedRoles) { // Find the user security roles var result = RetrieveUserRoles(); var foundResult = false; // Loop through the allowed role list checking if the user belongs to one of the roles. for (i=0;i<=allowedRoles.length;i++) { if (result.indexOf(allowedRoles[i]) > -1 ) { foundResult = true; break; } } return foundResult; } // Method to return the user's security roles function RetrieveUserRoles() { // Define URL to CRM API service var serverUrl = "/mscrmservices/2007/crmservice.asmx"; // Set up XMLHTTP request var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.open("POST", serverUrl, false); xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8") // Specify correct SOAP action in the header xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple") // Define the retrievemultiple message var message = [ "<?xml version='1.0' encoding='utf-8'?>", "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">", "<soap:Header>", "<CrmAuthenticationToken xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">", "<AuthenticationType xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">0</AuthenticationType>", // Change Microsoft for your Organization name here. "<OrganizationName xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">MicrosoftCRM</OrganizationName>", "<CallerId xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">00000000-0000-0000-0000-000000000000</CallerId>", "</CrmAuthenticationToken>", "</soap:Header>", "<soap:Body>", "<RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>", "<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:QueryExpression'>", "<q1:EntityName>role</q1:EntityName>", "<q1:ColumnSet xsi:type='q1:ColumnSet'><q1:Attributes><q1:Attribute>name</q1:Attribute></q1:Attributes></q1:ColumnSet>", "<q1:Distinct>false</q1:Distinct>", "<q1:LinkEntities>", "<q1:LinkEntity>", "<q1:LinkFromAttributeName>roleid</q1:LinkFromAttributeName>", "<q1:LinkFromEntityName>role</q1:LinkFromEntityName>", "<q1:LinkToEntityName>systemuserroles</q1:LinkToEntityName>", "<q1:LinkToAttributeName>roleid</q1:LinkToAttributeName>", "<q1:JoinOperator>Inner</q1:JoinOperator>", "<q1:LinkEntities>", "<q1:LinkEntity>", "<q1:LinkFromAttributeName>systemuserid</q1:LinkFromAttributeName>", "<q1:LinkFromEntityName>systemuserroles</q1:LinkFromEntityName>", "<q1:LinkToEntityName>systemuser</q1:LinkToEntityName>", "<q1:LinkToAttributeName>systemuserid</q1:LinkToAttributeName>", "<q1:JoinOperator>Inner</q1:JoinOperator>", "<q1:LinkCriteria>", "<q1:FilterOperator>And</q1:FilterOperator>", "<q1:Conditions>", "<q1:Condition>", "<q1:AttributeName>systemuserid</q1:AttributeName>", "<q1:Operator>Equal</q1:Operator>", "<q1:Values>", "<q1:Value xmlns:q2='http://microsoft.com/wsdl/types/' xsi:type='q2:guid'>", GetUserId(), "</q1:Value>", "</q1:Values>", "</q1:Condition>", "</q1:Conditions>", "</q1:LinkCriteria>", "</q1:LinkEntity>", "</q1:LinkEntities>", "</q1:LinkEntity>", "</q1:LinkEntities>", "</query>", "</RetrieveMultiple>", "</soap:Body>", "</soap:Envelope>" ].join(""); // Submit to the CRM API web service and receive a response xmlhttp.send(message); return xmlhttp.responseXML.text; } // Method to return the current user's systemuserid function GetUserId() { // Define URL to CRM API service var serverUrl = "/mscrmservices/2007/crmservice.asmx"; // Set up XMLHTTP request var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.open("POST", serverUrl, false); xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8") // Specify correct SOAP action in the header xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute") // Define the execute message var message = [ "<?xml version='1.0' encoding='utf-8'?>", "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">", "<soap:Header>", "<CrmAuthenticationToken xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">", "<AuthenticationType xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">0</AuthenticationType>", // Change MicrosoftCRM for your Organization name here. "<OrganizationName xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">MicrosoftCRM</OrganizationName>", "<CallerId xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">00000000-0000-0000-0000-000000000000</CallerId>", "</CrmAuthenticationToken>", "</soap:Header>", "<soap:Body>", "<Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>", "<Request xsi:type='WhoAmIRequest' />", "</Execute>", "</soap:Body>", "</soap:Envelope>" ].join(""); // Submit to the CRM API web service and receive a response xmlhttp.send(message); var result = xmlhttp.responseXML.xml; // Create a new DOM document and load the response XML var doc = new ActiveXObject("MSXML2.DOMDocument"); doc.async = false; doc.loadXML(result); // Return the userid node var returnNode = doc.selectSingleNode("//UserId"); if( returnNode != null ) { // If the userid node exists, return its value return returnNode.text; } else { return null; } } Wenn Ihr jetzt vom Grid-Button aus, die Funktion DoSomething() ausführen würdet, dann müssen die Benutzer mindestens eine der ausgewählten Rechterollen zugewiesen haben, um die Funktion ausführen zu können. Damit ist der Button zwar auch für die anderen Benutzer im Grid sichtbar. Ein Klick darauf bewirkt jedoch, dass entweder die Funktion ausgeführt wird oder eben nicht.
引用通告此日志的引用通告 URL 是: http://carstengroth.spaces.live.com/blog/cns!97768EC3728C1FF3!622.trak 引用此项的网络日志
|
|
|