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
@@ -65,18 +65,72 @@ final class ModuleRegistry
|
||||
}
|
||||
}
|
||||
|
||||
/** @return array<string, string> permission value => label, of the active modules only */
|
||||
/** @return array<string, Permission> permission value => permission, of the active modules only */
|
||||
public function permissions(): array
|
||||
{
|
||||
$permissions = [];
|
||||
|
||||
foreach ($this->active() as $module) {
|
||||
$permissions += $module->permissions();
|
||||
foreach ($module->permissions() as $permission) {
|
||||
$permissions[$permission->value] = $permission;
|
||||
}
|
||||
}
|
||||
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
public function permissionValues(): array
|
||||
{
|
||||
return array_keys($this->permissions());
|
||||
}
|
||||
|
||||
/**
|
||||
* The given values without what is no permission (any more), completed with what they
|
||||
* need, in the order of the permissions.
|
||||
*
|
||||
* @param array<array-key, mixed> $values
|
||||
* @return list<string>
|
||||
*/
|
||||
public function complete(array $values): array
|
||||
{
|
||||
$known = $this->permissions();
|
||||
$wanted = [];
|
||||
|
||||
foreach ($values as $value) {
|
||||
if (is_string($value) && isset($known[$value])) {
|
||||
$wanted[$value] = true;
|
||||
|
||||
foreach ($known[$value]->needs as $needed) {
|
||||
$wanted[$needed] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_filter(array_keys($known), fn (string $value) => isset($wanted[$value])));
|
||||
}
|
||||
|
||||
/**
|
||||
* The list for the group form, per section.
|
||||
*
|
||||
* @return list<array{section: string, permissions: list<array{value: string, label: string, needs: list<string>}>}>
|
||||
*/
|
||||
public function catalogue(): array
|
||||
{
|
||||
$sections = [];
|
||||
|
||||
foreach ($this->permissions() as $permission) {
|
||||
$sections[$permission->section][] = ['value' => $permission->value, 'label' => $permission->label, 'needs' => $permission->needs];
|
||||
}
|
||||
|
||||
$catalogue = [];
|
||||
foreach ($sections as $section => $permissions) {
|
||||
$catalogue[] = ['section' => $section, 'permissions' => $permissions];
|
||||
}
|
||||
|
||||
return $catalogue;
|
||||
}
|
||||
|
||||
/** @return list<array{label: string, route: string, permission: string}> */
|
||||
public function navigation(): array
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user