Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pagination for banned users in the mod panel #1043

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class BannedUsersPage : BaseLayout
{
public BannedUsersPage(DatabaseContext database) : base(database)

Check notice on line 13 in ProjectLighthouse.Servers.Website/Pages/Moderation/BannedUsersPage.cshtml.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert constructor into primary constructor

Convert into primary constructor
{}

public List<UserEntity> Users = new();
Expand All @@ -21,21 +21,25 @@

public int UserCount;

public async Task<IActionResult> OnGet([FromRoute] int pageNumber, [FromQuery] string? name)
public async Task<IActionResult> OnGet([FromRoute] int pageNumber)
{
WebTokenEntity? token = this.Database.WebTokenFromRequest(this.Request);
if (token == null) return this.Redirect("/login");

this.Users = await this.Database.Users
.Where(u => u.PermissionLevel < 0)
this.UserCount = await this.Database.Users.CountAsync(u => u.PermissionLevel < 0);

this.PageNumber = pageNumber;
this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.UserCount / ServerStatics.PageSize));

if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount)
return this.Redirect($"/moderation/bannedUsers/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");

this.Users = await this.Database.Users.Where(u => u.PermissionLevel < 0)
.OrderByDescending(u => u.UserId)
.Skip(pageNumber * ServerStatics.PageSize)
.Take(ServerStatics.PageSize)
.ToListAsync();

this.UserCount = await this.Database.Users.CountAsync(u => u.PermissionLevel < 0);

this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.UserCount / ServerStatics.PageSize));

return this.Page();
}
}
Loading