Skip to content

Commit 2a82fa8

Browse files
committed
wip: delete stacks on remote shares
Signed-off-by: grnd-alt <github@belakkaf.net>
1 parent f721f5e commit 2a82fa8

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

appinfo/routes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@
139139
['name' => 'new_card#create', 'url' => '/api/v{apiVersion}/cards', 'verb' => 'POST'],
140140

141141
['name' => 'new_stack#create', 'url' => '/api/v{apiVersion}/stacks', 'verb' => 'POST'],
142+
['name' => 'new_stack#delete', 'url' => '/api/v{apiVersion}/stacks/{stackId}', 'verb' => 'DELETE'],
143+
['name' => 'new_stack#delete', 'url' => '/api/v{apiVersion}/stacks/{stackId}/{boardId}', 'verb' => 'DELETE'],
142144

143145
['name' => 'Config#get', 'url' => '/api/v{apiVersion}/config', 'verb' => 'GET'],
144146
['name' => 'Config#setValue', 'url' => '/api/v{apiVersion}/config/{key}', 'verb' => 'POST'],

lib/Controller/NewStackController.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,21 @@ public function create(string $title, int $boardId, int $order = 0) {
3838
return new DataResponse($stack);
3939
};
4040
}
41+
42+
#[NoAdminRequired]
43+
#[PublicPage]
44+
#[NoCSRFRequired]
45+
#[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)]
46+
public function delete(int $stackId, ?int $boardId = null) {
47+
if ($boardId) {
48+
$board = $this->boardService->find($boardId, false);
49+
if ($board->getExternalId()) {
50+
$result = $this->externalBoardService->deleteStackOnRemote($board, $stackId);
51+
return new DataResponse($result);
52+
}
53+
}
54+
$result = $this->stackService->delete($stackId);
55+
return new DataResponse($result);
56+
}
57+
4158
}

lib/Federation/DeckFederationProxy.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ public function get(string $cloudId, string $shareToken, string $url, array $par
108108
public function post(string $cloudId, string $shareToken, string $url, array $params = []):IResponse {
109109
return $this->request("post", $cloudId, $shareToken, $url, $params);
110110
}
111+
public function delete(string $cloudId, string $shareToken, string $url, array $params = []):IResponse {
112+
return $this->request("delete", $cloudId, $shareToken, $url, $params);
113+
}
111114
public function getOCSData(IResponse $response, array $allowedStatusCodes = [Http::STATUS_OK]): array {
112115
if (!in_array($response->getStatusCode(), $allowedStatusCodes, true)) {
113116
$this->logUnexpectedStatusCode(__METHOD__, $response->getStatusCode());

lib/Service/ExternalBoardService.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,13 @@ public function createStackOnRemote(
9696
$stack = $this->proxy->getOcsData($resp);
9797
return $this->localizeRemoteStacks([$stack], $localBoard)[0];
9898
}
99+
100+
public function deleteStackOnRemote(Board $localBoard, int $stackId): array {
101+
$shareToken = $localBoard->getShareToken();
102+
$participantCloudId = $this->cloudIdManager->getCloudId($this->userId, null);
103+
$ownerCloudId = $this->cloudIdManager->resolveCloudId($localBoard->getOwner());
104+
$url = $ownerCloudId->getRemote() . "/ocs/v2.php/apps/deck/api/v1.0/stacks/" . $stackId;
105+
$resp = $this->proxy->delete($participantCloudId->getId(), $shareToken, $url, []);
106+
return $this->proxy->getOcsData($resp);
107+
}
99108
}

0 commit comments

Comments
 (0)