From c1a03613928052606fbe97a22cbadd53695ac901 Mon Sep 17 00:00:00 2001 From: eldadfux Date: Thu, 25 Jun 2026 16:31:24 -0400 Subject: [PATCH] Update onboarding configuration to include account creation permissions and adjust API role checks. Modify migration versioning for consistency and refactor project stage tests to streamline project ID retrieval. --- app/config/onboarding.php | 2 + app/controllers/shared/api.php | 2 +- src/Appwrite/Migration/Migration.php | 1 + .../Modules/Projects/Http/Stages/Update.php | 2 +- tests/e2e/Services/Project/StagesBase.php | 76 ++++--------------- .../Project/StagesConsoleClientTest.php | 4 +- 6 files changed, 21 insertions(+), 66 deletions(-) diff --git a/app/config/onboarding.php b/app/config/onboarding.php index 72f2861206..38f2bb8ec5 100644 --- a/app/config/onboarding.php +++ b/app/config/onboarding.php @@ -17,6 +17,8 @@ return [ // Auth 'users.create' => true, + 'account.create' => true, + 'account.createAnonymousSession' => true, 'teams.create' => true, // Databases — tablesDB diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index c16e590f4a..9a894c4587 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -1178,7 +1178,7 @@ Http::shutdown() $byMethod = []; } - $actorType = ($apiKey !== null && $apiKey->getRole() === User::ROLE_APPS) + $actorType = ($apiKey !== null && $apiKey->getRole() === User::ROLE_KEYS) ? match ($apiKey->getType()) { API_KEY_ACCOUNT => ACTOR_TYPE_KEY_ACCOUNT, API_KEY_ORGANIZATION => ACTOR_TYPE_KEY_ORGANIZATION, diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 77c62bce96..93d8994d7c 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -98,6 +98,7 @@ abstract class Migration '1.9.3' => 'V24', '1.9.4' => 'V24', '1.9.5' => 'V24', + '1.9.6' => 'V25', ]; /** diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Stages/Update.php b/src/Appwrite/Platform/Modules/Projects/Http/Stages/Update.php index 910b2dcf63..c345712bc8 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Stages/Update.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Stages/Update.php @@ -126,7 +126,7 @@ class Update extends Action private function resolveActorType(?Key $apiKey, User $user, string $mode): string { - if ($apiKey !== null && $apiKey->getRole() === User::ROLE_APPS) { + if ($apiKey !== null && $apiKey->getRole() === User::ROLE_KEYS) { return match ($apiKey->getType()) { API_KEY_ACCOUNT => ACTOR_TYPE_KEY_ACCOUNT, API_KEY_ORGANIZATION => ACTOR_TYPE_KEY_ORGANIZATION, diff --git a/tests/e2e/Services/Project/StagesBase.php b/tests/e2e/Services/Project/StagesBase.php index ff7a56359d..471fdd9acb 100644 --- a/tests/e2e/Services/Project/StagesBase.php +++ b/tests/e2e/Services/Project/StagesBase.php @@ -3,24 +3,19 @@ namespace Tests\E2E\Services\Project; use Appwrite\Extend\Exception; -use Appwrite\Tests\Async; use Tests\E2E\Client; use Utopia\Config\Config; -use Utopia\Database\Helpers\ID; use Utopia\Database\Validator\Datetime as DatetimeValidator; -use Utopia\System\System; trait StagesBase { - use Async; - // ========================================================================= // List stages tests // ========================================================================= public function testListProjectStages(): void { - $projectId = $this->createTeamAndProject(); + $projectId = $this->getProject()['$id']; $response = $this->listStages($projectId); @@ -38,20 +33,12 @@ trait StagesBase $this->assertArrayHasKey('status', $stage); $this->assertArrayHasKey('at', $stage); $this->assertArrayHasKey('actorType', $stage); - $this->assertSame('pending', $stage['status']); } - - // Verify via GET for unknown project - $response = $this->listStages(ID::unique()); - $this->assertSame(404, $response['headers']['status-code']); - $this->assertSame(Exception::PROJECT_NOT_FOUND, $response['body']['type']); } public function testListProjectStagesWithoutAuthentication(): void { - $projectId = $this->createTeamAndProject(); - - $response = $this->listStages($projectId, false); + $response = $this->listStages($this->getProject()['$id'], false); $this->assertSame(401, $response['headers']['status-code']); } @@ -62,7 +49,7 @@ trait StagesBase public function testUpdateProjectStageSkip(): void { - $projectId = $this->createTeamAndProject(); + $projectId = $this->getProject()['$id']; $method = 'tablesDB.create'; $response = $this->updateStage($projectId, $method, true); @@ -93,15 +80,11 @@ trait StagesBase $response = $this->updateStage($projectId, 'unknown.method', true); $this->assertSame(400, $response['headers']['status-code']); $this->assertSame(Exception::GENERAL_ARGUMENT_INVALID, $response['body']['type']); - - $response = $this->updateStage(ID::unique(), 'storage.createBucket', true); - $this->assertSame(404, $response['headers']['status-code']); - $this->assertSame(Exception::PROJECT_NOT_FOUND, $response['body']['type']); } public function testUpdateProjectStageSkipFalseLeavesPending(): void { - $projectId = $this->createTeamAndProject(); + $projectId = $this->getProject()['$id']; $method = 'storage.createBucket'; $response = $this->updateStage($projectId, $method, false); @@ -113,9 +96,7 @@ trait StagesBase public function testUpdateProjectStageWithoutAuthentication(): void { - $projectId = $this->createTeamAndProject(); - - $response = $this->updateStage($projectId, 'tablesDB.create', true, false); + $response = $this->updateStage($this->getProject()['$id'], 'tablesDB.create', true, false); $this->assertSame(401, $response['headers']['status-code']); } @@ -126,13 +107,15 @@ trait StagesBase protected function listStages(string $projectId, bool $authenticated = true): mixed { + // Stages live under /projects (console scope); use the root console session. $headers = [ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => 'console', ]; if ($authenticated) { - $headers = array_merge($headers, $this->getHeaders()); + $headers['origin'] = 'http://localhost'; + $headers['cookie'] = 'a_session_console=' . $this->getRoot()['session']; } return $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/stages', $headers, []); @@ -142,49 +125,16 @@ trait StagesBase { $headers = [ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => 'console', ]; if ($authenticated) { - $headers = array_merge($headers, $this->getHeaders()); + $headers['origin'] = 'http://localhost'; + $headers['cookie'] = 'a_session_console=' . $this->getRoot()['session']; } - return $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/stages/' . $stageId, $headers, [ + return $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/stages/' . rawurlencode($stageId), $headers, [ 'skip' => $skip, ]); } - - /** - * Creates a new team and child project under the console session (isolated from cached getProject()). - */ - protected function createTeamAndProject(): string - { - $teamId = ID::unique(); - $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], $this->getHeaders()), [ - 'teamId' => $teamId, - 'name' => 'Stages E2E Team', - ]); - - $this->assertContains($team['headers']['status-code'], [201, 409]); - if ($team['headers']['status-code'] === 201) { - $teamId = $team['body']['$id']; - } - - $project = $this->client->call(Client::METHOD_POST, '/projects', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], $this->getHeaders()), [ - 'projectId' => ID::unique(), - 'name' => 'Stages E2E Project', - 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), - ]); - - $this->assertSame(201, $project['headers']['status-code']); - - return $project['body']['$id']; - } } diff --git a/tests/e2e/Services/Project/StagesConsoleClientTest.php b/tests/e2e/Services/Project/StagesConsoleClientTest.php index cde4f4ab79..51ba5fa3e4 100644 --- a/tests/e2e/Services/Project/StagesConsoleClientTest.php +++ b/tests/e2e/Services/Project/StagesConsoleClientTest.php @@ -1,12 +1,14 @@