getWorkspace($workspace); } $isGranted = match ($permission) { Permission::WORKSPACE_MANAGE => $this->canManage($user, $workspace), default => false }; if (!$isGranted) { throw new HttpException(statusCode: StatusCode::FORBIDDEN); } } private function canManage(UserEntity $user, WorkspaceEntity $workspace): bool { if ( $workspace->getOwner()->getId()->getValue()->toString() !== $user->getId()->getValue()->toString() ) { return false; } return true; } /** * @throws NoHandlerFoundException * @throws NotFoundException */ private function getWorkspace(string $id): WorkspaceEntity { try { $cmd = new ReadWorkspaceCommand($id); /** @var WorkspaceEntity */ $workspace = $this->dispatcher->dispatch($cmd); } catch (WorkspaceNotFoundException $th) { throw new NotFoundException( param: 'id', previous: $th ); } return $workspace; } }