/// <summary> /// 获取所有非虚拟的用户组(即可以往其中添加成员的用户组) /// </summary> /// <returns></returns> public RoleCollection GetNonVirtualRoles() { if (m_NonVirtualRoles == null) { m_NonVirtualRoles = GetRoles(delegate(Role role) { return(role.IsVirtualRole == false); }); } return(m_NonVirtualRoles); }
/// <summary> /// 获取所有管理员用户组(即可以往其中添加成员的用户组) /// </summary> /// <returns></returns> public RoleCollection GetNormalRoles() { if (m_NormalRoles == null) { m_NormalRoles = GetRoles(delegate(Role role) { return(role.IsNormal); }); } return(m_NormalRoles); }
/// <summary> /// 获取所有管理员用户组(即可以往其中添加成员的用户组) /// </summary> /// <returns></returns> public RoleCollection GetLevelRoles() { if (m_LevelRoles == null) { m_LevelRoles = GetRoles(delegate(Role role) { return(role.IsLevel); }); } return(m_LevelRoles); }
/// <summary> /// 获取所有管理员用户组(即可以往其中添加成员的用户组) /// </summary> /// <returns></returns> public RoleCollection GetBasicRoles() { if (m_BasicRoles == null) { m_BasicRoles = GetRoles(delegate(Role role) { return(role.IsBasic); }); } return(m_BasicRoles); }
/// <summary> /// 获取指定条件的用户组(推荐使用匿名委托来指定条件) /// </summary> /// <param name="resolver"></param> /// <returns></returns> public RoleCollection GetRoles(RoleResolver resolver) { RoleCollection roles = new RoleCollection(); foreach (Role role in Roles) { if (resolver(role)) { roles.Add(role); } } return(roles); }
/// <summary> /// 获取所有管理员用户组(即可以往其中添加成员的用户组) /// </summary> /// <returns></returns> public RoleCollection GetManagerRoles() { if (m_ManagerRoles == null) { RoleCollection roles = GetRoles(delegate(Role role) { return(role.IsManager); }); m_ManagerRoles = roles; } return(m_ManagerRoles); }
public T GetValue(User my) { UserRoleCollection roles = my.Roles; Role maxRole = my.MaxRole; RoleCollection systemRoles = AllSettings.Current.RoleSettings.Roles; foreach (ExceptionItem <T> item in this) { if (item.LevelStatus == LevelStatus.Above) { Role role; if (systemRoles.TryGetValue(item.RoleID, out role) == false) { continue; } if (maxRole >= role) { return(item.Value); } } else if (item.LevelStatus == LevelStatus.Below) { Role role; if (systemRoles.TryGetValue(item.RoleID, out role) == false) { continue; } if (maxRole <= role) { return(item.Value); } } else { foreach (UserRole role in roles) { if (role.RoleID == item.RoleID) { return(item.Value); } } } } return(this[0].Value); }
/// <summary> /// 获取给后台作为自动加入的用户组列表。例如:作为任务奖励自动加入用户组,那么只能在这些用户组里面选择 /// </summary> /// <returns></returns> public RoleCollection GetRolesForAutoAdd() { RoleCollection roles = new RoleCollection(); foreach (Role r in Roles) { if ((r.Type & RoleType.Normal) == RoleType.Normal && (r.Type & RoleType.Virtual) != RoleType.Virtual && (r.Type & RoleType.System) != RoleType.System ) { roles.Add(r); } } return(roles); }
/// <summary> /// 获取所有用户组,但排除掉指定的用户组 /// </summary> /// <param name="exceptRoleIds"></param> /// <returns></returns> public RoleCollection GetRoles(params Role[] exceptRoles) { RoleCollection roles = new RoleCollection(); foreach (Role role in Roles) { bool isExcept = false; foreach (Role exceptRole in exceptRoles) { if (role == exceptRole) { isExcept = true; break; } } if (isExcept == false) { roles.Add(role); } } return(roles); }
/// <summary> /// 通过调用此方法来得到我到底没有权限管理哪些用户组 /// TODO : 尚未检查 BeforePermissionCheck /// </summary> public Guid[] GetNoPermissionTargetRoleIds(User my, PermissionTargetType permissionTargetType) { RoleCollection allRoles = AllSettings.Current.RoleSettings.Roles; //User user = UserBO.Instance.GetUser(operatorUserID); if (my == null) { return(allRoles.GetKeys()); } //如果是创始人,直接返回null if (my.IsOwner) { return(new Guid[0]); } //管理类权限而我不是管理员 if (IsManagement && my.IsManager == false) { return(allRoles.GetKeys()); } PermissionLimit limit; switch (permissionTargetType) { case PermissionTargetType.Content: limit = AllSettings.Current.PermissionSettings.ContentPermissionLimit; break; case PermissionTargetType.User: limit = AllSettings.Current.PermissionSettings.UserPermissionLimit; break; default: throw new NotSupportedException("Action with target must defined 'PermissionSetWithTargetType'"); } if (limit.LimitType == PermissionLimitType.Unlimited) { return(new Guid[0]); } List <Guid> allowRoleIds = new List <Guid>(); foreach (UserRole userRole in my.Roles) { //不是管理员 if (IsManagement && userRole.Role.IsManager == false) { continue; } RoleCollection allowRoles; if (limit.LimitType == PermissionLimitType.RoleLevelLowerMe) { allowRoles = AllSettings.Current.RoleSettings.GetRoles(delegate(Role role) { if (role < userRole.Role) { return(true); } return(false); }); } else if (limit.LimitType == PermissionLimitType.RoleLevelLowerOrSameMe) { allowRoles = AllSettings.Current.RoleSettings.GetRoles(delegate(Role role) { if (role <= userRole.Role) { return(true); } return(false); }); } else if (limit.LimitType == PermissionLimitType.ExcludeCustomRoles) { List <Guid> excludeRoleIds = null; limit.ExcludeRoles.TryGetValue(userRole.RoleID, out excludeRoleIds); if (excludeRoleIds != null && excludeRoleIds.Count != 0) { allowRoles = AllSettings.Current.RoleSettings.GetRoles(delegate(Role role) { if (excludeRoleIds.Contains(role.RoleID)) { return(false); } return(true); }); } else { allowRoles = AllSettings.Current.RoleSettings.Roles; } } else { throw new NotSupportedException(); } foreach (Role allowRole in allowRoles) { if (allowRoleIds.Contains(allowRole.RoleID) == false) { allowRoleIds.Add(allowRole.RoleID); } } } int noPermissionRolesCount = allRoles.Count - allowRoleIds.Count; Guid[] noPermissionRoleIds = new Guid[noPermissionRolesCount]; int i = 0; foreach (Role role in allRoles) { if (allowRoleIds.Contains(role.RoleID) == false) { noPermissionRoleIds[i] = role.RoleID; i++; } } return(noPermissionRoleIds); }
public RoleSettings() { string iconPath = Globals.GetRelativeUrl(SystemDirecotry.Assets_RoleIcon); Roles = new RoleCollection(); Roles.Add(Role.Everyone); Roles.Add(Role.Guests); Roles.Add(Role.Users); Roles.Add(Role.ForumBannedUsers); Roles.Add(Role.FullSiteBannedUsers); Roles.Add(Role.NewUsers); Roles.Add(Role.EmailNotProvedUsers); Roles.Add(Role.RealnameNotProvedUsers); //Roles.Add(Role.InviteLessUsers); Roles.Add(Role.JackarooModerators); Roles.Add(Role.Moderators); Roles.Add(Role.CategoryModerators); Roles.Add(Role.SuperModerators); Roles.Add(Role.Administrators); Roles.Add(Role.Owners); Roles.Add(Role.NoLevel); LevelLieOn = LevelLieOn.Post; /*-----------------------默认图标------------------------*/ Role.CategoryModerators.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips10.gif"); Role.Administrators.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips10.gif"); Role.SuperModerators.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips10.gif"); Role.Owners.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips10.gif"); Role.Moderators.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips9.gif"); Role.JackarooModerators.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips8.gif"); /*-------------------默认等级用户组------------------*/ Role levelRole = new Role(); levelRole.Name = "新手上路"; levelRole.RequiredPoint = 0; levelRole.RoleID = new Guid(new byte[] { 74, 115, 163, 71, 186, 53, 83, 71, 183, 179, 236, 16, 210, 32, 146, 103 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips1.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "侠客"; levelRole.RequiredPoint = 50; levelRole.RoleID = new Guid(new byte[] { 248, 152, 64, 183, 181, 77, 53, 77, 182, 73, 89, 85, 162, 252, 146, 41 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips2.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "圣骑士"; levelRole.RequiredPoint = 200; levelRole.RoleID = new Guid(new byte[] { 29, 40, 140, 204, 235, 17, 207, 73, 174, 43, 138, 98, 96, 82, 219, 68 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips3.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "精灵"; levelRole.RequiredPoint = 500; levelRole.RoleID = new Guid(new byte[] { 26, 191, 38, 123, 38, 152, 103, 71, 171, 98, 16, 19, 63, 224, 29, 77 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips4.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "精灵王"; levelRole.RequiredPoint = 1000; levelRole.RoleID = new Guid(new byte[] { 92, 96, 198, 205, 96, 80, 220, 66, 172, 38, 16, 150, 6, 184, 0, 251 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips5.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "风云使者"; levelRole.RequiredPoint = 5000; levelRole.RoleID = new Guid(new byte[] { 165, 75, 133, 177, 234, 6, 16, 66, 162, 12, 235, 64, 5, 68, 248, 140 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips6.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "光明使者"; levelRole.RequiredPoint = 10000; levelRole.RoleID = new Guid(new byte[] { 185, 185, 243, 95, 132, 73, 233, 67, 128, 221, 168, 188, 74, 206, 151, 196 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips7.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "天使"; levelRole.RequiredPoint = 50000; levelRole.RoleID = new Guid(new byte[] { 164, 254, 210, 237, 225, 87, 214, 77, 171, 96, 92, 245, 221, 54, 78, 154 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips8.gif"); levelRole.IsNew = false; Roles.Add(levelRole); levelRole = new Role(); levelRole.Name = "法老"; levelRole.RequiredPoint = 100000; levelRole.RoleID = new Guid(new byte[] { 188, 159, 219, 20, 145, 63, 6, 67, 184, 52, 226, 115, 211, 207, 90, 98 }); levelRole.Title = levelRole.Name; levelRole.Type = RoleType.Custom | RoleType.Level | RoleType.Virtual; levelRole.IconUrlSrc = UrlUtil.JoinUrl(iconPath, "pips9.gif"); levelRole.IsNew = false; Roles.Add(levelRole); /*-----------------------end-------------------------*/ Roles.Sort(); }