|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * The Confirm this entry is current action of the application and usage pages. |
| 5 | + * |
| 6 | + * @category Controller |
| 7 | + * @package OCA\Stackiq\Controller |
| 8 | + * @author Conduction b.v. <info@conduction.nl> |
| 9 | + * @copyright 2026 Conduction B.V. |
| 10 | + * @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 |
| 11 | + * @version GIT: <git_id> |
| 12 | + * @link https://github.com/ConductionNL/stackiq |
| 13 | + * |
| 14 | + * @spec openspec/changes/landscape-completeness-score/specs/catalogue-data-quality/spec.md#requirement-req-cdq-002-a-user-confirms-an-entry-is-current-and-its-freshness-resets |
| 15 | + * |
| 16 | + * SPDX-FileCopyrightText: 2026 Conduction B.V. <info@conduction.nl> |
| 17 | + * SPDX-License-Identifier: EUPL-1.2 |
| 18 | + */ |
| 19 | + |
| 20 | +declare(strict_types=1); |
| 21 | + |
| 22 | +namespace OCA\Stackiq\Controller; |
| 23 | + |
| 24 | +use OCA\Stackiq\Kernel\Contracts\EntryConfirmationServiceInterface; |
| 25 | +use OCA\Stackiq\Service\EntryConfirmationRefused; |
| 26 | +use OCP\AppFramework\Controller; |
| 27 | +use OCP\AppFramework\Http; |
| 28 | +use OCP\AppFramework\Http\Attribute\NoAdminRequired; |
| 29 | +use OCP\AppFramework\Http\JSONResponse; |
| 30 | +use OCP\IRequest; |
| 31 | +use OCP\IUserSession; |
| 32 | + |
| 33 | +/** |
| 34 | + * Confirms an application or a usage is current. |
| 35 | + * |
| 36 | + * @category Controller |
| 37 | + * @package OCA\Stackiq\Controller |
| 38 | + * @author Conduction b.v. <info@conduction.nl> |
| 39 | + * @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 |
| 40 | + * @link https://github.com/ConductionNL/stackiq |
| 41 | + * |
| 42 | + * @spec openspec/changes/landscape-completeness-score/specs/catalogue-data-quality/spec.md#requirement-req-cdq-002-a-user-confirms-an-entry-is-current-and-its-freshness-resets |
| 43 | + */ |
| 44 | +class EntryConfirmationController extends Controller { |
| 45 | + /** |
| 46 | + * Constructor. |
| 47 | + * |
| 48 | + * @param string $appName The app name. |
| 49 | + * @param IRequest $request The request. |
| 50 | + * @param EntryConfirmationServiceInterface $confirmation Sets lastConfirmedAt. |
| 51 | + * @param IUserSession $userSession The current session. |
| 52 | + * |
| 53 | + * @spec exclude pure framework plumbing: constructor dependency injection. |
| 54 | + */ |
| 55 | + public function __construct( |
| 56 | + string $appName, |
| 57 | + IRequest $request, |
| 58 | + private readonly EntryConfirmationServiceInterface $confirmation, |
| 59 | + private readonly IUserSession $userSession, |
| 60 | + ) { |
| 61 | + parent::__construct(appName: $appName, request: $request); |
| 62 | + }//end __construct() |
| 63 | + |
| 64 | + /** |
| 65 | + * Confirm the entry is current. |
| 66 | + * |
| 67 | + * @param string $kind module or usage. |
| 68 | + * @param string $id The entry's id. |
| 69 | + * |
| 70 | + * @return JSONResponse `{lastConfirmedAt}`, or the refusal: 401 without a session, 403 without the update right, |
| 71 | + * 404 for an entry the user cannot read. |
| 72 | + * |
| 73 | + * @spec openspec/changes/landscape-completeness-score/specs/catalogue-data-quality/spec.md#requirement-req-cdq-002-a-user-confirms-an-entry-is-current-and-its-freshness-resets |
| 74 | + */ |
| 75 | + #[NoAdminRequired] |
| 76 | + public function confirm(string $kind, string $id): JSONResponse { |
| 77 | + if ($this->userSession->getUser() === null) { |
| 78 | + return new JSONResponse(['error' => 'not-logged-in'], Http::STATUS_UNAUTHORIZED); |
| 79 | + } |
| 80 | + |
| 81 | + try { |
| 82 | + return new JSONResponse($this->confirmation->confirm(kind: $kind, id: $id)); |
| 83 | + } catch (EntryConfirmationRefused $refusal) { |
| 84 | + $data = ['error' => $refusal->reason]; |
| 85 | + if ($refusal->getMessage() !== '') { |
| 86 | + $data['message'] = $refusal->getMessage(); |
| 87 | + } |
| 88 | + |
| 89 | + return new JSONResponse($data, $refusal->status); |
| 90 | + } |
| 91 | + }//end confirm() |
| 92 | +}//end class |
0 commit comments