-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add route to get account warnings from server
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
- Loading branch information
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
apps/settings/lib/AccountWarnings/AccountWarningsManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>}> | ||
*/ | ||
public function getAll(): array { | ||
$results = []; | ||
$providerRegistrations = $this->coordinator->getRegistrationContext()->getAccountWarningsProviders(); | ||
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; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
apps/settings/lib/Controller/AccountWarningsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |