diff --git a/appinfo/routes.php b/appinfo/routes.php index 6e2c273087..e208a347ca 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -139,16 +139,24 @@ ['name' => 'board_ocs#index', 'url' => '/api/v{apiVersion}/boards', 'verb' => 'GET'], ['name' => 'board_ocs#read', 'url' => '/api/v{apiVersion}/board/{boardId}', 'verb' => 'GET'], ['name' => 'stack_ocs#index', 'url' => '/api/v{apiVersion}/stacks/{boardId}', 'verb' => 'GET'], + ['name' => 'stack_ocs#getArchived', 'url' => '/api/v{apiVersion}/stacks/{boardId}/archived', 'verb' => 'GET'], ['name' => 'board_ocs#create', 'url' => '/api/v{apiVersion}/boards', 'verb' => 'POST'], + ['name' => 'board_ocs#update', 'url' => '/api/v{apiVersion}/boards/{boardId}', 'verb' => 'PUT'], ['name' => 'board_ocs#addAcl', 'url' => '/api/v{apiVersion}/boards/{boardId}/acl', 'verb' => 'POST'], + ['name' => 'board_ocs#leave', 'url' => '/api/v{apiVersion}/boards/{boardId}/leave', 'verb' => 'POST'], ['name' => 'card_ocs#create', 'url' => '/api/v{apiVersion}/cards', 'verb' => 'POST'], ['name' => 'card_ocs#update', 'url' => '/api/v{apiVersion}/cards/{cardId}', 'verb' => 'PUT'], + ['name' => 'card_ocs#delete', 'url' => '/api/v{apiVersion}/cards/{cardId}', 'verb' => 'DELETE'], ['name' => 'card_ocs#assignLabel', 'url' => '/api/v{apiVersion}/cards/{cardId}/label/{labelId}', 'verb' => 'POST'], ['name' => 'card_ocs#assignUser', 'url' => '/api/v{apiVersion}/cards/{cardId}/assign', 'verb' => 'POST'], ['name' => 'card_ocs#unAssignUser', 'url' => '/api/v{apiVersion}/cards/{cardId}/unassign', 'verb' => 'PUT'], ['name' => 'card_ocs#removeLabel', 'url' => '/api/v{apiVersion}/cards/{cardId}/label/{labelId}', 'verb' => 'DELETE'], ['name' => 'card_ocs#reorder', 'url' => '/api/v{apiVersion}/cards/{cardId}/reorder', 'verb' => 'PUT'], + ['name' => 'card_ocs#archive', 'url' => '/api/v{apiVersion}/cards/{cardId}/archive', 'verb' => 'PUT'], + ['name' => 'card_ocs#unarchive', 'url' => '/api/v{apiVersion}/cards/{cardId}/unarchive', 'verb' => 'PUT'], + ['name' => 'card_ocs#done', 'url' => '/api/v{apiVersion}/cards/{cardId}/done', 'verb' => 'PUT'], + ['name' => 'card_ocs#undone', 'url' => '/api/v{apiVersion}/cards/{cardId}/undone', 'verb' => 'PUT'], ['name' => 'card_ocs#assignDependentCard', 'url' => '/api/v{apiVersion}/cards/{cardId}/dependentCards/{dependentCardId}', 'verb' => 'POST'], ['name' => 'card_ocs#removeDependentCard', 'url' => '/api/v{apiVersion}/cards/{cardId}/dependentCards/{dependentCardId}', 'verb' => 'DELETE'], diff --git a/lib/Controller/BoardController.php b/lib/Controller/BoardController.php index 5c43ab7b12..5383e0adae 100644 --- a/lib/Controller/BoardController.php +++ b/lib/Controller/BoardController.php @@ -67,7 +67,12 @@ public function deleteUndo(int $boardId): Board { #[NoAdminRequired] public function leave(int $boardId) { - return $this->boardService->leave($boardId); + $localBoard = $this->boardService->find($boardId, true, true); + $result = $this->boardService->leave($boardId); + if ($localBoard->getExternalId() !== null) { + $this->externalBoardService->leaveBoardOnRemote($localBoard); + } + return $result; } #[NoAdminRequired] diff --git a/lib/Controller/BoardOcsController.php b/lib/Controller/BoardOcsController.php index 2616194cd9..43d4d21438 100644 --- a/lib/Controller/BoardOcsController.php +++ b/lib/Controller/BoardOcsController.php @@ -49,6 +49,18 @@ public function create(string $title, string $color): DataResponse { return new DataResponse($this->boardService->create($title, $this->userId, $color)); } + #[NoAdminRequired] + #[PublicPage] + public function update(int $boardId, string $title, string $color, bool $archived): DataResponse { + $updatedBoard = $this->boardService->update($boardId, $title, $color, $archived); + + if ($updatedBoard->getExternalId()) { + return $this->externalBoardService->updateBoardOnRemote($updatedBoard, $title, $color, $archived); + } + + return new DataResponse($updatedBoard); + } + #[NoAdminRequired] public function addAcl(int $boardId, int $type, string $participant, bool $permissionEdit, bool $permissionShare, bool $permissionManage, ?string $remote = null): DataResponse { return new DataResponse($this->boardService->addAcl($boardId, $type, $participant, $permissionEdit, $permissionShare, $permissionManage)); @@ -58,4 +70,10 @@ public function addAcl(int $boardId, int $type, string $participant, bool $permi public function updateAcl(int $id, bool $permissionEdit, bool $permissionShare, bool $permissionManage): DataResponse { return new DataResponse($this->boardService->updateAcl($id, $permissionEdit, $permissionShare, $permissionManage)); } + + #[NoAdminRequired] + #[PublicPage] + public function leave(int $boardId): DataResponse { + return new DataResponse($this->boardService->leave($boardId)); + } } diff --git a/lib/Controller/CardOcsController.php b/lib/Controller/CardOcsController.php index 7ca27a0ef6..1358a03874 100644 --- a/lib/Controller/CardOcsController.php +++ b/lib/Controller/CardOcsController.php @@ -139,7 +139,9 @@ public function update(int $id, string $title, int $stackId, string $type, int $ $duedate, $deletedAt, $archived, - $done + $done, + $startdate, + $color, )); } @@ -159,6 +161,18 @@ public function update(int $id, string $title, int $stackId, string $type, int $ )); } + #[NoAdminRequired] + #[PublicPage] + public function delete(int $cardId, ?int $boardId = null): DataResponse { + if ($boardId) { + $board = $this->boardService->find($boardId, false); + if ($board->getExternalId()) { + return new DataResponse($this->externalBoardService->deleteCardOnRemote($board, $cardId)); + } + } + return new DataResponse($this->cardService->delete($cardId)); + } + #[NoAdminRequired] #[PublicPage] public function reorder(int $cardId, int $stackId, int $order, ?int $boardId): DataResponse { @@ -171,6 +185,30 @@ public function reorder(int $cardId, int $stackId, int $order, ?int $boardId): D return new DataResponse($this->cardService->reorder($cardId, $stackId, $order)); } + #[NoAdminRequired] + #[PublicPage] + public function archive(int $cardId, int $boardId): DataResponse { + if ($boardId) { + $board = $this->boardService->find($boardId, false); + if ($board->getExternalId()) { + return new DataResponse($this->externalBoardService->archiveCardOnRemote($board, $cardId)); + } + } + return new DataResponse($this->cardService->archive($cardId)); + } + + #[NoAdminRequired] + #[PublicPage] + public function unarchive(int $cardId, int $boardId): DataResponse { + if ($boardId) { + $board = $this->boardService->find($boardId, false); + if ($board->getExternalId()) { + return new DataResponse($this->externalBoardService->unarchiveCardOnRemote($board, $cardId)); + } + } + return new DataResponse($this->cardService->unarchive($cardId)); + } + #[NoAdminRequired] #[PublicPage] public function assignDependentCard(int $cardId, int $dependentCardId, ?int $boardId = null): DataResponse { @@ -194,4 +232,28 @@ public function removeDependentCard(int $cardId, int $dependentCardId, ?int $boa } return new DataResponse($this->cardService->removeDependentCard($cardId, $dependentCardId)); } + + #[NoAdminRequired] + #[PublicPage] + public function done(int $cardId, ?int $boardId): DataResponse { + if ($boardId) { + $board = $this->boardService->find($boardId, false); + if ($board->getExternalId()) { + return new DataResponse($this->externalBoardService->setDoneCardOnRemote($board, $cardId)); + } + } + return new DataResponse($this->cardService->done($cardId)); + } + + #[NoAdminRequired] + #[PublicPage] + public function undone(int $cardId, ?int $boardId): DataResponse { + if ($boardId) { + $board = $this->boardService->find($boardId, false); + if ($board->getExternalId()) { + return new DataResponse($this->externalBoardService->setUndoneCardOnRemote($board, $cardId)); + } + } + return new DataResponse($this->cardService->undone($cardId)); + } } diff --git a/lib/Controller/CommentsApiController.php b/lib/Controller/CommentsApiController.php index 1794db5eae..8885660c2f 100644 --- a/lib/Controller/CommentsApiController.php +++ b/lib/Controller/CommentsApiController.php @@ -7,9 +7,12 @@ namespace OCA\Deck\Controller; +use OCA\Deck\Service\BoardService; use OCA\Deck\Service\CommentService; +use OCA\Deck\Service\ExternalBoardService; use OCA\Deck\StatusException; use OCP\AppFramework\Http\Attribute\NoAdminRequired; +use OCP\AppFramework\Http\Attribute\PublicPage; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; use OCP\IRequest; @@ -22,6 +25,9 @@ public function __construct( string $appName, IRequest $request, private CommentService $commentService, + private BoardService $boardService, + private ExternalBoardService $externalBoardService, + private ?string $userId, string $corsMethods = 'PUT, POST, GET, DELETE, PATCH', string $corsAllowedHeaders = 'Authorization, Content-Type, Accept', int $corsMaxAge = 1728000, @@ -33,7 +39,14 @@ public function __construct( * @throws StatusException */ #[NoAdminRequired] - public function list(int $cardId, int $limit = 20, int $offset = 0): DataResponse { + #[PublicPage] + public function list(int $cardId, int $limit = 20, int $offset = 0, ?int $boardId = null): DataResponse { + if ($boardId) { + $board = $this->boardService->find($boardId, false); + if ($board->getExternalId()) { + return new DataResponse($this->externalBoardService->getCardCommentsFromRemote($board, $cardId, $limit, $offset)); + } + } return $this->commentService->list($cardId, $limit, $offset); } @@ -41,7 +54,15 @@ public function list(int $cardId, int $limit = 20, int $offset = 0): DataRespons * @throws StatusException */ #[NoAdminRequired] - public function create(int $cardId, string $message, int $parentId = 0): DataResponse { + #[PublicPage] + public function create(int $cardId, string $message, int $parentId = 0, ?int $boardId = null): DataResponse { + if ($boardId) { + $board = $this->boardService->find($boardId, false); + if ($board->getExternalId()) { + return new DataResponse($this->externalBoardService->createCardCommentOnRemote($board, $cardId, $message, $parentId)); + } + } + return $this->commentService->create($cardId, $message, $parentId); } @@ -49,7 +70,14 @@ public function create(int $cardId, string $message, int $parentId = 0): DataRes * @throws StatusException */ #[NoAdminRequired] - public function update(int $cardId, int $commentId, string $message): DataResponse { + #[PublicPage] + public function update(int $cardId, int $commentId, string $message, ?int $boardId = null): DataResponse { + if ($boardId) { + $board = $this->boardService->find($boardId, false); + if ($board->getExternalId()) { + return new DataResponse($this->externalBoardService->updateCardCommentOnRemote($board, $cardId, $commentId, $message)); + } + } return $this->commentService->update($cardId, $commentId, $message); } @@ -57,7 +85,14 @@ public function update(int $cardId, int $commentId, string $message): DataRespon * @throws StatusException */ #[NoAdminRequired] - public function delete(int $cardId, int $commentId): DataResponse { + #[PublicPage] + public function delete(int $cardId, int $commentId, ?int $boardId = null): DataResponse { + if ($boardId) { + $board = $this->boardService->find($boardId, false); + if ($board->getExternalId()) { + return new DataResponse($this->externalBoardService->deleteCardCommentOnRemote($board, $cardId, $commentId)); + } + } return $this->commentService->delete($cardId, $commentId); } } diff --git a/lib/Controller/StackOcsController.php b/lib/Controller/StackOcsController.php index cada24f8e5..ecf73ae175 100644 --- a/lib/Controller/StackOcsController.php +++ b/lib/Controller/StackOcsController.php @@ -48,7 +48,7 @@ public function create(string $title, int $boardId, int $order = 0):DataResponse } else { $stack = $this->stackService->create($title, $boardId, $order); return new DataResponse($stack); - }; + } } #[NoAdminRequired] @@ -91,4 +91,16 @@ public function reorder(int $stackId, int $order, ?int $boardId):DataResponse { return new DataResponse($stacks); } + #[NoAdminRequired] + #[PublicPage] + public function getArchived(int $boardId): DataResponse { + $board = $this->boardService->find($boardId, false); + if ($board->getExternalId()) { + $stacks = $this->externalBoardService->getArchivedStacksFromRemote($board); + return new DataResponse($stacks); + } + $stacks = $this->stackService->findAllArchived($boardId); + return new DataResponse($stacks); + } + } diff --git a/lib/Db/CardMapper.php b/lib/Db/CardMapper.php index 47f3e58af3..f47c7a8b70 100644 --- a/lib/Db/CardMapper.php +++ b/lib/Db/CardMapper.php @@ -14,6 +14,7 @@ use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\QBMapper; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Federation\ICloudIdManager; use OCP\ICache; use OCP\ICacheFactory; use OCP\IDBConnection; @@ -36,6 +37,8 @@ class CardMapper extends QBMapper implements IPermissionMapper { private $notificationManager; /** @var ICache */ private $cache; + /** @var ICloudIdManager */ + private $cloudIdManager; private $databaseType; private $database4ByteSupport; @@ -46,6 +49,7 @@ public function __construct( IGroupManager $groupManager, IManager $notificationManager, ICacheFactory $cacheFactory, + ICloudIdManager $cloudIdManager, $databaseType = 'sqlite3', $database4ByteSupport = true, ) { @@ -55,6 +59,7 @@ public function __construct( $this->groupManager = $groupManager; $this->notificationManager = $notificationManager; $this->cache = $cacheFactory->createDistributed('deck-cardMapper'); + $this->cloudIdManager = $cloudIdManager; $this->databaseType = $databaseType; $this->database4ByteSupport = $database4ByteSupport; } @@ -747,10 +752,15 @@ public function findBoardId(int $id): ?int { public function mapOwner(Card &$card) { $userManager = $this->userManager; - $card->resolveRelation('owner', function ($owner) use (&$userManager) { + $cloudIdManager = $this->cloudIdManager; + $card->resolveRelation('owner', function ($owner) use (&$userManager, &$cloudIdManager) { if ($userManager->userExists($owner)) { return new User($owner, $this->userManager); } + if ($cloudIdManager->isValidCloudId($owner)) { + $cloudId = $cloudIdManager->resolveCloudId($owner); + return new FederatedUser($cloudId); + } return null; }); } diff --git a/lib/Federation/DeckFederationProxy.php b/lib/Federation/DeckFederationProxy.php index 2ab77fd515..8386b918ca 100644 --- a/lib/Federation/DeckFederationProxy.php +++ b/lib/Federation/DeckFederationProxy.php @@ -10,6 +10,10 @@ use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\ServerException; use OC\Http\Client\Response; +use OCA\Deck\BadRequestException; +use OCA\Deck\NoPermissionException; +use OCA\Deck\NotFoundException; +use OCA\Deck\StatusException; use OCP\AppFramework\Http; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; @@ -60,7 +64,7 @@ protected function prependProtocolIfNotAvailable(string $url): string { /** * @param 'get'|'post'|'put'|'delete' $verb - * @throws \Exception + * @throws \Exception|StatusException */ protected function request( string $verb, @@ -96,7 +100,18 @@ protected function request( $clientException = new \Exception($e->getMessage(), $status, $e); $this->logger->debug('Client error from remote', ['exception' => $clientException]); - return new Response($e->getResponse(), false); + + switch ($status) { + case 400: + throw new BadRequestException($data['ocs']['meta']['message'] ?? 'Bad request'); + case 401: + case 403: + throw new NoPermissionException($data['ocs']['meta']['message'] ?? 'No permission'); + case 404: + throw new NotFoundException($data['ocs']['meta']['message'] ?? 'Not found'); + default: + return new Response($e->getResponse(), false); + } } catch (ServerException|\Throwable $e) { $serverException = new \Exception($e->getMessage(), $e->getCode(), $e); $this->logger->error('Could not reach remote', ['exception' => $serverException]); diff --git a/lib/Service/BoardService.php b/lib/Service/BoardService.php index 1610352ae3..80ec4f8265 100644 --- a/lib/Service/BoardService.php +++ b/lib/Service/BoardService.php @@ -520,7 +520,8 @@ public function leave(int $boardId): ?Acl { throw new BadRequestException('Board owner cannot leave board'); } - $acl = $this->aclMapper->findParticipantFromBoard($boardId, Acl::PERMISSION_TYPE_USER, $this->userId); + $userId = $this->userId ?? $this->permissionService->getUserId(); + $acl = $this->aclMapper->findParticipantFromBoard($boardId, Acl::PERMISSION_TYPE_USER, $userId); if (!$acl) { throw new BadRequestException('Not a participant of this board'); diff --git a/lib/Service/CardService.php b/lib/Service/CardService.php index 5d30ccaafc..baf3e00d23 100644 --- a/lib/Service/CardService.php +++ b/lib/Service/CardService.php @@ -85,7 +85,7 @@ public function enrichCards(array $cards): array { // TODO We should find a better way just to get the comment count so we can save 1-3 queries per card here $countComments = $this->commentsManager->getNumberOfCommentsForObject('deckCard', (string)$card->getId()); - $lastRead = $countComments > 0 ? $this->commentsManager->getReadMark('deckCard', (string)$card->getId(), $user) : null; + $lastRead = $countComments > 0 && $user ? $this->commentsManager->getReadMark('deckCard', (string)$card->getId(), $user) : null; $countUnreadComments = $lastRead ? $this->commentsManager->getNumberOfCommentsForObject('deckCard', (string)$card->getId(), $lastRead) : 0; $card->setCommentsUnread($countUnreadComments); $card->setCommentsCount($countComments); diff --git a/lib/Service/CommentService.php b/lib/Service/CommentService.php index e5d4bc140e..0cdd1e0dd7 100644 --- a/lib/Service/CommentService.php +++ b/lib/Service/CommentService.php @@ -18,6 +18,8 @@ use OCP\Comments\ICommentsManager; use OCP\Comments\MessageTooLongException; use OCP\Comments\NotFoundException as CommentNotFoundException; +use OCP\Federation\ICloudIdManager; +use OCP\IURLGenerator; use OCP\IUserManager; use OutOfBoundsException; use Psr\Log\LoggerInterface; @@ -30,6 +32,8 @@ public function __construct( private CardMapper $cardMapper, private IUserManager $userManager, private LoggerInterface $logger, + private ICloudIdManager $cloudIdManager, + private IURLGenerator $urlGenerator, private ?string $userId, ) { } @@ -110,7 +114,7 @@ public function create(int $cardId, string $message, int $replyTo = 0): DataResp } try { - $comment = $this->commentsManager->create('users', $this->userId, Application::COMMENT_ENTITY_TYPE, (string)$cardId); + $comment = $this->commentsManager->create('users', $this->userId ?? $this->permissionService->getUserId(), Application::COMMENT_ENTITY_TYPE, (string)$cardId); $comment->setMessage($message); $comment->setVerb('comment'); $comment->setParentId((string)$replyTo); @@ -128,7 +132,8 @@ public function create(int $cardId, string $message, int $replyTo = 0): DataResp public function update(int $cardId, int $commentId, string $message): DataResponse { $comment = $this->get($cardId, $commentId); - if ($comment->getActorType() !== 'users' || $comment->getActorId() !== $this->userId) { + $userId = $this->userId ?? $this->permissionService->getUserId(); + if ($comment->getActorType() !== 'users' || $comment->getActorId() !== $userId) { throw new NoPermissionException('Only authors are allowed to edit their comment.'); } @@ -148,7 +153,8 @@ public function delete(int $cardId, int $commentId): DataResponse { } catch (CommentNotFoundException $e) { throw new NotFoundException('No comment found.'); } - if ($comment->getActorType() !== 'users' || $comment->getActorId() !== $this->userId) { + $userId = $this->userId ?? $this->permissionService->getUserId(); + if ($comment->getActorType() !== 'users' || $comment->getActorId() !== $userId) { throw new NoPermissionException('Only authors are allowed to edit their comment.'); } $this->commentsManager->delete((string)$commentId); @@ -163,20 +169,28 @@ private function formatComment(IComment $comment, bool $addReplyTo = false): arr 'objectId' => (int)$comment->getObjectId(), 'message' => $comment->getMessage(), 'actorId' => $comment->getActorId(), + 'actorRemote' => $this->cloudIdManager->isValidCloudId($comment->getActorId()) ? $this->cloudIdManager->resolveCloudId($comment->getActorId())->getRemote() : null, 'actorType' => $comment->getActorType(), 'actorDisplayName' => $actorDisplayName, 'creationDateTime' => $comment->getCreationDateTime()->format(\DateTime::ATOM), 'mentions' => array_map(function ($mention) { + $remote = $this->cloudIdManager->isValidCloudId($mention['id']) ? $this->cloudIdManager->resolveCloudId($mention['id'])->getRemote() : null; + try { $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); } catch (OutOfBoundsException $e) { $this->logger->warning('Mention type not registered, can not resolve display name.', ['exception' => $e, 'mention_type' => $mention['type']]); // No display name, upon client's discretion what to display. - $displayName = ''; + $displayName = $mention['id'] ?? ''; + if ($remote === $this->urlGenerator->getBaseUrl()) { + $uid = $this->cloudIdManager->resolveCloudId($mention['id'])->getUser(); + $displayName = $this->commentsManager->resolveDisplayName('user', $uid); + } } return [ 'mentionId' => $mention['id'], + 'mentionRemote' => $remote, 'mentionType' => $mention['type'], 'mentionDisplayName' => $displayName ]; diff --git a/lib/Service/ExternalBoardService.php b/lib/Service/ExternalBoardService.php index fd48517ec1..4b1a6b8be0 100644 --- a/lib/Service/ExternalBoardService.php +++ b/lib/Service/ExternalBoardService.php @@ -43,6 +43,15 @@ public function getExternalBoardFromRemote(Board $localBoard):DataResponse { $url = $ownerCloudId->getRemote() . '/ocs/v2.php/apps/deck/api/v1.0/board/' . $localBoard->getExternalId(); $resp = $this->proxy->get($participantCloudId->getId(), $shareToken, $url); $ocs = $this->proxy->getOCSData($resp); + + // Sync local board data with remote data + if ($ocs['title'] !== $localBoard->getTitle() || $ocs['color'] !== $localBoard->getColor() || $ocs['archived'] !== $localBoard->isArchived()) { + $localBoard->setTitle($ocs['title']); + $localBoard->setColor($ocs['color']); + $localBoard->setArchived($ocs['archived']); + $this->boardMapper->update($localBoard); + } + return new DataResponse($this->LocalizeRemoteBoard($ocs, $localBoard)); } public function getExternalStacksFromRemote(Board $localBoard):DataResponse { @@ -85,7 +94,8 @@ public function LocalizeRemoteStacks(array $stacks, Board $localBoard) { $stack['cards'][$j]['assignedUsers'] = array_map(function ($assignment) use ($localBoard) { $assignment['participant'] = $this->localizeRemoteUser($localBoard, $assignment['participant']); return $assignment; - }, $card['assignedUsers']); + }, $card['assignedUsers'] ?? []); + $stack['cards'][$j]['owner'] = $this->localizeRemoteUser($localBoard, $card['owner']); } $stacks[$i] = $stack; } @@ -98,6 +108,7 @@ public function LocalizeRemoteBoard(array $remoteBoard, Board $localBoard) { $remoteBoard['acl'] = $localBoard->getAcl(); $remoteBoard['permissions'] = $localBoard->getPermissions(); $remoteBoard['users'] = $this->localizeRemoteUsers($remoteBoard['users'], $localBoard); + $remoteBoard['externalId'] = $localBoard->getExternalId(); return $remoteBoard; } @@ -110,6 +121,56 @@ public function localizeRemoteUsers(array $users, Board $localBoard) { return $localizedUsers; } + public function localizeRemoteComments(Board $localBoard, array $comments): array { + foreach ($comments as $i => $comment) { + // Localize actors + $localizedActor = $this->localizeRemoteUser($localBoard, ['uid' => $comment['actorId'], 'remote' => $comment['actorRemote']]); + if ($localizedActor instanceof FederatedUser) { + $comments[$i]['actorDisplayName'] = $localizedActor->getCloudId()->getId(); + $comments[$i]['actorId'] = $localizedActor->getCloudId()->getId(); + $comments[$i]['actorRemote'] = $localizedActor->getCloudId()->getRemote(); + } + if ($localizedActor instanceof User) { + $comments[$i]['actorDisplayName'] = $localizedActor->getDisplayName(); + $comments[$i]['actorId'] = $localizedActor->getUID(); + $comments[$i]['actorRemote'] = null; + } + if ($comment['replyTo']) { + $localizedReplyActor = $this->localizeRemoteUser($localBoard, ['uid' => $comment['replyTo']['actorId'], 'remote' => $comment['replyTo']['actorRemote']]); + if ($localizedReplyActor instanceof FederatedUser) { + $comments[$i]['replyTo']['actorDisplayName'] = $localizedReplyActor->getCloudId()->getId(); + $comments[$i]['replyTo']['actorId'] = $localizedReplyActor->getCloudId()->getId(); + $comments[$i]['replyTo']['actorRemote'] = $localizedReplyActor->getCloudId()->getRemote(); + } + if ($localizedReplyActor instanceof User) { + $comments[$i]['replyTo']['actorDisplayName'] = $localizedReplyActor->getDisplayName(); + $comments[$i]['replyTo']['actorId'] = $localizedReplyActor->getUID(); + $comments[$i]['replyTo']['actorRemote'] = null; + } + } + + // Localize mentions + foreach ($comment['mentions'] as $j => $mention) { + $localizedMention = $this->localizeRemoteUser($localBoard, ['uid' => $mention['mentionId'], 'remote' => $mention['mentionRemote']]); + if ($localizedMention instanceof User) { + $comments[$i]['message'] = str_replace('@"federated_user/' . $mention['mentionId'], '@"' . $localizedMention->getUID(), $comment['message']); + $comments[$i]['mentions'][$j]['mentionDisplayName'] = $localizedMention->getDisplayName(); + $comments[$i]['mentions'][$j]['mentionId'] = $localizedMention->getUID(); + $comments[$i]['mentions'][$j]['mentionRemote'] = null; + $comments[$i]['mentions'][$j]['mentionType'] = 'user'; + } + if ($localizedMention instanceof FederatedUser) { + $comments[$i]['message'] = str_replace('@' . $mention['mentionId'], '@federated_user/' . $localizedMention->getUID(), $comment['message']); + $comments[$i]['mentions'][$j]['mentionDisplayName'] = $localizedMention->getCloudId()->getId(); + $comments[$i]['mentions'][$j]['mentionId'] = $localizedMention->getCloudId()->getId(); + $comments[$i]['mentions'][$j]['mentionRemote'] = $localizedMention->getCloudId()->getRemote(); + $comments[$i]['mentions'][$j]['mentionType'] = 'federated_user'; + } + } + } + return $comments; + } + public function createCardOnRemote( Board $localBoard, string $title, @@ -154,6 +215,8 @@ public function updateCardOnRemote( ?int $deletedAt = null, ?bool $archived = null, ?OptionalNullableValue $done = null, + ?string $startdate = null, + ?string $color = null, ): array { $this->configService->ensureFederationEnabled(); $this->permissionService->checkPermission($this->boardMapper, $localBoard->getId(), Acl::PERMISSION_EDIT, $this->userId, false, false); @@ -173,12 +236,26 @@ public function updateCardOnRemote( 'deletedAt' => $deletedAt, 'archived' => $archived, 'done' => $done->getValue() ?? null, + 'startdate' => $startdate, + 'color' => $color, 'boardId' => $localBoard->getExternalId(), ]; $resp = $this->proxy->put($participantCloudId->getId(), $shareToken, $url, $params); return $this->proxy->getOcsData($resp); } + public function deleteCardOnRemote(Board $localBoard, int $cardId): array { + $this->configService->ensureFederationEnabled(); + $this->permissionService->checkPermission($this->boardMapper, $localBoard->getId(), Acl::PERMISSION_EDIT, $this->userId, false, false); + $shareToken = $localBoard->getShareToken(); + $ownerCloudId = $this->cloudIdManager->resolveCloudId($localBoard->getOwner()); + $url = $ownerCloudId->getRemote() . '/ocs/v2.php/apps/deck/api/v1.0/cards/' . $cardId; + $resp = $this->proxy->delete($ownerCloudId->getId(), $shareToken, $url, [ + 'boardId' => $localBoard->getExternalId(), + ]); + return $this->proxy->getOcsData($resp); + } + public function assignLabelOnRemote(Board $localBoard, int $cardId, int $labelId): array { $this->configService->ensureFederationEnabled(); $this->permissionService->checkPermission($this->boardMapper, $localBoard->getId(), Acl::PERMISSION_EDIT, $this->userId, false, false); @@ -351,4 +428,162 @@ public function reorderStackOnRemote(Board $localBoard, int $stackId, int $order $resp = $this->proxy->put($participantCloudId->getId(), $shareToken, $url, $params); return $this->proxy->getOcsData($resp); } + + public function getArchivedStacksFromRemote(Board $localBoard): array { + $this->configService->ensureFederationEnabled(); + $shareToken = $localBoard->getShareToken(); + $participantCloudId = $this->cloudIdManager->getCloudId($this->userId, null); + $ownerCloudId = $this->cloudIdManager->resolveCloudId($localBoard->getOwner()); + $url = $ownerCloudId->getRemote() . '/ocs/v2.php/apps/deck/api/v1.0/stacks/' . $localBoard->getExternalId() . '/archived'; + $resp = $this->proxy->get($participantCloudId->getId(), $shareToken, $url); + $ocs = $this->proxy->getOCSData($resp); + return $this->LocalizeRemoteStacks($ocs, $localBoard); + } + + public function archiveCardOnRemote(Board $localBoard, int $cardId): array { + $this->configService->ensureFederationEnabled(); + $this->permissionService->checkPermission($this->boardMapper, $localBoard->getId(), Acl::PERMISSION_EDIT, $this->userId, false, false); + $shareToken = $localBoard->getShareToken(); + $participantCloudId = $this->cloudIdManager->getCloudId($this->userId, null); + $ownerCloudId = $this->cloudIdManager->resolveCloudId($localBoard->getOwner()); + $url = $ownerCloudId->getRemote() . '/ocs/v2.php/apps/deck/api/v1.0/cards/' . $cardId . '/archive'; + $params = [ + 'boardId' => $localBoard->getExternalId(), + ]; + $resp = $this->proxy->put($participantCloudId->getId(), $shareToken, $url, $params); + return $this->proxy->getOcsData($resp); + } + + public function unarchiveCardOnRemote(Board $localBoard, int $cardId): array { + $this->configService->ensureFederationEnabled(); + $this->permissionService->checkPermission($this->boardMapper, $localBoard->getId(), Acl::PERMISSION_EDIT, $this->userId, false, false); + $shareToken = $localBoard->getShareToken(); + $participantCloudId = $this->cloudIdManager->getCloudId($this->userId, null); + $ownerCloudId = $this->cloudIdManager->resolveCloudId($localBoard->getOwner()); + $url = $ownerCloudId->getRemote() . '/ocs/v2.php/apps/deck/api/v1.0/cards/' . $cardId . '/unarchive'; + $params = [ + 'boardId' => $localBoard->getExternalId(), + ]; + $resp = $this->proxy->put($participantCloudId->getId(), $shareToken, $url, $params); + return $this->proxy->getOcsData($resp); + } + + public function setDoneCardOnRemote(Board $localBoard, int $cardId): array { + $this->configService->ensureFederationEnabled(); + $this->permissionService->checkPermission($this->boardMapper, $localBoard->getId(), Acl::PERMISSION_EDIT, $this->userId, false, false); + $shareToken = $localBoard->getShareToken(); + $participantCloudId = $this->cloudIdManager->getCloudId($this->userId, null); + $ownerCloudId = $this->cloudIdManager->resolveCloudId($localBoard->getOwner()); + $url = $ownerCloudId->getRemote() . '/ocs/v2.php/apps/deck/api/v1.0/cards/' . $cardId . '/done'; + $params = [ + 'boardId' => $localBoard->getExternalId(), + ]; + $resp = $this->proxy->put($participantCloudId->getId(), $shareToken, $url, $params); + return $this->proxy->getOcsData($resp); + } + + public function setUndoneCardOnRemote(Board $localBoard, int $cardId): array { + $this->configService->ensureFederationEnabled(); + $this->permissionService->checkPermission($this->boardMapper, $localBoard->getId(), Acl::PERMISSION_EDIT, $this->userId, false, false); + $shareToken = $localBoard->getShareToken(); + $participantCloudId = $this->cloudIdManager->getCloudId($this->userId, null); + $ownerCloudId = $this->cloudIdManager->resolveCloudId($localBoard->getOwner()); + $url = $ownerCloudId->getRemote() . '/ocs/v2.php/apps/deck/api/v1.0/cards/' . $cardId . '/undone'; + $params = [ + 'boardId' => $localBoard->getExternalId(), + ]; + $resp = $this->proxy->put($participantCloudId->getId(), $shareToken, $url, $params); + return $this->proxy->getOcsData($resp); + } + + public function getCardCommentsFromRemote(Board $localBoard, int $cardId, int $limit = 20, int $offset = 0): array { + $this->configService->ensureFederationEnabled(); + $this->permissionService->checkPermission($this->boardMapper, $localBoard->getId(), Acl::PERMISSION_READ, $this->userId, false, false); + $shareToken = $localBoard->getShareToken(); + $participantCloudId = $this->cloudIdManager->getCloudId($this->userId, null); + $ownerCloudId = $this->cloudIdManager->resolveCloudId($localBoard->getOwner()); + $url = $ownerCloudId->getRemote() . '/ocs/v2.php/apps/deck/api/v1.0/cards/' . $cardId . '/comments'; + $params = [ + 'boardId' => $localBoard->getExternalId(), + 'limit' => $limit, + 'offset' => $offset, + ]; + $resp = $this->proxy->get($participantCloudId->getId(), $shareToken, $url, $params); + $comments = $this->proxy->getOcsData($resp); + return $this->localizeRemoteComments($localBoard, $comments); + } + + public function createCardCommentOnRemote(Board $localBoard, int $cardId, string $message, int $parentId = 0): array { + $this->configService->ensureFederationEnabled(); + $this->permissionService->checkPermission($this->boardMapper, $localBoard->getId(), Acl::PERMISSION_READ, $this->userId, false, false); + $shareToken = $localBoard->getShareToken(); + $participantCloudId = $this->cloudIdManager->getCloudId($this->userId, null); + $ownerCloudId = $this->cloudIdManager->resolveCloudId($localBoard->getOwner()); + $url = $ownerCloudId->getRemote() . '/ocs/v2.php/apps/deck/api/v1.0/cards/' . $cardId . '/comments'; + + $params = [ + 'boardId' => $localBoard->getExternalId(), + 'message' => $message, + 'parentId' => $parentId, + ]; + $resp = $this->proxy->post($participantCloudId->getId(), $shareToken, $url, $params); + $newComment = $this->proxy->getOcsData($resp); + return $this->localizeRemoteComments($localBoard, [$newComment])[0]; + } + + public function updateCardCommentOnRemote(Board $localBoard, int $cardId, int $commentId, string $message): array { + $this->configService->ensureFederationEnabled(); + $this->permissionService->checkPermission($this->boardMapper, $localBoard->getId(), Acl::PERMISSION_READ, $this->userId, false, false); + $shareToken = $localBoard->getShareToken(); + $participantCloudId = $this->cloudIdManager->getCloudId($this->userId, null); + $ownerCloudId = $this->cloudIdManager->resolveCloudId($localBoard->getOwner()); + $url = $ownerCloudId->getRemote() . '/ocs/v2.php/apps/deck/api/v1.0/cards/' . $cardId . '/comments/' . $commentId; + $params = [ + 'boardId' => $localBoard->getExternalId(), + 'message' => $message, + ]; + $resp = $this->proxy->put($participantCloudId->getId(), $shareToken, $url, $params); + $updatedComment = $this->proxy->getOcsData($resp); + return $this->localizeRemoteComments($localBoard, [$updatedComment])[0]; + } + + public function deleteCardCommentOnRemote(Board $localBoard, int $cardId, int $commentId): array { + $this->configService->ensureFederationEnabled(); + $this->permissionService->checkPermission($this->boardMapper, $localBoard->getId(), Acl::PERMISSION_READ, $this->userId, false, false); + $shareToken = $localBoard->getShareToken(); + $participantCloudId = $this->cloudIdManager->getCloudId($this->userId, null); + $ownerCloudId = $this->cloudIdManager->resolveCloudId($localBoard->getOwner()); + $url = $ownerCloudId->getRemote() . '/ocs/v2.php/apps/deck/api/v1.0/cards/' . $cardId . '/comments/' . $commentId; + $params = [ + 'boardId' => $localBoard->getExternalId(), + ]; + $resp = $this->proxy->delete($participantCloudId->getId(), $shareToken, $url, $params); + return $this->proxy->getOcsData($resp); + } + + public function updateBoardOnRemote(Board $localBoard, string $title, string $color, bool $archived): DataResponse { + $this->configService->ensureFederationEnabled(); + $this->permissionService->checkPermission($this->boardMapper, $localBoard->getId(), Acl::PERMISSION_MANAGE, $this->userId, false, false); + $shareToken = $localBoard->getShareToken(); + $participantCloudId = $this->cloudIdManager->getCloudId($this->userId, null); + $ownerCloudId = $this->cloudIdManager->resolveCloudId($localBoard->getOwner()); + $url = $ownerCloudId->getRemote() . '/ocs/v2.php/apps/deck/api/v1.0/boards/' . $localBoard->getExternalId(); + $params = [ + 'title' => $title, + 'color' => $color, + 'archived' => $archived, + ]; + $resp = $this->proxy->put($participantCloudId->getId(), $shareToken, $url, $params); + $updatedBoard = $this->proxy->getOcsData($resp); + return new DataResponse($this->LocalizeRemoteBoard($updatedBoard, $localBoard)); + } + + public function leaveBoardOnRemote(Board $localBoard): void { + $this->configService->ensureFederationEnabled(); + $shareToken = $localBoard->getShareToken(); + $participantCloudId = $this->cloudIdManager->getCloudId($this->userId, null); + $ownerCloudId = $this->cloudIdManager->resolveCloudId($localBoard->getOwner()); + $url = $ownerCloudId->getRemote() . '/ocs/v2.php/apps/deck/api/v1.0/boards/' . $localBoard->getExternalId() . '/leave'; + $this->proxy->post($participantCloudId->getId(), $shareToken, $url); + } } diff --git a/src/components/board/SharingTabSidebar.vue b/src/components/board/SharingTabSidebar.vue index 59d7088256..31fa3e8825 100644 --- a/src/components/board/SharingTabSidebar.vue +++ b/src/components/board/SharingTabSidebar.vue @@ -12,21 +12,20 @@