コード例 #1
0
ファイル: RoleManager.cs プロジェクト: linoh/XrmToolBox
        /// <summary>
        /// Removes list of privileges to each role in the specified list
        /// </summary>
        /// <param name="privileges">List of privileges to remove</param>
        /// <param name="role">List of roles to update</param>
        public void RemovePrivilegesToRole(List <RolePrivilege> privileges, Entity role)
        {
            bool hasChanged = false;

            Guid roleId = (Guid)role["roleid"];

            // Retrieve the privileges for the current security role
            var request = new RetrieveRolePrivilegesRoleRequest {
                RoleId = roleId
            };
            var response =
                (RetrieveRolePrivilegesRoleResponse)innerService.Execute(request);
            List <RolePrivilege> rolePrivileges = response.RolePrivileges.ToList();

            // If the privilege exists in the privileges set of the security role,
            // we remove it
            foreach (RolePrivilege privilege in privileges)
            {
                var request3 = new RemovePrivilegeRoleRequest
                {
                    RoleId      = roleId,
                    PrivilegeId = privilege.PrivilegeId
                };

                innerService.Execute(request3);
            }
        }
コード例 #2
0
        private void ModifyRolePrivileges(Guid idRole
                                          , IEnumerable <RolePrivilege> privilegesAdd
                                          , IEnumerable <RolePrivilege> privilegesRemove
                                          )
        {
            if (privilegesAdd != null && privilegesAdd.Any())
            {
                AddPrivilegesRoleRequest request = new AddPrivilegesRoleRequest()
                {
                    RoleId     = idRole,
                    Privileges = privilegesAdd.ToArray(),
                };

                _service.Execute(request);
            }

            if (privilegesRemove != null && privilegesRemove.Any())
            {
                foreach (var priv in privilegesRemove)
                {
                    RemovePrivilegeRoleRequest request = new RemovePrivilegeRoleRequest()
                    {
                        RoleId      = idRole,
                        PrivilegeId = priv.PrivilegeId
                    };

                    _service.Execute(request);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Remove a privilege from the current role.
        /// </summary>
        /// <param name="Service">Organization Service</param>
        /// <param name="Privilege">Id of the privilege to remove.</param>
        public void RemovePrivilege(IOrganizationService Service, Guid Privilege)
        {
            RemovePrivilegeRoleRequest Request = new RemovePrivilegeRoleRequest()
            {
                RoleId = this.Id, PrivilegeId = Privilege
            };

            Service.Execute(Request);
        }
コード例 #4
0
        /// <summary>
        /// Remove a <c>Privilege</c> from <c>Role</c>.
        /// <para>
        /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.removeprivilegerolerequest(v=crm.8).aspx
        /// </para>
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="privilegeId"></param>
        /// <returns>
        /// <see cref="RemovePrivilegeRoleResponse"/>
        /// </returns>
        public RemovePrivilegeRoleResponse RemovePrivilege(Guid roleId, Guid privilegeId)
        {
            ExceptionThrow.IfGuidEmpty(roleId, "roleId");
            ExceptionThrow.IfGuidEmpty(privilegeId, "privilegeId");

            RemovePrivilegeRoleRequest request = new RemovePrivilegeRoleRequest()
            {
                PrivilegeId = privilegeId,
                RoleId      = roleId
            };

            return((RemovePrivilegeRoleResponse)this.OrganizationService.Execute(request));
        }
コード例 #5
0
ファイル: RoleManager.cs プロジェクト: rehanhsyed/XrmToolBox
        /// <summary>
        /// Removes list of privileges to each role in the specified list
        /// </summary>
        /// <param name="privileges">List of privileges to remove</param>
        /// <param name="role">List of roles to update</param>
        public void RemovePrivilegesToRole(List<RolePrivilege> privileges, Entity role)
        {
            bool hasChanged = false;

            Guid roleId = (Guid)role["roleid"];

            // Retrieve the privileges for the current security role
            var request = new RetrieveRolePrivilegesRoleRequest { RoleId = roleId };
            var response =
                (RetrieveRolePrivilegesRoleResponse)innerService.Execute(request);
            List<RolePrivilege> rolePrivileges = response.RolePrivileges.ToList();

            // If the privilege exists in the privileges set of the security role,
            // we remove it
            foreach (RolePrivilege privilege in privileges)
            {
                var request3 = new RemovePrivilegeRoleRequest
                                   {
                                       RoleId = roleId,
                                       PrivilegeId = privilege.PrivilegeId
                                   };

                innerService.Execute(request3);
            }
        }