コード例 #1
0
        public void AddRole(Entities objectContext, string name, NewRoleRights roleRights)
        {
            Tools.CheckObjectContext(objectContext);

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            if (roleRights == null)
            {
                throw new ArgumentNullException("roleRights");
            }

            lock (addingRoleSync)
            {
                if (GetRole(objectContext, name, false) != null)
                {
                    throw new InvalidOperationException("There is already role with same name");
                }

                Role newRole = new Role();

                newRole.name = name;

                objectContext.AddToRoleSet(newRole);
                Tools.Save(objectContext);

                AddRoleRights(objectContext, newRole, roleRights);
            }
        }
コード例 #2
0
        public void EditRole(Entities objectContext, Role currRole, string newName, NewRoleRights editedRights)
        {
            Tools.CheckObjectContext(objectContext);

            if (currRole == null)
            {
                throw new ArgumentNullException("currRole");
            }

            lock (editingRoleSync)
            {
                if (!string.IsNullOrEmpty(newName))
                {
                    currRole.name = newName;
                    Tools.Save(objectContext);
                }

                ChangeRoleRights(objectContext, currRole, editedRights);
            }
        }
コード例 #3
0
        private void AddRoleRights(Entities objectContext, Role newRole, NewRoleRights roleRights)
        {
            Tools.CheckObjectContext(objectContext);

            if (roleRights == null)
            {
                throw new ArgumentNullException("roleRights");
            }

            if (newRole == null)
            {
                throw new ArgumentNullException("newRole");
            }

            newRole.Role_Rights.Load();

            if (newRole.Role_Rights.Count > 0)
            {
                throw new InvalidOperationException("newRole already have rights attached.");
            }

            List <Right> allRights = GetAllRights(objectContext);


            Role_Right rSearchUsers = new Role_Right();

            rSearchUsers.Role    = newRole;
            rSearchUsers.Right   = allRights[0];
            rSearchUsers.enabled = roleRights.SearchForUsersEnabled;
            rSearchUsers.visible = roleRights.SearchForUsersVisible;
            objectContext.AddToRole_RightSet(rSearchUsers);

            Role_Right rAddReport = new Role_Right();

            rAddReport.Role    = newRole;
            rAddReport.Right   = allRights[1];
            rAddReport.enabled = roleRights.AddReportEnabled;
            rAddReport.visible = roleRights.AddReportVisible;
            objectContext.AddToRole_RightSet(rAddReport);

            Role_Right rSeeVisibleReports = new Role_Right();

            rSeeVisibleReports.Role    = newRole;
            rSeeVisibleReports.Right   = allRights[2];
            rSeeVisibleReports.enabled = roleRights.SeeVisibleReportsEnabled;
            rSeeVisibleReports.visible = roleRights.SeeVisibleReportsVisible;
            objectContext.AddToRole_RightSet(rSeeVisibleReports);

            Role_Right rSeeDeletedReports = new Role_Right();

            rSeeDeletedReports.Role    = newRole;
            rSeeDeletedReports.Right   = allRights[3];
            rSeeDeletedReports.enabled = roleRights.SeeDeletedReportsEnabled;
            rSeeDeletedReports.visible = roleRights.SeeDeletedReportVisible;
            objectContext.AddToRole_RightSet(rSeeDeletedReports);

            Role_Right rMarkReportResolved = new Role_Right();

            rMarkReportResolved.Role    = newRole;
            rMarkReportResolved.Right   = allRights[4];
            rMarkReportResolved.enabled = roleRights.MarkReportAsResolvedEnabled;
            rMarkReportResolved.visible = roleRights.MarkReportAsResolvedVisible;
            objectContext.AddToRole_RightSet(rMarkReportResolved);

            Role_Right rDeleteReport = new Role_Right();

            rDeleteReport.Role    = newRole;
            rDeleteReport.Right   = allRights[5];
            rDeleteReport.enabled = roleRights.DeleteReportEnabled;
            rDeleteReport.visible = roleRights.DeleteReportVisible;
            objectContext.AddToRole_RightSet(rDeleteReport);

            Tools.Save(objectContext);
        }
コード例 #4
0
        private void ChangeRoleRights(Entities objectContext, Role currRole, NewRoleRights newRights)
        {
            Tools.CheckObjectContext(objectContext);

            if (currRole == null)
            {
                throw new ArgumentNullException("currRole");
            }

            if (newRights == null)
            {
                throw new ArgumentNullException("newRights");
            }

            Role_Right currRight = objectContext.Role_RightSet.FirstOrDefault(rr => rr.Right.ID == UserRights.SearchForUsers && rr.Role.ID == currRole.ID);

            if (currRight == null)
            {
                throw new InvalidOperationException("role doesn't have set right ID : 1");
            }

            currRight.enabled = newRights.SearchForUsersEnabled;
            currRight.visible = newRights.SearchForUsersVisible;

            Tools.Save(objectContext);

            currRight = objectContext.Role_RightSet.FirstOrDefault(rr => rr.Right.ID == UserRights.AddReport && rr.Role.ID == currRole.ID);
            if (currRight == null)
            {
                throw new InvalidOperationException("role doesn't have set right ID : 2");
            }

            currRight.enabled = newRights.AddReportEnabled;
            currRight.visible = newRights.AddReportVisible;

            Tools.Save(objectContext);

            currRight = objectContext.Role_RightSet.FirstOrDefault(rr => rr.Right.ID == UserRights.SeeVisibleReports && rr.Role.ID == currRole.ID);
            if (currRight == null)
            {
                throw new InvalidOperationException("role doesn't have set right ID : 3");
            }

            currRight.enabled = newRights.SeeVisibleReportsEnabled;
            currRight.visible = newRights.SeeVisibleReportsVisible;

            Tools.Save(objectContext);

            currRight = objectContext.Role_RightSet.FirstOrDefault(rr => rr.Right.ID == UserRights.SeeDeletedReports && rr.Role.ID == currRole.ID);
            if (currRight == null)
            {
                throw new InvalidOperationException("role doesn't have set right ID : 4");
            }

            currRight.enabled = newRights.SeeDeletedReportsEnabled;
            currRight.visible = newRights.SeeDeletedReportVisible;

            Tools.Save(objectContext);

            currRight = objectContext.Role_RightSet.FirstOrDefault(rr => rr.Right.ID == UserRights.MarkReportAsSolved && rr.Role.ID == currRole.ID);
            if (currRight == null)
            {
                throw new InvalidOperationException("role doesn't have set right ID : 5");
            }

            currRight.enabled = newRights.MarkReportAsResolvedEnabled;
            currRight.visible = newRights.MarkReportAsResolvedVisible;

            Tools.Save(objectContext);

            currRight = objectContext.Role_RightSet.FirstOrDefault(rr => rr.Right.ID == UserRights.DeleteReports && rr.Role.ID == currRole.ID);
            if (currRight == null)
            {
                throw new InvalidOperationException("role doesn't have set right ID : 6");
            }

            currRight.enabled = newRights.DeleteReportEnabled;
            currRight.visible = newRights.DeleteReportVisible;

            Tools.Save(objectContext);
        }