public RoleGroup(RoleGroupInfo info) { Name = info.Name; Rank = info.Rank; Status = info.Status; AppearAsGM = info.AppearAsGM; AppearAsQA = info.AppearAsQA; CanUseCommandsOnOthers = info.CanUseCommandsOnOthers; CanHandleTickets = info.CanHandleTickets; MaySkipAuthQueue = info.MaySkipAuthQueue; ScrambleChat = info.ScrambleChat; if (info.InheritanceList != null) { InheritanceList = info.InheritanceList; } else { InheritanceList = new string[0]; } CommandNames = info.CommandNames; foreach (var cmdName in info.CommandNames) { if (cmdName == RoleGroupInfo.AllCommands) { // all commands foreach (var command in RealmCommandHandler.Instance.Commands) { if (!m_commands.Contains(command)) { m_commands.Add(command); } } break; } else if (cmdName == RoleGroupInfo.StatusCommands) { // all default Commands allowed for the given Role foreach (var command in RealmCommandHandler.Instance.Commands) { if (command is RealmServerCommand && info.Status >= ((RealmServerCommand)command).RequiredStatusDefault //&& !m_commands.Contains(command) ) { m_commands.Add(command); } } } else { var cmd = RealmCommandHandler.Instance[cmdName]; if (cmd != null) { m_commands.Add(cmd); } else { LogManager.GetCurrentClassLogger().Warn("Invalid Command \"{0}\" specified for Role \"{1}\"", cmdName, info); } } } }
public RoleGroup(RoleGroupInfo roleGroupInfo, Team team) { Name = roleGroupInfo.Name; PossibleRoles = new List <Role>(); Team = team; }
private void ProcessRoleGroups(ExportImportJob importJob, ImportDto importDto, IEnumerable <ExportRoleGroup> otherRoleGroups) { var changedGroups = new List <RoleGroupItem>(); var portalId = importJob.PortalId; var localRoleGroups = CBO.FillCollection <ExportRoleGroup>(DataProvider.Instance().GetAllRoleGroups(portalId, DateUtils.GetDatabaseUtcTime().AddYears(1), null)); foreach (var other in otherRoleGroups) { if (this.CheckCancelled(importJob)) { return; } var createdBy = Util.GetUserIdByName(importJob, other.CreatedByUserID, other.CreatedByUserName); var modifiedBy = Util.GetUserIdByName(importJob, other.LastModifiedByUserID, other.LastModifiedByUserName); var local = localRoleGroups.FirstOrDefault(t => t.RoleGroupName == other.RoleGroupName); if (local != null) { other.LocalId = local.RoleGroupID; switch (importDto.CollisionResolution) { case CollisionResolution.Ignore: this.Result.AddLogEntry("Ignored role group", other.RoleGroupName); break; case CollisionResolution.Overwrite: var roleGroup = new RoleGroupInfo(local.RoleGroupID, portalId, false) { RoleGroupName = other.RoleGroupName, Description = other.Description, }; RoleController.UpdateRoleGroup(roleGroup, false); changedGroups.Add(new RoleGroupItem(roleGroup.RoleGroupID, createdBy, modifiedBy)); DataCache.ClearCache(string.Format(DataCache.RoleGroupsCacheKey, local.RoleGroupID)); this.Result.AddLogEntry("Updated role group", other.RoleGroupName); break; default: throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString()); } } else { var roleGroup = new RoleGroupInfo() { PortalID = portalId, RoleGroupName = other.RoleGroupName, Description = other.Description, }; other.LocalId = RoleController.AddRoleGroup(roleGroup); changedGroups.Add(new RoleGroupItem(roleGroup.RoleGroupID, createdBy, modifiedBy)); this.Result.AddLogEntry("Added role group", other.RoleGroupName); } } if (changedGroups.Count > 0) { RefreshRecordsUserIds(changedGroups); } }
/// <summary> /// DeleteRoleGroup deletes a RoleGroup from the Data Store /// </summary> /// <param name="roleGroup">The RoleGroup to delete from the Data Store.</param> /// <history> /// [cnurse] 03/28/2006 created /// </history> public override void DeleteRoleGroup(RoleGroupInfo roleGroup) { dataProvider.DeleteRoleGroup(roleGroup.RoleGroupID); }
/// <summary> /// Update a RoleGroup /// </summary> /// <param name="roleGroup">The RoleGroup to update</param> /// <history> /// [cnurse] 03/28/2006 created /// </history> public override void UpdateRoleGroup(RoleGroupInfo roleGroup) { dataProvider.UpdateRoleGroup(roleGroup.RoleGroupID, roleGroup.RoleGroupName, roleGroup.Description); }
/// <summary> /// CreateRoleGroup persists a RoleGroup to the Data Store /// </summary> /// <remarks> /// </remarks> /// <param name="roleGroup">The RoleGroup to persist to the Data Store.</param> /// <returns>A Boolean indicating success or failure.</returns> /// <history> /// [cnurse] 03/28/2006 created /// </history> public override int CreateRoleGroup(RoleGroupInfo roleGroup) { roleGroup.RoleGroupID = Convert.ToInt32(dataProvider.AddRoleGroup(roleGroup.PortalID, roleGroup.RoleGroupName, roleGroup.Description)); return(1); }
/// ----------------------------------------------------------------------------- /// <summary> /// Update a RoleGroup /// </summary> /// <param name="roleGroup">The RoleGroup to update</param> /// <history> /// [cnurse] 03/28/2006 created /// [jlucarino] 02/26/2009 added LastModifiedByUserID parameter /// </history> /// ----------------------------------------------------------------------------- public override void UpdateRoleGroup(RoleGroupInfo roleGroup) { dataProvider.UpdateRoleGroup(roleGroup.RoleGroupID, roleGroup.RoleGroupName, roleGroup.Description, UserController.GetCurrentUserInfo().UserID); }
/// ----------------------------------------------------------------------------- /// <summary> /// CreateRoleGroup persists a RoleGroup to the Data Store /// </summary> /// <remarks> /// </remarks> /// <param name="roleGroup">The RoleGroup to persist to the Data Store.</param> /// <returns>The Id of the new role.</returns> /// <history> /// [cnurse] 03/28/2006 created /// [jlucarino] 02/26/2009 added CreatedByUserID parameter /// </history> /// ----------------------------------------------------------------------------- public override int CreateRoleGroup(RoleGroupInfo roleGroup) { return(Convert.ToInt32(dataProvider.AddRoleGroup(roleGroup.PortalID, roleGroup.RoleGroupName, roleGroup.Description, UserController.GetCurrentUserInfo().UserID))); }
/// <summary> /// 设置角色和用户的关系 /// </summary> /// <returns>返回已经添加的角色</returns> private List <String> SetDataItem(ref RoleGroupInfo RoleGroupItem) { Int32 SelectGroupID = WebHelper.GetIntParam(Request, "ddlSelectGroup", -1); String SelectRoles = String.Empty; String SelectRoleTexts = String.Empty; WebHelper.GetSelected(cblRoles, out SelectRoleTexts, out SelectRoles); List <String> RoleStatus = new List <string>(); if (SelectGroupID >= 0) { //请求出待改变的角色分组信息 RoleGroupItem = RoleController.GetRoleGroup(PortalId, SelectGroupID); if (!String.IsNullOrEmpty(SelectRoles)) { List <String> RoleIDs = Common.Split <String>(Common.GetList(SelectRoles), 1, 9999); var OldRoleGroups = Playngo_ClientZone_RoleGroup.FindListByGroup(SelectGroupID); //角色选择中不存在的需要删除 if (OldRoleGroups != null && OldRoleGroups.Count > 0) { foreach (var OldRoleGroup in OldRoleGroups) { //但原RoleId在选择列表中不存在时需要删除 if (!(RoleIDs != null && RoleIDs.Count > 0) || !RoleIDs.Exists(r => r == OldRoleGroup.RoleId.ToString())) { if (OldRoleGroup.Delete() > 0) { //构造删除角色列表状态 var role = RoleController.Instance.GetRoleById(PortalId, OldRoleGroup.RoleId); if (role != null && role.RoleID >= 0) { RoleStatus.Add(role.RoleName); } } } } } //角色选择中多出的需要添加 if (RoleIDs != null && RoleIDs.Count > 0) { foreach (var strRoleID in RoleIDs) { Int32 RoleId = 0; if (int.TryParse(strRoleID, out RoleId) && RoleId >= 0) { if (!(OldRoleGroups != null && OldRoleGroups.Count > 0) || !OldRoleGroups.Exists(r => r.RoleId == RoleId)) { if (new Playngo_ClientZone_RoleGroup() { GroupId = SelectGroupID, RoleId = RoleId }.Insert() > 0) { //构造增加角色列表状态 var role = RoleController.Instance.GetRoleById(PortalId, RoleId); if (role != null && role.RoleID >= 0) { RoleStatus.Add(role.RoleName); } } } } } } } else { //未选择角色分组 XTrace.WriteLine("未选择角色分组"); } } else { //未选择用户 XTrace.WriteLine("未选择用户"); } return(RoleStatus); }
public HttpResponseMessage GetAllGroups() { try { var portalId = PortalSettings.PortalId; var filteredRoleGroups = string.Empty; int loginStatus = 1; if (UserInfo == null || (UserInfo != null && UserInfo.UserID < 1)) { loginStatus = 0; // you can only get information if you're logged in Exceptions.LogException(new AccessViolationException("Unauthorized attempt to access GetAllGroups API end point")); // return 404 error simply to discourage hacking return(Request.CreateResponse(HttpStatusCode.OK, loginStatus)); } // get all role groups var roleGroups = Controllers.RoleController.GetRoleGroups(portalId); if (UserInfo.IsInRole(PortalSettings.AdministratorRoleName) || UserInfo.IsSuperUser) { // return ALL role groups filteredRoleGroups = roleGroups.ToJson(); } else { // get a listing of the unique role group IDs var roleGroupIds = roleGroups.Select(g => g.RoleGroupID).ToList(); var userRoles = Controllers.RoleController.GetUserRoles(UserInfo); // filter the role groups by only those that have a matching role for the user var filteredRoleGroupIds = userRoles.Where(r => roleGroupIds.Contains(r.RoleGroupID)).Select(r => r.RoleGroupID).ToList(); // return only the role groups that the user is a part of var uncleanRoleGroups = roleGroups.Where(g => filteredRoleGroupIds.Contains(g.RoleGroupID)); // remove any roles that the user is not a part of, and system roles var roleGroupsToReturn = new List <RoleGroupInfo>(); foreach (var group in uncleanRoleGroups.ToList()) { var newGroup = new RoleGroupInfo(); newGroup = group; foreach (var role in newGroup.Roles.ToList()) { var roleInfo = (RoleInfo)role.Value; if (roleInfo.IsSystemRole || !UserInfo.IsInRole(roleInfo.RoleName) || roleInfo.Status.ToString() == "Disabled") { newGroup.Roles.Remove(role.Key); } } roleGroupsToReturn.Add(newGroup); } filteredRoleGroups = roleGroupsToReturn.ToJson(); } return(Request.CreateResponse(HttpStatusCode.OK, filteredRoleGroups)); } catch (Exception exc) { Exceptions.LogException(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }