Skip to content

Commit 8a321ab

Browse files
committed
feat(rss): add filter to rss feed, allowing share only feed
Fix #464 Signed-off-by: Anna Larch <anna@nextcloud.com>
1 parent df9a4ea commit 8a321ab

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

lib/Controller/FeedController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(
4646
#[PublicPage]
4747
#[NoCSRFRequired]
4848
#[BruteForceProtection('activityRssFeed')]
49-
public function show(): TemplateResponse {
49+
public function show(string $filter = 'all'): TemplateResponse {
5050
$response = new TemplateResponse('activity', 'rss', [], '');
5151
try {
5252
$user = $this->activityManager->getCurrentUserId();
@@ -56,8 +56,9 @@ public function show(): TemplateResponse {
5656
$this->l = $this->l10nFactory->get('activity', $userLang);
5757
$this->helper->setL10n($this->l);
5858

59+
$filter = $this->data->validateFilter($filter);
5960
$description = $this->l->t('Personal activity feed for %s', $user);
60-
$data = $this->data->get($this->helper, $this->settings, $user, 0, self::DEFAULT_PAGE_SIZE, 'desc', 'all');
61+
$data = $this->data->get($this->helper, $this->settings, $user, 0, self::DEFAULT_PAGE_SIZE, 'desc', $filter);
6162
$activities = $data['data'];
6263
} catch (\UnexpectedValueException $e) {
6364
$this->l = $this->l10nFactory->get('activity');

tests/Controller/FeedControllerTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,54 @@ public function testShowNoToken(?string $acceptHeader, string $expectedHeader):
144144
$this->assertStringContainsString($description, $renderedResponse);
145145
}
146146

147+
public function testShowWithFilter(): void {
148+
$this->mockUserSession('test');
149+
$this->data
150+
->method('validateFilter')
151+
->with('files')
152+
->willReturn('files');
153+
$this->data
154+
->expects($this->once())
155+
->method('get')
156+
->with($this->helper, $this->userSettings, 'test', 0, FeedController::DEFAULT_PAGE_SIZE, 'desc', 'files')
157+
->willReturn(['data' => []]);
158+
159+
$templateResponse = $this->controller->show('files');
160+
$this->assertInstanceOf(TemplateResponse::class, $templateResponse);
161+
}
162+
163+
public function testShowWithInvalidFilter(): void {
164+
$this->mockUserSession('test');
165+
$this->data
166+
->method('validateFilter')
167+
->with('invalid_filter')
168+
->willReturn('all');
169+
$this->data
170+
->expects($this->once())
171+
->method('get')
172+
->with($this->helper, $this->userSettings, 'test', 0, FeedController::DEFAULT_PAGE_SIZE, 'desc', 'all')
173+
->willReturn(['data' => []]);
174+
175+
$templateResponse = $this->controller->show('invalid_filter');
176+
$this->assertInstanceOf(TemplateResponse::class, $templateResponse);
177+
}
178+
179+
public function testShowDefaultsToAllFilter(): void {
180+
$this->mockUserSession('test');
181+
$this->data
182+
->method('validateFilter')
183+
->with('all')
184+
->willReturn('all');
185+
$this->data
186+
->expects($this->once())
187+
->method('get')
188+
->with($this->helper, $this->userSettings, 'test', 0, FeedController::DEFAULT_PAGE_SIZE, 'desc', 'all')
189+
->willReturn(['data' => []]);
190+
191+
$templateResponse = $this->controller->show();
192+
$this->assertInstanceOf(TemplateResponse::class, $templateResponse);
193+
}
194+
147195
protected function mockUserSession(string $user): void {
148196
$mockUser = $this->createMock(IUser::class);
149197
$mockUser

0 commit comments

Comments
 (0)