Skip to content
Merged
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
10 changes: 5 additions & 5 deletions apps/dashboard/lib/Controller/DashboardApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Config\IUserConfig;
use OCP\Dashboard\IAPIWidget;
use OCP\Dashboard\IAPIWidgetV2;
use OCP\Dashboard\IButtonWidget;
Expand All @@ -30,7 +31,6 @@
use OCP\Dashboard\Model\WidgetItem;

use OCP\Dashboard\Model\WidgetOptions;
use OCP\IConfig;
use OCP\IRequest;

/**
Expand All @@ -45,7 +45,7 @@ public function __construct(
IRequest $request,
private IManager $dashboardManager,
private IAppConfig $appConfig,
private IConfig $config,
private IUserConfig $userConfig,
private ?string $userId,
private DashboardService $service,
) {
Expand All @@ -59,7 +59,7 @@ public function __construct(
private function getShownWidgets(array $widgetIds): array {
if (empty($widgetIds)) {
$systemDefault = $this->appConfig->getAppValueString('layout', 'recommendations,spreed,mail,calendar');
$widgetIds = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault));
$widgetIds = explode(',', $this->userConfig->getValueString($this->userId, 'dashboard', 'layout', $systemDefault));
}

return array_filter(
Expand Down Expand Up @@ -202,7 +202,7 @@ public function getLayout(): DataResponse {
#[NoAdminRequired]
#[ApiRoute(verb: 'POST', url: '/api/v3/layout')]
public function updateLayout(array $layout): DataResponse {
$this->config->setUserValue($this->userId, 'dashboard', 'layout', implode(',', $layout));
$this->userConfig->setValueString($this->userId, 'dashboard', 'layout', implode(',', $layout));
return new DataResponse(['layout' => $layout]);
}

Expand Down Expand Up @@ -230,7 +230,7 @@ public function getStatuses(): DataResponse {
#[NoAdminRequired]
#[ApiRoute(verb: 'POST', url: '/api/v3/statuses')]
public function updateStatuses(array $statuses): DataResponse {
$this->config->setUserValue($this->userId, 'dashboard', 'statuses', implode(',', $statuses));
$this->userConfig->setValueString($this->userId, 'dashboard', 'statuses', implode(',', $statuses));
return new DataResponse(['statuses' => $statuses]);
}
}
8 changes: 4 additions & 4 deletions apps/dashboard/lib/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
use OCP\AppFramework\Http\FeaturePolicy;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Config\IUserConfig;
use OCP\Dashboard\IIconWidget;
use OCP\Dashboard\IManager;
use OCP\Dashboard\IWidget;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
Expand All @@ -33,9 +33,9 @@ public function __construct(
string $appName,
IRequest $request,
private IInitialState $initialState,
private IEventDispatcher $eventDispatcher,
private IManager $dashboardManager,
private IConfig $config,
private IUserConfig $userConfig,
private IL10N $l10n,
private ?string $userId,
private DashboardService $service,
Expand Down Expand Up @@ -67,9 +67,9 @@ public function index(): TemplateResponse {
$this->initialState->provideInitialState('statuses', $this->service->getStatuses());
$this->initialState->provideInitialState('layout', $this->service->getLayout());
$this->initialState->provideInitialState('appStoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));
$this->initialState->provideInitialState('firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1');
$this->initialState->provideInitialState('firstRun', $this->userConfig->getValueBool($this->userId, 'dashboard', 'firstRun', true));
$this->initialState->provideInitialState('birthdate', $this->service->getBirthdate());
$this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0');
$this->userConfig->setValueBool($this->userId, 'dashboard', 'firstRun', false);

$response = new TemplateResponse('dashboard', 'index', [
'id-app-content' => '#app-dashboard',
Expand Down
15 changes: 9 additions & 6 deletions apps/dashboard/lib/Service/DashboardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
use OCP\Accounts\IAccountManager;
use OCP\Accounts\PropertyDoesNotExistException;
use OCP\AppFramework\Services\IAppConfig;
use OCP\IConfig;
use OCP\Config\IUserConfig;
use OCP\IUserManager;

class DashboardService {
public function __construct(
private IConfig $config,
private IUserConfig $userConfig,
private IAppConfig $appConfig,
private ?string $userId,
private IUserManager $userManager,
Expand All @@ -31,21 +31,24 @@ public function __construct(
*/
public function getLayout(): array {
$systemDefault = $this->appConfig->getAppValueString('layout', 'recommendations,spreed,mail,calendar');
return array_values(array_filter(explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault)), fn (string $value) => $value !== ''));
return array_values(array_filter(
explode(',', $this->userConfig->getValueString($this->userId, 'dashboard', 'layout', $systemDefault)),
fn (string $value) => $value !== '')
);
}

/**
* @return list<string>
*/
public function getStatuses() {
$configStatuses = $this->config->getUserValue($this->userId, 'dashboard', 'statuses', '');
public function getStatuses(): array {
$configStatuses = $this->userConfig->getValueString($this->userId, 'dashboard', 'statuses');
try {
// Parse the old format
/** @var array<string, bool> $statuses */
$statuses = json_decode($configStatuses, true, 512, JSON_THROW_ON_ERROR);
// We avoid getting an empty array as it will not produce an object in UI's JS
return array_keys(array_filter($statuses, static fn (bool $value) => $value));
} catch (JsonException $e) {
} catch (JsonException) {
return array_values(array_filter(explode(',', $configStatuses), fn (string $value) => $value !== ''));
}
}
Expand Down
10 changes: 5 additions & 5 deletions apps/dashboard/tests/DashboardServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
use OCA\Dashboard\Service\DashboardService;
use OCP\Accounts\IAccountManager;
use OCP\AppFramework\Services\IAppConfig;
use OCP\IConfig;
use OCP\Config\IUserConfig;
use OCP\IUser;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class DashboardServiceTest extends TestCase {

private IConfig&MockObject $config;
private IUserConfig&MockObject $userConfig;
private IAppConfig&MockObject $appConfig;
private IUserManager&MockObject $userManager;
private IAccountManager&MockObject $accountManager;
Expand All @@ -30,13 +30,13 @@ class DashboardServiceTest extends TestCase {
protected function setUp(): void {
parent::setUp();

$this->config = $this->createMock(IConfig::class);
$this->userConfig = $this->createMock(IUserConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->accountManager = $this->createMock(IAccountManager::class);

$this->service = new DashboardService(
$this->config,
$this->userConfig,
$this->appConfig,
'alice',
$this->userManager,
Expand Down Expand Up @@ -90,7 +90,7 @@ public function testGetBirthdateUserNotFound(): void {

public function testGetBirthdateNoUserId(): void {
$service = new DashboardService(
$this->config,
$this->userConfig,
$this->appConfig,
null,
$this->userManager,
Expand Down
19 changes: 0 additions & 19 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,6 @@
<code><![CDATA[CommentsEvent::EVENT_PRE_UPDATE]]></code>
</DeprecatedConstant>
</file>
<file src="apps/dashboard/lib/Controller/DashboardApiController.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dashboard/lib/Controller/DashboardController.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[setUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dashboard/lib/Service/DashboardService.php">
<DeprecatedMethod>
<code><![CDATA[getUserValue]]></code>
<code><![CDATA[getUserValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/dav/appinfo/v1/publicwebdav.php">
<InternalMethod>
<code><![CDATA[Filesystem::logWarningWhenAddingStorageWrapper($previousLog)]]></code>
Expand Down
Loading