Snapshot of main at 9f39a6e1e (2026-11-02)

This commit is contained in:
Ronald Huynen committed 2026-11-02 10:41:47 +01:00
commit 6ccf1792d7
2580 files changed
+1040202

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Spatie\Permission\Models\Role;
class AdminRole extends Model
{
protected $fillable = ['name', 'label', 'permissions'];
protected $casts = [
'permissions' => 'array',
'is_system' => 'boolean',
];
public function getPermissionsListAttribute(): array
{
return $this->permissions ?? [];
}
public function scopeNotSystem($query)
{
return $query->where('is_system', false);
}
/**
* The role a user linked to a new admin profile gets: the platform setting
* admin_settings.default_admin_role, 'administrator' when it is not set.
*/
public static function defaultName(): string
{
return (string) (timebank_config('admin_settings.default_admin_role') ?: 'administrator');
}
/**
* Give a user this role on one admin profile: the scoped Spatie role Admin\{adminId}\{name}, created
* when missing and synced with this definition's permissions.
*/
public function assignScopedTo(User $user, int $adminId): Role
{
$role = Role::findOrCreate("Admin\\{$adminId}\\{$this->name}", 'web');
$role->syncPermissions($this->permissions ?? []);
if (!$user->hasRole($role)) {
$user->assignRole($role);
}
return $role;
}
}