Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/dashboard/lib/Controller/DashboardApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ public function getLayout(): DataResponse {
#[NoAdminRequired]
#[ApiRoute(verb: 'POST', url: '/api/v3/layout')]
public function updateLayout(array $layout): DataResponse {
$layout = $this->service->sanitizeLayout($layout);
$this->userConfig->setValueString($this->userId, 'dashboard', 'layout', implode(',', $layout));
return new DataResponse(['layout' => $layout]);
}
Expand Down
22 changes: 20 additions & 2 deletions apps/dashboard/lib/Service/DashboardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,30 @@ public function __construct(
*/
public function getLayout(): array {
$systemDefault = $this->appConfig->getAppValueString('layout', 'recommendations,spreed,mail,calendar');
return array_values(array_filter(
return $this->sanitizeLayout(
explode(',', $this->userConfig->getValueString($this->userId, 'dashboard', 'layout', $systemDefault)),
fn (string $value) => $value !== '')
);
}

/**
* @param list<string> $layout
* @return list<string>
*/
public function sanitizeLayout(array $layout): array {
$seen = [];
$result = [];
foreach ($layout as $value) {
if ($value === '' || isset($seen[$value])) {
continue;
}

$seen[$value] = true;
$result[] = $value;
}

return $result;
}

/**
* @return list<string>
*/
Expand Down
19 changes: 19 additions & 0 deletions apps/dashboard/tests/DashboardServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@ protected function setUp(): void {
);
}

public function testGetLayoutRemovesEmptyAndDuplicateEntries(): void {
$this->appConfig->method('getAppValueString')
->with('layout', 'recommendations,spreed,mail,calendar')
->willReturn('recommendations,spreed,mail,calendar');
$this->userConfig->method('getValueString')
->with('alice', 'dashboard', 'layout', 'recommendations,spreed,mail,calendar')
->willReturn('spreed,,mail,mail,calendar,spreed');

$layout = $this->service->getLayout();

$this->assertSame(['spreed', 'mail', 'calendar'], $layout);
}

public function testSanitizeLayoutRemovesEmptyAndDuplicateEntries(): void {
$layout = $this->service->sanitizeLayout(['files', 'calendar', 'files', '', 'mail', 'calendar']);

$this->assertSame(['files', 'calendar', 'mail'], $layout);
}

public function testGetBirthdate(): void {
$user = $this->createMock(IUser::class);
$this->userManager->method('get')
Expand Down
Loading