Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],

Expand Down
7 changes: 6 additions & 1 deletion lib/Controller/BoardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 18 additions & 0 deletions lib/Controller/BoardOcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
}
}
64 changes: 63 additions & 1 deletion lib/Controller/CardOcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ public function update(int $id, string $title, int $stackId, string $type, int $
$duedate,
$deletedAt,
$archived,
$done
$done,
$startdate,
$color,
));
}

Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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));
}
}
43 changes: 39 additions & 4 deletions lib/Controller/CommentsApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -33,31 +39,60 @@ 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);
}

/**
* @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);
}

/**
* @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);
}

/**
* @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);
}
}
14 changes: 13 additions & 1 deletion lib/Controller/StackOcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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);
}

}
12 changes: 11 additions & 1 deletion lib/Db/CardMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,6 +37,8 @@ class CardMapper extends QBMapper implements IPermissionMapper {
private $notificationManager;
/** @var ICache */
private $cache;
/** @var ICloudIdManager */
private $cloudIdManager;
private $databaseType;
private $database4ByteSupport;

Expand All @@ -46,6 +49,7 @@ public function __construct(
IGroupManager $groupManager,
IManager $notificationManager,
ICacheFactory $cacheFactory,
ICloudIdManager $cloudIdManager,
$databaseType = 'sqlite3',
$database4ByteSupport = true,
) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
});
}
Expand Down
19 changes: 17 additions & 2 deletions lib/Federation/DeckFederationProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]);
Expand Down
3 changes: 2 additions & 1 deletion lib/Service/BoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/CardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading
Loading