protected void Page_Load(object sender, EventArgs e) { LiHyperLink.SetNameToCompare(Context, "UserManagement"); IGraffitiUser currentUser = GraffitiUsers.Current; if (Request.QueryString["user"] != null) { if (!IsPostBack) { user = GraffitiUsers.GetUser(Request.QueryString["user"]); if (user == null) throw new Exception("This user does not exist or cannot be edited."); if (!GraffitiUsers.IsAdmin(currentUser) && user.Name != currentUser.Name) throw new SecurityException("You do not have permission to edit this user"); if (Request.QueryString["new"] != null && !IsPostBack) { Message.Text = "The user <strong>" + user.Name + "</strong> was created."; Message.Type = StatusType.Success; } PageText.Text = "Update " + user.ProperName + "'s profile."; AdminUserLinks.Visible = true; PasswordLink.NavigateUrl = string.Format("~/graffiti-admin/user-management/users/changepassword.aspx?user={0}", Request.QueryString["user"]); if (GraffitiUsers.CanRenameUsers && GraffitiUsers.IsAdmin(GraffitiUsers.Current)) { AdminUserLinksDelim.Visible = true; RenameLink.Visible = true; RenameLink.NavigateUrl = string.Format("javascript:Telligent_Modal.Open('RenameUser.aspx?user={0}', 400, 200, null);", Request.QueryString["user"]); } txtExistingUserName.Text = Server.HtmlDecode(user.Name); txtProperName.Text = Server.HtmlDecode(user.ProperName); txtExistingEmail.Text = user.Email; txtAvatar.Text = user.Avatar; Editor.Text = user.Bio; txtWebsite.Text = string.IsNullOrEmpty(user.WebSite) ? new Macros().FullUrl(new Urls().Home) : Server.HtmlEncode(user.WebSite); bool isAdmin = GraffitiUsers.IsUserInRole(GraffitiUsers.Current.Name, GraffitiUsers.AdminRole); role_section.Visible = isAdmin; AllRoles.Visible = isAdmin; if (!isAdmin) Cancel_Edit.NavigateUrl = "~/graffiti-admin/"; if (isAdmin) { RolePermissionsCollection rp = RolePermissionManager.GetRolePermissions(); RolePermissionsCollection newrp = new RolePermissionsCollection(); newrp.AddRange(rp); RolePermissions temp = newrp.Find(delegate(RolePermissions r) { return r.RoleName == GraffitiUsers.EveryoneRole; }); if (temp != null) newrp.Remove(temp); newrp.Sort(delegate(RolePermissions rp1, RolePermissions rp2) { return Comparer<string>.Default.Compare(rp1.RoleName, rp2.RoleName); }); Roles.DataSource = newrp; Roles.DataBind(); foreach (string role in user.Roles) { if (role == GraffitiUsers.AdminRole) { chkAdmin.Checked = true; if (GraffitiUsers.Current.Name == user.Name) chkAdmin.Enabled = false; } } } } new_user_container.Visible = false; User_List.Visible = false; user_edit_form.Visible = true; } else { if (!GraffitiUsers.IsUserInRole(currentUser.Name, GraffitiUsers.AdminRole)) Response.Redirect("?user="******"*"); User_List.DataSource = users; User_List.DataBind(); // filter out everyone if they are not a content publisher for licensing List<IGraffitiUser> filteredUsers = new List<IGraffitiUser>(); filteredUsers.AddRange(users); bool isEveryonePublisher = RolePermissionManager.IsEveryoneAContentPublisher(); if (!isEveryonePublisher) { foreach (IGraffitiUser user in users) { if (user.Roles != null && user.Roles[0] == GraffitiUsers.EveryoneRole) filteredUsers.Remove(user); } } } }
protected void Page_Load(object sender, EventArgs e) { LiHyperLink.SetNameToCompare(Context, "UserManagement"); string role = DecodeFromQS("role"); if (!Page.IsPostBack) { SetupTogglePermissionsScript(read, edit, publish, read, "read"); SetupTogglePermissionsScript(read, edit, publish, edit, "edit"); SetupTogglePermissionsScript(read, edit, publish, publish, "publish"); SetupTogglePermissionsScript(readRolePermission, editRolePermission, publishRolePermission, readRolePermission, "read"); SetupTogglePermissionsScript(readRolePermission, editRolePermission, publishRolePermission, editRolePermission, "edit"); SetupTogglePermissionsScript(readRolePermission, editRolePermission, publishRolePermission, publishRolePermission, "publish"); if (!String.IsNullOrEmpty(role)) { RolePermissionsCollection rpc = RolePermissionManager.GetRolePermissions(); RolePermissions rp = rpc.Find( delegate(RolePermissions rper) { return(rper.RoleName.ToLower() == role.ToLower()); }); if (rp != null) { readRolePermission.Checked = rp.HasRead; editRolePermission.Checked = rp.HasEdit; publishRolePermission.Checked = rp.HasPublish; } } } if (role != null) { string encodedRoleName = HttpUtility.HtmlEncode(role); if (!IsPostBack) { if (Request.QueryString["new"] != null) { Message.Text = string.Format("The role <strong>{0}</strong> was created.", encodedRoleName); Message.Type = StatusType.Success; } litExistingRoleName.Text = encodedRoleName; PageText.Text = "Update " + encodedRoleName; CategoryList.DataSource = new CategoryController().GetAllCachedCategories(); CategoryList.DataBind(); } new_role_container.Visible = false; Role_List.Visible = false; role_edit_form.Visible = true; } else { if (!Page.IsPostBack) { RolePermissionsCollection rps = RolePermissionManager.GetRolePermissions(); rps.Sort(delegate(RolePermissions rp1, RolePermissions rp2) { return(Comparer <string> .Default.Compare(rp1.RoleName, rp2.RoleName)); }); // move everyone to the top RolePermissionsCollection rpss = new RolePermissionsCollection(); foreach (RolePermissions rp in rps) { if (rp.RoleName == GraffitiUsers.EveryoneRole) { rpss.Insert(0, rp); } } foreach (RolePermissions rp in rps) { if (rp.RoleName != GraffitiUsers.EveryoneRole) { rpss.Add(rp); } } Role_List.DataSource = rpss; Role_List.DataBind(); if (Request.QueryString["roleSaved"] != null) { string roleSaved = HttpUtility.UrlDecode(Request.QueryString["roleSaved"]); Message.Text = string.Format("The role <strong>{0}</strong> was updated.", roleSaved); Message.Type = StatusType.Success; } } new_role_container.Visible = true; role_edit_form.Visible = false; Role_List.Visible = true; } }
protected void Page_Load(object sender, EventArgs e) { LiHyperLink.SetNameToCompare(Context, "UserManagement"); IGraffitiUser currentUser = GraffitiUsers.Current; if (Request.QueryString["user"] != null) { if (!IsPostBack) { user = GraffitiUsers.GetUser(Request.QueryString["user"]); if (user == null) { throw new Exception("This user does not exist or cannot be edited."); } if (!GraffitiUsers.IsAdmin(currentUser) && user.Name != currentUser.Name) { throw new SecurityException("You do not have permission to edit this user"); } if (Request.QueryString["new"] != null && !IsPostBack) { Message.Text = "The user <strong>" + user.Name + "</strong> was created."; Message.Type = StatusType.Success; } PageText.Text = "Update " + user.ProperName + "'s profile."; AdminUserLinks.Visible = true; PasswordLink.NavigateUrl = string.Format("~/graffiti-admin/user-management/users/changepassword.aspx?user={0}", Request.QueryString["user"]); if (GraffitiUsers.CanRenameUsers && GraffitiUsers.IsAdmin(GraffitiUsers.Current)) { AdminUserLinksDelim.Visible = true; RenameLink.Visible = true; RenameLink.NavigateUrl = string.Format("javascript:Telligent_Modal.Open('RenameUser.aspx?user={0}', 400, 200, null);", Request.QueryString["user"]); } txtExistingUserName.Text = Server.HtmlDecode(user.Name); txtProperName.Text = Server.HtmlDecode(user.ProperName); txtExistingEmail.Text = user.Email; txtAvatar.Text = user.Avatar; Editor.Text = user.Bio; txtWebsite.Text = string.IsNullOrEmpty(user.WebSite) ? new Macros().FullUrl(new Urls().Home) : Server.HtmlEncode(user.WebSite); bool isAdmin = GraffitiUsers.IsUserInRole(GraffitiUsers.Current.Name, GraffitiUsers.AdminRole); role_section.Visible = isAdmin; AllRoles.Visible = isAdmin; if (!isAdmin) { Cancel_Edit.NavigateUrl = "~/graffiti-admin/"; } if (isAdmin) { RolePermissionsCollection rp = RolePermissionManager.GetRolePermissions(); RolePermissionsCollection newrp = new RolePermissionsCollection(); newrp.AddRange(rp); RolePermissions temp = newrp.Find(delegate(RolePermissions r) { return(r.RoleName == GraffitiUsers.EveryoneRole); }); if (temp != null) { newrp.Remove(temp); } newrp.Sort(delegate(RolePermissions rp1, RolePermissions rp2) { return(Comparer <string> .Default.Compare(rp1.RoleName, rp2.RoleName)); }); Roles.DataSource = newrp; Roles.DataBind(); foreach (string role in user.Roles) { if (role == GraffitiUsers.AdminRole) { chkAdmin.Checked = true; if (GraffitiUsers.Current.Name == user.Name) { chkAdmin.Enabled = false; } } } } } new_user_container.Visible = false; User_List.Visible = false; user_edit_form.Visible = true; } else { if (!GraffitiUsers.IsUserInRole(currentUser.Name, GraffitiUsers.AdminRole)) { Response.Redirect("?user="******"*"); User_List.DataSource = users; User_List.DataBind(); // filter out everyone if they are not a content publisher for licensing List <IGraffitiUser> filteredUsers = new List <IGraffitiUser>(); filteredUsers.AddRange(users); bool isEveryonePublisher = RolePermissionManager.IsEveryoneAContentPublisher(); if (!isEveryonePublisher) { foreach (IGraffitiUser user in users) { if (user.Roles != null && user.Roles[0] == GraffitiUsers.EveryoneRole) { filteredUsers.Remove(user); } } } } }