Fixed Login for Superuser

This commit is contained in:
2026-06-20 18:02:00 +02:00
parent 710e27c344
commit a83cec94ab
6 changed files with 86 additions and 18 deletions
+33 -3
View File
@@ -3,6 +3,7 @@
namespace App\Providers;
use App\Enumerations\UserRole;
use App\Models\User;
class AuthCheckProvider {
public function checkLoggedIn() : bool {
@@ -16,7 +17,7 @@ class AuthCheckProvider {
return $user->active;
}
if ($user->user_role_main === UserRole::USER_ROLE_ADMIN) {
if ($this->isMainAdministrator($user)) {
return true;
}
@@ -28,10 +29,39 @@ class AuthCheckProvider {
return null;
}
$user = auth()->user();
if (app('tenant')->slug === 'lv') {
return auth()->user()->user_role_main;
return $user->user_role_main;
}
return auth()->user()->user_role_local_group;
// "Bundesrecht steht über Landesrecht":
// Ein ROLE_ADMINISTRATOR auf LV-Ebene ist auf jedem Sub-Tenant automatisch Administrator,
// unabhängig von user_role_local_group.
if ($this->isMainAdministrator($user)) {
return UserRole::USER_ROLE_ADMIN;
}
return $user->user_role_local_group;
}
/**
* Gibt true zurück, wenn der Nutzer auf LV-Ebene Administrator ist.
* Diese Rolle hebt das lokale Rechtesystem für alle Sub-Tenants auf.
*/
public function isMainAdministrator(?User $user = null) : bool {
$user ??= auth()->user();
return $user !== null
&& $user->user_role_main === UserRole::USER_ROLE_ADMIN;
}
/**
* Bequemer Helper für die Berechtigungs-Checks im gesamten System.
* Gibt true zurück, wenn der aktuell eingeloggte Nutzer im Kontext des
* aktuellen Tenants effektiv Administrator ist.
*/
public function isAdministrator() : bool {
return $this->getUserRole() === UserRole::USER_ROLE_ADMIN;
}
}