Refactor models.

This commit is contained in:
James Cole
2025-09-14 09:00:01 +02:00
parent 935453796e
commit 9d9483e20f
46 changed files with 688 additions and 676 deletions

View File

@@ -47,19 +47,19 @@ class UserGroup extends Model
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$userGroupId = (int) $value;
$userGroupId = (int)$value;
/** @var User $user */
$user = auth()->user();
$user = auth()->user();
/** @var null|UserGroup $userGroup */
$userGroup = self::find($userGroupId);
$userGroup = self::find($userGroupId);
if (null === $userGroup) {
throw new NotFoundHttpException();
}
// need at least ready only to be aware of the user group's existence,
// but owner/full role (in the group) or global owner role may overrule this.
$access = $user->hasRoleInGroupOrOwner($userGroup, UserRoleEnum::READ_ONLY) || $user->hasRole('owner');
$access = $user->hasRoleInGroupOrOwner($userGroup, UserRoleEnum::READ_ONLY) || $user->hasRole('owner');
if ($access) {
return $userGroup;
}