Merge pull request #59335 from mykh-hailo/fix/duplicate-dashboard-widget

fix: duplicate dashboard widget
This commit is contained in:
Ferdinand Thiessen 2026-04-02 23:22:12 +02:00 committed by GitHub
commit 521e61828f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 2 deletions

View file

@ -202,6 +202,7 @@ class DashboardApiController extends OCSController {
#[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]);
}

View file

@ -31,12 +31,30 @@ class DashboardService {
*/
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>
*/

View file

@ -44,6 +44,25 @@ class DashboardServiceTest extends TestCase {
);
}
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')