From 071aa2f5c97b8bb99a07d41b5c1e87eabb35ece5 Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 12 Jun 2026 17:22:20 +0200 Subject: [PATCH] implemented step 05 by Gemini added action saveConsent and ConsentService --- .gitignore | 5 ++- public/ajax.php | 13 +++++++ src/Services/ConsentService.php | 60 +++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/Services/ConsentService.php diff --git a/.gitignore b/.gitignore index 7f83026..70ab577 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ -/data/users/*.json +/data/admin/*.json +/data/consent/*.json +/data/llm/*.json /data/projects/*.json +/data/users/*.json diff --git a/public/ajax.php b/public/ajax.php index 8dbc05f..7270e16 100644 --- a/public/ajax.php +++ b/public/ajax.php @@ -52,6 +52,7 @@ try { // Router $projectActions = new \App\Actions\ProjectActions(); + $consentService = new \App\Services\ConsentService(); switch ($action) { case 'ping': @@ -78,6 +79,18 @@ try { sendResponse(true, $projectActions->getProjectStatus($userId, $projectId)); break; + case 'saveConsent': + $projectId = $data['project_id'] ?? null; + $consentText = $data['payload']['consent_text'] ?? null; + + if (!$projectId || !$consentText) { + sendResponse(false, ['code' => 'MISSING_DATA', 'message' => 'Project ID and consent text are required.'], 400); + } + + $success = $consentService->saveConsent($projectId, $userId, $consentText); + sendResponse($success, ['message' => 'Consent saved successfully.']); + break; + default: sendResponse(false, ['code' => 'UNKNOWN_ACTION', 'message' => "Action '$action' is not defined."], 404); break; diff --git a/src/Services/ConsentService.php b/src/Services/ConsentService.php new file mode 100644 index 0000000..2f2fc84 --- /dev/null +++ b/src/Services/ConsentService.php @@ -0,0 +1,60 @@ +storage = new FileStorage(); + } + + /** + * Saves user consent for a specific project. + */ + public function saveConsent(string $projectId, string $userId, string $consentText): bool + { + // Verify project exists and belongs to user + $projectData = $this->storage->get("projects/{$projectId}.json"); + if (!$projectData) { + throw new Exception("Project not found.", 404); + } + if ($projectData['user_id'] !== $userId) { + throw new Exception("Unauthorized access to project.", 403); + } + + $consentData = [ + 'project_id' => $projectId, + 'user_id' => $userId, + 'consent_text_version' => self::CONSENT_VERSION, + 'consent_text' => $consentText, + 'accepted' => true, + 'accepted_at' => gmdate('Y-m-d\TH:i:s\Z') + ]; + + return $this->storage->put("consent/{$projectId}.json", $consentData); + } + + /** + * Checks if a project has a valid consent record. + */ + public function hasConsent(string $projectId): bool + { + return $this->storage->exists("consent/{$projectId}.json"); + } + + /** + * Returns the current consent version. + */ + public function getVersion(): string + { + return self::CONSENT_VERSION; + } +}