Skip to content

Commit 0f5390d

Browse files
miaulalalaAndyScherzinger
authored andcommitted
feat(rss): add filter to rss feed, allowing share only feed
Fix #464 Signed-off-by: Anna Larch <anna@nextcloud.com>
1 parent 71e6871 commit 0f5390d

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
@@ -47,7 +47,7 @@ public function __construct(
4747
#[PublicPage]
4848
#[NoCSRFRequired]
4949
#[BruteForceProtection('activityRssFeed')]
50-
public function show(): TemplateResponse {
50+
public function show(string $filter = 'all'): TemplateResponse {
5151
$response = new TemplateResponse('activity', 'rss', [], '');
5252
try {
5353
$user = $this->activityManager->getCurrentUserId();
@@ -57,8 +57,9 @@ public function show(): TemplateResponse {
5757
$this->l = $this->l10nFactory->get('activity', $userLang);
5858
$this->helper->setL10n($this->l);
5959

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

tests/Controller/FeedControllerTest.php

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

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

0 commit comments

Comments
 (0)