Fix registration form redirecting when max_users is falsy

pull/7135/head
Your Name 2 weeks ago
parent daf83fd564
commit afcb68c183

@ -157,10 +157,11 @@ class RegisterController extends Controller
$count = User::where(function ($q) {
return $q->whereNull('status')->orWhereNotIn('status', ['deleted', 'delete']);
})->count();
if ($limit <= $count) {
// A falsy max_users means "no limit" (matches register() and the
// help view). Guard on $limit so 0/null/'' does not redirect.
if ($limit && $limit <= $count) {
return redirect(route('help.instance-max-users-limit'));
}
abort_if($limit <= $count, 404);
return view('auth.register');
} else {

@ -103,3 +103,36 @@ it('redirects authenticated users away from the register page', function () {
->get('/register')
->assertRedirect();
});
it('shows the registration form when enforce_max_users is on but max_users is falsy', function () {
// Falsy max_users means "no limit"; the GET form must not redirect to the
// instance-full page (must match the POST handler and the help view).
config(['pixelfed.open_registration' => true]);
config(['pixelfed.enforce_max_users' => true]);
config(['pixelfed.max_users' => 0]);
$this->get('/register')
->assertOk();
});
it('redirects the registration form when a real max_users limit is reached', function () {
config(['pixelfed.open_registration' => true]);
config(['pixelfed.enforce_max_users' => true]);
config(['pixelfed.max_users' => 1]);
User::factory()->create();
$this->get('/register')
->assertRedirect(route('help.instance-max-users-limit'));
});
it('shows the registration form when under a real max_users limit', function () {
config(['pixelfed.open_registration' => true]);
config(['pixelfed.enforce_max_users' => true]);
config(['pixelfed.max_users' => 1000]);
User::factory()->create();
$this->get('/register')
->assertOk();
});

Loading…
Cancel
Save