Skip to content
Open
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
3 changes: 2 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
'ocs' => [
['name' => 'board_ocs#index', 'url' => '/api/v{apiVersion}/boards', 'verb' => 'GET'],
['name' => 'board_ocs#read', 'url' => '/api/v{apiVersion}/board/{boardId}', 'verb' => 'GET'],
['name' => 'board_ocs#stacks', 'url' => '/api/v{apiVersion}/stacks/{boardId}', 'verb' => 'GET'],
['name' => 'stack_ocs#index', 'url' => '/api/v{apiVersion}/stacks/{boardId}', 'verb' => 'GET'],
['name' => 'board_ocs#create', 'url' => '/api/v{apiVersion}/boards', 'verb' => 'POST'],
['name' => 'board_ocs#addAcl', 'url' => '/api/v{apiVersion}/boards/{boardId}/acl', 'verb' => 'POST'],

Expand All @@ -145,6 +145,7 @@
['name' => 'card_ocs#removeLabel', 'url' => '/api/v{apiVersion}/cards/{cardId}/label/{labelId}', 'verb' => 'DELETE'],

['name' => 'stack_ocs#create', 'url' => '/api/v{apiVersion}/stacks', 'verb' => 'POST'],
['name' => 'stack_ocs#setDoneStack', 'url' => '/api/v{apiVersion}/stacks/{stackId}/done', 'verb' => 'PUT'],
['name' => 'stack_ocs#delete', 'url' => '/api/v{apiVersion}/stacks/{stackId}/{boardId}', 'verb' => 'DELETE', 'defaults' => ['boardId' => null]],

['name' => 'Config#get', 'url' => '/api/v{apiVersion}/config', 'verb' => 'GET'],
Expand Down
9 changes: 3 additions & 6 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
use OCP\Capabilities\ICapability;

class Capabilities implements ICapability {

/** @var IAppManager */
private $appManager;
/** @var PermissionService */
private $permissionService;
private IAppManager $appManager;
private PermissionService $permissionService;


public function __construct(IAppManager $appManager, PermissionService $permissionService) {
Expand All @@ -27,7 +24,7 @@ public function __construct(IAppManager $appManager, PermissionService $permissi
/**
* Function an app uses to return the capabilities
*
* @return array{deck: array{version: string, canCreateBoards: bool, apiVersions: array<string>}}
* @return array{deck: array{version: string, canCreateBoards: bool, supportsDoneColumn:true, apiVersions: array<string>}}
* @since 8.2.0
*/
public function getCapabilities() {
Expand Down
16 changes: 0 additions & 16 deletions lib/Controller/BoardOcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\ExternalBoardService;
use OCA\Deck\Service\StackService;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\PublicPage;
Expand All @@ -26,7 +25,6 @@ public function __construct(
private BoardService $boardService,
private ExternalBoardService $externalBoardService,
private LoggerInterface $logger,
private StackService $stackService,
private $userId,
) {
parent::__construct($appName, $request);
Expand Down Expand Up @@ -58,20 +56,6 @@ public function create(string $title, string $color): DataResponse {
return new DataResponse($this->boardService->create($title, $this->userId, $color));
}

#[NoAdminRequired]
#[PublicPage]
#[NoCSRFRequired]
#[RequestHeader(name: 'x-nextcloud-federation', description: 'Set to 1 when the request is performed by another Nextcloud Server to indicate a federation request', indirect: true)]
public function stacks(int $boardId): DataResponse {
$localBoard = $this->boardService->find($boardId, true, true);
// Board on other instance -> get it from other instance
if ($localBoard->getExternalId() !== null) {
return $this->externalBoardService->getExternalStacksFromRemote($localBoard);
} else {
return new DataResponse($this->stackService->findAll($boardId));
}
}

#[NoAdminRequired]
#[NoCSRFRequired]
public function addAcl(int $boardId, int $type, string $participant, bool $permissionEdit, bool $permissionShare, bool $permissionManage, ?string $remote = null): DataResponse {
Expand Down
1 change: 1 addition & 0 deletions lib/Controller/StackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ public function delete(int $stackId): Stack {
public function deleted(int $boardId): array {
return $this->stackService->fetchDeleted($boardId);
}

}
27 changes: 27 additions & 0 deletions lib/Controller/StackOcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ public function __construct(
parent::__construct($appName, $request);
}

#[NoAdminRequired]
#[PublicPage]
#[NoCSRFRequired]
#[RequestHeader(name: 'x-nextcloud-federation', description: 'Set to 1 when the request is performed by another Nextcloud Server to indicate a federation request', indirect: true)]
public function index(int $boardId): DataResponse {
$localBoard = $this->boardService->find($boardId, true, true);
if ($localBoard->getExternalId() !== null) {
return $this->externalBoardService->getExternalStacksFromRemote($localBoard);
} else {
return new DataResponse($this->stackService->findAll($boardId));
}
}

#[NoAdminRequired]
#[PublicPage]
#[NoCSRFRequired]
Expand All @@ -44,6 +57,20 @@ public function create(string $title, int $boardId, int $order = 0):DataResponse
};
}

#[NoAdminRequired]
#[PublicPage]
#[NoCSRFRequired]
#[RequestHeader(name: 'x-nextcloud-federation', description: 'Set to 1 when the request is performed by another Nextcloud Server to indicate a federation request', indirect: true)]
public function setDoneStack(int $stackId, int $boardId, bool $isDone): DataResponse {
$board = $this->boardService->find($boardId, false);
if ($board->getExternalId()) {
$result = $this->externalBoardService->setDoneStackOnRemote($board, $stackId, $isDone);
return new DataResponse($result);
}
$this->stackService->setDoneStack($stackId, $boardId, $isDone);
return new DataResponse();
}

#[NoAdminRequired]
#[PublicPage]
#[NoCSRFRequired]
Expand Down
4 changes: 4 additions & 0 deletions lib/Db/Stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @method \int getOrder()
* @method void setOrder(int $order)
* @method Card[] getCards()
* @method bool getIsDoneColumn()
* @method void setIsDoneColumn(bool $isDoneColumn)
*/
class Stack extends RelationalEntity {
protected $title;
Expand All @@ -30,13 +32,15 @@ class Stack extends RelationalEntity {
protected $lastModified = 0;
protected $cards = [];
protected $order;
protected $isDoneColumn = false;

public function __construct() {
$this->addType('id', 'integer');
$this->addType('boardId', 'integer');
$this->addType('deletedAt', 'integer');
$this->addType('lastModified', 'integer');
$this->addType('order', 'integer');
$this->addType('isDoneColumn', 'boolean');
}

public function setCards($cards) {
Expand Down
30 changes: 30 additions & 0 deletions lib/Db/StackMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,36 @@ public function update(Entity $entity): Entity {
return $result;
}

public function clearDoneColumnForBoard(int $boardId): void {
$qb = $this->db->getQueryBuilder();
$qb->update($this->getTableName())
->set('is_done_column', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL))
->where($qb->expr()->eq('board_id', $qb->createNamedParameter($boardId, IQueryBuilder::PARAM_INT)))
->executeStatement();
}

public function setIsDoneColumn(int $stackId, bool $isDone): void {
$qb = $this->db->getQueryBuilder();
$qb->update($this->getTableName())
->set('is_done_column', $qb->createNamedParameter($isDone, IQueryBuilder::PARAM_BOOL))
->where($qb->expr()->eq('id', $qb->createNamedParameter($stackId, IQueryBuilder::PARAM_INT)))
->executeStatement();
}

public function findDoneColumnForBoard(int $boardId): ?Stack {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('board_id', $qb->createNamedParameter($boardId, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->eq('is_done_column', $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL)))
->andWhere($qb->expr()->eq('deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)));
try {
return $this->findEntity($qb);
} catch (DoesNotExistException|MultipleObjectsReturnedException $e) {
return null;
}
}

public function delete(Entity $entity): Entity {
// delete cards on stack
$this->cardMapper->deleteByStack($entity->getId());
Expand Down
30 changes: 30 additions & 0 deletions lib/Migration/Version11002Date20260228000000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

declare(strict_types=1);
namespace OCA\Deck\Migration;

use Closure;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version11002Date20260228000000 extends SimpleMigrationStep {
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
$schema = $schemaClosure();

if ($schema->hasTable('deck_stacks')) {
$table = $schema->getTable('deck_stacks');
if (!$table->hasColumn('is_done_column')) {
$table->addColumn('is_done_column', 'boolean', [
'notnull' => false,
'default' => false,
]);
}
}
return $schema;
}
}
23 changes: 23 additions & 0 deletions lib/Service/CardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,21 @@ public function reorder(int $id, int $stackId, int $order): array {
throw new StatusException('Operation not allowed. This card is archived.');
}
$changes = new ChangeSet($card);
$oldStackId = $card->getStackId();
$card->setStackId($stackId);

if ($stackId !== $oldStackId) {
$newStack = $this->stackMapper->find($stackId);
if ($newStack->getIsDoneColumn()) {
$card->setDone(new \DateTime());
} else {
$oldStack = $this->stackMapper->find($oldStackId);
if ($oldStack->getIsDoneColumn()) {
$card->setDone(null);
}
}
}

$this->cardMapper->update($card);
$changes->setAfter($card);
$this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_CARD, $changes, ActivityManager::SUBJECT_CARD_UPDATE);
Expand Down Expand Up @@ -533,6 +547,15 @@ public function done(int $id): Card {
$changes = new ChangeSet($card);
$card->setDone(new \DateTime());
$newCard = $this->cardMapper->update($card);
// Auto-move to done column if one is configured and card is not already there
$currentStack = $this->stackMapper->find($newCard->getStackId());
if (!$currentStack->getIsDoneColumn()) {
$doneStack = $this->stackMapper->findDoneColumnForBoard($currentStack->getBoardId());
if ($doneStack !== null) {
$newCard->setStackId($doneStack->getId());
$newCard = $this->cardMapper->update($newCard);
}
}
$this->notificationHelper->markDuedateAsRead($card);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $newCard, ActivityManager::SUBJECT_CARD_UPDATE_DONE);
$this->changeHelper->cardChanged($id, false);
Expand Down
33 changes: 33 additions & 0 deletions lib/Service/ExternalBoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,39 @@ public function createStackOnRemote(
return $this->localizeRemoteStacks([$stack], $localBoard)[0];
}

public function getRemoteCapabilities(Board $localBoard): array {
$ownerCloudId = $this->cloudIdManager->resolveCloudId($localBoard->getOwner());
$url = $ownerCloudId->getRemote() . '/ocs/v2.php/cloud/capabilities';
$resp = $this->proxy->get('', '', $url);
$data = $this->proxy->getOCSData($resp);
return $data['capabilities']['deck'] ?? [];
}

public function remoteSupportsCapability(Board $localBoard, string $capability): bool {
$capabilities = $this->getRemoteCapabilities($localBoard);
return !empty($capabilities[$capability]);
}

public function setDoneStackOnRemote(Board $localBoard, int $stackId, bool $isDone): array {
$this->configService->ensureFederationEnabled();
$this->permissionService->checkPermission($this->boardMapper, $localBoard->getId(), Acl::PERMISSION_MANAGE, $this->userId, false, false);

if (!$this->remoteSupportsCapability($localBoard, 'supportsDoneColumn')) {
throw new \Exception('Remote server does not support the done column feature');
}

$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/' . $stackId . '/done';
$params = [
'boardId' => $localBoard->getExternalId(),
'isDone' => $isDone,
];
$resp = $this->proxy->put($participantCloudId->getId(), $shareToken, $url, $params);
return $this->proxy->getOcsData($resp);
}

public function deleteStackOnRemote(Board $localBoard, int $stackId): array {
$this->configService->ensureFederationEnabled();
$this->permissionService->checkPermission($this->boardMapper, $localBoard->getId(), Acl::PERMISSION_EDIT, $this->userId, false, false);
Expand Down
33 changes: 33 additions & 0 deletions lib/Service/StackService.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,37 @@ public function reorder(int $id, int $order): array {

return $result;
}

/**
* Set or unset a stack as the "done column" for the board
*
* @throws StatusException
* @throws \OCA\Deck\NoPermissionException
* @throws \OCP\AppFramework\Db\DoesNotExistException
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws BadRequestException
*/
public function setDoneStack(int $stackId, int $boardId, bool $isDone): void {
$this->permissionService->checkPermission($this->stackMapper, $stackId, Acl::PERMISSION_MANAGE);

if ($this->boardService->isArchived($this->stackMapper, $stackId)) {
throw new NoPermissionException('Operation not allowed. This board is archived.');
}

if ($isDone) {
$this->stackMapper->clearDoneColumnForBoard($boardId);
// Mark all existing cards in the stack as done
/** @var Card $card */
foreach ($this->cardMapper->findAll($stackId) as $card) {
if ($card->getDone() === null) {
$card->setDone(new \DateTime());
$this->cardMapper->update($card);
}
}
}

$this->stackMapper->setIsDoneColumn($stackId, $isDone);
$this->changeHelper->boardChanged($boardId);
$this->eventDispatcher->dispatchTyped(new BoardUpdatedEvent($boardId));
}
}
Loading
Loading