/// <summary> /// 获取REPORT所有用户 /// </summary> /// <param name="userSofts"></param> /// <param name="allSofts"></param> /// <returns></returns> public List <User> GetReportUsers(out Dictionary <int, HashSet <int> > userSofts, out List <Soft> allSofts) { //权限判断 loginService.HaveSuperAdminRight(); return(DABasicInfoHelper.GetReportUsers(out userSofts, out allSofts)); }
/// <summary> /// 登录 /// </summary> public void Login() { ReturnedLoginResult loginResult = CheckLogin(); UserContext user = new UserContext { LoginUser = GetUser(loginResult.result.account) }; SetUserRights(user, DACommonHelper.REPORT_SYS_ID); HttpContext.Current.Session[SessionKeyForUserInfo] = user; //输出登录凭证 ResponseCredentials(user.LoginUser.Account); //更新登录时间 DABasicInfoHelper.UpdateLastLoginTime(user.LoginUser.ID); //记录登录日志 DABasicInfoHelper.AddAdminLog( new AdminLog { Account = user.LoginUser.Account, AccountType = user.LoginUser.AccountType, AddTime = DateTime.Now, IP = currentClientIP, TrueName = user.LoginUser.TrueName, PageUrl = "Login.aspx", SystemID = DACommonHelper.REPORT_SYS_ID, Memo = "登录" }); //跳转至默认页 HttpContext.Current.Response.Redirect("/index.aspx"); }
/// <summary> /// 更新用户状态 /// </summary> /// <param name="userId"></param> /// <param name="status"></param> public void UpdateUserStatus(int userId, StatusOptions status) { User user = DABasicInfoHelper.GetUser(userId); user.Status = status; UpdateUser(user); }
/// <summary> /// 获取权限信息列表 /// </summary> /// <param name="sysId"></param> /// <param name="parentId"></param> /// <returns></returns> public List <Right> GetRights(int sysId, int parentId) { //权限判断 loginService.HaveAdminRight(sysId); return(DABasicInfoHelper.GetRights(sysId, parentId)); }
/// <summary> /// 验证是否有管理员权限(没有权限抛出NotRightException异常) /// </summary> /// <param name="userId"></param> /// <param name="allowProductAdmin"></param> /// <returns></returns> internal User HaveAdminRightForUserEdit(int userId, bool allowProductAdmin) { User user = DABasicInfoHelper.GetUser(userId); HaveAdminRightForUserEdit(user, allowProductAdmin); return(user); }
/// <summary> /// 获取系统信息列表 /// </summary> /// <returns></returns> public List <SystemInfo> GetSystems() { //权限判断 loginService.HaveSuperAdminRight(); return(DABasicInfoHelper.GetSystems());; }
/// <summary> /// 获取角色列表 /// </summary> /// <param name="sysId"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="recordCount"></param> /// <returns></returns> public List <Role> GetRoles(int sysId, int pageIndex, int pageSize, ref int recordCount) { //权限判断 loginService.HaveAdminRight(sysId); return(DABasicInfoHelper.GetRoles(sysId, pageIndex, pageSize, ref recordCount)); }
/// <summary> /// 清掉缓存,重新加载 /// </summary> internal void ReloadAdminSystems() { List <SystemInfo> systems = DABasicInfoHelper.GetSystems(CacheTimeOption.Short, true); List <int> sysIds = DARightsHelper.GetAdminSystemIds(curUser.LoginUser.ID); curUser.AdminSystems = systems.Where(a => sysIds.Contains(a.ID)).ToList(); }
/// <summary> /// 获取操作日志列表 /// </summary> /// <param name="sysId"></param> /// <param name="keyword"></param> /// <param name="beginTime"></param> /// <param name="endTime"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="recordCount"></param> /// <returns></returns> public List <AdminLog> GetAdminLogs(int sysId, string keyword, DateTime beginTime, DateTime endTime, int pageIndex, int pageSize, ref int recordCount) { //权限判断 loginService.HaveAdminRight(sysId, false); return(DABasicInfoHelper.GetAdminLogs(sysId, keyword, beginTime, endTime, pageIndex, pageSize, ref recordCount)); }
/// <summary> /// 获取软件信息列表 /// </summary> /// <param name="softType"></param> /// <param name="keyword"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="recordCount"></param> /// <returns></returns> public List <Soft> GetSofts(SoftTypeOptions softType, string keyword, int pageIndex, int pageSize, ref int recordCount) { //权限判断 loginService.HaveSuperAdminRight(); return(DABasicInfoHelper.GetSofts(softType, keyword, pageIndex, pageSize, ref recordCount)); }
/// <summary> /// 验证是否有管理员权限(没有权限抛出NotRightException异常) /// </summary> /// <param name="roleId"></param> internal Role HaveAdminRightForRole(int roleId) { Role role = DABasicInfoHelper.GetRole(roleId); if (!CheckAdminRightForRole(role)) { throw new NotRightException(); } return(role); }
/// <summary> /// 设置用户的权限 /// </summary> /// <param name="user"></param> /// <param name="sysId"></param> private void SetUserRights(UserContext user, int sysId) { UserTypeOptions userType = user.LoginUser.AccountType; bool isSuperAdmin = userType == UserTypeOptions.SuperAdmin; bool isWhiteUser = user.LoginUser.IsWhiteUser; if (user.AvailableRights == null) { List <Right> availableRights = DABasicInfoHelper.GetRights(sysId, -1, CacheTimeOption.Short); List <int> rights = DARightsHelper.GetUserRights(sysId, user.LoginUser.ID, user.LoginUser.AccountType).Select(a => a.RightID).ToList(); user.AvailableRights = availableRights.Where(a => (isSuperAdmin || internalRequest || !a.OnlyInternal || isWhiteUser) && rights.Contains(a.ID)).ToList(); } //只有report才有这些权限 if (sysId == DACommonHelper.REPORT_SYS_ID) { if (user.AvailableSofts == null) { //从Report平台获得的产品权限 List <Soft> availableSofts = GetAvailableSofts(); List <int> rights = DARightsHelper.GetUserSoftRights(user.LoginUser.ID).Select(a => a.RightID).ToList(); user.AvailableSofts = availableSofts.Where(a => a.Status == StatusOptions.Valid && (isSuperAdmin || internalRequest || !a.OnlyInternal || isWhiteUser) && rights.Contains(a.ID)).ToList(); } if (user.AvailableProjectSources == null) { List <ProjectSource> availableProjectSources = GetAvailableProjectSources(); List <int> rights = DARightsHelper.GetUserProjectSourceRights(user.LoginUser.ID).Select(a => a.RightID).ToList(); user.AvailableProjectSources = availableProjectSources.Where(a => (isSuperAdmin || internalRequest || !a.OnlyInternal || isWhiteUser) && rights.Contains(a.ProjectSourceID)).ToList(); } if (internalRequest && user.AvailableResIds == null) { user.AvailableResIds = DARightsHelper.GetUserResRights(user.LoginUser.ID).Select(a => a.RightID).ToList(); } } else { if (user.AvailableSofts == null) { user.AvailableSofts = new List <Soft>(); } if (user.AvailableProjectSources == null) { user.AvailableProjectSources = new List <ProjectSource>(); } if (internalRequest && user.AvailableResIds == null) { user.AvailableResIds = new List <int>(); } } if (user.AdminSystems == null) { List <SystemInfo> systems = DABasicInfoHelper.GetSystems(CacheTimeOption.Short); List <int> sysIds = DARightsHelper.GetAdminSystemIds(user.LoginUser.ID); user.AdminSystems = systems.Where(a => sysIds.Contains(a.ID)).ToList(); } }
/// <summary> /// 根据账号或姓名模糊查找,并分页返回用户信息列表 /// </summary> /// <param name="sysId"></param> /// <param name="status"></param> /// <param name="accountType"></param> /// <param name="keyword"></param> /// <param name="onlyWhiteUser"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="recordCount"></param> /// <returns></returns> public List <User> GetUsers(int sysId, StatusOptions status, UserTypeOptions accountType, string keyword, bool onlyWhiteUser, int pageIndex, int pageSize, ref int recordCount) { //权限判断 loginService.HaveAdminRight(sysId, true); //if (loginService.LoginUser.AccountType == UserTypeOptions.ProductAdmin) //{ // return DABasicInfoHelper.GetUsers(sysId, status, accountType, keyword, onlyWhiteUser, pageIndex, pageSize, ref recordCount); //} return(DABasicInfoHelper.GetUsers(sysId, status, accountType, keyword, onlyWhiteUser, pageIndex, pageSize, ref recordCount)); }
/// <summary> /// 根据ID获取项目来源信息 /// </summary> /// <param name="projectSourceId"></param> /// <param name="softId"></param> /// <returns></returns> public ProjectSource GetProjectSource(int projectSourceId, int softId) { ////权限判断 //loginService.HaveSuperAdminRight(); ProjectSource projectSource = DABasicInfoHelper.GetProjectSource(projectSourceId, softId); //if (projectSource == null) // throw new NotRightException(); return(projectSource); }
/// <summary> /// 添加项目来源信息 /// </summary> /// <param name="projectSource"></param> public void AddPrjectSource(ProjectSource projectSource) { //权限判断 loginService.HaveSuperAdminRight(); DABasicInfoHelper.AddProjectSource(projectSource); //记录登录日志 loginService.AddLog( "AddPrjectSource", string.Format("添加项目来源(PrjectSource={0},Name={1})", projectSource.ProjectSourceID, projectSource.Name)); }
/// <summary> /// 获取或添加用户信息 /// </summary> /// <param name="account"></param> /// <returns></returns> private User GetUser(string account) { User user = DABasicInfoHelper.GetUser(account); //如果用户不存在,则抛出异常 if (user == null || user.Status == StatusOptions.Invalid) { Logout(); HttpContext.Current.Response.Redirect("~/Login.aspx", true); } return(user); }
/// <summary> /// 添加权限信息 /// </summary> /// <param name="right"></param> public void AddRight(Right right) { //权限判断 loginService.HaveAdminRight(right.SystemID, false); DABasicInfoHelper.AddRight(right); //记录登录日志 loginService.AddLog( "AddRight", string.Format("添加权限(Name={0},PageUrl={1})", right.Name, right.PageUrl)); }
/// <summary> /// 删除角色信息 /// </summary> /// <param name="roleId"></param> public void DeleteRole(int roleId) { //权限判断 Role role = loginService.HaveAdminRightForRole(roleId); DABasicInfoHelper.DeleteRole(roleId); //记录登录日志 loginService.AddLog( "DeleteRole", string.Format("删除角色(ID={0},Name={1})", roleId, role.Name)); }
/// <summary> /// 根据ID获取产品信息 /// </summary> /// <param name="softId"></param> /// <returns></returns> public Soft GetSoft(int softId) { ////权限判断 //loginService.HaveSuperAdminRight(); Soft soft = DABasicInfoHelper.GetSoft(softId); //if (soft == null) // throw new NotRightException(); return(soft); }
/// <summary> /// 添加产品信息 /// </summary> /// <param name="soft"></param> public void AddSoft(Soft soft) { //权限判断 loginService.HaveSuperAdminRight(); DABasicInfoHelper.AddSoft(soft); //记录登录日志 loginService.AddLog( "AddSoft", string.Format("添加产品(ID={0},OutID={1},Name={2},SoftType={3})", soft.ID, soft.OutID, soft.Name, soft.SoftType)); }
/// <summary> /// 获取指定产品的用户列表 /// </summary> /// <param name="softId"></param> /// <param name="accountTypes"></param> /// <returns></returns> public List <User> GetUsersBySoft(int softId, UserTypeOptions[] accountTypes) { //权限判断 loginService.HaveAdminRight(DACommonHelper.REPORT_SYS_ID); if (loginService.LoginUser.AccountType == UserTypeOptions.ProductAdmin && !loginService.AvailableSofts.Exists(a => a.ID == softId)) { throw new NotRightException(); } return(DABasicInfoHelper.GetUsersBySoft(softId, accountTypes)); }
/// <summary> /// 获取有效的项目来源列表 /// </summary> /// <returns></returns> private List <ProjectSource> GetAvailableProjectSources() { string cacheKey = "net91com.Reports.UserRights.URLoginService.GetAvailableProjectSources"; if (CacheHelper.Contains(cacheKey)) { return(CacheHelper.Get <List <ProjectSource> >(cacheKey)); } List <ProjectSource> projectSources = DABasicInfoHelper.GetProjectSources(); CacheHelper.Set <List <ProjectSource> >(cacheKey, projectSources, CacheTimeOption.Short, CacheExpirationOption.AbsoluteExpiration); return(projectSources); }
/// <summary> /// 获取系统信息 /// </summary> /// <param name="sysId"></param> /// <returns></returns> public SystemInfo GetSystem(int sysId) { //权限判断 loginService.HaveSuperAdminRight(); SystemInfo system = DABasicInfoHelper.GetSystem(sysId); if (system == null) { throw new NotRightException(); } return(system); }
/// <summary> /// 获取权限信息 /// </summary> /// <returns></returns> public Right GetRight(int rightId) { Right right = DABasicInfoHelper.GetRight(rightId); if (right == null) { throw new NotRightException(); } //权限判断 loginService.HaveAdminRight(right.SystemID, false); return(right); }
/// <summary> /// 添加用户信息 /// </summary> /// <param name="user"></param> public void AddUser(User user) { user.ID = 0; //权限判断 loginService.HaveAdminRightForUserEdit(user); user.AdminUserID = loginService.LoginUser.ID; DABasicInfoHelper.AddUser(user); //记录登录日志 loginService.AddLog( "AddUser", string.Format("添加用户(Account={0},AccountType={1},TrueName={2})" , user.Account, user.AccountType, user.TrueName)); }
/// <summary> /// 添加系统信息 /// </summary> /// <param name="system"></param> public void AddSystem(SystemInfo system) { //权限判断 loginService.HaveSuperAdminRight(); system.Md5Key = Guid.NewGuid().ToString(); DABasicInfoHelper.AddSystem(system); loginService.ReloadAdminSystems(); //记录日志 loginService.AddLog( "AddSystem", string.Format("添加系统(Name={0},Md5Key={1})", system.Name, system.Md5Key)); }
/// <summary> /// 添加操作日志 /// </summary> /// <param name="actionUrl"></param> /// <param name="message"></param> public void AddLog(string actionUrl, string message) { //记录登录日志 DABasicInfoHelper.AddAdminLog( new AdminLog { Account = LoginUser.Account, AccountType = LoginUser.AccountType, AddTime = DateTime.Now, IP = CurrentClientIP, TrueName = LoginUser.TrueName, PageUrl = actionUrl, Memo = message, SystemID = DACommonHelper.REPORT_SYS_ID }); }
/// <summary> /// 验证是否有管理员权限(没有权限抛出NotRightException异常) /// </summary> /// <param name="sysId"></param> /// <param name="userId"></param> /// <returns></returns> internal User HaveAdminRightForUserGrant(int sysId, int userId, bool allowProductAdmin) { User user = DABasicInfoHelper.GetUser(userId); if (!CheckAdminRightForUserGrant(sysId, user, allowProductAdmin)) { throw new NotRightException(); } //必须当前用户有该系统的权限 if (sysId > 0 && !DARightsHelper.GetUserSystems(user.ID).Exists(a => a.SystemID == sysId)) { throw new NotRightException(); } return(user); }
/// <summary> /// 获取软件信息列表 /// </summary> /// <param name="softType"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="recordCount"></param> /// <returns></returns> public List <Soft> GetSofts() { //权限判断 loginService.HaveAdminRight(DACommonHelper.REPORT_SYS_ID); List <Soft> softs = DABasicInfoHelper.GetSofts(); if (loginService.LoginUser.AccountType == UserTypeOptions.ProductAdmin) { List <RightItem> rangeRights = DARightsHelper.GetUserSoftRights(loginService.LoginUser.ID); var availableRights = from r in softs join rr in rangeRights on r.ID equals rr.RightID select r; return(availableRights.ToList()); } return(softs); }
/// <summary> /// 更新用户信息 /// </summary> /// <param name="user"></param> public void UpdateUser(User user) { //权限判断 User oldUser = loginService.HaveAdminRightForUserEdit(user.ID); loginService.HaveAdminRightForUserEdit(user); DABasicInfoHelper.UpdateUser(user); //记录登录日志 loginService.AddLog( "UpdateUser", string.Format( "更新用户(ID={0},Account={1},AccountType={2}(Old={3}),TrueName={4}(Old={5}),EndTime={6}(Old={7}),IsSpecialUser={8}(Old={9}))", user.ID, user.Account, user.AccountType, oldUser.AccountType, user.TrueName, oldUser.TrueName, user.EndTime, oldUser.EndTime, user.IsSpecialUser, oldUser.IsSpecialUser)); }