mirror of
https://github.com/nextcloud/server.git
synced 2026-02-03 20:41:22 -05:00
refactor(dashboard): Fix all psalm issues
Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
This commit is contained in:
parent
89fcefbfa0
commit
6111ecefbc
5 changed files with 23 additions and 39 deletions
|
|
@ -18,6 +18,7 @@ use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
|
|||
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;
|
||||
|
|
@ -30,7 +31,6 @@ use OCP\Dashboard\Model\WidgetButton;
|
|||
use OCP\Dashboard\Model\WidgetItem;
|
||||
|
||||
use OCP\Dashboard\Model\WidgetOptions;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
|
||||
/**
|
||||
|
|
@ -45,7 +45,7 @@ class DashboardApiController extends OCSController {
|
|||
IRequest $request,
|
||||
private IManager $dashboardManager,
|
||||
private IAppConfig $appConfig,
|
||||
private IConfig $config,
|
||||
private IUserConfig $userConfig,
|
||||
private ?string $userId,
|
||||
private DashboardService $service,
|
||||
) {
|
||||
|
|
@ -59,7 +59,7 @@ class DashboardApiController extends OCSController {
|
|||
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(
|
||||
|
|
@ -202,7 +202,7 @@ class DashboardApiController extends OCSController {
|
|||
#[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]);
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +230,7 @@ class DashboardApiController extends OCSController {
|
|||
#[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]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ use OCP\AppFramework\Http\Attribute\OpenAPI;
|
|||
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;
|
||||
|
|
@ -33,9 +33,9 @@ class DashboardController extends Controller {
|
|||
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,
|
||||
|
|
@ -67,9 +67,9 @@ class DashboardController extends Controller {
|
|||
$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',
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@ use JsonException;
|
|||
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,
|
||||
|
|
@ -31,21 +31,24 @@ class DashboardService {
|
|||
*/
|
||||
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 !== ''));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use OC\Accounts\Account;
|
|||
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;
|
||||
|
|
@ -21,7 +21,7 @@ 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;
|
||||
|
|
@ -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,
|
||||
|
|
@ -90,7 +90,7 @@ class DashboardServiceTest extends TestCase {
|
|||
|
||||
public function testGetBirthdateNoUserId(): void {
|
||||
$service = new DashboardService(
|
||||
$this->config,
|
||||
$this->userConfig,
|
||||
$this->appConfig,
|
||||
null,
|
||||
$this->userManager,
|
||||
|
|
|
|||
|
|
@ -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/caldav.php">
|
||||
<DeprecatedMethod>
|
||||
<code><![CDATA[exec]]></code>
|
||||
|
|
|
|||
Loading…
Reference in a new issue