bookmarkMapper = $bookmarkMapper; $this->url = $url; $this->authorizer = $authorizer; $this->logger = $logger; } /** * @inheritDoc */ public function getType(): string { return self::RESOURCE_TYPE; } /** * @inheritDoc */ public function getResourceRichObject(IResource $resource): array { $bookmark = $this->getBookmark($resource); $favicon = $this->url->linkToRouteAbsolute('bookmarks.internal_bookmark.get_bookmark_favicon', ['id' => $bookmark->getId()]); $resourceUrl = $this->url->linkToRouteAbsolute('bookmarks.web_view.indexbookmark', ['bookmark' => $bookmark->getId()]); return [ 'type' => self::RESOURCE_TYPE, 'id' => $resource->getId(), 'name' => $bookmark->getTitle(), 'link' => $resourceUrl, 'iconUrl' => $favicon, ]; } /** * @inheritDoc */ public function canAccessResource(IResource $resource, ?IUser $user): bool { if ($resource->getType() !== self::RESOURCE_TYPE || !($user instanceof IUser)) { return false; } $bookmark = $this->getBookmark($resource); if ($bookmark === null) { return false; } if ($bookmark->getUserId() === $user->getUID()) { return true; } $permissions = $this->authorizer->getUserPermissionsForBookmark($user->getUID(), $bookmark->getId()); return Authorizer::hasPermission(Authorizer::PERM_READ, $permissions); } private function getBookmark(IResource $resource) : ?Bookmark { try { return $this->bookmarkMapper->find((int) $resource->getId()); } catch (MultipleObjectsReturnedException|DoesNotExistException $e) { return null; } } }