public ActionResult ManagePermissionItems()
        {
            //应用下的角色名
            IEnumerable<Role> rolesApplication = null;

            //所有的角色名(包括全局角色名)
            IEnumerable<Role> rolesAll = null;

            //应用的权限项
            IEnumerable<PermissionItem> permissionItems = null;

            //存储角色名称获取PermissionItemInUserRole表里对应的记录
            IEnumerable<PermissionItemInUserRole> permissionItemInUserRoles = null;

            //查出所有应用
            IEnumerable<ApplicationBase> applicationBases = appService.GetAll(true);

            //根据应用ID获取全局角色名(ApplicationId=0的)
            IEnumerable<Role> globalRoles = roleService.GetRoles(true, 0, true);

            Role moderatedUserRole = new Role
            {
                RoleName = RoleNames.Instance().ModeratedUser(),
                Description = string.Empty,
                FriendlyRoleName = "管制用户",
                ConnectToUser = true,
                IsBuiltIn = true,
                IsEnabled = true,
                RoleImage = string.Empty
            };
            Role registeredUsersRole = new Role
            {
                RoleName = RoleNames.Instance().RegisteredUsers(),
                Description = string.Empty,
                FriendlyRoleName = "注册会员",
                ConnectToUser = true,
                IsBuiltIn = true,
                IsEnabled = true,
                RoleImage = string.Empty
            };
            IList<Role> globalRolesList = globalRoles.ToList();
            globalRolesList.Add(moderatedUserRole);
            globalRolesList.Add(registeredUsersRole);
            globalRoles = globalRolesList;

            //根据应用ID获取每个应用下的权限角色和应用的权限项
            foreach (var applicationBase in applicationBases)
            {
                //根据应用ID获取出该应用下的角色名
                rolesApplication = roleService.GetRoles(true, applicationBase.ApplicationId, true);
                rolesAll = globalRoles.Union(rolesApplication);
                ViewData["role_" + applicationBase.ApplicationKey] = rolesAll;

                //根据应用ID获取出该应用的权限项
                permissionItems = permissionService.GetPermissionItems(applicationBase.ApplicationId);
                ViewData["permissionItem_" + applicationBase.ApplicationKey] = permissionItems;
            }

            //获取以角色名跟权限key为键,一条记录为值的字典集合
            Dictionary<string, PermissionItemInUserRole> dicPermissionItemInUserRoles = new Dictionary<string, PermissionItemInUserRole>();
            var allApplicationRoles = roleService.GetRoles(true, null, true);
            List<Role> allApplicationRolesList = allApplicationRoles.ToList();
            allApplicationRolesList.RemoveAll(n => n.RoleName == RoleNames.Instance().SuperAdministrator() || n.RoleName == RoleNames.Instance().ContentAdministrator());
            allApplicationRolesList.Add(registeredUsersRole);
            allApplicationRolesList.Add(moderatedUserRole);
            foreach (var role in allApplicationRolesList)
            {
                permissionItemInUserRoles = permissionService.GetPermissionItemsInUserRole(role.RoleName);
                foreach (var permissionItemInUserRole in permissionItemInUserRoles)
                {
                    string key = permissionItemInUserRole.RoleName + "_" + permissionItemInUserRole.ItemKey;
                    dicPermissionItemInUserRoles[key] = permissionItemInUserRole;
                }
            }
            ViewData["PermissionItemsInUserRoles"] = dicPermissionItemInUserRoles;

            pageResourceManager.InsertTitlePart("权限设置");
            return View(applicationBases);
        }
        public ActionResult ManageAuditItems()
        {
            SiteSettings siteSettings = siteSettingsManager.Get();
            pageResourceManager.InsertTitlePart("审核规则");

            //用来装应用下的角色
            Dictionary<int, IEnumerable<Role>> roles = new Dictionary<int, IEnumerable<Role>>();
            //用来装应用下的审核项
            Dictionary<int, IEnumerable<AuditItem>> auditItems = new Dictionary<int, IEnumerable<AuditItem>>();
            //用来装应用下的对外显示状态
            Dictionary<int, PubliclyAuditStatus> applicationStatus = new Dictionary<int, PubliclyAuditStatus>();
            Dictionary<int, Dictionary<string, IEnumerable<AuditItemInUserRole>>> appForAuditItemInUserRole = new Dictionary<int, Dictionary<string, IEnumerable<AuditItemInUserRole>>>();
            IEnumerable<Role> roleLists = null;
            //全局角色
            IEnumerable<Role> globalRoles = roleService.GetRoles(true, 0, true);
            Role moderatedUserRole = new Role
            {
                RoleName = RoleNames.Instance().ModeratedUser(),
                Description = string.Empty,
                FriendlyRoleName = "管制用户",
                ConnectToUser = true,
                IsBuiltIn = true,
                IsEnabled = true,
                RoleImage = string.Empty
            };
            Role registeredUsersRole = new Role
            {
                RoleName = RoleNames.Instance().RegisteredUsers(),
                Description = string.Empty,
                FriendlyRoleName = "注册会员",
                ConnectToUser = true,
                IsBuiltIn = true,
                IsEnabled = true,
                RoleImage = string.Empty
            };

            IList<Role> globalRolesList = globalRoles.ToList();
            globalRolesList.Add(registeredUsersRole);
            globalRolesList.Add(moderatedUserRole);
            globalRoles = globalRolesList;

            roles[0] = globalRoles;//全局内容块下的角色
            auditItems[0] = auditService.GetAuditItems(0);//全局下的审核项
            //用来装审核项跟角色的关联
            Dictionary<string, IEnumerable<AuditItemInUserRole>> auditItemInUserRoles = new Dictionary<string, IEnumerable<AuditItemInUserRole>>();
            foreach (Role gloubRole in globalRoles)//角色的审核设置
            {
                auditService.GetAuditItemsInUserRole(gloubRole.RoleName, 0);
                auditItemInUserRoles[gloubRole.RoleName] = auditService.GetAuditItemsInUserRole(gloubRole.RoleName, 0);
            }

            appForAuditItemInUserRole[0] = auditItemInUserRoles;
            applicationStatus[0] = auditService.GetPubliclyAuditStatus(0);//全局的对外显示状态

            IEnumerable<ApplicationBase> apps = appService.GetAll();//获取所有应用
            foreach (var app in apps)
            {
                roleLists = new List<Role>();
                roleLists = roleLists.Union(globalRoles);//全局角色
                roleLists = roleLists.Union(roleService.GetRoles(true, app.ApplicationId, true));//应用下角色
                roles[app.ApplicationId] = roleLists;

                auditItems[app.ApplicationId] = auditService.GetAuditItems(app.ApplicationId);//角色下的审核项

                auditItemInUserRoles = new Dictionary<string, IEnumerable<AuditItemInUserRole>>();
                foreach (Role role in roleLists)//角色的审核设置
                {
                    auditItemInUserRoles[role.RoleName] = auditService.GetAuditItemsInUserRole(role.RoleName, app.ApplicationId);
                }

                appForAuditItemInUserRole[app.ApplicationId] = auditItemInUserRoles;
                applicationStatus[app.ApplicationId] = auditService.GetPubliclyAuditStatus(app.ApplicationId);//全局的对外显示状态
            }

            ViewData["roles"] = roles;
            ViewData["appForAuditItemInUserRole"] = appForAuditItemInUserRole;
            ViewData["auditItems"] = auditItems;
            ViewData["applicationStatus"] = applicationStatus;
            ViewData["userSettings"] = userSettingsManager.Get();
            ViewData["allRoles"] = roleService.GetRoles(true, null, true);
            return View(apps);
        }
Exemple #3
0
        /// <summary>
        /// 转换为Role用于数据库存储
        /// </summary>
        public Role AsRole()
        {
            RoleService roleService = DIContainer.Resolve<RoleService>();

            Role role = roleService.Get(RoleName);
            if (role != null)
            {
                role.FriendlyRoleName = this.FriendlyRoleName;
                role.ApplicationId = this.ApplicationId;
                role.Description = this.Description;
                role.IsEnabled = this.IsEnabled;
                role.IsPublic = this.IsPublic;
                role.ConnectToUser = this.ConnectToUser;
                role.RoleImage = this.RoleImage;
            }
            else
            {
                role = new Role();
                role.RoleName = this.RoleName;
                role.FriendlyRoleName = this.FriendlyRoleName;
                role.ApplicationId = this.ApplicationId;
                role.Description = this.Description;
                role.IsEnabled = this.IsEnabled;
                role.IsPublic = this.IsPublic;
                role.RoleImage = this.RoleName;
                role.ConnectToUser = this.ConnectToUser;
            }
            return role;
        }
Exemple #4
0
 /// <summary>
 /// 更新角色
 /// </summary>
 /// <param name="role"><see cref="Role"/>要更新的角色</param>
 /// <param name="stream">输入流</param>
 public void Update(Role role, Stream stream)
 {
     if (roleRepository.Exists(role.RoleName))
     {
         EventBus<Role>.Instance().OnBefore(role, new CommonEventArgs(EventOperationType.Instance().Update()));
         role.RoleImage = logoService.UploadLogo(role.RoleName, stream);
         roleRepository.Update(role);
         EventBus<Role>.Instance().OnAfter(role, new CommonEventArgs(EventOperationType.Instance().Update()));
     }
 }
Exemple #5
0
 /// <summary>
 /// 添加角色
 /// </summary>
 /// <param name="role"><see cref="Role"/>要添加的角色</param>
 /// <param name="stream">输入流</param>
 public bool Create(Role role, Stream stream)
 {
     if (!roleRepository.Exists(role.RoleName))
     {
         EventBus<Role>.Instance().OnBefore(role, new CommonEventArgs(EventOperationType.Instance().Create()));
         role.RoleImage = logoService.UploadLogo(role.RoleName, stream);
         roleRepository.Insert(role);
         EventBus<Role>.Instance().OnAfter(role, new CommonEventArgs(EventOperationType.Instance().Create()));
         return true;
     }
     else
         return false;
 }
        public ActionResult _CreateRole(string roleName)
        {
            RoleEditModel model = new RoleEditModel();
            if (!string.IsNullOrEmpty(roleName))
            {
                Role role = new Role();
                role = roleService.Get(roleName);
                if (role != null)
                    model = role.AsEditModel();
            }

            EditUserRole_GenerateFormItem();

            return View(model);
        }