Users module: accounts, groups, permissions with needs, manager:create-user
This commit is contained in:
1 parent
08289db744
commit
f86f5aea28
25 files changed
+744
-58
No files matched your search
@@ -9,6 +9,9 @@ use IriksIT\Manager\Support\ModuleRegistry;
|
||||
|
||||
class ManagerServiceProvider extends ServiceProvider
|
||||
{
|
||||
/** Only a super admin: the groups decide what everyone else may do. Not a permission of a group. */
|
||||
public const MANAGE_GROUPS = 'groups.manage';
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
$this->mergeConfigFrom(__DIR__.'/../config/manager.php', 'manager');
|
||||
@@ -24,25 +27,35 @@ class ManagerServiceProvider extends ServiceProvider
|
||||
$modules->validate();
|
||||
|
||||
$this->publishes([__DIR__.'/../config/manager.php' => config_path('manager.php')], 'manager-config');
|
||||
|
||||
$this->loadViewsFrom(__DIR__.'/../resources/views', 'manager');
|
||||
|
||||
// A module that is off adds no migrations, so a site without reviews has no reviews table.
|
||||
foreach ($modules->active() as $module) {
|
||||
if ($module->migrations() !== null) {
|
||||
$this->loadMigrationsFrom($module->migrations());
|
||||
}
|
||||
|
||||
if ($this->app->runningInConsole() && $module->commands() !== []) {
|
||||
$this->commands($module->commands());
|
||||
}
|
||||
|
||||
$module->boot();
|
||||
}
|
||||
|
||||
$this->registerGates($modules);
|
||||
$this->registerRoutes($modules);
|
||||
}
|
||||
|
||||
/**
|
||||
* One gate per permission, and no Gate::before: a package must never answer for abilities
|
||||
* of the host app. A super admin passes inside hasManagerPermission, for these gates only.
|
||||
*/
|
||||
private function registerGates(ModuleRegistry $modules): void
|
||||
{
|
||||
foreach (array_keys($modules->permissions()) as $permission) {
|
||||
foreach ($modules->permissionValues() as $permission) {
|
||||
Gate::define($permission, fn ($user) => method_exists($user, 'hasManagerPermission') && $user->hasManagerPermission($permission));
|
||||
}
|
||||
|
||||
Gate::define(self::MANAGE_GROUPS, fn ($user) => method_exists($user, 'isManagerSuperAdmin') && $user->isManagerSuperAdmin());
|
||||
}
|
||||
|
||||
private function registerRoutes(ModuleRegistry $modules): void
|
||||
@@ -59,5 +72,12 @@ class ManagerServiceProvider extends ServiceProvider
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Files for visitors: outside the manager, no prefix and none of its middleware.
|
||||
foreach ($modules->active() as $module) {
|
||||
if ($module->publicRoutes() !== null) {
|
||||
$this->loadRoutesFrom($module->publicRoutes());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user