Add ability to change user's permissions from admin panel user list

This commit is contained in:
jvyden 2022-06-10 17:02:02 -04:00
commit 1037a6eddb
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
6 changed files with 44 additions and 3 deletions

View file

@ -34,7 +34,7 @@ public class AdminBanUserPage : BaseLayout
this.TargetedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == id);
if (this.TargetedUser == null) return this.NotFound();
this.TargetedUser.PermissionLevel = PermissionLevel.Default;
this.TargetedUser.PermissionLevel = PermissionLevel.Banned;
this.TargetedUser.BannedReason = reason;
// invalidate all currently active gametokens

View file

@ -10,7 +10,7 @@
}
<p>There are currently @Model.UserCount users registered to your instance.</p>
<p><b>Note:</b> Users are ordered by most-recent-first.</p>
<p><b>Note:</b> Users are ordered by their permissions, then by most-recent-first.</p>
<div class="ui grid">
@foreach (User user in Model.Users)
@ -56,6 +56,19 @@
<a href="/user/@user.UserId">@user.Username</a>
</h2>
<h3>@subtitle</h3>
<form method="post" action="/admin/user/@user.UserId/setPermissionLevel">
<div class="ui right action input">
<select name="role" class="ui selection dropdown">
@foreach (PermissionLevel level in Enum.GetValues<PermissionLevel>())
{
string selected = level == user.PermissionLevel ? " selected" : "";
<option value="@((int)level)"@selected>@level.ToString()</option>
}
</select>
<input type="submit" class="ui green button" value="Apply"/>
</div>
</form>
</div>
</div>
}

View file

@ -21,7 +21,11 @@ public class AdminPanelUsersPage : BaseLayout
if (user == null) return this.Redirect("~/login");
if (!user.IsAdmin) return this.NotFound();
this.Users = await this.Database.Users.OrderByDescending(u => u.UserId).ToListAsync();
this.Users = await this.Database.Users
.OrderByDescending(u => u.PermissionLevel)
.ThenByDescending(u => u.UserId)
.ToListAsync();
this.UserCount = this.Users.Count;
return this.Page();