|
10 | 10 |
|
11 | 11 | use DateTimeInterface; |
12 | 12 | use OCA\Libresign\AppInfo\Application; |
| 13 | +use OCA\Libresign\Enum\DocMdpLevel; |
13 | 14 | use OCA\Libresign\Exception\LibresignException; |
14 | 15 | use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory; |
15 | 16 | use OCA\Libresign\Handler\CertificateEngine\IEngineHandler; |
16 | 17 | use OCA\Libresign\Helper\ConfigureCheckHelper; |
17 | 18 | use OCA\Libresign\ResponseDefinitions; |
18 | 19 | use OCA\Libresign\Service\Certificate\ValidateService; |
19 | 20 | use OCA\Libresign\Service\CertificatePolicyService; |
| 21 | +use OCA\Libresign\Service\DocMdpConfigService; |
20 | 22 | use OCA\Libresign\Service\FooterService; |
21 | 23 | use OCA\Libresign\Service\Install\ConfigureCheckService; |
22 | 24 | use OCA\Libresign\Service\Install\InstallService; |
@@ -64,6 +66,7 @@ public function __construct( |
64 | 66 | private ValidateService $validateService, |
65 | 67 | private ReminderService $reminderService, |
66 | 68 | private FooterService $footerService, |
| 69 | + private DocMdpConfigService $docMdpConfigService, |
67 | 70 | ) { |
68 | 71 | parent::__construct(Application::APP_ID, $request); |
69 | 72 | $this->eventSource = $this->eventSourceFactory->create(); |
@@ -857,4 +860,41 @@ public function footerTemplatePreviewPdf(string $template = '', int $width = 595 |
857 | 860 | ], Http::STATUS_BAD_REQUEST); |
858 | 861 | } |
859 | 862 | } |
| 863 | + |
| 864 | + /** |
| 865 | + * Set DocMDP configuration |
| 866 | + * |
| 867 | + * @param bool $enabled Enable or disable DocMDP certification |
| 868 | + * @param int $defaultLevel Default DocMDP level (0-3): 0=none, 1=no changes, 2=form fill, 3=form fill + annotations |
| 869 | + * @return DataResponse<Http::STATUS_OK, array{message: string}, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: string}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{error: string}, array{}> |
| 870 | + * |
| 871 | + * 200: Configuration saved successfully |
| 872 | + * 400: Invalid DocMDP level provided |
| 873 | + * 500: Internal server error |
| 874 | + */ |
| 875 | + #[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/admin/docmdp/config', requirements: ['apiVersion' => '(v1)'])] |
| 876 | + public function setDocMdpConfig(bool $enabled, int $defaultLevel): DataResponse { |
| 877 | + try { |
| 878 | + $this->docMdpConfigService->setEnabled($enabled); |
| 879 | + |
| 880 | + if ($enabled) { |
| 881 | + $level = DocMdpLevel::tryFrom($defaultLevel); |
| 882 | + if ($level === null) { |
| 883 | + return new DataResponse([ |
| 884 | + 'error' => $this->l10n->t('Invalid DocMDP level'), |
| 885 | + ], Http::STATUS_BAD_REQUEST); |
| 886 | + } |
| 887 | + |
| 888 | + $this->docMdpConfigService->setLevel($level); |
| 889 | + } |
| 890 | + |
| 891 | + return new DataResponse([ |
| 892 | + 'message' => $this->l10n->t('Settings saved'), |
| 893 | + ]); |
| 894 | + } catch (\Exception $e) { |
| 895 | + return new DataResponse([ |
| 896 | + 'error' => $e->getMessage(), |
| 897 | + ], Http::STATUS_INTERNAL_SERVER_ERROR); |
| 898 | + } |
| 899 | + } |
860 | 900 | } |
0 commit comments