Skip to content
Merged
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
2 changes: 2 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,11 @@
['name' => 'card_ocs#update', 'url' => '/api/v{apiVersion}/cards/{cardId}', 'verb' => 'PUT'],
['name' => 'card_ocs#assignLabel', 'url' => '/api/v{apiVersion}/cards/{cardId}/label/{labelId}', 'verb' => 'POST'],
['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' => 'stack_ocs#create', 'url' => '/api/v{apiVersion}/stacks', 'verb' => 'POST'],
['name' => 'stack_ocs#delete', 'url' => '/api/v{apiVersion}/stacks/{stackId}/{boardId}', 'verb' => 'DELETE', 'defaults' => ['boardId' => null]],
['name' => 'stack_ocs#reorder', 'url' => '/api/v{apiVersion}/stacks/{stackId}/reorder', 'verb' => 'PUT'],

['name' => 'Config#get', 'url' => '/api/v{apiVersion}/config', 'verb' => 'GET'],
['name' => 'Config#setValue', 'url' => '/api/v{apiVersion}/config/{key}', 'verb' => 'POST'],
Expand Down
13 changes: 13 additions & 0 deletions lib/Controller/CardOcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,17 @@ public function update(int $id, string $title, int $stackId, string $type, int $
$done
));
}

#[NoAdminRequired]
#[PublicPage]
#[NoCSRFRequired]
public function reorder(int $cardId, int $stackId, int $order, ?int $boardId): DataResponse {
if ($boardId) {
$board = $this->boardService->find($boardId, false);
if ($board->getExternalId()) {
return new DataResponse($this->externalBoardService->reorderCardOnRemote($board, $cardId, $stackId, $order));
}
}
return new DataResponse($this->cardService->reorder($cardId, $stackId, $order));
}
}
17 changes: 17 additions & 0 deletions lib/Controller/StackOcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,21 @@ public function delete(int $stackId, ?int $boardId = null):DataResponse {
return new DataResponse($result);
}


#[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 reorder(int $stackId, int $order, ?int $boardId):DataResponse {
if ($boardId !== null) {
$board = $this->boardService->find($boardId, false);
if ($board->getExternalId()) {
$stacks = $this->externalBoardService->reorderStackOnRemote($board, $stackId, $order);
return new DataResponse($stacks);
}
}
$stacks = $this->stackService->reorder($stackId, $order);
return new DataResponse($stacks);
}

}
31 changes: 31 additions & 0 deletions lib/Service/ExternalBoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,35 @@ public function deleteStackOnRemote(Board $localBoard, int $stackId): array {
$resp = $this->proxy->delete($participantCloudId->getId(), $shareToken, $url, []);
return $this->proxy->getOcsData($resp);
}

public function reorderCardOnRemote(Board $localBoard, int $cardId, int $stackId, int $order): 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 . '/reorder';
$params = [
'stackId' => $stackId,
'order' => $order,
'boardId' => $localBoard->getExternalId(),
];
$resp = $this->proxy->put($participantCloudId->getId(), $shareToken, $url, $params);
return $this->proxy->getOcsData($resp);
}

public function reorderStackOnRemote(Board $localBoard, int $stackId, int $order): 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/stacks/' . $stackId . '/reorder';
$params = [
'order' => $order,
'boardId' => $localBoard->getExternalId(),
];
$resp = $this->proxy->put($participantCloudId->getId(), $shareToken, $url, $params);
return $this->proxy->getOcsData($resp);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also add a helper function like 'reorderRemote' for the shared code, and just pass params to it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is a bit duplicated but have very different semantics for calling the endpoint for either cards or stacks so I think having a clear separation by functions makes sense? arguably getting the shareToken and cloudId etc. could be unified, but that would apply to all functions in here so I'd say not to do that here.

}
6 changes: 3 additions & 3 deletions src/services/CardApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ export class CardApi {
})
}

reorderCard(card) {
return axios.put(this.url(`/cards/${card.id}/reorder`), card)
reorderCard(card, boardId) {
return axios.put(this.ocsUrl(`/cards/${card.id}/reorder`), { ...card, boardId: boardId ?? null })
.then(
(response) => {
return Promise.resolve(response.data)
return Promise.resolve(response.data.ocs.data)
},
(err) => {
return Promise.reject(err)
Expand Down
6 changes: 3 additions & 3 deletions src/services/StackApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ export class StackApi {
})
}

reorderStack(stackId, order) {
return axios.put(this.url(`/stacks/${stackId}/reorder`), { order })
reorderStack(stackId, order, boardId) {
return axios.put(this.ocsUrl(`/stacks/${stackId}/reorder`), { order, boardId: boardId ?? null })
.then(
(response) => {
return Promise.resolve(response.data)
return Promise.resolve(response.data.ocs.data)
},
(err) => {
return Promise.reject(err)
Expand Down
3 changes: 2 additions & 1 deletion src/store/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ export default function cardModuleFactory() {
newCards.push(card)
await commit('updateCardsReorder', newCards)

apiClient.reorderCard(card).then((cards) => {
const stack = getters.stackById(card.stackId)
apiClient.reorderCard(card, stack.boardId).then((cards) => {
commit('updateCardsReorder', Object.values(cards))
})
},
Expand Down
2 changes: 1 addition & 1 deletion src/store/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function stackModuleFactory() {
actions: {
orderStack({ commit }, { stack, removedIndex, addedIndex }) {
commit('orderStack', { stack, removedIndex, addedIndex })
apiClient.reorderStack(stack.id, addedIndex)
apiClient.reorderStack(stack.id, addedIndex, stack.boardId)
.catch((err) => {
OC.Notification.showTemporary('Failed to change order')
console.error(err.response.data.message)
Expand Down
Loading