From 49946f69add611ee026d665e786d0be539bd8916 Mon Sep 17 00:00:00 2001 From: Anna Larch Date: Tue, 10 Mar 2026 01:27:09 +0100 Subject: [PATCH 1/2] feat(rss): add filter to rss feed, allowing share only feed Fix https://github.com/nextcloud/activity/issues/464 Signed-off-by: Anna Larch --- lib/Controller/FeedController.php | 5 +-- tests/Controller/FeedControllerTest.php | 48 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php index 2357a63c6..982d7f878 100644 --- a/lib/Controller/FeedController.php +++ b/lib/Controller/FeedController.php @@ -47,7 +47,7 @@ public function __construct( #[PublicPage] #[NoCSRFRequired] #[BruteForceProtection('activityRssFeed')] - public function show(): TemplateResponse { + public function show(string $filter = 'all'): TemplateResponse { $response = new TemplateResponse('activity', 'rss', [], ''); try { $user = $this->activityManager->getCurrentUserId(); @@ -57,8 +57,9 @@ public function show(): TemplateResponse { $this->l = $this->l10nFactory->get('activity', $userLang); $this->helper->setL10n($this->l); + $filter = $this->data->validateFilter($filter); $description = $this->l->t('Personal activity feed for %s', $user); - $data = $this->data->get($this->helper, $this->settings, $user, 0, self::DEFAULT_PAGE_SIZE, 'desc', 'all'); + $data = $this->data->get($this->helper, $this->settings, $user, 0, self::DEFAULT_PAGE_SIZE, 'desc', $filter); $activities = $data['data']; } catch (\UnexpectedValueException $e) { $this->l = $this->l10nFactory->get('activity'); diff --git a/tests/Controller/FeedControllerTest.php b/tests/Controller/FeedControllerTest.php index 2a4394016..1fad583e8 100644 --- a/tests/Controller/FeedControllerTest.php +++ b/tests/Controller/FeedControllerTest.php @@ -143,6 +143,54 @@ public function testShowNoToken(?string $acceptHeader, string $expectedHeader): $this->assertStringContainsString($description, $renderedResponse); } + public function testShowWithFilter(): void { + $this->mockUserSession('test'); + $this->data + ->method('validateFilter') + ->with('files') + ->willReturn('files'); + $this->data + ->expects($this->once()) + ->method('get') + ->with($this->helper, $this->userSettings, 'test', 0, FeedController::DEFAULT_PAGE_SIZE, 'desc', 'files') + ->willReturn(['data' => []]); + + $templateResponse = $this->controller->show('files'); + $this->assertInstanceOf(TemplateResponse::class, $templateResponse); + } + + public function testShowWithInvalidFilter(): void { + $this->mockUserSession('test'); + $this->data + ->method('validateFilter') + ->with('invalid_filter') + ->willReturn('all'); + $this->data + ->expects($this->once()) + ->method('get') + ->with($this->helper, $this->userSettings, 'test', 0, FeedController::DEFAULT_PAGE_SIZE, 'desc', 'all') + ->willReturn(['data' => []]); + + $templateResponse = $this->controller->show('invalid_filter'); + $this->assertInstanceOf(TemplateResponse::class, $templateResponse); + } + + public function testShowDefaultsToAllFilter(): void { + $this->mockUserSession('test'); + $this->data + ->method('validateFilter') + ->with('all') + ->willReturn('all'); + $this->data + ->expects($this->once()) + ->method('get') + ->with($this->helper, $this->userSettings, 'test', 0, FeedController::DEFAULT_PAGE_SIZE, 'desc', 'all') + ->willReturn(['data' => []]); + + $templateResponse = $this->controller->show(); + $this->assertInstanceOf(TemplateResponse::class, $templateResponse); + } + protected function mockUserSession(string $user): void { $mockUser = $this->createMock(IUser::class); $mockUser From 2da068674cdc7757c92e60e4416b0a609443ed5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 15 Sep 2026 09:56:54 +0200 Subject: [PATCH 2/2] chore: Type method validateFilter and mock it properly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/Data.php | 9 +-------- tests/Controller/FeedControllerTest.php | 3 +++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/Data.php b/lib/Data.php index d19359696..b10278b82 100644 --- a/lib/Data.php +++ b/lib/Data.php @@ -615,15 +615,8 @@ public function countDownloads(string $user, int $objectId, ?int $since = null): /** * Verify that the filter is valid - * - * @param string $filterValue - * @return string */ - public function validateFilter($filterValue) { - if (!isset($filterValue)) { - return 'all'; - } - + public function validateFilter(string $filterValue): string { switch ($filterValue) { case 'filter': return $filterValue; diff --git a/tests/Controller/FeedControllerTest.php b/tests/Controller/FeedControllerTest.php index 1fad583e8..5112b111c 100644 --- a/tests/Controller/FeedControllerTest.php +++ b/tests/Controller/FeedControllerTest.php @@ -96,6 +96,9 @@ public function testShow(?string $acceptHeader, string $expectedHeader): void { $this->data ->method('get') ->willReturn(['data' => []]); + $this->data + ->method('validateFilter') + ->willReturn('all'); if ($acceptHeader !== null) { $this->request ->method('getHeader')