Fix admin instance stats endpoint 404 on Postgres via strict is_admin check

pull/7126/head
Your Name 2 weeks ago
parent c40814d9b3
commit df1e771f93

@ -808,7 +808,7 @@ class AdminApiController extends Controller
{
abort_if(! $request->user() || ! $request->user()->token(), 404);
abort_unless($request->user()->is_admin === 1, 404);
abort_unless($request->user()->is_admin == 1, 404);
abort_unless($request->user()->tokenCan('admin:read'), 404);
if ($request->has('refresh')) {

@ -212,6 +212,19 @@ describe('admin access granted to admin users', function () {
->assertOk();
});
it('allows admin to access instance stats API when is_admin is a boolean', function () {
// Postgres hydrates the boolean `is_admin` column to a PHP bool, so
// the guard must accept `true` and not just the integer 1. Force the
// boolean here so the test is driver-independent (SQLite hydrates 1).
$admin = User::factory()->admin()->create();
$admin->refresh();
$admin->is_admin = true;
Passport::actingAs($admin, ['admin:read']);
$this->getJson('/api/admin/instance/stats')
->assertOk();
});
it('allows admin to access admin users API', function () {
$admin = User::factory()->admin()->create();
$admin->refresh();

Loading…
Cancel
Save