public IHttpActionResult SavePermissions(int adminId) { try { var request = new AuthenticatedRequest(); if (!request.IsAdminLoggin || !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.SettingsPermissions.Admin)) { return(Unauthorized()); } if (!request.AdminPermissions.IsSuperAdmin()) { return(Unauthorized()); } var adminLevel = request.GetPostString("adminLevel"); var checkedSites = request.GetPostObject <List <int> >("checkedSites"); var checkedRoles = request.GetPostObject <List <string> >("checkedRoles"); var adminInfo = AdminManager.GetAdminInfoByUserId(adminId); DataProvider.AdministratorsInRolesDao.RemoveUser(adminInfo.UserName); if (adminLevel == "SuperAdmin") { DataProvider.AdministratorsInRolesDao.AddUserToRole(adminInfo.UserName, EPredefinedRoleUtils.GetValue(EPredefinedRole.ConsoleAdministrator)); } else if (adminLevel == "SiteAdmin") { DataProvider.AdministratorsInRolesDao.AddUserToRole(adminInfo.UserName, EPredefinedRoleUtils.GetValue(EPredefinedRole.SystemAdministrator)); } else { DataProvider.AdministratorsInRolesDao.AddUserToRole(adminInfo.UserName, EPredefinedRoleUtils.GetValue(EPredefinedRole.Administrator)); DataProvider.AdministratorsInRolesDao.AddUserToRoles(adminInfo.UserName, checkedRoles.ToArray()); } DataProvider.AdministratorDao.UpdateSiteIdCollection(adminInfo, adminLevel == "SiteAdmin" ? TranslateUtils.ObjectCollectionToString(checkedSites) : string.Empty); PermissionsImpl.ClearAllCache(); request.AddAdminLog("设置管理员权限", $"管理员:{adminInfo.UserName}"); return(Ok(new { Value = true, Roles = AdminManager.GetRoles(adminInfo.UserName) })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public void Delete(int siteId) { var siteInfo = SiteManager.GetSiteInfo(siteId); var list = ChannelManager.GetChannelIdList(siteId); DataProvider.TableStyleDao.Delete(list, siteInfo.TableName); DataProvider.TagDao.DeleteTags(siteId); DataProvider.ChannelDao.DeleteAll(siteId); UpdateParentIdToZero(siteId); ExecuteNonQuery($"DELETE FROM siteserver_Site WHERE Id = {siteId}"); SiteManager.ClearCache(); ChannelManager.RemoveCacheBySiteId(siteId); PermissionsImpl.ClearAllCache(); }
public override void Submit_OnClick(object sender, EventArgs e) { var isChanged = false; try { var allRoles = EPredefinedRoleUtils.GetAllPredefinedRoleName(); foreach (var roleName in allRoles) { DataProvider.AdministratorsInRolesDao.RemoveUserFromRole(_userName, roleName); } DataProvider.AdministratorsInRolesDao.AddUserToRole(_userName, DdlPredefinedRole.SelectedValue); var adminInfo = AdminManager.GetAdminInfoByUserName(_userName); DataProvider.AdministratorDao.UpdateSiteIdCollection(adminInfo, EPredefinedRoleUtils.Equals(EPredefinedRole.SystemAdministrator, DdlPredefinedRole.SelectedValue) ? ControlUtils.SelectedItemsValueToStringCollection(CblSiteId.Items) : string.Empty); PermissionsImpl.ClearAllCache(); AuthRequest.AddAdminLog("设置管理员权限", $"管理员:{_userName}"); SuccessMessage("权限设置成功!"); isChanged = true; } catch (Exception ex) { FailMessage(ex, "权限设置失败!"); } if (isChanged) { var redirectUrl = PageAdministrator.GetRedirectUrl(); LayerUtils.CloseAndRedirect(Page, redirectUrl); } }
public IHttpActionResult UpdateRole(int roleId) { try { var request = new AuthenticatedRequest(); if (!request.IsAdminLoggin || !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.SettingsPermissions.Admin)) { return(Unauthorized()); } var roleName = request.GetPostString("roleName"); var description = request.GetPostString("description"); var generalPermissionList = request.GetPostObject <List <string> >("generalPermissions"); var sitePermissionsInRolesInfoList = request.GetPostObject <List <SitePermissionsInfo> >("sitePermissions"); var roleInfo = DataProvider.RoleDao.GetRoleInfo(roleId); if (roleInfo.RoleName != roleName) { if (EPredefinedRoleUtils.IsPredefinedRole(roleName)) { return(BadRequest($"角色添加失败,{roleName}为系统角色!")); } if (DataProvider.RoleDao.IsRoleExists(roleName)) { return(BadRequest("角色名称已存在,请更换角色名称!")); } } DataProvider.PermissionsInRolesDao.Delete(roleInfo.RoleName); DataProvider.SitePermissionsDao.Delete(roleInfo.RoleName); if (generalPermissionList != null && generalPermissionList.Count > 0) { var permissionsInRolesInfo = new PermissionsInRolesInfo(0, roleName, TranslateUtils.ObjectCollectionToString(generalPermissionList)); DataProvider.PermissionsInRolesDao.Insert(permissionsInRolesInfo); } if (sitePermissionsInRolesInfoList != null && sitePermissionsInRolesInfoList.Count > 0) { foreach (var sitePermissionsInfo in sitePermissionsInRolesInfoList) { sitePermissionsInfo.RoleName = roleName; DataProvider.SitePermissionsDao.Insert(sitePermissionsInfo); } } roleInfo.RoleName = roleName; roleInfo.Description = description; DataProvider.RoleDao.UpdateRole(roleInfo); PermissionsImpl.ClearAllCache(); request.AddAdminLog("修改管理员角色", $"角色名称:{roleName}"); return(Ok(new { Value = true })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public override void Submit_OnClick(object sender, EventArgs e) { if (!Page.IsPostBack || !Page.IsValid) { return; } if (!string.IsNullOrEmpty(_theRoleName)) { try { var sitePermissionsInRolesInfoList = Session[SystemPermissionsInfoListKey] as List <SitePermissionsInfo>; var generalPermissionList = ControlUtils.GetSelectedListControlValueStringList(CblPermissions); DataProvider.PermissionsInRolesDao.UpdateRoleAndGeneralPermissions(_theRoleName, TbDescription.Text, generalPermissionList); DataProvider.SitePermissionsDao.UpdateSitePermissions(_theRoleName, sitePermissionsInRolesInfoList); PermissionsImpl.ClearAllCache(); AuthRequest.AddAdminLog("修改管理员角色", $"角色名称:{_theRoleName}"); SuccessMessage("角色修改成功!"); AddWaitAndRedirectScript(PageAdminRole.GetRedirectUrl()); } catch (Exception ex) { FailMessage(ex, "角色修改失败!"); } } else { if (EPredefinedRoleUtils.IsPredefinedRole(TbRoleName.Text)) { FailMessage($"角色添加失败,{TbRoleName.Text}为系统角色!"); } else if (DataProvider.RoleDao.IsRoleExists(TbRoleName.Text)) { FailMessage("角色添加失败,角色标识已存在!"); } else { var sitePermissionsInRolesInfoList = Session[SystemPermissionsInfoListKey] as List <SitePermissionsInfo>; var generalPermissionList = ControlUtils.GetSelectedListControlValueStringList(CblPermissions); try { DataProvider.SitePermissionsDao.InsertRoleAndPermissions(TbRoleName.Text, AuthRequest.AdminName, TbDescription.Text, generalPermissionList, sitePermissionsInRolesInfoList); PermissionsImpl.ClearAllCache(); AuthRequest.AddAdminLog("新增管理员角色", $"角色名称:{TbRoleName.Text}"); SuccessMessage("角色添加成功!"); AddWaitAndRedirectScript(PageAdminRole.GetRedirectUrl()); } catch (Exception ex) { FailMessage(ex, $"角色添加失败,{ex.Message}"); } } } }