Skip to content

Commit 041f3e6

Browse files
authored
Merge pull request #5440 from nextcloud/backport/5296/stable25
[stable25] Fix small issues around delete/undo
2 parents 9b78550 + 23901ff commit 041f3e6

8 files changed

Lines changed: 36 additions & 14 deletions

File tree

.github/workflows/phpunit.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ jobs:
7070
path: apps/${{ env.APP_NAME }}
7171

7272
- name: Set up php ${{ matrix.php-versions }}
73-
uses: shivammathur/setup-php@2.21.2
73+
uses: shivammathur/setup-php@2.24.0
7474
with:
7575
php-version: ${{ matrix.php-versions }}
7676
tools: phpunit
7777
extensions: zip, gd, mbstring, iconv, fileinfo, intl, sqlite, pdo_sqlite, mysql, pdo_mysql, pgsql, pdo_pgsql
78+
ini-file: development
7879
coverage: none
7980

8081
- name: Set up PHPUnit

lib/Collaboration/Resources/ResourceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function canAccessResource(IResource $resource, ?IUser $user): bool {
111111

112112
private function getBoard(IResource $resource) {
113113
try {
114-
return $this->boardMapper->find($resource->getId(), false, true);
114+
return $this->boardMapper->find((int)$resource->getId(), false, true);
115115
} catch (DoesNotExistException $e) {
116116
} catch (MultipleObjectsReturnedException $e) {
117117
return null;

lib/Db/BoardMapper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ public function __construct(
7979
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
8080
* @throws DoesNotExistException
8181
*/
82-
public function find($id, $withLabels = false, $withAcl = false): Board {
82+
public function find(int $id, bool $withLabels = false, bool $withAcl = false, bool $allowDeleted = false): Board {
8383
if (!isset($this->boardCache[$id])) {
8484
$qb = $this->db->getQueryBuilder();
85+
$deletedWhere = $allowDeleted ? $qb->expr()->gte('deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)) : $qb->expr()->eq('deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT));
8586
$qb->select('*')
8687
->from('deck_boards')
8788
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
89+
->andWhere($deletedWhere)
8890
->orderBy('id');
8991
$this->boardCache[$id] = $this->findEntity($qb);
9092
}

lib/Service/BoardService.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function findAll($since = -1, $details = null, $includeArchived = true) {
183183
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
184184
* @throws BadRequestException
185185
*/
186-
public function find($boardId) {
186+
public function find($boardId, bool $allowDeleted = false) {
187187
$this->boardServiceValidator->check(compact('boardId'));
188188
if ($this->boardsCache && isset($this->boardsCache[$boardId])) {
189189
return $this->boardsCache[$boardId];
@@ -194,7 +194,7 @@ public function find($boardId) {
194194

195195
$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ);
196196
/** @var Board $board */
197-
$board = $this->boardMapper->find($boardId, true, true);
197+
$board = $this->boardMapper->find((int)$boardId, true, true, $allowDeleted);
198198
$this->boardMapper->mapOwner($board);
199199
if ($board->getAcl() !== null) {
200200
foreach ($board->getAcl() as $acl) {
@@ -369,7 +369,7 @@ public function deleteUndo($id) {
369369
$this->boardServiceValidator->check(compact('id'));
370370

371371
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
372-
$board = $this->find($id);
372+
$board = $this->find($id, true);
373373
$board->setDeletedAt(0);
374374
$board = $this->boardMapper->update($board);
375375
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $board, ActivityManager::SUBJECT_BOARD_RESTORE);
@@ -390,7 +390,7 @@ public function deleteForce($id) {
390390
$this->boardServiceValidator->check(compact('id'));
391391

392392
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
393-
$board = $this->find($id);
393+
$board = $this->find($id, true);
394394
$delete = $this->boardMapper->delete($board);
395395

396396
return $delete;

lib/Service/CardService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ public function update($id, $title, $stackId, $type, $owner, $description = '',
277277
if ($archived !== null && $card->getArchived() && $archived === true) {
278278
throw new StatusException('Operation not allowed. This card is archived.');
279279
}
280+
281+
if ($card->getDeletedAt() !== 0) {
282+
if ($deletedAt === null) {
283+
// Only allow operations when restoring the card
284+
throw new StatusException('Operation not allowed. This card was deleted.');
285+
}
286+
}
287+
280288
$changes = new ChangeSet($card);
281289
if ($card->getLastEditor() !== $this->currentUser && $card->getLastEditor() !== null) {
282290
$this->activityManager->triggerEvent(

lib/Service/PermissionService.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ public function userIsBoardOwner($boardId, $userId = null) {
194194
* @throws MultipleObjectsReturnedException
195195
* @throws DoesNotExistException
196196
*/
197-
private function getBoard($boardId): Board {
198-
if (!isset($this->boardCache[$boardId])) {
199-
$this->boardCache[$boardId] = $this->boardMapper->find($boardId, false, true);
197+
private function getBoard(int $boardId): Board {
198+
if (!isset($this->boardCache[(string)$boardId])) {
199+
$this->boardCache[(string)$boardId] = $this->boardMapper->find($boardId, false, true);
200200
}
201-
return $this->boardCache[$boardId];
201+
return $this->boardCache[(string)$boardId];
202202
}
203203

204204
/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
68024

tests/unit/Activity/ActivityManagerTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ private function expectEventCreation($subject, $subjectParams) {
131131

132132
public function testCreateEvent() {
133133
$board = new Board();
134+
$board->setId(123);
134135
$board->setTitle('');
135136
$this->boardMapper->expects(self::once())
136137
->method('find')
@@ -148,6 +149,7 @@ public function testCreateEvent() {
148149

149150
public function testCreateEventDescription() {
150151
$board = new Board();
152+
$board->setId(123);
151153
$board->setTitle('');
152154
$this->boardMapper->expects(self::once())
153155
->method('find')
@@ -162,7 +164,9 @@ public function testCreateEventDescription() {
162164
->method('find')
163165
->willReturn($card);
164166

165-
$stack = Stack::fromRow([]);
167+
$stack = Stack::fromRow([
168+
'boardId' => 123,
169+
]);
166170
$this->stackMapper->expects(self::any())
167171
->method('find')
168172
->willReturn($stack);
@@ -192,6 +196,7 @@ public function testCreateEventDescription() {
192196

193197
public function testCreateEventLongDescription() {
194198
$board = new Board();
199+
$board->setId(123);
195200
$board->setTitle('');
196201
$this->boardMapper->expects(self::once())
197202
->method('find')
@@ -205,7 +210,9 @@ public function testCreateEventLongDescription() {
205210
->method('find')
206211
->willReturn($card);
207212

208-
$stack = new Stack();
213+
$stack = Stack::fromRow([
214+
'boardId' => 123,
215+
]);
209216
$this->stackMapper->expects(self::any())
210217
->method('find')
211218
->willReturn($stack);
@@ -235,6 +242,7 @@ public function testCreateEventLongDescription() {
235242

236243
public function testCreateEventLabel() {
237244
$board = Board::fromRow([
245+
'id' => 123,
238246
'title' => 'My board'
239247
]);
240248
$this->boardMapper->expects(self::once())
@@ -249,7 +257,9 @@ public function testCreateEventLabel() {
249257
->method('find')
250258
->willReturn($card);
251259

252-
$stack = Stack::fromParams([]);
260+
$stack = Stack::fromRow([
261+
'boardId' => 123,
262+
]);
253263
$this->stackMapper->expects(self::any())
254264
->method('find')
255265
->willReturn($stack);

0 commit comments

Comments
 (0)