Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| SettingController | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasRootCert | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Controller; |
| 10 | |
| 11 | use OCA\Libresign\AppInfo\Application; |
| 12 | use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory; |
| 13 | use OCP\AppFramework\Http; |
| 14 | use OCP\AppFramework\Http\Attribute\ApiRoute; |
| 15 | use OCP\AppFramework\Http\Attribute\NoAdminRequired; |
| 16 | use OCP\AppFramework\Http\Attribute\NoCSRFRequired; |
| 17 | use OCP\AppFramework\Http\Attribute\OpenAPI; |
| 18 | use OCP\AppFramework\Http\DataResponse; |
| 19 | use OCP\IRequest; |
| 20 | |
| 21 | /** |
| 22 | * @psalm-import-type LibresignHasRootCertResponse from \OCA\Libresign\ResponseDefinitions |
| 23 | */ |
| 24 | class SettingController extends AEnvironmentAwareController { |
| 25 | public function __construct( |
| 26 | IRequest $request, |
| 27 | private CertificateEngineFactory $certificateEngineFactory, |
| 28 | ) { |
| 29 | parent::__construct(Application::APP_ID, $request); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Has root certificate |
| 34 | * |
| 35 | * Checks whether the root certificate has been configured by checking the Nextcloud configuration table to see if the root certificate settings have |
| 36 | * |
| 37 | * @return DataResponse<Http::STATUS_OK, LibresignHasRootCertResponse, array{}> |
| 38 | * |
| 39 | * 200: OK |
| 40 | */ |
| 41 | #[NoAdminRequired] |
| 42 | #[NoCSRFRequired] |
| 43 | #[OpenAPI(scope: OpenAPI::SCOPE_ADMINISTRATION)] |
| 44 | #[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/setting/has-root-cert', requirements: ['apiVersion' => '(v1)'])] |
| 45 | public function hasRootCert(): DataResponse { |
| 46 | $engine = $this->certificateEngineFactory->getEngine(); |
| 47 | $checkData = [ |
| 48 | 'hasRootCert' => $engine->getName() !== 'none' && $engine->isSetupOk() |
| 49 | ]; |
| 50 | |
| 51 | return new DataResponse($checkData); |
| 52 | } |
| 53 | } |