From 21c4955001ae473807766d47a3c9782defb654bc Mon Sep 17 00:00:00 2001 From: Luka Trovic Date: Tue, 20 Dec 2022 21:34:10 +0100 Subject: [PATCH] fix: merge conflicts Signed-off-by: Luka Trovic --- lib/Capabilities.php | 3 ++- lib/Controller/AttachmentApiController.php | 12 +++++++++++- lib/Controller/AttachmentController.php | 13 +++++++++++-- lib/Db/AttachmentMapper.php | 10 ++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/lib/Capabilities.php b/lib/Capabilities.php index 491b5a7fc..c44966a4c 100644 --- a/lib/Capabilities.php +++ b/lib/Capabilities.php @@ -53,7 +53,8 @@ class Capabilities implements ICapability { 'canCreateBoards' => $this->permissionService->canCreate(), 'apiVersions' => [ '1.0', - '1.1' + '1.1', + '1.2' ] ] ]; diff --git a/lib/Controller/AttachmentApiController.php b/lib/Controller/AttachmentApiController.php index debf93f6f..244d97abd 100644 --- a/lib/Controller/AttachmentApiController.php +++ b/lib/Controller/AttachmentApiController.php @@ -27,13 +27,16 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; use OCA\Deck\Service\AttachmentService; +use OCA\Deck\Db\AttachmentMapper; class AttachmentApiController extends ApiController { private $attachmentService; + private $attachmentMapper; - public function __construct($appName, IRequest $request, AttachmentService $attachmentService) { + public function __construct($appName, IRequest $request, AttachmentService $attachmentService, AttachmentMapper $attachmentMapper) { parent::__construct($appName, $request); $this->attachmentService = $attachmentService; + $this->attachmentMapper = $attachmentMapper; } /** @@ -49,6 +52,13 @@ class AttachmentApiController extends ApiController { return $attachment->getType() === 'deck_file'; }); } + + if ($apiVersion === '1.2') { + foreach ($attachment as &$attachment) { + $this->attachmentMapper->mapOwner($attachment); + } + } + return new DataResponse($attachment, HTTP::STATUS_OK); } diff --git a/lib/Controller/AttachmentController.php b/lib/Controller/AttachmentController.php index 38334199a..979200271 100644 --- a/lib/Controller/AttachmentController.php +++ b/lib/Controller/AttachmentController.php @@ -26,22 +26,31 @@ namespace OCA\Deck\Controller; use OCA\Deck\Service\AttachmentService; use OCP\AppFramework\Controller; use OCP\IRequest; +use OCA\Deck\Db\AttachmentMapper; class AttachmentController extends Controller { /** @var AttachmentService */ private $attachmentService; + private $attachmentMapper; - public function __construct($appName, IRequest $request, AttachmentService $attachmentService) { + public function __construct($appName, IRequest $request, AttachmentService $attachmentService, AttachmentMapper $attachmentMapper) { parent::__construct($appName, $request); $this->attachmentService = $attachmentService; + $this->attachmentMapper = $attachmentMapper; } /** * @NoAdminRequired */ public function getAll($cardId) { - return $this->attachmentService->findAll($cardId, true); + $attachments = $this->attachmentService->findAll($cardId, true); + + foreach ($attachments as &$attachment) { + $this->attachmentMapper->mapOwner($attachment); + } + + return $attachments; } /** diff --git a/lib/Db/AttachmentMapper.php b/lib/Db/AttachmentMapper.php index 727e3cce1..07a294a8d 100644 --- a/lib/Db/AttachmentMapper.php +++ b/lib/Db/AttachmentMapper.php @@ -156,4 +156,14 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper { } return $this->cardMapper->findBoardId($attachment->getCardId()); } + + public function mapOwner(Attachment &$attachment) { + $attachment->resolveRelation('createdBy', function ($userId) { + $user = $this->userManager->get($userId); + if ($user !== null) { + return new User($user); + } + return $user; + }); + } }