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

feat: Disable Signups for new users #7254

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

davpsh
Copy link

@davpsh davpsh commented May 2, 2024

These changes allow to enable/disable new user registration based on ENV setting. The feature was implemented in version 4.x and was not present in chandler. Fixes #6687

Changes:

  • added new environment parameter APP_DISABLE_SIGNUP
  • restricting registration access based on env setting value

@CLAassistant
Copy link

CLAassistant commented May 2, 2024

CLA assistant check
All committers have signed the CLA.

lang/en/auth.php Outdated Show resolved Hide resolved
Copy link
Member

@asbiin asbiin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the work.
However it is a little bit more complicated than needed, please see my reviews.

app/Helpers/SignupHelper.php Outdated Show resolved Hide resolved
app/Http/Controllers/Auth/LoginController.php Outdated Show resolved Hide resolved
app/Http/Middleware/EnsureSignupIsEnabled.php Outdated Show resolved Hide resolved
app/Http/Middleware/EnsureSignupIsEnabled.php Outdated Show resolved Hide resolved
phpunit.xml Outdated
@@ -8,6 +8,7 @@
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Feature</directory>
<directory suffix="Test.php">./tests/Unit</directory>
<directory suffix="Test.php">./tests/PHPUnit</directory>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't create another testsuite. Those tests should be placed under Unit

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asbiin, Unit tests in Laravel are not a classic pure unit test, because they bootstrap the kernel, database, and much more. A pure unit test only works with abstractions and does not depend on anything, for this reason it is cleaner and faster. I can move the tests to the unit folder, but I would still suggest separating test types

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asbiin, change reverted

use Tests\TestCase;

class RegistrationTest extends TestCase
{
use DatabaseTransactions;

#[Test]
public function registration_screen_can_be_rendered()
public function testAccessToRegistrationPage(): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing #[Test] ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asbiin, it is enough that the name of the method begins with the word “test” and the phpunit recognizes it as a test method. The attribute is not needed here. see https://docs.phpunit.de/en/11.1/attributes.html#test

Comment on lines 67 to 80
protected function patchRoutes(): void
{
if ($this->app->routesAreCached()) {
return;
}

$router = $this->app->make(Router::class);
$routes = $router->getRoutes();
collect(['create', 'store'])->each(function ($method) use ($routes) {
if ($route = $routes->getByAction(RegisteredUserController::class . '@' . $method)) {
$route->middleware('monica.signup_is_enabled');
}
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go directly in the routes/web.php file, there is no need to "patch" the route

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asbiin, no, it shouldn't be in the routes/web.php.

Routes and controller are part of the fortify package. I don’t want to redefine the entire route, we just need to add our custom middleware, that’s why we alter the routes in the service provider.

davpsh and others added 6 commits May 4, 2024 18:12
Co-authored-by: Alexis Saettler <alexis@saettler.org>
Co-authored-by: Alexis Saettler <alexis@saettler.org>
Co-authored-by: Alexis Saettler <alexis@saettler.org>
Co-authored-by: Alexis Saettler <alexis@saettler.org>
@davpsh davpsh changed the title Issue 6687: Disable Signups for new users feat: Disable Signups for new users May 8, 2024
@davpsh davpsh requested a review from asbiin May 8, 2024 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How do disable Signups for new users?
3 participants