Skip to content

Commit

Permalink
Add route to get account warnings from server
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Oct 3, 2023
1 parent f306239 commit b55394a
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/settings/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

['name' => 'AuthSettings#wipe', 'url' => '/settings/personal/authtokens/wipe/{id}', 'verb' => 'POST' , 'root' => ''],
['name' => 'ClientDiagnostics#update', 'url' => '/settings/diagnostics', 'verb' => 'PUT' , 'root' => ''],
['name' => 'AccountWarnings#getAll', 'url' => '/settings/accountwarnings', 'verb' => 'GET' , 'root' => ''],

['name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST' , 'root' => ''],
['name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST' , 'root' => ''],
Expand Down
2 changes: 2 additions & 0 deletions apps/settings/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

return array(
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
'OCA\\Settings\\AccountWarnings\\AccountWarningsManager' => $baseDir . '/../lib/AccountWarnings/AccountWarningsManager.php',
'OCA\\Settings\\AccountWarnings\\OutdatedClientWarning' => $baseDir . '/../lib/AccountWarnings/OutdatedClientWarning.php',
'OCA\\Settings\\AccountWarnings\\OutdatedClientWarningsProvider' => $baseDir . '/../lib/AccountWarnings/OutdatedClientWarningsProvider.php',
'OCA\\Settings\\Activity\\GroupProvider' => $baseDir . '/../lib/Activity/GroupProvider.php',
Expand All @@ -19,6 +20,7 @@
'OCA\\Settings\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
'OCA\\Settings\\BackgroundJobs\\VerifyUserData' => $baseDir . '/../lib/BackgroundJobs/VerifyUserData.php',
'OCA\\Settings\\Controller\\AISettingsController' => $baseDir . '/../lib/Controller/AISettingsController.php',
'OCA\\Settings\\Controller\\AccountWarningsController' => $baseDir . '/../lib/Controller/AccountWarningsController.php',
'OCA\\Settings\\Controller\\AdminSettingsController' => $baseDir . '/../lib/Controller/AdminSettingsController.php',
'OCA\\Settings\\Controller\\AppSettingsController' => $baseDir . '/../lib/Controller/AppSettingsController.php',
'OCA\\Settings\\Controller\\AuthSettingsController' => $baseDir . '/../lib/Controller/AuthSettingsController.php',
Expand Down
2 changes: 2 additions & 0 deletions apps/settings/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ComposerStaticInitSettings

public static $classMap = array (
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
'OCA\\Settings\\AccountWarnings\\AccountWarningsManager' => __DIR__ . '/..' . '/../lib/AccountWarnings/AccountWarningsManager.php',
'OCA\\Settings\\AccountWarnings\\OutdatedClientWarning' => __DIR__ . '/..' . '/../lib/AccountWarnings/OutdatedClientWarning.php',
'OCA\\Settings\\AccountWarnings\\OutdatedClientWarningsProvider' => __DIR__ . '/..' . '/../lib/AccountWarnings/OutdatedClientWarningsProvider.php',
'OCA\\Settings\\Activity\\GroupProvider' => __DIR__ . '/..' . '/../lib/Activity/GroupProvider.php',
Expand All @@ -34,6 +35,7 @@ class ComposerStaticInitSettings
'OCA\\Settings\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
'OCA\\Settings\\BackgroundJobs\\VerifyUserData' => __DIR__ . '/..' . '/../lib/BackgroundJobs/VerifyUserData.php',
'OCA\\Settings\\Controller\\AISettingsController' => __DIR__ . '/..' . '/../lib/Controller/AISettingsController.php',
'OCA\\Settings\\Controller\\AccountWarningsController' => __DIR__ . '/..' . '/../lib/Controller/AccountWarningsController.php',
'OCA\\Settings\\Controller\\AdminSettingsController' => __DIR__ . '/..' . '/../lib/Controller/AdminSettingsController.php',
'OCA\\Settings\\Controller\\AppSettingsController' => __DIR__ . '/..' . '/../lib/Controller/AppSettingsController.php',
'OCA\\Settings\\Controller\\AuthSettingsController' => __DIR__ . '/..' . '/../lib/Controller/AuthSettingsController.php',
Expand Down
58 changes: 58 additions & 0 deletions apps/settings/lib/AccountWarnings/AccountWarningsManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
*
* @author Côme Chilliet <come.chilliet@nextcloud.com>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\Settings\AccountWarnings;

use OCP\Settings\IAccountWarningsProvider;
use OC\AppFramework\Bootstrap\Coordinator;

class AccountWarningsManager {
public function __construct(
private Coordinator $coordinator,
) {
}

/**
* @return array<class-string, array{name:string,warnings:array<string,string>}>

Check failure on line 38 in apps/settings/lib/AccountWarnings/AccountWarningsManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidReturnType

apps/settings/lib/AccountWarnings/AccountWarningsManager.php:38:13: InvalidReturnType: The declared return type 'array<class-string, array{name: string, warnings: array<string, string>}>' for OCA\Settings\AccountWarnings\AccountWarningsManager::getAll is incorrect, got 'array<class-string<OCP\Settings\IAccountWarningsProvider>, array{name: string, warnings: array<'error'|'info'|'warning', non-empty-list<string>>}>' (see https://psalm.dev/011)

Check failure

Code scanning / Psalm

InvalidReturnType Error

The declared return type 'array<class-string, array{name: string, warnings: array<string, string>}>' for OCA\Settings\AccountWarnings\AccountWarningsManager::getAll is incorrect, got 'array<class-string<OCP\Settings\IAccountWarningsProvider>, array{name: string, warnings: array<'error'|'info'|'warning', non-empty-list>}>'
*/
public function getAll(): array {
$results = [];
$providerRegistrations = $this->coordinator->getRegistrationContext()->getAccountWarningsProviders();

Check notice

Code scanning / Psalm

PossiblyNullReference Note

Cannot call method getAccountWarningsProviders on possibly null value
foreach ($providerRegistrations as $providerRegistration) {
/** @var IAccountWarningsProvider $provider */
$provider = \OCP\Server::get($providerRegistration->getService());
$warnings = $provider->getAccountWarnings();
$results[$provider::class] = ['name' => $provider->getName(),'warnings' => []];
foreach ($warnings as $warning) {
$category = $warning->getSeverity();
if (!isset($results[$provider::class]['warnings'][$category])) {
$results[$provider::class]['warnings'][$category] = [];
}
$results[$provider::class]['warnings'][$category][] = $warning->getText();
}
}
return $results;

Check failure on line 56 in apps/settings/lib/AccountWarnings/AccountWarningsManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidReturnStatement

apps/settings/lib/AccountWarnings/AccountWarningsManager.php:56:10: InvalidReturnStatement: The inferred type 'array<class-string<OCP\Settings\IAccountWarningsProvider>, array{name: string, warnings: array<'error'|'info'|'warning', non-empty-list<string>>}>' does not match the declared return type 'array<class-string, array{name: string, warnings: array<string, string>}>' for OCA\Settings\AccountWarnings\AccountWarningsManager::getAll (see https://psalm.dev/128)

Check failure

Code scanning / Psalm

InvalidReturnStatement Error

The inferred type 'array<class-string<OCP\Settings\IAccountWarningsProvider>, array{name: string, warnings: array<'error'|'info'|'warning', non-empty-list>}>' does not match the declared return type 'array<class-string, array{name: string, warnings: array<string, string>}>' for OCA\Settings\AccountWarnings\AccountWarningsManager::getAll
}
}
45 changes: 45 additions & 0 deletions apps/settings/lib/Controller/AccountWarningsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
*
* @author Côme Chilliet <come.chilliet@nextcloud.com>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\Settings\Controller;

use OCA\Settings\AccountWarnings\AccountWarningsManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;

class AccountWarningsController extends Controller {
public function __construct(
string $appName,
IRequest $request,
private AccountWarningsManager $manager,
) {
parent::__construct($appName, $request);
}

public function getAll(): DataResponse {
return new DataResponse($this->manager->getAll());
}
}

0 comments on commit b55394a

Please sign in to comment.