Esempio n. 1
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            Guid[] currentSetIds = SecurityManagementHelper.GetUsersInTeam(_repository, Team).Select(e => e.Id).ToArray();
            Guid[] addSet        = Users.Except(currentSetIds).ToArray();
            if (addSet != null && addSet.Length > 0)
            {
                SecurityManagementHelper.AddUsersToTeam(_repository, Team, addSet);
            }
            //Remove associations which are in current and not in new
            if (Overwrite)
            {
                Guid[] removeSet = currentSetIds.Except(Users).ToArray();
                if (removeSet != null && removeSet.Length > 0)
                {
                    SecurityManagementHelper.RemoveUsersFromTeam(_repository, Team, removeSet);
                }
            }

            if (PassThru)
            {
                WriteObject(_repository.Get("team", Team));
            }
        }
Esempio n. 2
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            Guid[] userIds        = Users;
            Guid   businessUnitId = BusinessUnit ?? SecurityManagementHelper.GetDefaultBusinessUnitId(_repository);

            Entity newTeam = new Entity("team")
            {
                Attributes = new AttributeCollection()
            };

            newTeam.Attributes.Add("name", Name);
            newTeam.Attributes.Add("teamtype", new OptionSetValue((int)TeamType));
            newTeam.Attributes.Add("administratorid", new EntityReference("systemuser", Administrator));
            newTeam.Attributes.Add("businessunitid", new EntityReference("businessunit", businessUnitId));
            if (!string.IsNullOrWhiteSpace(Description))
            {
                newTeam.Attributes.Add("description", Description);
            }

            Guid newTeamId = _repository.Add(newTeam);

            if (Users != null && Users.Length != 0)
            {
                SecurityManagementHelper.AddUsersToTeam(_repository, newTeamId, Users);
            }

            if (PassThru)
            {
                WriteObject(_repository.Get("team", newTeamId));
            }
        }
Esempio n. 3
0
        private void RemoveRolePrincipalsSelected()
        {
            string secondaryEntityName = null;

            switch (PrincipalType)
            {
            case CrmPrincipalType.User:
                secondaryEntityName = "systemuser";
                break;

            case CrmPrincipalType.Team:
                secondaryEntityName = "team";
                break;

            default:
                break;
            }

            string primaryEntityName = "role";

            foreach (Guid roleId in Role)
            {
                Guid   primaryEntityId    = roleId;
                Guid[] secondaryEntityIds = Principals;
                Guid[] currentSetIds      = SecurityManagementHelper.GetPrincipalsInRole(_repository, PrincipalType.Value, roleId).Select(e => e.Id).ToArray();
                Guid[] removeSet          = secondaryEntityIds.Intersect(currentSetIds).ToArray();

                if (removeSet != null && removeSet.Length > 0)
                {
                    SecurityManagementHelper.UnlinkPrincipalRoles(_repository, primaryEntityName, primaryEntityId, secondaryEntityName, removeSet);
                }
            }
        }
Esempio n. 4
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            Guid[] roleIds        = Roles;
            Guid   businessUnitId = BusinessUnit ?? SecurityManagementHelper.GetDefaultBusinessUnitId(_repository);

            Entity newUser = new Entity("systemuser")
            {
                Attributes = new AttributeCollection()
            };

            newUser.Attributes.Add("domainname", UserName);
            newUser.Attributes.Add("firstname", Firstname);
            newUser.Attributes.Add("lastname", Lastname);
            newUser.Attributes.Add("accessmode", new OptionSetValue((int)Access));
            newUser.Attributes.Add("caltype", new OptionSetValue((int)License));
            newUser.Attributes.Add("businessunitid", new EntityReference("businessunit", businessUnitId));

            Guid newUserId = _repository.Add(newUser);

            SecurityManagementHelper.LinkPrincipalRoles(_repository, "systemuser", newUserId, "role", roleIds);

            if (PassThru)
            {
                WriteObject(_repository.Get("systemuser", newUserId));
            }
        }
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            Guid[] currentSetIds = SecurityManagementHelper.GetTeamsForUser(_repository, User).Select(e => e.Id).ToArray();

            Guid[] addSet = Teams.Except(currentSetIds).ToArray();
            if (addSet != null && addSet.Length > 0)
            {
                foreach (var item in addSet)
                {
                    SecurityManagementHelper.AddUsersToTeam(_repository, item, new Guid[] { User });
                }
            }
            //Remove associations which are in current and not in new
            if (Overwrite)
            {
                Guid[] removeSet = currentSetIds.Except(Teams).ToArray();
                if (removeSet != null && removeSet.Length > 0)
                {
                    foreach (var item in removeSet)
                    {
                        SecurityManagementHelper.RemoveUsersFromTeam(_repository, item, new Guid[] { User });
                    }
                }
            }

            if (PassThru)
            {
                WriteObject(_repository.Get("systemuser", User));
            }
        }
 protected override void ExecuteCmdlet()
 {
     base.ExecuteCmdlet();
     foreach (Guid id in Team)
     {
         WriteObject(SecurityManagementHelper.GetUsersInTeam(_repository, id), true);
     }
 }
Esempio n. 7
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            IEnumerable <Entity> teamRoles = SecurityManagementHelper.GetRolesForPrincipal(_repository, CrmPrincipalType.Team, Principal);

            WriteObject(teamRoles, true);

            IEnumerable <Entity> userRoles = SecurityManagementHelper.GetRolesForPrincipal(_repository, CrmPrincipalType.User, Principal);

            WriteObject(userRoles, true);
        }
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            IEnumerable <Entity> teams = SecurityManagementHelper.GetPrincipalsInRole(_repository, CrmPrincipalType.Team, Role);

            WriteObject(teams, true);

            IEnumerable <Entity> users = SecurityManagementHelper.GetPrincipalsInRole(_repository, CrmPrincipalType.User, Role);

            WriteObject(users, true);
        }
Esempio n. 9
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            string secondaryEntityName = null;

            switch (PrincipalType)
            {
            case CrmPrincipalType.User:
                secondaryEntityName = "systemuser";
                break;

            case CrmPrincipalType.Team:
                secondaryEntityName = "team";
                break;

            default:
                break;
            }

            string primaryEntityName = "role";

            foreach (Guid roleId in Role)
            {
                Guid   primaryEntityId    = roleId;
                Guid[] secondaryEntityIds = Principals;
                Guid[] currentSetIds      = SecurityManagementHelper.GetPrincipalsInRole(_repository, PrincipalType, roleId).Select(e => e.Id).ToArray();

                Guid[] addSet = secondaryEntityIds.Except(currentSetIds).ToArray();
                if (addSet != null && addSet.Length > 0)
                {
                    SecurityManagementHelper.LinkPrincipalRoles(_repository, primaryEntityName, primaryEntityId, secondaryEntityName, addSet);
                }
                //Remove associations which are in current and not in new
                if (Overwrite)
                {
                    Guid[] removeSet = currentSetIds.Except(secondaryEntityIds).ToArray();
                    if (removeSet != null && removeSet.Length > 0)
                    {
                        SecurityManagementHelper.UnlinkPrincipalRoles(_repository, primaryEntityName, primaryEntityId, secondaryEntityName, removeSet);
                    }
                }

                if (PassThru)
                {
                    WriteObject(_repository.Get(primaryEntityName, primaryEntityId));
                }
            }
        }
Esempio n. 10
0
        private void RemoveRoleTeamsAll(Guid roleId)
        {
            string secondaryEntityName = "team";
            string primaryEntityName   = "role";
            Guid   primaryEntityId     = roleId;

            Guid[] secondaryEntityIds = Principals;
            Guid[] currentSetIds      = SecurityManagementHelper.GetPrincipalsInRole(_repository, PrincipalType.Value, roleId).Select(e => e.Id).ToArray();
            Guid[] removeSet          = secondaryEntityIds.Intersect(currentSetIds).ToArray();

            if (removeSet != null && removeSet.Length > 0)
            {
                SecurityManagementHelper.UnlinkPrincipalRoles(_repository, primaryEntityName, primaryEntityId, secondaryEntityName, removeSet);
            }
        }
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            foreach (Guid id in Team)
            {
                Guid[] currentSetIds = SecurityManagementHelper.GetUsersInTeam(_repository, id).Select(e => e.Id).ToArray();
                Guid[] removeSet     = Users;
                if (this.ParameterSetName == RemoveTeamUsersAllParameterSet)
                {
                    removeSet = currentSetIds;
                }

                if (removeSet != null && removeSet.Length > 0)
                {
                    SecurityManagementHelper.RemoveUsersFromTeam(_repository, id, removeSet);
                }
            }
        }
Esempio n. 12
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            Guid businessUnitId = BusinessUnit ?? SecurityManagementHelper.GetDefaultBusinessUnitId(_repository);

            Entity newRole = new Entity("role")
            {
                Attributes = new AttributeCollection()
            };

            newRole.Attributes.Add("name", Name);
            newRole.Attributes.Add("businessunitid", new EntityReference("businessunit", businessUnitId));

            Guid newRoleId = _repository.Add(newRole);

            if (PassThru)
            {
                WriteObject(_repository.Get("role", newRoleId));
            }
        }
Esempio n. 13
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            foreach (Guid id in User)
            {
                Guid[] currentSetIds = SecurityManagementHelper.GetTeamsForUser(_repository, id).Select(e => e.Id).ToArray();
                Guid[] removeSet     = Teams;
                if (this.ParameterSetName == RemoveUserTeamsAllParameterSet)
                {
                    removeSet = currentSetIds;
                }

                if (removeSet != null && removeSet.Length > 0)
                {
                    foreach (var item in removeSet)
                    {
                        SecurityManagementHelper.RemoveUsersFromTeam(_repository, item, new Guid[] { id });
                    }
                }
            }
        }
Esempio n. 14
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            string primaryEntityName = null;

            switch (PrincipalType)
            {
            case CrmPrincipalType.User:
                primaryEntityName = "systemuser";
                break;

            case CrmPrincipalType.Team:
                primaryEntityName = "team";
                break;

            default:
                break;
            }

            string secondaryEntityName = "role";

            foreach (Guid id in Principal)
            {
                Guid   primaryEntityId = id;
                Guid[] currentSetIds   = SecurityManagementHelper.GetRolesForPrincipal(_repository, PrincipalType, id).Select(e => e.Id).ToArray();
                Guid[] removeSet       = Roles;

                if (this.ParameterSetName == RemovePrincipalRolesAllParameterSet)
                {
                    removeSet = currentSetIds;
                }

                if (removeSet != null && removeSet.Length > 0)
                {
                    SecurityManagementHelper.UnlinkPrincipalRoles(_repository, primaryEntityName, primaryEntityId, secondaryEntityName, removeSet);
                }
            }
        }
Esempio n. 15
0
 protected override void ExecuteCmdlet()
 {
     base.ExecuteCmdlet();
     WriteObject(SecurityManagementHelper.GetTeamsForUser(_repository, User), true);
 }
Esempio n. 16
0
 protected override void ExecuteCmdlet()
 {
     base.ExecuteCmdlet();
     WriteObject(SecurityManagementHelper.GetUsersInTeam(_repository, Team), true);
 }