Skip to content

Commit 00381ef

Browse files
committed
fix: Limit card activities for deleted cards
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent f4791aa commit 00381ef

4 files changed

Lines changed: 53 additions & 2 deletions

File tree

lib/Activity/ActivityManager.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use OCA\Deck\Db\Label;
3939
use OCA\Deck\Db\Stack;
4040
use OCA\Deck\Db\StackMapper;
41+
use OCA\Deck\NoPermissionException;
4142
use OCA\Deck\Service\PermissionService;
4243
use OCP\Activity\IEvent;
4344
use OCP\Activity\IManager;
@@ -564,4 +565,24 @@ private function findDetailsForAcl($aclId) {
564565
'board' => $board
565566
];
566567
}
568+
569+
public function canSeeCardActivity($cardId) {
570+
try {
571+
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_READ);
572+
$card = $this->cardMapper->find($cardId);
573+
return $card->getDeletedAt() === 0;
574+
} catch (NoPermissionException $e) {
575+
return false;
576+
}
577+
}
578+
579+
public function canSeeBoardActivity($boardId) {
580+
try {
581+
$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ);
582+
$board = $this->boardMapper->find($boardId);
583+
return $board->getDeletedAt() === 0;
584+
} catch (NoPermissionException $e) {
585+
return false;
586+
}
587+
}
567588
}

lib/Activity/DeckProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public function parse($language, IEvent $event, IEvent $previousEvent = null): I
111111
$event->setAuthor($author);
112112
}
113113
if ($event->getObjectType() === ActivityManager::DECK_OBJECT_BOARD) {
114+
if (!$this->activityManager->canSeeBoardActivity($event->getObjectId())) {
115+
throw new \InvalidArgumentException();
116+
}
114117
if (isset($subjectParams['board']) && $event->getObjectName() === '') {
115118
$event->setObject($event->getObjectType(), $event->getObjectId(), $subjectParams['board']['title']);
116119
}
@@ -125,6 +128,9 @@ public function parse($language, IEvent $event, IEvent $previousEvent = null): I
125128
}
126129

127130
if (isset($subjectParams['card']) && $event->getObjectType() === ActivityManager::DECK_OBJECT_CARD) {
131+
if (!$this->activityManager->canSeeCardActivity($event->getObjectId())) {
132+
throw new \InvalidArgumentException();
133+
}
128134
if ($event->getObjectName() === '') {
129135
$event->setObject($event->getObjectType(), $event->getObjectId(), $subjectParams['card']['title']);
130136
}

tests/integration/features/bootstrap/BoardContext.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class BoardContext implements Context {
1717
/** @var array last card response */
1818
private $card = null;
1919
private array $storedCards = [];
20+
private ?array $activities = null;
2021

21-
/** @var ServerContext */
22-
private $serverContext;
22+
private ServerContext $serverContext;
2323

2424
/** @BeforeScenario */
2525
public function gatherContexts(BeforeScenarioScope $scope) {
@@ -303,4 +303,23 @@ public function deleteTheCard() {
303303
public function deleteTheBoard() {
304304
$this->requestContext->sendJSONrequest('DELETE', '/index.php/apps/deck/boards/' . $this->board['id']);
305305
}
306+
307+
308+
/**
309+
* @Given /^get the activities for the last card$/
310+
*/
311+
public function getActivitiesForTheLastCard() {
312+
$card = $this->getLastUsedCard();
313+
$this->requestContext->sendOCSRequest('GET', '/apps/activity/api/v2/activity/filter?format=json&type=deck&since=0&object_type=deck_card&object_id=' . $card['id'] . '&limit=50');
314+
$this->activities = json_decode((string)$this->getResponse()->getBody(), true)['ocs']['data'] ?? null;
315+
}
316+
317+
/**
318+
* @Then the fetched activities should have :count entries
319+
*/
320+
public function theFetchedActivitiesShouldHaveEntries($count) {
321+
Assert::assertEquals($count, count($this->activities ?? []));
322+
}
323+
324+
306325
}

tests/integration/features/decks.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,13 @@ Feature: decks
103103
And uploads an attachment to the last used card
104104
And remember the last attachment as "my-attachment"
105105
And post a comment with content "My first comment" on the card
106+
When get the activities for the last card
107+
Then the fetched activities should have 3 entries
106108
And delete the card
107109

110+
When get the activities for the last card
111+
Then the fetched activities should have 0 entries
112+
108113
When fetching the attachment "my-attachment" for the card "deletedCard"
109114
Then the response should have a status code 403
110115

0 commit comments

Comments
 (0)