Пример #1
0
        /// <summary>
        /// Edits the specified role,displays the view of editing information on role object.
        /// </summary>
        /// <param name="roleId">The role id.</param>
        public void Edit(int roleId)
        {
            #region Logging
            if (log.IsDebugEnabled) log.Debug(Messages.MethodEnter);
            #endregion

            IRoleSvc roleSvc = GatekeeperFactory.RoleSvc;

            //Gets the role object of a specified roleId.
            Role role = roleSvc.Get(roleId);

            //Gets the application object of a specified role.
            Application application = GatekeeperFactory.ApplicationSvc.Get(role.Application.Id);

            //Gets the list of securableObjectType objects of a specified applicatuion.
            IList<SecurableObjectType> securableObjectTypes = GatekeeperFactory.SecurableObjectTypeSvc.Get(application);
            SecurableObjectType securableObjectType = GatekeeperFactory.SecurableObjectTypeSvc.Get(role.SecurableObjectType.Id);
            RightCollection rights =
            GatekeeperFactory.RightSvc.Get(securableObjectType);

            RoleRightAssignmentCollection roleRightAssignments =
                GatekeeperFactory.RoleRightAssignmentSvc.Get(role);

            IList<GrantedRight> grantedRights = new List<GrantedRight>();

            foreach (Right right in rights)
            {
                GrantedRight grantedRight = new GrantedRight()
                {
                    Id = right.Id,
                    Name = right.Name,
                    Description = right.Description,
                    Application = right.Application,
                    SecurableObjectType = right.SecurableObjectType
                };

                foreach (RoleRightAssignment rra in roleRightAssignments)
                {
                    if (rra.Right.Id == right.Id)
                    {
                        grantedRight.IsGranted = true;
                        break;
                    }
                }

                grantedRights.Add(grantedRight);
            }

            //Creates the PropertyBag variables
            this.PropertyBag["rights"] = grantedRights;
            this.PropertyBag["role"] = role;
            this.PropertyBag["securableObjectTypes"] = securableObjectTypes;

            this.AddToBreadcrumbTrail(new Link() { Text = "Home", Controller = "home", Action = "default" });
            this.AddToBreadcrumbTrail(new Link() { Text = application.Name, Controller = "application", Action = "display", QueryString = string.Format("applicationId={0}", application.Id) });
            this.AddToBreadcrumbTrail(new Link() { Text = "Roles", Controller = "role", Action = "default", QueryString = string.Format("applicationId={0}", application.Id) });
            this.AddToBreadcrumbTrail(new Link() { Text = role.Name, Controller = "role", Action = "display", QueryString = string.Format("roleId={0}", roleId) });
            this.AddToBreadcrumbTrail(new Link() { Text = "Edit" });
            this.RenderBreadcrumbTrail();

            #region Logging
            if (log.IsDebugEnabled) log.Debug(Messages.MethodLeave);
            #endregion
        }
Пример #2
0
        /// <summary>
        /// Associates with role.
        /// </summary>
        /// <param name="roleId">The role id.</param>
        public void AssociateWithRole(int roleId)
        {
            #region Logging
            if (log.IsDebugEnabled) log.Debug(Messages.MethodEnter);
            #endregion

            //Gets role object of specified roleId
            Role role = GatekeeperFactory.RoleSvc.Get(roleId);

            //Gets application object of a specified role object.
            Application application = GatekeeperFactory.ApplicationSvc.Get(role.Application.Id);

            //Gets securableObjectType object of a specified application and role.
            SecurableObjectType securableObjectType = GatekeeperFactory.SecurableObjectTypeSvc.Get(role.SecurableObjectType.Id);

            //Gets the RightCollection of a specified securableObjectType.
            RightCollection rights =
                GatekeeperFactory.RightSvc.Get(securableObjectType);

            //Gets the RoleRightAssignmentCollection of a specified role.
            RoleRightAssignmentCollection roleRightAssignments =
                GatekeeperFactory.RoleRightAssignmentSvc.Get(role);

            //Creates a Ilist collection of GrantedRight objects.
            IList<GrantedRight> grantedRights = new List<GrantedRight>();

            //Initializes right objects.
            foreach (Right right in rights)
            {
                GrantedRight grantedRight = new GrantedRight()
                {
                    Id = right.Id,
                    Name = right.Name,
                    Description = right.Description,
                    Application = right.Application,
                    SecurableObjectType = right.SecurableObjectType
                };

                //Checking whether a particular rights is in RoleRightAssignment.
                foreach (RoleRightAssignment rra in roleRightAssignments)
                {
                    if (rra.Right.Id == right.Id)
                    {
                        grantedRight.IsGranted = true;
                        break;
                    }
                }

                grantedRights.Add(grantedRight);
            }

            //Creates PropertyBag variables rights,application and role.
            this.PropertyBag["rights"] = grantedRights;
            this.PropertyBag["application"] = application;
            this.PropertyBag["role"] = role;

            this.AddToBreadcrumbTrail(new Link() { Text = "Home", Controller = "home", Action = "default" });
            this.AddToBreadcrumbTrail(new Link() { Text = application.Name, Controller = "application", Action = "display", QueryString = string.Format("applicationId={0}", application.Id) });
            this.AddToBreadcrumbTrail(new Link() { Text = "Roles", Controller = "role", Action = "default", QueryString = string.Format("applicationId={0}", application.Id) });
            this.AddToBreadcrumbTrail(new Link() { Text = role.Name, Controller = "role", Action = "display", QueryString = string.Format("roleId={0}", roleId) });
            this.AddToBreadcrumbTrail(new Link() { Text = "Rights", Controller = "right", Action = "displayByRole", QueryString = string.Format("roleId={0}", roleId) });
            this.AddToBreadcrumbTrail(new Link() { Text = "Grant" });
            this.RenderBreadcrumbTrail();

            #region Logging
            if (log.IsDebugEnabled) log.Debug(Messages.MethodLeave);
            #endregion
        }