-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start creating new permissions for registration
Introduce a new setting that determines what registration forms are shown as the pages are accessed: PUBLIC (or not set) : All registration forms are available and non-users can register an account PROJECTADMIN: The public form is hidden and users must be added via the "Manage project users" or "Manage users" by someone with Project Administrator priviliges or highter. ADMIN: Only the Site administrators may register a new account via the two available forms. DISABLED: All registration forms are disabled and registration must occur through a different means (via OAuth/LDAP).
- Loading branch information
1 parent
0c5b5bb
commit fedf702
Showing
14 changed files
with
344 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
enum RegistrationPermissionsLevel: int | ||
{ | ||
case PUBLIC = 0; | ||
case PROJECT_ADMIN = 1; | ||
case ADMIN = 2; | ||
case DISABLED = 3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Policies; | ||
|
||
use App\Enums\RegistrationPermissionsLevel; | ||
use App\Models\Project; | ||
use App\Models\User; | ||
use Illuminate\Support\Str; | ||
|
||
class UserPolicy | ||
{ | ||
protected function AttemptValueBuild(): int | ||
{ | ||
return (bool) env('USER_REGISTRATION_FORM_ENABLED', true) ? RegistrationPermissionsLevel::PUBLIC->value : ((bool) env('PROJECT_ADMIN_REGISTRATION_FORM_ENABLED', true) ? RegistrationPermissionsLevel::PROJECT_ADMIN->value : RegistrationPermissionsLevel::ADMIN->value); | ||
} | ||
|
||
/** | ||
* Determine whether the user can create models. | ||
*/ | ||
public function create(User $user): bool | ||
{ | ||
$user_permission_level = Project::whereRelation('administrators', 'users.id', request()->user()?->id)->exists() ? 1 : 0; | ||
$user_permission_level = $user->admin ? 2 : $user_permission_level; | ||
$registration_permission_level_required = match (Str::upper(config('auth.user_registration_access_level_required'))) { | ||
'PUBLIC' => RegistrationPermissionsLevel::PUBLIC->value, | ||
'PROJECT_ADMIN' => RegistrationPermissionsLevel::PROJECT_ADMIN->value, | ||
'ADMIN' => RegistrationPermissionsLevel::ADMIN->value, | ||
'DISABLED' => RegistrationPermissionsLevel::DISABLED->value, | ||
default => $this->AttemptValueBuild(), | ||
}; | ||
|
||
// Fail if the caller is requesting a value that the setting disallows | ||
return $user_permission_level >= $registration_permission_level_required; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
APP_NAME=CDash | ||
APP_ENV=testing | ||
APP_KEY=DV5SQLqXCbpnme4z2pKNujd6gFW9hrj5 | ||
APP_DEBUG=true | ||
APP_URL=http://localhost:8080 | ||
|
||
LOG_CHANNEL=single | ||
|
||
DB_DATABASE=cdash4simpletest | ||
DB_PASSWORD=cdash4simpletest | ||
|
||
REGISTRATION_EMAIL_VERIFY=false | ||
|
||
QUEUE_CONNECTION=sync | ||
USER_REGISTRATION_ACCESS_LEVEL_REQUIRED=ADMIN | ||
# Disable the slow page warning messages when testing | ||
SLOW_PAGE_TIME=1000000 | ||
|
||
MAIL_MAILER=smtp | ||
MAIL_HOST=mailpit | ||
MAIL_PORT=1025 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
APP_NAME=CDash | ||
APP_ENV=testing | ||
APP_KEY=DV5SQLqXCbpnme4z2pKNujd6gFW9hrj5 | ||
APP_DEBUG=true | ||
APP_URL=http://localhost:8080 | ||
|
||
LOG_CHANNEL=single | ||
|
||
DB_DATABASE=cdash4simpletest | ||
DB_PASSWORD=cdash4simpletest | ||
|
||
REGISTRATION_EMAIL_VERIFY=false | ||
|
||
QUEUE_CONNECTION=sync | ||
USER_REGISTRATION_ACCESS_LEVEL_REQUIRED=DISABLED | ||
# Disable the slow page warning messages when testing | ||
SLOW_PAGE_TIME=1000000 | ||
|
||
MAIL_MAILER=smtp | ||
MAIL_HOST=mailpit | ||
MAIL_PORT=1025 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
APP_NAME=CDash | ||
APP_ENV=testing | ||
APP_KEY=DV5SQLqXCbpnme4z2pKNujd6gFW9hrj5 | ||
APP_DEBUG=true | ||
APP_URL=http://localhost:8080 | ||
|
||
LOG_CHANNEL=single | ||
|
||
DB_DATABASE=cdash4simpletest | ||
DB_PASSWORD=cdash4simpletest | ||
|
||
REGISTRATION_EMAIL_VERIFY=false | ||
|
||
QUEUE_CONNECTION=sync | ||
USER_REGISTRATION_ACCESS_LEVEL_REQUIRED=PROJECT_ADMIN | ||
# Disable the slow page warning messages when testing | ||
SLOW_PAGE_TIME=1000000 | ||
|
||
MAIL_MAILER=smtp | ||
MAIL_HOST=mailpit | ||
MAIL_PORT=1025 |
Oops, something went wrong.