Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 8m49s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 8m47s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 8m40s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 9m24s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 11m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 12m4s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 10m37s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 45s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m12s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 10m41s
Rollen-Schalter simple_ui: größere Schrift, Leichte Sprache automatisch, Startseite mit großen Kacheln; Hinweis in „Was sieht wer?“. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Support\Permissions\Permissions;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Support\Str;
|
|
|
|
#[Fillable(['name', 'slug', 'description', 'is_system', 'simple_ui'])]
|
|
class Role extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
public const ADMINISTRATION = 'administration';
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::saving(function (Role $role) {
|
|
$role->slug = $role->slug ?: Str::slug($role->name, language: 'de');
|
|
});
|
|
|
|
static::saved(fn () => Permissions::flush());
|
|
static::deleted(fn () => Permissions::flush());
|
|
}
|
|
|
|
protected function casts(): array
|
|
{
|
|
return ['is_system' => 'boolean', 'simple_ui' => 'boolean'];
|
|
}
|
|
|
|
public static function administration(): self
|
|
{
|
|
$role = static::query()->firstOrCreate(['slug' => self::ADMINISTRATION], [
|
|
'name' => 'Administration',
|
|
'description' => 'Voller Zugriff auf alle Bereiche und Einstellungen.',
|
|
'is_system' => true,
|
|
]);
|
|
|
|
if (! $role->grants()->where('ability', '*')->exists()) {
|
|
$role->grants()->create(['ability' => '*']);
|
|
}
|
|
|
|
return $role;
|
|
}
|
|
|
|
/**
|
|
* @return BelongsToMany<User, $this>
|
|
*/
|
|
public function users(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(User::class)->withPivot('source', 'source_ref', 'created_at');
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<Grant, $this>
|
|
*/
|
|
public function grants(): HasMany
|
|
{
|
|
return $this->hasMany(Grant::class);
|
|
}
|
|
|
|
public function isAdministration(): bool
|
|
{
|
|
return $this->slug === self::ADMINISTRATION;
|
|
}
|
|
}
|