Beispiel #1
0
        public void ApplyChanges(List <RolePrivilege> privileges, Guid roleId)
        {
            var apRequest = new ReplacePrivilegesRoleRequest
            {
                RoleId     = roleId,
                Privileges = privileges.ToArray()
            };

            innerService.Execute(apRequest);
        }
        /// <summary>
        /// Replace the <c>Privilege</c> set of <c>Role</c>.
        /// This effectively deletes all existing privileges from the role and adds the new specified privileges.
        /// <para>
        /// For more information look at https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.replaceprivilegesrolerequest(v=crm.8).aspx
        /// </para>
        /// </summary>
        /// <param name="roleId">Role Id</param>
        /// <param name="privilegeList">Privilege List</param>
        /// <returns>
        /// <see cref="ReplacePrivilegesRoleResponse"/>
        /// </returns>
        public ReplacePrivilegesRoleResponse ReplacePrivileges(Guid roleId, List <RolePrivilege> privilegeList)
        {
            ExceptionThrow.IfGuidEmpty(roleId, "roleId");
            ExceptionThrow.IfNullOrEmpty(privilegeList, "privilegeList");

            ReplacePrivilegesRoleRequest request = new ReplacePrivilegesRoleRequest()
            {
                RoleId     = roleId,
                Privileges = privilegeList.ToArray()
            };

            return((ReplacePrivilegesRoleResponse)this.OrganizationService.Execute(request));
        }
        private void ReplaceRolePrivilege(Guid idRole, IEnumerable <RolePrivilege> privileges)
        {
            if (privileges != null)
            {
                ReplacePrivilegesRoleRequest request = new ReplacePrivilegesRoleRequest()
                {
                    RoleId     = idRole,
                    Privileges = privileges.ToArray(),
                };

                _service.Execute(request);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Adds list of privileges to each role in the specified list
        /// </summary>
        /// <param name="privileges">List of privileges to add</param>
        /// <param name="role">List of roles to update</param>
        public void AddPrivilegesToRole(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 isn't already in the current security role
            // privileges, it is added
            foreach (RolePrivilege privilege in privileges)
            {
                var rp = rolePrivileges.Find(x => x.PrivilegeId == privilege.PrivilegeId);
                if (rp == null)
                {
                    rolePrivileges.Add(privilege);
                    hasChanged = true;
                }
                else if (rp.Depth != privilege.Depth)
                {
                    rolePrivileges[rolePrivileges.IndexOf(rp)] = privilege;
                    hasChanged = true;
                }
            }

            // If some privileges have been added, we can update the security role
            if (hasChanged)
            {
                var apRequest = new ReplacePrivilegesRoleRequest
                {
                    RoleId     = roleId,
                    Privileges = rolePrivileges.ToArray()
                };

                innerService.Execute(apRequest);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Adds list of privileges to each role in the specified list
        /// </summary>
        /// <param name="privileges">List of privileges to add</param>
        /// <param name="role">List of roles to update</param>
        public void AddPrivilegesToRole(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 isn't already in the current security role
            // privileges, it is added
            foreach (RolePrivilege privilege in privileges)
            {
                var rp = rolePrivileges.Find(x => x.PrivilegeId == privilege.PrivilegeId);
                if (rp == null)
                {
                    rolePrivileges.Add(privilege);
                    hasChanged = true;
                }
                else if (rp.Depth != privilege.Depth)
                {
                    rolePrivileges[rolePrivileges.IndexOf(rp)] = privilege;
                    hasChanged = true;
                }
            }

            // If some privileges have been added, we can update the security role
            if (hasChanged)
            {
                var apRequest = new ReplacePrivilegesRoleRequest
                                    {
                                        RoleId = roleId,
                                        Privileges = rolePrivileges.ToArray()
                                    };

                innerService.Execute(apRequest);
            }
        }
Beispiel #6
0
        public void ApplyChanges(List<RolePrivilege> privileges, Guid roleId)
        {
            var apRequest = new ReplacePrivilegesRoleRequest
                                {
                                    RoleId = roleId,
                                    Privileges = privileges.ToArray()
                                };

            innerService.Execute(apRequest);
        }