Skip to content

NOW MANAGED ON CODEBERG

Roles: fixed error upon created_at sorting

Dan Brown18ee80a743cc
diff --git a/app/Users/Queries/RolesAllPaginatedAndSorted.php b/app/Users/Queries/RolesAllPaginatedAndSorted.php
index 7fd4048df..c9602ee71 100644
--- a/app/Users/Queries/RolesAllPaginatedAndSorted.php
+++ b/app/Users/Queries/RolesAllPaginatedAndSorted.php
@@ -15,7 +15,7 @@ class RolesAllPaginatedAndSorted
{
$sort = $listOptions->getSort();
if ($sort === 'created_at') {
- $sort = 'users.created_at';
+ $sort = 'roles.created_at';
}
$query = Role::query()->select(['*'])
diff --git a/tests/User/RoleManagementTest.php b/tests/User/RoleManagementTest.php
index 4d61cf6e6..5722a0b08 100644
--- a/tests/User/RoleManagementTest.php
+++ b/tests/User/RoleManagementTest.php
@@ -260,4 +260,30 @@ class RoleManagementTest extends TestCase
$this->actingAs($viewer)->get($page->getUrl())->assertStatus(404);
}
+
+ public function test_index_listing_sorting()
+ {
+ $this->asAdmin();
+ $role = $this->users->createRole();
+ $role->display_name = 'zz test role';
+ $role->created_at = now()->addDays(1);
+ $role->save();
+
+ $runTest = function (string $order, string $direction, bool $expectFirstResult) use ($role) {
+ setting()->putForCurrentUser('roles_sort', $order);
+ setting()->putForCurrentUser('roles_sort_order', $direction);
+ $html = $this->withHtml($this->get('/settings/roles'));
+ $selector = ".item-list-row:first-child a[href$=\"/roles/{$role->id}\"]";
+ if ($expectFirstResult) {
+ $html->assertElementExists($selector);
+ } else {
+ $html->assertElementNotExists($selector);
+ }
+ };
+
+ $runTest('name', 'asc', false);
+ $runTest('name', 'desc', true);
+ $runTest('created_at', 'desc', true);
+ $runTest('created_at', 'asc', false);
+ }
}