diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index c0e238bbe..e326d82bb 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -21,6 +21,7 @@ use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\AppFramework\OCSController; +use OCP\Files\IRootFolder; use OCP\IRequest; use Psr\Log\LoggerInterface; @@ -37,6 +38,7 @@ public function __construct( string $appName, IRequest $request, private PageService $service, + private IRootFolder $rootFolder, private AttachmentService $attachmentService, private SearchService $indexedSearchService, private CollectiveService $collectiveService, @@ -266,7 +268,9 @@ public function trash(int $collectiveId, int $id): DataResponse { */ #[NoAdminRequired] public function getAttachments(int $collectiveId, int $id): DataResponse { - $attachments = $this->handleErrorResponse(fn (): array => $this->attachmentService->getAttachments($collectiveId, $id, $this->userId), $this->logger); + $pageFile = $this->service->getPageFile($collectiveId, $id, $this->userId); + $userFolder = $this->rootFolder->getUserFolder($this->userId); + $attachments = $this->handleErrorResponse(fn (): array => $this->attachmentService->getAttachments($pageFile, $userFolder), $this->logger); return new DataResponse(['attachments' => $attachments]); } diff --git a/lib/Controller/PublicPageController.php b/lib/Controller/PublicPageController.php index 15371eadb..789cf1529 100644 --- a/lib/Controller/PublicPageController.php +++ b/lib/Controller/PublicPageController.php @@ -441,7 +441,9 @@ public function getAttachments(int $id): DataResponse { if (0 !== $sharePageId = $this->getCollectiveShare()->getPageId()) { $this->checkPageShareAccess($collectiveId, $sharePageId, $id, $owner); } - return $this->attachmentService->getAttachments($collectiveId, $id, $owner); + $pageFile = $this->service->getPageFile($collectiveId, $id, $owner); + $shareFolder = $this->getShare()->getNode(); + return $this->attachmentService->getAttachments($pageFile, $shareFolder); }, $this->logger); return new DataResponse(['attachments' => $attachments]); } diff --git a/lib/Controller/PublicStartController.php b/lib/Controller/PublicStartController.php index f710e569e..b7edb1c7b 100644 --- a/lib/Controller/PublicStartController.php +++ b/lib/Controller/PublicStartController.php @@ -11,6 +11,7 @@ use OCA\Collectives\Db\CollectiveShareMapper; use OCA\DAV\Connector\Sabre\PublicAuth; +use OCA\Files_Sharing\Event\ShareLinkAccessedEvent; use OCA\Viewer\Event\LoadViewer; use OCP\App\IAppManager; use OCP\AppFramework\AuthPublicShareController; @@ -110,10 +111,12 @@ public function showShare(): PublicTemplateResponse { if ($appsMissing = $this->checkDependencies()) { return new PublicTemplateResponse('collectives', 'error', ['appsMissing' => $appsMissing]); // templates/error.php } - $this->eventDispatcher->dispatch(LoadViewer::class, new LoadViewer()); + $this->eventDispatcher->dispatchTyped(new LoadViewer()); + $this->eventDispatcher->dispatchTyped(new ShareLinkAccessedEvent($this->getShare(), 'show')); $response = new PublicTemplateResponse('collectives', 'main', [ // templates/main.php 'id-app-content' => '#app-content-vue', 'id-app-navigation' => '#app-navigation-vue', + 'token' => $this->getToken(), ]); $response->setFooterVisible(false); return $response; diff --git a/lib/Service/AttachmentService.php b/lib/Service/AttachmentService.php index 0cb989ec9..0e04b66a0 100644 --- a/lib/Service/AttachmentService.php +++ b/lib/Service/AttachmentService.php @@ -17,7 +17,6 @@ class AttachmentService { public function __construct( - private PageService $pageService, private IPreview $preview, ) { } @@ -25,7 +24,7 @@ public function __construct( /** * @throws NotFoundException */ - private function fileToInfo(File $file, string $userId): array { + private function fileToInfo(File $file, folder $folder): array { try { return [ 'id' => $file->getId(), @@ -33,7 +32,7 @@ private function fileToInfo(File $file, string $userId): array { 'filesize' => $file->getSize(), 'mimetype' => $file->getMimeType(), 'timestamp' => $file->getMTime(), - 'path' => substr($file->getPath(), strlen('/' . $userId . '/files')), + 'path' => $folder->getRelativePath($file->getPath()), 'internalPath' => $file->getInternalPath(), 'hasPreview' => $this->preview->isAvailable($file), ]; @@ -62,12 +61,14 @@ private function getAttachmentDirectory(File $pageFile): Folder { } /** + * @param File $pageFile file of the page with the attachments. + * @param Folder $folder user or share folder for relative paths. + * * @throws MissingDependencyException * @throws NotFoundException * @throws NotPermittedException */ - public function getAttachments(int $collectiveId, int $pageId, string $userId): array { - $pageFile = $this->pageService->getPageFile($collectiveId, $pageId, $userId); + public function getAttachments(File $pageFile, Folder $folder): array { try { $attachmentDir = $this->getAttachmentDirectory($pageFile); } catch (NotFoundException) { @@ -76,6 +77,6 @@ public function getAttachments(int $collectiveId, int $pageId, string $userId): } // Only return files, ignore folders - return array_map(fn ($file) => $this->fileToInfo($file, $userId), array_filter($attachmentDir->getDirectoryListing(), static fn ($node) => $node instanceof File)); + return array_map(fn ($file) => $this->fileToInfo($file, $folder), array_filter($attachmentDir->getDirectoryListing(), static fn ($node) => $node instanceof File)); } } diff --git a/src/components/Nav/TemplatesDialog.vue b/src/components/Nav/TemplatesDialog.vue index e76f9eccf..dea215bba 100644 --- a/src/components/Nav/TemplatesDialog.vue +++ b/src/components/Nav/TemplatesDialog.vue @@ -6,6 +6,7 @@