From 544861aa73879ccfbe913c193cbb2c52c43ac695 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 15 Jul 2026 17:40:23 +0530 Subject: [PATCH] (feat): gate console URL scheme behind _APP_CONSOLE_URL_SCHEME for legacy compatibility --- .../skills/patch-release-checklist/SKILL.md | 2 +- app/config/variables.php | 9 ++++ app/controllers/api/account.php | 10 +++-- app/controllers/general.php | 33 +++++++++----- docker-compose.yml | 5 ++- src/Appwrite/Platform/Workers/Webhooks.php | 6 ++- src/Appwrite/Vcs/Comment.php | 10 ++++- tests/unit/Platform/Workers/WebhooksTest.php | 45 ++++++++++++++++++- 8 files changed, 101 insertions(+), 19 deletions(-) diff --git a/.claude/skills/patch-release-checklist/SKILL.md b/.claude/skills/patch-release-checklist/SKILL.md index d052640f23..e365cc23ea 100644 --- a/.claude/skills/patch-release-checklist/SKILL.md +++ b/.claude/skills/patch-release-checklist/SKILL.md @@ -7,7 +7,7 @@ When bumping a patch version (e.g., `1.9.0` -> `1.9.1`), follow this checklist. ### Bump console image Update the console Docker image tag: -- [ ] `docker-compose.yml` -- update `image: appwrite/vibes:X.Y.Z` (the `appwrite-console` service) +- [ ] `docker-compose.yml` -- update `image: appwrite/new:X.Y.Z` (the `appwrite-console` service) ### Bump Appwrite version diff --git a/app/config/variables.php b/app/config/variables.php index 0eb43f783b..7107d7b7b1 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -223,6 +223,15 @@ return [ 'question' => '', 'filter' => '' ], + [ + 'name' => '_APP_CONSOLE_URL_SCHEME', + 'description' => 'Console URL scheme used when the backend generates links to the console (OAuth callbacks, emails, error page CTAs, VCS comments). Set to \'root\' for the new console served at the root path (appwrite/new), or \'legacy\' for the older console served under the /console path prefix. The default value is \'legacy\'.', + 'introduction' => '2.0.0', + 'default' => 'legacy', + 'required' => false, + 'question' => '', + 'filter' => '' + ], [ 'name' => '_APP_CONSOLE_HOSTNAMES', 'description' => 'This option allows you to add additional hostnames to your Appwrite console. This option is very useful for allowing access to the console project from additional domains. To enable it, pass a list of allowed hostnames separated by a comma.', diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 216e825dcd..5e3d3900d7 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -76,8 +76,10 @@ use Utopia\Validator\Range; use Utopia\Validator\Text; use Utopia\Validator\WhiteList; -$oauthDefaultSuccess = '/auth/oauth2/success'; -$oauthDefaultFailure = '/auth/oauth2/failure'; +$legacyConsolePaths = System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root'; + +$oauthDefaultSuccess = $legacyConsolePaths ? '/console/auth/oauth2/success' : '/auth/oauth2/success'; +$oauthDefaultFailure = $legacyConsolePaths ? '/console/auth/oauth2/failure' : '/auth/oauth2/failure'; $createSession = function (string $userId, string $secret, Request $request, Response $response, User $user, Database $dbForProject, Document $project, array $platform, Locale $locale, GeoRecord $geoRecord, Event $queueForEvents, Bus $bus, Store $store, ProofsToken $proofForToken, ProofsCode $proofForCode, bool $domainVerification, ?string $cookieDomain, Authorization $authorization) { @@ -2396,7 +2398,9 @@ Http::post('/v1/account/tokens/magic-url') } elseif ($protocol === 'http' && $port !== '80') { $callbackBase .= ':' . $port; } - $url = $callbackBase . '/auth/magic-url'; + $url = System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root' + ? "{$callbackBase}/console/auth/magic-url" + : "{$callbackBase}/auth/magic-url"; } $url = Template::parseURL($url); diff --git a/app/controllers/general.php b/app/controllers/general.php index 498d2de3c1..bb47346e67 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -125,7 +125,7 @@ function router(Http $utopia, Database $dbForPlatform, callable $getProjectDB, S if (\str_ends_with($host, $denyDomain)) { $exception = new AppwriteException(AppwriteException::RULE_NOT_FOUND, 'This domain is not connected to any Appwrite resources. Visit domains tab under function/site settings to configure it.', view: $errorView); - $exception->addCTA('Start with this domain', $url); + $exception->addCTA('Start with this domain', System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root' ? "{$url}/console" : $url); throw $exception; } } @@ -200,7 +200,11 @@ function router(Http $utopia, Database $dbForPlatform, callable $getProjectDB, S $resourceId = $rule->getAttribute('deploymentResourceId', ''); $type = ($resourceType === 'site') ? 'sites' : 'functions'; $exception = new AppwriteException(AppwriteException::DEPLOYMENT_NOT_FOUND, view: $errorView); - $exception->addCTA('View deployments', $url . '/projects/' . $projectId . '/' . $type . '/' . $resourceId); + $region = $project->getAttribute('region', 'default'); + $ctaUrl = System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root' + ? "/console/project-{$region}-{$projectId}/{$type}/{$resourceType}-{$resourceId}" + : "/projects/{$projectId}/{$type}/{$resourceId}"; + $exception->addCTA('View deployments', $url . $ctaUrl); throw $exception; } @@ -289,7 +293,7 @@ function router(Http $utopia, Database $dbForPlatform, callable $getProjectDB, S $response ->addHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') ->addHeader('Pragma', 'no-cache') - ->redirect($url . '/auth/preview?' + ->redirect($url . (System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root' ? '/console/auth/preview?' : '/auth/preview?') . \http_build_query([ 'projectId' => $projectId, 'origin' => $protocol . '://' . $host, @@ -346,23 +350,28 @@ function router(Http $utopia, Database $dbForPlatform, callable $getProjectDB, S $allowAnyStatus = !\is_null($apiKey) && $apiKey->isDeploymentStatusIgnored(); if (!$allowAnyStatus && $deployment->getAttribute('status') !== 'ready') { $status = $deployment->getAttribute('status'); + $region = $project->getAttribute('region', 'default'); + $legacyConsolePaths = System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root'; + $siteUrl = $legacyConsolePaths + ? "/console/project-{$region}-{$project->getId()}/sites/site-{$resource->getId()}" + : "/projects/{$project->getId()}/sites/{$resource->getId()}"; + $deploymentUrl = $legacyConsolePaths + ? "{$siteUrl}/deployments/deployment-{$deployment->getId()}" + : "{$siteUrl}/deployments/{$deployment->getId()}"; switch ($status) { case 'failed': $exception = new AppwriteException(AppwriteException::BUILD_FAILED, view: $errorView); - $ctaUrl = '/projects/' . $project->getId() . '/sites/' . $resource->getId() . '/deployments/' . $deployment->getId(); - $exception->addCTA('View logs', $url . $ctaUrl); + $exception->addCTA('View logs', $url . $deploymentUrl); break; case 'canceled': $exception = new AppwriteException(AppwriteException::BUILD_CANCELED, view: $errorView); - $ctaUrl = '/projects/' . $project->getId() . '/sites/' . $resource->getId() . '/deployments'; - $exception->addCTA('View deployments', $url . $ctaUrl); + $exception->addCTA('View deployments', $url . $siteUrl . '/deployments'); break; default: $exception = new AppwriteException(AppwriteException::BUILD_NOT_READY, view: $errorView); - $ctaUrl = '/projects/' . $project->getId() . '/sites/' . $resource->getId() . '/deployments/' . $deployment->getId(); $exception->addCTA('Reload', '/'); - $exception->addCTA('View logs', $url . $ctaUrl); + $exception->addCTA('View logs', $url . $deploymentUrl); break; } throw $exception; @@ -372,7 +381,11 @@ function router(Http $utopia, Database $dbForPlatform, callable $getProjectDB, S $permissions = $resource->getAttribute('execute'); if (!(\in_array('any', $permissions)) && !(\in_array('guests', $permissions))) { $exception = new AppwriteException(AppwriteException::FUNCTION_EXECUTE_PERMISSION_MISSING, view: $errorView); - $exception->addCTA('View settings', $url . '/projects/' . $project->getId() . '/functions/' . $resource->getId() . '/settings'); + $region = $project->getAttribute('region', 'default'); + $ctaUrl = System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root' + ? "/console/project-{$region}-{$project->getId()}/functions/function-{$resource->getId()}/settings" + : "/projects/{$project->getId()}/functions/{$resource->getId()}/settings"; + $exception->addCTA('View settings', $url . $ctaUrl); throw $exception; } } diff --git a/docker-compose.yml b/docker-compose.yml index 6cb71e9398..95dfe83588 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -104,6 +104,7 @@ services: - _APP_NOTIFICATIONS_TRACKING_SECRET - _APP_DOMAIN - _APP_CONSOLE_DOMAIN + - _APP_CONSOLE_URL_SCHEME=root - _APP_CONSOLE_TRUSTED_PROJECTS - _APP_DOMAIN_TARGET_CNAME - _APP_DOMAIN_TARGET_AAAA @@ -218,7 +219,7 @@ services: max-file: "5" max-size: 10m container_name: appwrite-console - image: appwrite/vibes:0.3.16 + image: appwrite/new:0.3.24 restart: unless-stopped networks: - appwrite @@ -328,6 +329,7 @@ services: - _APP_LOGGING_CONFIG - _APP_WEBHOOK_MAX_FAILED_ATTEMPTS - _APP_DATABASE_SHARED_TABLES + - _APP_CONSOLE_URL_SCHEME=root appwrite-worker-deletes: entrypoint: worker-deletes logging: @@ -490,6 +492,7 @@ services: - _APP_OPTIONS_ROUTER_FORCE_HTTPS - _APP_DOMAIN - _APP_CONSOLE_DOMAIN + - _APP_CONSOLE_URL_SCHEME=root - _APP_CONSOLE_TRUSTED_PROJECTS - _APP_STORAGE_DEVICE - _APP_STORAGE_S3_ACCESS_KEY diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index bce33f0efb..e357a7c13e 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -259,6 +259,8 @@ class Webhooks extends Action $projectId = $project->getId(); $projectInternalId = $project->getSequence(); + $region = $project->getAttribute('region', 'default'); + $webhookId = $webhook->getId(); $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS', 'disabled') === 'disabled' ? 'http' : 'https'; $consoleHostname = System::getEnv('_APP_CONSOLE_DOMAIN', System::getEnv('_APP_DOMAIN', 'localhost')); @@ -302,7 +304,9 @@ class Webhooks extends Action $template->setParam('{{url}}', $webhook->getAttribute('url')); $template->setParam('{{error}}', 'The server returned ' . $statusCode . ' status code'); $template->setParam('{{host}}', $protocol . '://' . $consoleHostname); - $template->setParam('{{path}}', "/projects/$projectId/settings/webhooks"); + $template->setParam('{{path}}', System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root' + ? "/console/project-{$region}-{$projectId}/settings/webhooks/{$webhookId}" + : "/projects/{$projectId}/settings/webhooks"); $template->setParam('{{attempts}}', $attempts); $publisherForNotifications->enqueue(new NotificationMessage( diff --git a/src/Appwrite/Vcs/Comment.php b/src/Appwrite/Vcs/Comment.php index 77df933a04..ac0f6e1dae 100644 --- a/src/Appwrite/Vcs/Comment.php +++ b/src/Appwrite/Vcs/Comment.php @@ -161,7 +161,10 @@ class Comment }; if ($site['action']['type'] === 'logs') { - $action = '[View Logs](' . $protocol . '://' . $hostname . '/projects/' . $projectId . '/sites/' . $siteId . '/deployments/' . $site['deploymentId'] . ')'; + $logsUrl = System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root' + ? "{$protocol}://{$hostname}/console/project-{$site['region']}-{$projectId}/sites/site-{$siteId}/deployments/deployment-{$site['deploymentId']}" + : "{$protocol}://{$hostname}/projects/{$projectId}/sites/{$siteId}/deployments/{$site['deploymentId']}"; + $action = "[View Logs]({$logsUrl})"; } else { $action = '[Authorize](' . $site['action']['url'] . ')'; } @@ -209,7 +212,10 @@ class Comment }; if ($function['action']['type'] === 'logs') { - $action = '[View Logs](' . $protocol . '://' . $hostname . '/projects/' . $projectId . '/functions/' . $functionId . '/deployments/' . $function['deploymentId'] . ')'; + $logsUrl = System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root' + ? "{$protocol}://{$hostname}/console/project-{$function['region']}-{$projectId}/functions/function-{$functionId}/deployment-{$function['deploymentId']}" + : "{$protocol}://{$hostname}/projects/{$projectId}/functions/{$functionId}/deployments/{$function['deploymentId']}"; + $action = "[View Logs]({$logsUrl})"; } else { $action = '[Authorize](' . $function['action']['url'] . ')'; } diff --git a/tests/unit/Platform/Workers/WebhooksTest.php b/tests/unit/Platform/Workers/WebhooksTest.php index cf611e285b..9065aef41c 100644 --- a/tests/unit/Platform/Workers/WebhooksTest.php +++ b/tests/unit/Platform/Workers/WebhooksTest.php @@ -69,7 +69,7 @@ final class WebhooksTest extends TestCase ); $this->assertStringContainsString('Payments', (string) $payload['body']); $this->assertStringContainsString('Ada Lovelace', (string) $payload['body']); - $this->assertStringContainsString('/projects/project-1/settings/webhooks', (string) $payload['body']); + $this->assertStringContainsString('/console/project-fra-project-1/settings/webhooks/webhook-1', (string) $payload['body']); $this->assertStringNotContainsString('{{', (string) $payload['body']); $this->assertSame(APP_NAME, $payload['variables']['platform']); $this->assertSame(APP_EMAIL_LOGO_URL, $payload['variables']['logoUrl']); @@ -96,6 +96,49 @@ final class WebhooksTest extends TestCase ], $payload['recipients'][1]); } + public function testSendAlertUsesRootConsolePathsWhenConfigured(): void + { + $database = $this->createPlatformDatabase(); + $this->seedOwnerUser($database); + + $publisher = new MockPublisher(); + $publisherForNotifications = new NotificationPublisher($publisher, new Queue('v1-notifications')); + $worker = new Webhooks(); + + \putenv('_APP_CONSOLE_URL_SCHEME=root'); + + try { + $worker->sendAlert( + attempts: 10, + statusCode: 500, + webhook: new Document([ + '$id' => 'webhook-1', + '$updatedAt' => '2026-01-01T00:00:00.000+00:00', + 'name' => 'Payments', + 'url' => 'https://example.test/webhook', + ]), + project: new Document([ + '$id' => 'project-1', + '$sequence' => 'project-internal-1', + 'name' => 'Production', + 'teamInternalId' => 'team-internal-1', + 'region' => 'fra', + ]), + dbForPlatform: $database, + publisherForNotifications: $publisherForNotifications, + plan: [] + ); + } finally { + \putenv('_APP_CONSOLE_URL_SCHEME'); + } + + $events = $publisher->getEvents('v1-notifications'); + + $this->assertCount(1, $events); + $this->assertStringContainsString('/projects/project-1/settings/webhooks', (string) $events[0]['body']); + $this->assertStringNotContainsString('/console/', (string) $events[0]['body']); + } + public function testSendAlertPersonalizesBodyPerOwner(): void { $database = $this->createPlatformDatabase();