120 lines
No EOL
3.3 KiB
Text
120 lines
No EOL
3.3 KiB
Text
@page "/admin/users"
|
||
@using Iceshrimp.Backend.Components.Admin
|
||
@using Iceshrimp.Backend.Core.Configuration
|
||
@using Iceshrimp.Backend.Core.Database.Tables
|
||
@using Microsoft.EntityFrameworkCore
|
||
@using Microsoft.Extensions.Options
|
||
@inherits AdminComponentBase
|
||
<AdminPageHeader Title="Users"/>
|
||
|
||
<table>
|
||
<thead>
|
||
<th>Username</th>
|
||
<th>Status</th>
|
||
<th>Actions</th>
|
||
</thead>
|
||
<tbody>
|
||
@foreach (var user in _users)
|
||
{
|
||
<tr>
|
||
<td>@@@user.Username</td>
|
||
<td>
|
||
@{
|
||
var text = "Active";
|
||
if (user.IsSuspended)
|
||
text = "Suspended";
|
||
if (user.IsAdmin)
|
||
text += ", Administrator";
|
||
if (user.IsModerator)
|
||
text += ", Moderator";
|
||
}
|
||
<i>@text</i>
|
||
</td>
|
||
<td>
|
||
@if (user.Id == AuthUser.Id)
|
||
{
|
||
<i>It's you!</i>
|
||
}
|
||
else
|
||
{
|
||
if (!user.IsSuspended)
|
||
{
|
||
<a class="fake-link" onclick="suspendUser('@user.Id', event.target)">Suspend</a>
|
||
}
|
||
else
|
||
{
|
||
<a class="fake-link" onclick="unsuspendUser('@user.Id', event.target)">Unsuspend</a>
|
||
}
|
||
|
||
<span>
|
||
| <a class="fake-link" onclick="purgeUser('@user.Id', event.target)">Purge</a>
|
||
| <a class="fake-link" onclick="deleteUser('@user.Id', event.target)">Delete</a>
|
||
</span>
|
||
}
|
||
</td>
|
||
</tr>
|
||
}
|
||
</tbody>
|
||
</table>
|
||
|
||
@if (_users is [])
|
||
{
|
||
<p>
|
||
<i>No users found.</i>
|
||
</p>
|
||
}
|
||
else
|
||
{
|
||
<p>
|
||
<i>Listing @_count local users. </i>
|
||
|
||
@if (Options.Value.Registrations == Enums.Registrations.Invite)
|
||
{
|
||
<i>Registrations are invite-only. </i>
|
||
<a class="fake-link" id="gen-invite" onclick="generateInviteAndCopy()">Generate invite!</a>
|
||
}
|
||
else if (Options.Value.Registrations == Enums.Registrations.Open)
|
||
{
|
||
<i>Registrations are open.</i>
|
||
}
|
||
else
|
||
{
|
||
<i>Registrations are closed.</i>
|
||
}
|
||
</p>
|
||
}
|
||
|
||
@if (Offset is > 0)
|
||
{
|
||
<button role="link" data-target="/admin/users?offset=@(Math.Max(0, Offset.Value - 50))" onclick="navigate(event)">❮ Previous page</button>
|
||
}
|
||
else
|
||
{
|
||
<button disabled>❮ Previous page</button>
|
||
}
|
||
|
||
@if (_users.Length == 50)
|
||
{
|
||
<button role="link" data-target="/admin/users?offset=@((Offset ?? 0) + 50)" onclick="navigate(event)">Next page ❯</button>
|
||
}
|
||
else
|
||
{
|
||
<button disabled>Next page ❯</button>
|
||
}
|
||
|
||
@code {
|
||
[Inject] public required IOptionsSnapshot<Config.SecuritySection> Options { get; set; }
|
||
|
||
[CascadingParameter] public required User AuthUser { get; set; }
|
||
[SupplyParameterFromQuery] public int? Offset { get; set; }
|
||
|
||
private User[] _users = [];
|
||
private int _count;
|
||
|
||
protected override async Task OnGet()
|
||
{
|
||
var query = Database.Users.Where(p => p.IsLocalUser && !p.IsSystemUser);
|
||
_users = await query.OrderBy(p => p.Id).Skip(Offset ?? 0).Take(50).ToArrayAsync();
|
||
_count = await query.CountAsync();
|
||
}
|
||
} |