private RevokeAccessResponse HandleRevokeAccess(OrganizationRequest orgRequest, EntityReference userRef) { var request = MakeRequest <RevokeAccessRequest>(orgRequest); var resp = new RevokeAccessResponse(); dataMethods.RevokeAccess(request.Target, request.Revokee, userRef); return(resp); }
protected override void Execute(CodeActivityContext executionContext) { #region "Load CRM Service from context" Common objCommon = new Common(executionContext); objCommon.tracingService.Trace("Load CRM Service from context --- OK"); #endregion #region "Read Parameters" String _SharingRecordURL = this.SharingRecordURL.Get(executionContext); if (_SharingRecordURL == null || _SharingRecordURL == "") { return; } string[] urlParts = _SharingRecordURL.Split("?".ToArray()); string[] urlParams = urlParts[1].Split("&".ToCharArray()); string objectTypeCode = urlParams[0].Replace("etc=", ""); string objectId = urlParams[1].Replace("id=", ""); objCommon.tracingService.Trace("ObjectTypeCode=" + objectTypeCode + "--ParentId=" + objectId); EntityReference teamReference = this.Team.Get(executionContext); if (teamReference != null) { principals.Add(teamReference); } #endregion #region "ApplyRoutingRuteamReferenceleRequest Execution" string EntityName = objCommon.sGetEntityNameFromCode(objectTypeCode, objCommon.service); EntityReference refObject = new EntityReference(EntityName, new Guid(objectId)); RevokeAccessRequest revoqueRequest = new RevokeAccessRequest(); revoqueRequest.Target = refObject; foreach (EntityReference principalObject in principals) { revoqueRequest.Revokee = principalObject; RevokeAccessResponse revoqueResponse = (RevokeAccessResponse)objCommon.service.Execute(revoqueRequest); } objCommon.tracingService.Trace("Revoqued Permissions--- OK"); #endregion }
/// <summary> /// Demonstrates sharing records by exercising various access messages including: /// Grant, Modify, Revoke, RetrievePrincipalAccess, and /// RetrievePrincipalsAndAccess. /// </summary> /// <param name="serverConfig">Contains server connection information.</param> /// <param name="promptforDelete">When True, the user will be prompted to delete all /// created entities.</param> public void Run(ServerConnection.Configuration serverConfig, bool promptforDelete) { try { // Connect to the Organization service. // The using statement assures that the service proxy will be properly disposed. using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials)) { // This statement is required to enable early-bound type support. _serviceProxy.EnableProxyTypes(); _service = (IOrganizationService)_serviceProxy; CreateRequiredRecords(); #region GrantAccess Message // Create the request object and set the target and principal access // object. GrantAccessRequest grantRequest = new GrantAccessRequest() { Target = new EntityReference(Account.EntityLogicalName, _accountId), PrincipalAccess = new PrincipalAccess() { Principal = new EntityReference(SystemUser.EntityLogicalName, _userId), AccessMask = AccessRights.WriteAccess | AccessRights.ReadAccess | AccessRights.ShareAccess } }; // Execute the request. GrantAccessResponse grantResponse = (GrantAccessResponse)_service.Execute(grantRequest); Console.Write("Access Granted "); #endregion #region ModifyAccess Message // Create the request object and set the target and principal access // object. ModifyAccessRequest modifyRequest = new ModifyAccessRequest() { Target = new EntityReference(Account.EntityLogicalName, _accountId), PrincipalAccess = new PrincipalAccess() { Principal = new EntityReference(SystemUser.EntityLogicalName, _userId), AccessMask = AccessRights.ReadAccess | AccessRights.ShareAccess } }; // Execute the request. ModifyAccessResponse modifyResponse = (ModifyAccessResponse)_service.Execute(modifyRequest); Console.Write("and Modified. "); #endregion #region RetrievePrincipalAccess Message // Create the request object and set the target and principal. RetrievePrincipalAccessRequest retrieveRequest = new RetrievePrincipalAccessRequest() { Target = new EntityReference(Account.EntityLogicalName, _accountId), Principal = new EntityReference(SystemUser.EntityLogicalName, _userId) }; // Execute the request. RetrievePrincipalAccessResponse retrieveResponse = (RetrievePrincipalAccessResponse)_service.Execute(retrieveRequest); Console.Write("Retrieved principal access. "); #endregion #region RetrieveSharedPrincipalsAndAccess Message // Create the request object and set the target. RetrieveSharedPrincipalsAndAccessRequest retrieveSharedRequest = new RetrieveSharedPrincipalsAndAccessRequest() { Target = new EntityReference(Account.EntityLogicalName, _accountId) }; // Execute the request. RetrieveSharedPrincipalsAndAccessResponse retrieveSharedResponse = (RetrieveSharedPrincipalsAndAccessResponse)_service.Execute(retrieveSharedRequest); Console.Write("Retrieved principals and access. "); #endregion #region RevokeAccess Message // Create the request object and set the target and revokee. RevokeAccessRequest revokeRequest = new RevokeAccessRequest() { Target = new EntityReference(Account.EntityLogicalName, _accountId), Revokee = new EntityReference(SystemUser.EntityLogicalName, _userId) }; // Execute the request. RevokeAccessResponse revokeResponse = (RevokeAccessResponse)_service.Execute(revokeRequest); Console.Write("Revoked Access."); #endregion DeleteRequiredRecords(promptforDelete); } } // Catch any service fault exceptions that Microsoft Dynamics CRM throws. catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ) { // You can handle an exception here or pass it back to the calling method. throw; } }