$this->canRead($group, $user), self::CREATE => $this->canCreate($user), self::EDIT => $this->canEdit($group, $user), self::DELETE => $this->canDelete($group, $user), self::SELECT => $this->canSelect($group, $user), default => false, }; } private function canCreate(BackendUserAuthentication $user): bool { return isset($user->user['uid']) && (int)$user->user['uid'] > 0; } private function canRead(array $group, BackendUserAuthentication $user): bool { $userId = (int)$user->user['uid']; return (int)$group['userid'] === $userId; } private function canEdit(array $group, BackendUserAuthentication $user): bool { $groupId = $group['id'] ?? null; // System/global groups (integer IDs) are not editable if (is_int($groupId) || is_numeric($groupId)) { return false; } // User-created groups (UUID strings) are editable only if user owns them if (!isset($group['userid'])) { return false; } $userId = (int)$user->user['uid']; return (int)$group['userid'] === $userId; } private function canDelete(array $group, BackendUserAuthentication $user): bool { // Delete permission mirrors edit permission return $this->canEdit($group, $user); } private function canSelect(array $group, BackendUserAuthentication $user): bool { $groupId = $group['id'] ?? 0; // Global groups (negative IDs) are only selectable by admins if (is_int($groupId) && $groupId < 0) { return $user->isAdmin(); } return true; } }