-
Notifications
You must be signed in to change notification settings - Fork 327
Expand file tree
/
Copy pathCardOcsController.php
More file actions
142 lines (125 loc) · 4.3 KB
/
CardOcsController.php
File metadata and controls
142 lines (125 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Deck\Controller;
use OCA\Deck\Model\OptionalNullableValue;
use OCA\Deck\Service\BoardService;
use OCA\Deck\Service\CardService;
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;
use OCP\AppFramework\Http\Attribute\RequestHeader;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
class CardOcsController extends OCSController {
public function __construct(
string $appName,
IRequest $request,
private CardService $cardService,
private StackService $stackService,
private BoardService $boardService,
private ExternalBoardService $externalBoardService,
private ?string $userId,
) {
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 create(string $title, int $stackId, ?int $boardId = null, ?string $type = 'plain', ?string $owner = null, ?int $order = 999, ?string $description = '', $duedate = null, $startdate = null, ?array $labels = [], ?array $users = []) {
if ($boardId) {
$board = $this->boardService->find($boardId, false);
if ($board->getExternalId()) {
$card = $this->externalBoardService->createCardOnRemote($board, $title, $stackId, $type, $order, $description, $duedate, $users);
return new DataResponse($card);
}
}
if (!$owner) {
$owner = $this->userId;
}
$card = $this->cardService->create($title, $stackId, $type, $order, $owner, $description, $duedate, $startdate);
// foreach ($labels as $label) {
// $this->assignLabel($card->getId(), $label);
// }
// foreach ($users as $user) {
// $this->assignmentService->assignUser($card->getId(), $user['id'], $user['type']);
// }
return new DataResponse($card);
}
#[NoAdminRequired]
#[PublicPage]
#[NoCSRFRequired]
public function assignLabel(?int $boardId, int $cardId, int $labelId): DataResponse {
if ($boardId) {
$board = $this->boardService->find($boardId, false);
if ($board->getExternalId()) {
return new DataResponse($this->externalBoardService->assignLabelOnRemote($board, $cardId, $labelId));
}
}
return new DataResponse($this->cardService->assignLabel($cardId, $labelId));
}
#[NoAdminRequired]
#[PublicPage]
#[NoCSRFRequired]
public function removeLabel(?int $boardId, int $cardId, int $labelId): DataResponse {
if ($boardId) {
$board = $this->boardService->find($boardId, false);
if ($board->getExternalId()) {
return new DataResponse($this->externalBoardService->removeLabelOnRemote($board, $cardId, $labelId));
}
}
return new DataResponse($this->cardService->removeLabel($cardId, $labelId));
}
#[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 update(int $id, string $title, int $stackId, string $type, int $order, string $description, $duedate, $deletedAt, int $boardId, array|string|null $owner = null, $archived = null, $startdate = null): DataResponse {
$done = array_key_exists('done', $this->request->getParams())
? new OptionalNullableValue($this->request->getParam('done', null))
: null;
if (!$owner) {
$owner = $this->userId;
} else {
if (!is_string($owner)) {
$owner = $owner['uid'];
}
}
$localBoard = $this->boardService->find($boardId, false);
if ($localBoard->getExternalId()) {
return new DataResponse($this->externalBoardService->updateCardOnRemote(
$localBoard,
$id,
$title,
$stackId,
$type,
$owner,
$description,
$order,
$duedate,
$deletedAt,
$archived,
$done
));
}
return new DataResponse($this->cardService->update($id,
$title,
$stackId,
$type,
$owner,
$description,
$order,
$duedate,
$deletedAt,
$archived,
$done,
$startdate
));
}
}