Skip to content

Commit

Permalink
SporeServer: improve /Moderation/Management/Users
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Nov 8, 2024
1 parent ae0931f commit 5951091
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
22 changes: 15 additions & 7 deletions SporeServer/Pages/Moderation/Management/Users.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
{
var user = Model.Users[i];
bool odd = i % 2 != 0;
int assetCount = 0; // await Model.GetAssetCountByUserAsync(user);
<tr>
<td class="avatar@(odd ? " , odd" : "")">
<img src="/static/war/images/game/spd/NoAvatar.png" alt="Avatar" class="noavatar" />
Expand All @@ -57,12 +56,21 @@
<td class="username@(odd ? " , odd" : "")">
<a href="sporeprofile:@(user.Id)" style="">@(user.UserName)</a>
</td>
<td class="editButton@(odd ? " , odd" : "")">
<a href="/Moderation/Management/User/Edit/@(user.Id)" style=""><img src="utfres://0x011c0bde!icon_settings.png" /></a>
</td>
<td class="banButton@(odd ? " , odd" : "")">
<a href="sporeprofile:@(user.Id)" style=""><img src="utfres://AssetBrowserGraphics!0x9F681350.png" /></a>
</td>
@if (/* check if user isn't the current user */
Model.CurrentUser.Id != user.Id &&
/* check if user isn't an Admin */
!(await Model.IsUserInRoleAsync(user, "Admin")) &&
/* check if current user is a moderator, if so, they cannot manage other moderators */
((await Model.IsUserInRoleAsync(Model.CurrentUser, "Moderator")) &&
!(await Model.IsUserInRoleAsync(user, "Moderator"))))
{
<td class="editButton@(odd ? " , odd" : "")">
<a href="/Moderation/Management/User/Edit/@(user.Id)" style=""><img src="utfres://0x011c0bde!icon_settings.png" /></a>
</td>
<td class="banButton@(odd ? " , odd" : "")">
<a href="sporeprofile:@(user.Id)" style=""><img src="utfres://AssetBrowserGraphics!0x9F681350.png" /></a>
</td>
}
</tr>
}
</table>
Expand Down
23 changes: 23 additions & 0 deletions SporeServer/Pages/Moderation/Management/Users.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* SporeServer - https://github.com/Rosalie241/SporeServer
* Copyright (C) 2021 Rosalie Wanders <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -25,6 +34,10 @@ public UsersModel(UserManager<SporeServerUser> userManager, IUserSubscriptionMan
_assetManager = assetManager;
}

/// <summary>
/// Current User
/// </summary>
public SporeServerUser CurrentUser { get; set; }
/// <summary>
/// Search Results
/// </summary>
Expand All @@ -38,10 +51,20 @@ public UsersModel(UserManager<SporeServerUser> userManager, IUserSubscriptionMan
/// </summary>
public bool Searched { get; set; }

/// <summary>
/// Whether user is in specified role or not
/// </summary>
public async Task<bool> IsUserInRoleAsync(SporeServerUser user, string role)
{
return (await _userManager.GetRolesAsync(user)).Contains(role);
}

public async Task<IActionResult> OnGet()
{
SearchString = Request.Query["searchText"];

CurrentUser = await _userManager.GetUserAsync(User);

if (String.IsNullOrEmpty(SearchString))
{
Users = await _userManager.Users
Expand Down

0 comments on commit 5951091

Please sign in to comment.