Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| CertificatePolicyController | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCertificatePolicy | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| 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\Service\CertificatePolicyService; |
| 13 | use OCP\AppFramework\Controller; |
| 14 | use OCP\AppFramework\Http; |
| 15 | use OCP\AppFramework\Http\Attribute\AnonRateLimit; |
| 16 | use OCP\AppFramework\Http\Attribute\FrontpageRoute; |
| 17 | use OCP\AppFramework\Http\Attribute\NoCSRFRequired; |
| 18 | use OCP\AppFramework\Http\Attribute\PublicPage; |
| 19 | use OCP\AppFramework\Http\DataResponse; |
| 20 | use OCP\AppFramework\Http\FileDisplayResponse; |
| 21 | use OCP\Files\NotFoundException; |
| 22 | use OCP\IRequest; |
| 23 | |
| 24 | class CertificatePolicyController extends Controller { |
| 25 | public function __construct( |
| 26 | IRequest $request, |
| 27 | private CertificatePolicyService $certificatePolicyService, |
| 28 | ) { |
| 29 | parent::__construct(Application::APP_ID, $request); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Certificate policy of this instance |
| 34 | * |
| 35 | * @return FileDisplayResponse<Http::STATUS_OK, array{Content-Disposition: 'inline; filename="certificate-policy.pdf"', Content-Type: 'application/pdf'}>|DataResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}> |
| 36 | * |
| 37 | * 200: OK |
| 38 | * 404: Not found |
| 39 | */ |
| 40 | #[PublicPage] |
| 41 | #[NoCSRFRequired] |
| 42 | #[AnonRateLimit(limit: 10, period: 60)] |
| 43 | #[FrontpageRoute(verb: 'GET', url: '/certificate-policy.pdf')] |
| 44 | public function getCertificatePolicy(): FileDisplayResponse|DataResponse { |
| 45 | try { |
| 46 | $file = $this->certificatePolicyService->getFile(); |
| 47 | return new FileDisplayResponse($file, Http::STATUS_OK, [ |
| 48 | 'Content-Disposition' => 'inline; filename="certificate-policy.pdf"', |
| 49 | 'Content-Type' => 'application/pdf', |
| 50 | ]); |
| 51 | } catch (NotFoundException) { |
| 52 | return new DataResponse([], Http::STATUS_NOT_FOUND); |
| 53 | } |
| 54 | } |
| 55 | } |