PR CI / ledger (pull_request) Successful in 3s
PR CI / flow (pull_request) Successful in 4s
PR CI / ui (pull_request) Successful in 17s
PR CI / test (lowest) (pull_request) Successful in 45s
PR CI / test (stable) (pull_request) Successful in 48s
PR CI / security (pull_request) Successful in 54s
PR CI / pr-ci (pull_request) Successful in 1s
PR CI / release-automerge (pull_request) Successful in 3s
38 lines
981 B
PHP
38 lines
981 B
PHP
<?php
|
|
|
|
namespace IriksIT\Manager\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use IriksIT\Manager\Support\ModuleRegistry;
|
|
use IriksIT\Manager\Support\Names;
|
|
|
|
/**
|
|
* A set of permissions with a name ("Writers"). Accounts are put in groups; a group is the
|
|
* only place where permissions are set.
|
|
*
|
|
* @property list<string>|null $permissions
|
|
*/
|
|
class Group extends Model
|
|
{
|
|
protected function casts(): array
|
|
{
|
|
return ['permissions' => 'array'];
|
|
}
|
|
|
|
public function users(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(config('manager.user_model'), Names::table('group_user'), 'group_id', 'user_id');
|
|
}
|
|
|
|
/**
|
|
* What the group allows, without anything that is no permission (any more), for instance
|
|
* of a module that was switched off.
|
|
*
|
|
* @return list<string>
|
|
*/
|
|
public function allowed(): array
|
|
{
|
|
return app(ModuleRegistry::class)->complete($this->permissions ?? []);
|
|
}
|
|
}
|