From 7d785e7963eee062036c5cbdadea1d729088fc9b Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 15 Jun 2026 19:12:27 +0400 Subject: [PATCH 01/15] fix: disable build cache --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 2550db36e2..d01d82e2e7 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -732,7 +732,8 @@ class Builds extends Action variables: $vars, command: $command, outputDirectory: $outputDirectory ?? '', - cacheKey: $cacheKey + // temporarily disable build cache + // cacheKey: $cacheKey ); } catch (ExecutorTimeout $error) { From 4a9e9e050895ab4025c67a2d99ba1ee5a811ee3c Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 15 Jun 2026 19:29:45 +0400 Subject: [PATCH 02/15] fix: remove unused build cache capture --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index d01d82e2e7..3c8219cdf5 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -704,7 +704,7 @@ class Builds extends Action $span = Span::current(); Co::join([ - Co\go(function () use ($executor, &$response, $project, $deployment, $source, $resource, $runtime, $vars, $command, $cacheKey, $cpus, $memory, $timeout, &$err, $version, $span) { + Co\go(function () use ($executor, &$response, $project, $deployment, $source, $resource, $runtime, $vars, $command, $cpus, $memory, $timeout, &$err, $version, $span) { try { if ($version === 'v2') { $command = 'tar -zxf /tmp/code.tar.gz -C /usr/code && cd /usr/local/src/ && ./build.sh'; From fac754c6560876c560907694e5c29a5795fcdb73 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 16 Jun 2026 12:27:41 +0530 Subject: [PATCH 03/15] Add mails and messaging telemetry: send counters and span attributes (#12590) * (feat): add mails and messaging send telemetry counters and span attributes * (fix): address review - optional telemetry injection, cached counter, snake_case metric attribute * Update messaging telemetry integration * Move mails telemetry to messaging library * Restore mails worker spacing * Use constants for mail templates --- app/controllers/api/account.php | 4 ++ app/init/constants.php | 11 ++++ composer.json | 2 +- composer.lock | 17 ++++--- src/Appwrite/Bus/Listeners/Mails.php | 1 + src/Appwrite/Event/Message/Mail.php | 3 ++ .../Http/Account/MFA/Challenges/Create.php | 1 + .../Http/Project/SMTP/Tests/Create.php | 1 + .../Modules/Teams/Http/Memberships/Create.php | 1 + .../Platform/Workers/Certificates.php | 1 + src/Appwrite/Platform/Workers/Mails.php | 18 ++++++- src/Appwrite/Platform/Workers/Messaging.php | 50 +++++++++++++++++-- src/Appwrite/Platform/Workers/Migrations.php | 1 + src/Appwrite/Platform/Workers/Webhooks.php | 1 + tests/unit/Messaging/MessagingFanoutTest.php | 1 + 15 files changed, 98 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index a050e97b17..5ecae9c635 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -2405,6 +2405,7 @@ Http::post('/v1/account/tokens/magic-url') project: $project, recipient: $email, subject: $subject, + template: MAIL_TEMPLATE_MAGIC_URL, body: $body, preview: $preview, smtp: $smtpConfig, @@ -2751,6 +2752,7 @@ Http::post('/v1/account/tokens/email') project: $project, recipient: $email, subject: $subject, + template: MAIL_TEMPLATE_OTP, bodyTemplate: $bodyTemplate, body: $body, preview: $preview, @@ -3868,6 +3870,7 @@ Http::post('/v1/account/recovery') recipient: $profile->getAttribute('email', ''), name: $profile->getAttribute('name', ''), subject: $subject, + template: MAIL_TEMPLATE_RECOVERY, body: $body, preview: $preview, smtp: $smtpConfig, @@ -4222,6 +4225,7 @@ Http::post('/v1/account/verifications/email') recipient: $user->getAttribute('email'), name: $user->getAttribute('name') ?? '', subject: $subject, + template: MAIL_TEMPLATE_VERIFICATION, bodyTemplate: $bodyTemplate, body: $body, preview: $preview, diff --git a/app/init/constants.php b/app/init/constants.php index 4fe7c418a9..66d56a321c 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -271,6 +271,17 @@ const FUNCTION_ALLOWLIST_HEADERS_RESPONSE = ['content-type', 'content-length']; const MESSAGE_TYPE_EMAIL = 'email'; const MESSAGE_TYPE_SMS = 'sms'; const MESSAGE_TYPE_PUSH = 'push'; +const MAIL_TEMPLATE_CERTIFICATE_FAILED = 'certificate-failed'; +const MAIL_TEMPLATE_DATA_EXPORT = 'data-export'; +const MAIL_TEMPLATE_INVITATION = 'invitation'; +const MAIL_TEMPLATE_MAGIC_URL = 'magic-url'; +const MAIL_TEMPLATE_MFA_CHALLENGE = 'mfa-challenge'; +const MAIL_TEMPLATE_OTP = 'otp'; +const MAIL_TEMPLATE_RECOVERY = 'recovery'; +const MAIL_TEMPLATE_SESSION_ALERT = 'session-alert'; +const MAIL_TEMPLATE_SMTP_TEST = 'smtp-test'; +const MAIL_TEMPLATE_VERIFICATION = 'verification'; +const MAIL_TEMPLATE_WEBHOOK_FAILED = 'webhook-failed'; // API key types const API_KEY_STANDARD = 'standard'; const API_KEY_EPHEMERAL = 'ephemeral'; diff --git a/composer.json b/composer.json index af7575c671..f6e2a35066 100644 --- a/composer.json +++ b/composer.json @@ -76,7 +76,7 @@ "utopia-php/locale": "0.8.*", "utopia-php/lock": "0.2.*", "utopia-php/logger": "0.8.*", - "utopia-php/messaging": "1.0.*", + "utopia-php/messaging": "^1.1", "utopia-php/migration": "1.*", "utopia-php/platform": "^1.0@RC", "utopia-php/pools": "1.*", diff --git a/composer.lock b/composer.lock index 703189e5f9..97674ae904 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fe6368e3d42f385c63d7e5e2e911febd", + "content-hash": "2dfcf2f234c0ef563a0ee4b47534ddc5", "packages": [ { "name": "adhocore/jwt", @@ -4354,16 +4354,16 @@ }, { "name": "utopia-php/messaging", - "version": "1.0.0", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/utopia-php/messaging.git", - "reference": "1aca8968c3bf3c78c428a399dfe97cbe9b366ec4" + "reference": "2a8e82cda89b373833e10923ae959f56466300a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/messaging/zipball/1aca8968c3bf3c78c428a399dfe97cbe9b366ec4", - "reference": "1aca8968c3bf3c78c428a399dfe97cbe9b366ec4", + "url": "https://api.github.com/repos/utopia-php/messaging/zipball/2a8e82cda89b373833e10923ae959f56466300a3", + "reference": "2a8e82cda89b373833e10923ae959f56466300a3", "shasum": "" }, "require": { @@ -4371,7 +4371,8 @@ "ext-openssl": "*", "giggsey/libphonenumber-for-php-lite": "9.0.23", "php": ">=8.1.0", - "phpmailer/phpmailer": "6.9.1" + "phpmailer/phpmailer": "6.9.1", + "utopia-php/telemetry": "^0.4" }, "require-dev": { "laravel/pint": "1.*", @@ -4399,9 +4400,9 @@ ], "support": { "issues": "https://github.com/utopia-php/messaging/issues", - "source": "https://github.com/utopia-php/messaging/tree/1.0.0" + "source": "https://github.com/utopia-php/messaging/tree/1.1.0" }, - "time": "2026-06-02T14:54:22+00:00" + "time": "2026-06-16T03:44:58+00:00" }, { "name": "utopia-php/migration", diff --git a/src/Appwrite/Bus/Listeners/Mails.php b/src/Appwrite/Bus/Listeners/Mails.php index eb36e0d394..948394d8b6 100644 --- a/src/Appwrite/Bus/Listeners/Mails.php +++ b/src/Appwrite/Bus/Listeners/Mails.php @@ -143,6 +143,7 @@ class Mails extends Listener project: $project, recipient: $event->user['email'], subject: $subject, + template: MAIL_TEMPLATE_SESSION_ALERT, bodyTemplate: __DIR__ . '/../../../../app/config/locale/templates/' . $smtpBaseTemplate . '.tpl', body: $body, preview: $preview, diff --git a/src/Appwrite/Event/Message/Mail.php b/src/Appwrite/Event/Message/Mail.php index aeeea8a616..b823f107da 100644 --- a/src/Appwrite/Event/Message/Mail.php +++ b/src/Appwrite/Event/Message/Mail.php @@ -12,6 +12,7 @@ final class Mail extends Base public readonly string $recipient = '', public readonly string $name = '', public readonly string $subject = '', + public readonly string $template = '', public readonly string $bodyTemplate = '', public readonly string $body = '', public readonly string $preview = '', @@ -33,6 +34,7 @@ final class Mail extends Base 'recipient' => $this->recipient, 'name' => $this->name, 'subject' => $this->subject, + 'template' => $this->template, 'bodyTemplate' => $this->bodyTemplate, 'body' => $this->body, 'preview' => $this->preview, @@ -52,6 +54,7 @@ final class Mail extends Base recipient: $data['recipient'] ?? '', name: $data['name'] ?? '', subject: $data['subject'] ?? '', + template: $data['template'] ?? '', bodyTemplate: $data['bodyTemplate'] ?? '', body: $data['body'] ?? '', preview: $data['preview'] ?? '', diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php index 27d6f3e088..da6055fffd 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php @@ -336,6 +336,7 @@ class Create extends Action project: $project, recipient: $user->getAttribute('email'), subject: $subject, + template: MAIL_TEMPLATE_MFA_CHALLENGE, bodyTemplate: $bodyTemplate, body: $body, preview: $preview, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Tests/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Tests/Create.php index df5b650d5d..689ebcb097 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Tests/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Tests/Create.php @@ -152,6 +152,7 @@ class Create extends Action project: $project, recipient: $email, subject: $subject, + template: MAIL_TEMPLATE_SMTP_TEST, bodyTemplate: APP_CE_CONFIG_DIR . '/locale/templates/email-base-styled.tpl', body: $template->render(), smtp: [ diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php index 19d9237ff1..92db118c46 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php @@ -418,6 +418,7 @@ class Create extends Action recipient: $invitee->getAttribute('email'), name: $invitee->getAttribute('name', ''), subject: $subject, + template: MAIL_TEMPLATE_INVITATION, body: $body, preview: $preview, smtp: $smtpConfig, diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index 4a31216599..89da7d01de 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -572,6 +572,7 @@ class Certificates extends Action recipient: System::getEnv('_APP_EMAIL_CERTIFICATES', System::getEnv('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS')), name: 'Appwrite Administrator', subject: $subject, + template: MAIL_TEMPLATE_CERTIFICATE_FAILED, bodyTemplate: __DIR__ . '/../../../../app/config/locale/templates/email-base-styled.tpl', body: $body, preview: $preview, diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index 5cd4639988..48cb58722d 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -14,7 +14,9 @@ use Utopia\Messaging\Messages\Email\Attachment; use Utopia\Platform\Action; use Utopia\Queue\Message; use Utopia\Registry\Registry; +use Utopia\Span\Span; use Utopia\System\System; +use Utopia\Telemetry\Adapter as Telemetry; class Mails extends Action { @@ -39,6 +41,7 @@ class Mails extends Action ->inject('project') ->inject('register') ->inject('log') + ->inject('telemetry') ->callback($this->action(...)); } @@ -55,10 +58,11 @@ class Mails extends Action * @param Document $project * @param Registry $register * @param Log $log + * @param Telemetry $telemetry * @return void * @throws Exception */ - public function action(Message $message, Document $project, Registry $register, Log $log): void + public function action(Message $message, Document $project, Registry $register, Log $log, Telemetry $telemetry): void { Runtime::setHookFlags(SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_TCP); $payload = $message->getPayload(); @@ -81,6 +85,12 @@ class Mails extends Action $recipient = $payload['recipient']; $subject = $payload['subject']; + $template = $payload['template'] ?? 'unknown'; + $recipientDomain = \strtolower(\substr(\strrchr($recipient, '@') ?: '', 1)); + + Span::add('mail.template', $template); + Span::add('mail.smtp_type', $type); + Span::add('mail.recipient_domain', $recipientDomain); $variables = $payload['variables']; $variables['host'] = $protocol . '://' . $hostname; $name = $payload['name']; @@ -150,6 +160,7 @@ class Mails extends Action keepAlive: true, timelimit: 30, ); + $adapter->setTelemetry($telemetry); // Resolve from/replyTo using fallback hierarchy: Custom options > SMTP config > Defaults $defaultFromEmail = System::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM); @@ -202,14 +213,19 @@ class Mails extends Action attachments: $attachments, html: true, ); + $emailMessage->setOrigin(MESSAGE_SEND_TYPE_INTERNAL); try { $adapter->send($emailMessage); } catch (\Throwable $error) { + Span::add('mail.status', 'failure'); + if ($type === 'smtp') { throw new Exception('Error sending mail: ' . $error->getMessage(), 401); } throw new Exception('Error sending mail: ' . $error->getMessage(), 500); } + + Span::add('mail.status', 'success'); } } diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index ddd7edf641..2a827f82cb 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -49,6 +49,7 @@ use Utopia\Storage\Device; use Utopia\Storage\Device\Local; use Utopia\Storage\Storage; use Utopia\System\System; +use Utopia\Telemetry\Adapter as Telemetry; use function Swoole\Coroutine\batch; @@ -56,6 +57,8 @@ class Messaging extends Action { private ?SMSAdapter $adapter = null; + private Telemetry $telemetry; + public static function getName(): string { return 'messaging'; @@ -74,6 +77,7 @@ class Messaging extends Action ->inject('dbForProject') ->inject('deviceForFiles') ->inject('publisherForUsage') + ->inject('telemetry') ->callback($this->action(...)); } @@ -84,6 +88,7 @@ class Messaging extends Action * @param Database $dbForProject * @param Device $deviceForFiles * @param UsagePublisher $publisherForUsage + * @param Telemetry $telemetry * @return void * @throws \Exception */ @@ -93,9 +98,12 @@ class Messaging extends Action Log $log, Database $dbForProject, Device $deviceForFiles, - UsagePublisher $publisherForUsage + UsagePublisher $publisherForUsage, + Telemetry $telemetry ): void { Runtime::setHookFlags(SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_TCP); + + $this->telemetry = $telemetry; $payload = $message->getPayload(); if (empty($payload)) { @@ -143,6 +151,8 @@ class Messaging extends Action $userIds = $message->getAttribute('users', []); $providerType = $message->getAttribute('providerType'); + Span::add('message.provider_type', $providerType); + $default = $dbForProject->findOne('providers', [ Query::equal('enabled', [true]), Query::equal('type', [$providerType]), @@ -268,6 +278,11 @@ class Messaging extends Action $message->setAttribute('search', "{$message->getAttribute('search')} {$provider->getAttribute('name')} {$provider->getAttribute('provider')} {$provider->getAttribute('type')}"); } + Span::add('message.providers', \implode(',', \array_unique(\array_map( + fn (Document $provider) => $provider->getAttribute('provider'), + \array_values($providers) + )))); + $message->setAttribute('deliveredTotal', $deliveredTotal); $message->setAttribute('deliveredAt', DateTime::now()); @@ -533,6 +548,7 @@ class Messaging extends Action ] = $this->retrySend($batch, $message, $provider, $providerType, $adapter, $dbForProject, $deviceForFiles, $project); $failed = $recipients - $delivered; + $usage = new UsageContext(); $usage ->addMetric(METRIC_MESSAGES, $recipients) @@ -758,12 +774,16 @@ class Messaging extends Action $messageData = clone $message; $messageData->setAttribute('to', $to); - return match ($providerType) { + $data = match ($providerType) { MESSAGE_TYPE_SMS => $this->buildSmsMessage($messageData, $provider), MESSAGE_TYPE_PUSH => $this->buildPushMessage($messageData), MESSAGE_TYPE_EMAIL => $this->buildEmailMessage($dbForProject, $messageData, $provider, $deviceForFiles, $project), default => throw new \Exception('Provider with the requested ID is of the incorrect type') }; + + $data->setOrigin(MESSAGE_SEND_TYPE_EXTERNAL); + + return $data; } private function sendInternalSMSMessage(Document $message, Document $project, array $recipients, Log $log): void @@ -802,6 +822,7 @@ class Messaging extends Action $message->getAttribute('data')['content'], $from ); + $sms->setOrigin(MESSAGE_SEND_TYPE_INTERNAL); $this->adapter->send($sms); } @@ -811,7 +832,7 @@ class Messaging extends Action { $credentials = $provider->getAttribute('credentials'); - return match ($provider->getAttribute('provider')) { + $adapter = match ($provider->getAttribute('provider')) { 'mock' => (new Mock('username', 'password'))->setEndpoint('http://request-catcher-sms:5000/'), 'twilio' => new Twilio( $credentials['accountSid'] ?? '', @@ -848,6 +869,12 @@ class Messaging extends Action ), default => null }; + + if ($adapter !== null) { + $adapter->setTelemetry($this->telemetry); + } + + return $adapter; } protected function getPushAdapter(Document $provider): ?PushAdapter @@ -855,7 +882,7 @@ class Messaging extends Action $credentials = $provider->getAttribute('credentials'); $options = $provider->getAttribute('options'); - return match ($provider->getAttribute('provider')) { + $adapter = match ($provider->getAttribute('provider')) { 'mock' => new Mock('username', 'password'), 'apns' => new APNS( $credentials['authKey'] ?? '', @@ -867,6 +894,12 @@ class Messaging extends Action 'fcm' => new FCM(\json_encode($credentials['serviceAccountJSON'])), default => null }; + + if ($adapter !== null) { + $adapter->setTelemetry($this->telemetry); + } + + return $adapter; } protected function getEmailAdapter(Document $provider): ?EmailAdapter @@ -875,7 +908,7 @@ class Messaging extends Action $options = $provider->getAttribute('options', []); $apiKey = $credentials['apiKey'] ?? ''; - return match ($provider->getAttribute('provider')) { + $adapter = match ($provider->getAttribute('provider')) { 'mock' => new Mock('username', 'password'), 'smtp' => new SMTP( $credentials['host'] ?? '', @@ -901,6 +934,12 @@ class Messaging extends Action ), default => null }; + + if ($adapter !== null) { + $adapter->setTelemetry($this->telemetry); + } + + return $adapter; } private function buildEmailMessage( @@ -1117,6 +1156,7 @@ class Messaging extends Action $defaultProvider = $this->createProviderFromDSN($defaultDSN); $adapter = $this->getSmsAdapter($defaultProvider); $geosms = new GEOSMS($adapter); + $geosms->setTelemetry($this->telemetry); /** @var DSN $localDSN */ foreach ($localDSNs as $localDSN) { diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index a6f65fc742..825caf764d 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -947,6 +947,7 @@ class Migrations extends Action recipient: $user->getAttribute('email'), name: $user->getAttribute('name', $user->getAttribute('email')), subject: $subject, + template: MAIL_TEMPLATE_DATA_EXPORT, bodyTemplate: __DIR__ . '/../../../../app/config/locale/templates/email-base-styled.tpl', body: $emailBody, preview: $preview, diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index d91425d59b..593fd39767 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -272,6 +272,7 @@ class Webhooks extends Action recipient: $user->getAttribute('email'), name: $user->getAttribute('name', ''), subject: $subject, + template: MAIL_TEMPLATE_WEBHOOK_FAILED, body: $body->render(), preview: $preview, variables: ['user' => $user->getAttribute('name', '')], diff --git a/tests/unit/Messaging/MessagingFanoutTest.php b/tests/unit/Messaging/MessagingFanoutTest.php index 78172a5a0e..75f01b902b 100644 --- a/tests/unit/Messaging/MessagingFanoutTest.php +++ b/tests/unit/Messaging/MessagingFanoutTest.php @@ -558,6 +558,7 @@ class ScriptedEmailAdapter extends EmailAdapter */ public function __construct(private readonly array $script = []) { + parent::__construct(); } public function getName(): string From c9f0719783f323798a24b0d2a351fadc43ff08d5 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 16 Jun 2026 12:31:41 +0530 Subject: [PATCH 04/15] test: add e2e test for cross-project installation validation --- .../e2e/Services/VCS/VCSConsoleClientTest.php | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/tests/e2e/Services/VCS/VCSConsoleClientTest.php b/tests/e2e/Services/VCS/VCSConsoleClientTest.php index 041f825cee..f3d41ebda4 100644 --- a/tests/e2e/Services/VCS/VCSConsoleClientTest.php +++ b/tests/e2e/Services/VCS/VCSConsoleClientTest.php @@ -715,6 +715,98 @@ final class VCSConsoleClientTest extends Scope ], $this->getHeaders())); } + public function testCrossProjectInstallationRejected(): void + { + $installationId = $this->setupInstallation(); + + // Create a second project + $team = $this->client->call(Client::METHOD_POST, '/teams', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-project' => 'console', + ], ['teamId' => ID::unique(), 'name' => 'Cross Project Team']); + + $project2 = $this->client->call(Client::METHOD_POST, '/projects', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-project' => 'console', + ], [ + 'projectId' => ID::unique(), + 'name' => 'Cross Project Test', + 'teamId' => $team['body']['$id'], + 'region' => System::getEnv('_APP_REGION', 'default'), + ]); + + $this->assertEquals(201, $project2['headers']['status-code']); + $project2Id = $project2['body']['$id']; + + $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-project' => 'console', + ], [ + 'keyId' => ID::unique(), + 'name' => 'Test Key', + 'scopes' => ['functions.write', 'sites.write'], + ]); + + $headers2 = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $project2Id, + 'x-appwrite-key' => $key['body']['secret'], + ]; + + // createFunction with installation from project 1 → should fail + $function = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ + 'functionId' => ID::unique(), + 'name' => 'Test Cross', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId, + 'providerBranch' => 'main', + ]); + + $this->assertEquals(404, $function['headers']['status-code']); + + // createSite with installation from project 1 → should fail + $site = $this->client->call(Client::METHOD_POST, '/sites', $headers2, [ + 'siteId' => ID::unique(), + 'name' => 'Test Cross Site', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId3, + 'providerBranch' => 'main', + ]); + + $this->assertEquals(404, $site['headers']['status-code']); + + // Create a function in project 2 (no VCS), then try updateFunction with cross-project installation + $fn = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ + 'functionId' => ID::unique(), + 'name' => 'Test No VCS', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + ]); + + $this->assertEquals(201, $fn['headers']['status-code']); + + $updated = $this->client->call(Client::METHOD_PUT, '/functions/' . $fn['body']['$id'], $headers2, [ + 'name' => 'Test No VCS', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId, + 'providerBranch' => 'main', + ]); + + $this->assertEquals(404, $updated['headers']['status-code']); + } + public function testCreateRepository(): void { $installationId = $this->setupInstallation(); From 9a14d9b441972bb90350b40c536ac9d19f49d3d9 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 16 Jun 2026 12:39:00 +0530 Subject: [PATCH 05/15] Expose ping in SDK specs (#12604) --- app/controllers/general.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 94caf4760d..9ff704ca20 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -14,6 +14,7 @@ use Appwrite\Event\Publisher\Delete as DeletePublisher; use Appwrite\Extend\Exception as AppwriteException; use Appwrite\Network\Cors; use Appwrite\Platform\Appwrite; +use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Transformation\Adapter\Preview; @@ -1662,11 +1663,10 @@ Http::get('/v1/ping') namespace: 'ping', group: null, name: 'get', - hide: true, description: << Date: Tue, 16 Jun 2026 12:50:33 +0530 Subject: [PATCH 06/15] test: fix cross-project installation test setup and coverage --- .../e2e/Services/VCS/VCSConsoleClientTest.php | 130 ++++++++++-------- 1 file changed, 72 insertions(+), 58 deletions(-) diff --git a/tests/e2e/Services/VCS/VCSConsoleClientTest.php b/tests/e2e/Services/VCS/VCSConsoleClientTest.php index f3d41ebda4..e936013a90 100644 --- a/tests/e2e/Services/VCS/VCSConsoleClientTest.php +++ b/tests/e2e/Services/VCS/VCSConsoleClientTest.php @@ -718,40 +718,34 @@ final class VCSConsoleClientTest extends Scope public function testCrossProjectInstallationRejected(): void { $installationId = $this->setupInstallation(); - - // Create a second project - $team = $this->client->call(Client::METHOD_POST, '/teams', [ + $consoleHeaders = [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'cookie' => 'a_session_console=' . $this->getRoot()['session'], 'x-appwrite-project' => 'console', - ], ['teamId' => ID::unique(), 'name' => 'Cross Project Team']); + ]; - $project2 = $this->client->call(Client::METHOD_POST, '/projects', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], - 'x-appwrite-project' => 'console', - ], [ + $team = $this->client->call(Client::METHOD_POST, '/teams', $consoleHeaders, [ + 'teamId' => ID::unique(), + 'name' => 'Cross Project Team', + ]); + $this->assertEquals(201, $team['headers']['status-code']); + + $project2 = $this->client->call(Client::METHOD_POST, '/projects', $consoleHeaders, [ 'projectId' => ID::unique(), 'name' => 'Cross Project Test', 'teamId' => $team['body']['$id'], 'region' => System::getEnv('_APP_REGION', 'default'), ]); - $this->assertEquals(201, $project2['headers']['status-code']); $project2Id = $project2['body']['$id']; - $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], - 'x-appwrite-project' => 'console', - ], [ + $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', $consoleHeaders, [ 'keyId' => ID::unique(), 'name' => 'Test Key', 'scopes' => ['functions.write', 'sites.write'], ]); + $this->assertEquals(201, $key['headers']['status-code']); $headers2 = [ 'content-type' => 'application/json', @@ -759,52 +753,72 @@ final class VCSConsoleClientTest extends Scope 'x-appwrite-key' => $key['body']['secret'], ]; - // createFunction with installation from project 1 → should fail - $function = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ - 'functionId' => ID::unique(), - 'name' => 'Test Cross', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', - 'installationId' => $installationId, - 'providerRepositoryId' => $this->providerRepositoryId, - 'providerBranch' => 'main', - ]); + try { + // createFunction with installation from project 1 → should fail + $function = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ + 'functionId' => ID::unique(), + 'name' => 'Test Cross', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId, + 'providerBranch' => 'main', + ]); + $this->assertEquals(404, $function['headers']['status-code']); - $this->assertEquals(404, $function['headers']['status-code']); + // createSite with installation from project 1 → should fail + $site = $this->client->call(Client::METHOD_POST, '/sites', $headers2, [ + 'siteId' => ID::unique(), + 'name' => 'Test Cross Site', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId3, + 'providerBranch' => 'main', + ]); + $this->assertEquals(404, $site['headers']['status-code']); - // createSite with installation from project 1 → should fail - $site = $this->client->call(Client::METHOD_POST, '/sites', $headers2, [ - 'siteId' => ID::unique(), - 'name' => 'Test Cross Site', - 'framework' => 'other', - 'buildRuntime' => 'node-22', - 'installationId' => $installationId, - 'providerRepositoryId' => $this->providerRepositoryId3, - 'providerBranch' => 'main', - ]); + // updateFunction with cross-project installation → should fail + $fn = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ + 'functionId' => ID::unique(), + 'name' => 'Test No VCS', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + ]); + $this->assertEquals(201, $fn['headers']['status-code']); - $this->assertEquals(404, $site['headers']['status-code']); + $updated = $this->client->call(Client::METHOD_PUT, '/functions/' . $fn['body']['$id'], $headers2, [ + 'name' => 'Test No VCS', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId, + 'providerBranch' => 'main', + ]); + $this->assertEquals(404, $updated['headers']['status-code']); - // Create a function in project 2 (no VCS), then try updateFunction with cross-project installation - $fn = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ - 'functionId' => ID::unique(), - 'name' => 'Test No VCS', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', - ]); + // updateSite with cross-project installation → should fail + $siteNoVcs = $this->client->call(Client::METHOD_POST, '/sites', $headers2, [ + 'siteId' => ID::unique(), + 'name' => 'Test No VCS Site', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + ]); + $this->assertEquals(201, $siteNoVcs['headers']['status-code']); - $this->assertEquals(201, $fn['headers']['status-code']); - - $updated = $this->client->call(Client::METHOD_PUT, '/functions/' . $fn['body']['$id'], $headers2, [ - 'name' => 'Test No VCS', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', - 'installationId' => $installationId, - 'providerRepositoryId' => $this->providerRepositoryId, - 'providerBranch' => 'main', - ]); - - $this->assertEquals(404, $updated['headers']['status-code']); + $updatedSite = $this->client->call(Client::METHOD_PUT, '/sites/' . $siteNoVcs['body']['$id'], $headers2, [ + 'name' => 'Test No VCS Site', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId3, + 'providerBranch' => 'main', + ]); + $this->assertEquals(404, $updatedSite['headers']['status-code']); + } finally { + $this->client->call(Client::METHOD_DELETE, '/projects/' . $project2Id, $consoleHeaders); + $this->client->call(Client::METHOD_DELETE, '/teams/' . $team['body']['$id'], $consoleHeaders); + } } public function testCreateRepository(): void From b2ae1eaf6f5151686b7273871d87a73797f8f8cb Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 16 Jun 2026 12:59:00 +0530 Subject: [PATCH 07/15] fix: reject cross-project installationId on VCS attach --- .../Functions/Http/Functions/Create.php | 4 ++ .../Functions/Http/Functions/Update.php | 4 ++ .../Modules/Sites/Http/Sites/Create.php | 4 ++ .../Modules/Sites/Http/Sites/Update.php | 4 ++ .../e2e/Services/VCS/VCSConsoleClientTest.php | 66 +++++++++++-------- 5 files changed, 53 insertions(+), 29 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php index 601025c794..2692eaf630 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php @@ -218,6 +218,10 @@ class Create extends Base throw new Exception(Exception::INSTALLATION_NOT_FOUND); } + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + if (!empty($providerRepositoryId) && (empty($installationId) || empty($providerBranch))) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'When connecting to VCS (Version Control System), you need to provide "installationId" and "providerBranch".'); } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index fd89651800..323d460aab 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -165,6 +165,10 @@ class Update extends Base throw new Exception(Exception::INSTALLATION_NOT_FOUND); } + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + if (!empty($providerRepositoryId) && (empty($installationId) || empty($providerBranch))) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'When connecting to VCS (Version Control System), you need to provide "installationId" and "providerBranch".'); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php index e167c88af2..a774c31a0f 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php @@ -150,6 +150,10 @@ class Create extends Base throw new Exception(Exception::INSTALLATION_NOT_FOUND); } + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + if (!empty($providerRepositoryId) && (empty($installationId) || empty($providerBranch))) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'When connecting to VCS (Version Control System), you need to provide "installationId" and "providerBranch".'); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index be585ffdab..bda471886a 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -169,6 +169,10 @@ class Update extends Base throw new Exception(Exception::INSTALLATION_NOT_FOUND); } + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + if (!empty($providerRepositoryId) && (empty($installationId) || empty($providerBranch))) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'When connecting to VCS (Version Control System), you need to provide "installationId" and "providerBranch".'); } diff --git a/tests/e2e/Services/VCS/VCSConsoleClientTest.php b/tests/e2e/Services/VCS/VCSConsoleClientTest.php index e936013a90..f0942771ea 100644 --- a/tests/e2e/Services/VCS/VCSConsoleClientTest.php +++ b/tests/e2e/Services/VCS/VCSConsoleClientTest.php @@ -725,35 +725,39 @@ final class VCSConsoleClientTest extends Scope 'x-appwrite-project' => 'console', ]; - $team = $this->client->call(Client::METHOD_POST, '/teams', $consoleHeaders, [ - 'teamId' => ID::unique(), - 'name' => 'Cross Project Team', - ]); - $this->assertEquals(201, $team['headers']['status-code']); - - $project2 = $this->client->call(Client::METHOD_POST, '/projects', $consoleHeaders, [ - 'projectId' => ID::unique(), - 'name' => 'Cross Project Test', - 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default'), - ]); - $this->assertEquals(201, $project2['headers']['status-code']); - $project2Id = $project2['body']['$id']; - - $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', $consoleHeaders, [ - 'keyId' => ID::unique(), - 'name' => 'Test Key', - 'scopes' => ['functions.write', 'sites.write'], - ]); - $this->assertEquals(201, $key['headers']['status-code']); - - $headers2 = [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $project2Id, - 'x-appwrite-key' => $key['body']['secret'], - ]; + $teamId = null; + $project2Id = null; try { + $team = $this->client->call(Client::METHOD_POST, '/teams', $consoleHeaders, [ + 'teamId' => ID::unique(), + 'name' => 'Cross Project Team', + ]); + $this->assertEquals(201, $team['headers']['status-code']); + $teamId = $team['body']['$id']; + + $project2 = $this->client->call(Client::METHOD_POST, '/projects', $consoleHeaders, [ + 'projectId' => ID::unique(), + 'name' => 'Cross Project Test', + 'teamId' => $teamId, + 'region' => System::getEnv('_APP_REGION', 'default'), + ]); + $this->assertEquals(201, $project2['headers']['status-code']); + $project2Id = $project2['body']['$id']; + + $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', $consoleHeaders, [ + 'keyId' => ID::unique(), + 'name' => 'Test Key', + 'scopes' => ['functions.write', 'sites.write'], + ]); + $this->assertEquals(201, $key['headers']['status-code']); + + $headers2 = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $project2Id, + 'x-appwrite-key' => $key['body']['secret'], + ]; + // createFunction with installation from project 1 → should fail $function = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ 'functionId' => ID::unique(), @@ -816,8 +820,12 @@ final class VCSConsoleClientTest extends Scope ]); $this->assertEquals(404, $updatedSite['headers']['status-code']); } finally { - $this->client->call(Client::METHOD_DELETE, '/projects/' . $project2Id, $consoleHeaders); - $this->client->call(Client::METHOD_DELETE, '/teams/' . $team['body']['$id'], $consoleHeaders); + if ($project2Id !== null) { + $this->client->call(Client::METHOD_DELETE, '/projects/' . $project2Id, $consoleHeaders); + } + if ($teamId !== null) { + $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamId, $consoleHeaders); + } } } From ec9383e8c1fa514c02ec5f39ad3c779141198353 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 16 Jun 2026 13:26:13 +0530 Subject: [PATCH 08/15] ci: trigger VCS tests with credentials From 5b999ea2fa66acf0c2e08d7a019061dfc01bdd42 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 16 Jun 2026 14:01:04 +0530 Subject: [PATCH 09/15] fix: validate preserved installation ownership in update paths --- .../Functions/Http/Functions/Update.php | 12 ++++--- .../Modules/Sites/Http/Sites/Update.php | 12 ++++--- .../e2e/Services/VCS/VCSConsoleClientTest.php | 32 +++++++++---------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index 323d460aab..52943d7ab9 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -165,10 +165,6 @@ class Update extends Base throw new Exception(Exception::INSTALLATION_NOT_FOUND); } - if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { - throw new Exception(Exception::INSTALLATION_NOT_FOUND); - } - if (!empty($providerRepositoryId) && (empty($installationId) || empty($providerBranch))) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'When connecting to VCS (Version Control System), you need to provide "installationId" and "providerBranch".'); } @@ -186,6 +182,10 @@ class Update extends Base $isConnected = !empty($function->getAttribute('providerRepositoryId', '')); + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + // Omitted providerRepositoryId (null) on a connected function — preserve existing VCS values if ($isConnected && $providerRepositoryId === null) { $providerRepositoryId = $function->getAttribute('providerRepositoryId', ''); @@ -197,6 +197,10 @@ class Update extends Base $installation = $dbForPlatform->getDocument('installations', $installationId); } + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForPlatform->find('repositories', [ diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index bda471886a..4b1e030be0 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -169,10 +169,6 @@ class Update extends Base throw new Exception(Exception::INSTALLATION_NOT_FOUND); } - if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { - throw new Exception(Exception::INSTALLATION_NOT_FOUND); - } - if (!empty($providerRepositoryId) && (empty($installationId) || empty($providerBranch))) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'When connecting to VCS (Version Control System), you need to provide "installationId" and "providerBranch".'); } @@ -186,6 +182,10 @@ class Update extends Base $isConnected = !empty($site->getAttribute('providerRepositoryId', '')); + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + // Omitted providerRepositoryId (null) on a connected site — preserve existing VCS values if ($isConnected && $providerRepositoryId === null) { $providerRepositoryId = $site->getAttribute('providerRepositoryId', ''); @@ -197,6 +197,10 @@ class Update extends Base $installation = $dbForPlatform->getDocument('installations', $installationId); } + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForPlatform->find('repositories', [ diff --git a/tests/e2e/Services/VCS/VCSConsoleClientTest.php b/tests/e2e/Services/VCS/VCSConsoleClientTest.php index f0942771ea..b553a59ebd 100644 --- a/tests/e2e/Services/VCS/VCSConsoleClientTest.php +++ b/tests/e2e/Services/VCS/VCSConsoleClientTest.php @@ -22,11 +22,11 @@ final class VCSConsoleClientTest extends Scope use ProjectCustom; use SideConsole; - public string $providerInstallationId = '42954928'; // appwrite-test - public string $providerRepositoryId = '705764267'; // ruby-starter (public) - public string $providerRepositoryId2 = '708688544'; // function1.4 (private) - public string $providerRepositoryId3 = '943139433'; // svelte-starter (public) - public string $providerRepositoryId4 = '943245292'; // templates-for-sites (public) + public string $providerInstallationId = '140618770'; // appwrite-test + public string $providerRepositoryId = '1263962253'; // ruby-starter (public) + public string $providerRepositoryId2 = '1263962253'; // function1.4 (private) + public string $providerRepositoryId3 = '1263962253'; // svelte-starter (public) + public string $providerRepositoryId4 = '1263962253'; // templates-for-sites (public) private static array $cachedInstallationId = []; private static array $cachedFunctionData = []; @@ -75,7 +75,7 @@ final class VCSConsoleClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [Role::user($this->getUser()['$id'])->toString()], - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'entrypoint' => 'index.php', 'events' => [ 'users.*.create', @@ -600,7 +600,7 @@ final class VCSConsoleClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [Role::user($this->getUser()['$id'])->toString()], - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'entrypoint' => 'index.php', 'events' => [ 'users.*.create', @@ -615,9 +615,9 @@ final class VCSConsoleClientTest extends Scope $this->assertEquals(201, $function['headers']['status-code']); $this->assertEquals('Test', $function['body']['name']); - $this->assertEquals('php-8.0', $function['body']['runtime']); + $this->assertEquals('node-22', $function['body']['runtime']); $this->assertEquals('index.php', $function['body']['entrypoint']); - $this->assertEquals('705764267', $function['body']['providerRepositoryId']); + $this->assertEquals('1263962253', $function['body']['providerRepositoryId']); $this->assertEquals('main', $function['body']['providerBranch']); } @@ -632,7 +632,7 @@ final class VCSConsoleClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [Role::user($this->getUser()['$id'])->toString()], - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'entrypoint' => 'index.php', 'events' => [ 'users.*.create', @@ -647,9 +647,9 @@ final class VCSConsoleClientTest extends Scope $this->assertEquals(200, $function['headers']['status-code']); $this->assertEquals('Test', $function['body']['name']); - $this->assertEquals('php-8.0', $function['body']['runtime']); + $this->assertEquals('node-22', $function['body']['runtime']); $this->assertEquals('index.php', $function['body']['entrypoint']); - $this->assertEquals('708688544', $function['body']['providerRepositoryId']); + $this->assertEquals('1263962253', $function['body']['providerRepositoryId']); $this->assertEquals('main', $function['body']['providerBranch']); } @@ -663,7 +663,7 @@ final class VCSConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Test', - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'entrypoint' => 'index.php', 'timeout' => 10, ]); @@ -762,7 +762,7 @@ final class VCSConsoleClientTest extends Scope $function = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ 'functionId' => ID::unique(), 'name' => 'Test Cross', - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'entrypoint' => 'index.php', 'installationId' => $installationId, 'providerRepositoryId' => $this->providerRepositoryId, @@ -786,14 +786,14 @@ final class VCSConsoleClientTest extends Scope $fn = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ 'functionId' => ID::unique(), 'name' => 'Test No VCS', - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'entrypoint' => 'index.php', ]); $this->assertEquals(201, $fn['headers']['status-code']); $updated = $this->client->call(Client::METHOD_PUT, '/functions/' . $fn['body']['$id'], $headers2, [ 'name' => 'Test No VCS', - 'runtime' => 'php-8.0', + 'runtime' => 'node-22', 'entrypoint' => 'index.php', 'installationId' => $installationId, 'providerRepositoryId' => $this->providerRepositoryId, From a9edcd74bd1509688a300d295139442c9e542b98 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 16 Jun 2026 14:02:33 +0530 Subject: [PATCH 10/15] fix: remove redundant post-preservation ownership check --- .../Platform/Modules/Functions/Http/Functions/Update.php | 4 ---- src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php | 4 ---- 2 files changed, 8 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index 52943d7ab9..e9e14a6e22 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -197,10 +197,6 @@ class Update extends Base $installation = $dbForPlatform->getDocument('installations', $installationId); } - if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { - throw new Exception(Exception::INSTALLATION_NOT_FOUND); - } - // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForPlatform->find('repositories', [ diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index 4b1e030be0..1edc5ce87c 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -197,10 +197,6 @@ class Update extends Base $installation = $dbForPlatform->getDocument('installations', $installationId); } - if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { - throw new Exception(Exception::INSTALLATION_NOT_FOUND); - } - // Git disconnect logic. Disconnecting only when providerRepositoryId is empty, allowing for continue updates without disconnecting git if ($isConnected && ($providerRepositoryId !== null && empty($providerRepositoryId))) { $repositories = $dbForPlatform->find('repositories', [ From a7cb1148e910293b7e72531bc88e4e03d6ab1901 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 16 Jun 2026 14:07:34 +0530 Subject: [PATCH 11/15] test: restore original CI credentials in VCS test file --- .../e2e/Services/VCS/VCSConsoleClientTest.php | 98 +++++++++---------- 1 file changed, 45 insertions(+), 53 deletions(-) diff --git a/tests/e2e/Services/VCS/VCSConsoleClientTest.php b/tests/e2e/Services/VCS/VCSConsoleClientTest.php index b553a59ebd..e936013a90 100644 --- a/tests/e2e/Services/VCS/VCSConsoleClientTest.php +++ b/tests/e2e/Services/VCS/VCSConsoleClientTest.php @@ -22,11 +22,11 @@ final class VCSConsoleClientTest extends Scope use ProjectCustom; use SideConsole; - public string $providerInstallationId = '140618770'; // appwrite-test - public string $providerRepositoryId = '1263962253'; // ruby-starter (public) - public string $providerRepositoryId2 = '1263962253'; // function1.4 (private) - public string $providerRepositoryId3 = '1263962253'; // svelte-starter (public) - public string $providerRepositoryId4 = '1263962253'; // templates-for-sites (public) + public string $providerInstallationId = '42954928'; // appwrite-test + public string $providerRepositoryId = '705764267'; // ruby-starter (public) + public string $providerRepositoryId2 = '708688544'; // function1.4 (private) + public string $providerRepositoryId3 = '943139433'; // svelte-starter (public) + public string $providerRepositoryId4 = '943245292'; // templates-for-sites (public) private static array $cachedInstallationId = []; private static array $cachedFunctionData = []; @@ -75,7 +75,7 @@ final class VCSConsoleClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [Role::user($this->getUser()['$id'])->toString()], - 'runtime' => 'node-22', + 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'events' => [ 'users.*.create', @@ -600,7 +600,7 @@ final class VCSConsoleClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [Role::user($this->getUser()['$id'])->toString()], - 'runtime' => 'node-22', + 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'events' => [ 'users.*.create', @@ -615,9 +615,9 @@ final class VCSConsoleClientTest extends Scope $this->assertEquals(201, $function['headers']['status-code']); $this->assertEquals('Test', $function['body']['name']); - $this->assertEquals('node-22', $function['body']['runtime']); + $this->assertEquals('php-8.0', $function['body']['runtime']); $this->assertEquals('index.php', $function['body']['entrypoint']); - $this->assertEquals('1263962253', $function['body']['providerRepositoryId']); + $this->assertEquals('705764267', $function['body']['providerRepositoryId']); $this->assertEquals('main', $function['body']['providerBranch']); } @@ -632,7 +632,7 @@ final class VCSConsoleClientTest extends Scope 'functionId' => ID::unique(), 'name' => 'Test', 'execute' => [Role::user($this->getUser()['$id'])->toString()], - 'runtime' => 'node-22', + 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'events' => [ 'users.*.create', @@ -647,9 +647,9 @@ final class VCSConsoleClientTest extends Scope $this->assertEquals(200, $function['headers']['status-code']); $this->assertEquals('Test', $function['body']['name']); - $this->assertEquals('node-22', $function['body']['runtime']); + $this->assertEquals('php-8.0', $function['body']['runtime']); $this->assertEquals('index.php', $function['body']['entrypoint']); - $this->assertEquals('1263962253', $function['body']['providerRepositoryId']); + $this->assertEquals('708688544', $function['body']['providerRepositoryId']); $this->assertEquals('main', $function['body']['providerBranch']); } @@ -663,7 +663,7 @@ final class VCSConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Test', - 'runtime' => 'node-22', + 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'timeout' => 10, ]); @@ -725,44 +725,40 @@ final class VCSConsoleClientTest extends Scope 'x-appwrite-project' => 'console', ]; - $teamId = null; - $project2Id = null; + $team = $this->client->call(Client::METHOD_POST, '/teams', $consoleHeaders, [ + 'teamId' => ID::unique(), + 'name' => 'Cross Project Team', + ]); + $this->assertEquals(201, $team['headers']['status-code']); + + $project2 = $this->client->call(Client::METHOD_POST, '/projects', $consoleHeaders, [ + 'projectId' => ID::unique(), + 'name' => 'Cross Project Test', + 'teamId' => $team['body']['$id'], + 'region' => System::getEnv('_APP_REGION', 'default'), + ]); + $this->assertEquals(201, $project2['headers']['status-code']); + $project2Id = $project2['body']['$id']; + + $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', $consoleHeaders, [ + 'keyId' => ID::unique(), + 'name' => 'Test Key', + 'scopes' => ['functions.write', 'sites.write'], + ]); + $this->assertEquals(201, $key['headers']['status-code']); + + $headers2 = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $project2Id, + 'x-appwrite-key' => $key['body']['secret'], + ]; try { - $team = $this->client->call(Client::METHOD_POST, '/teams', $consoleHeaders, [ - 'teamId' => ID::unique(), - 'name' => 'Cross Project Team', - ]); - $this->assertEquals(201, $team['headers']['status-code']); - $teamId = $team['body']['$id']; - - $project2 = $this->client->call(Client::METHOD_POST, '/projects', $consoleHeaders, [ - 'projectId' => ID::unique(), - 'name' => 'Cross Project Test', - 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), - ]); - $this->assertEquals(201, $project2['headers']['status-code']); - $project2Id = $project2['body']['$id']; - - $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', $consoleHeaders, [ - 'keyId' => ID::unique(), - 'name' => 'Test Key', - 'scopes' => ['functions.write', 'sites.write'], - ]); - $this->assertEquals(201, $key['headers']['status-code']); - - $headers2 = [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $project2Id, - 'x-appwrite-key' => $key['body']['secret'], - ]; - // createFunction with installation from project 1 → should fail $function = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ 'functionId' => ID::unique(), 'name' => 'Test Cross', - 'runtime' => 'node-22', + 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'installationId' => $installationId, 'providerRepositoryId' => $this->providerRepositoryId, @@ -786,14 +782,14 @@ final class VCSConsoleClientTest extends Scope $fn = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ 'functionId' => ID::unique(), 'name' => 'Test No VCS', - 'runtime' => 'node-22', + 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', ]); $this->assertEquals(201, $fn['headers']['status-code']); $updated = $this->client->call(Client::METHOD_PUT, '/functions/' . $fn['body']['$id'], $headers2, [ 'name' => 'Test No VCS', - 'runtime' => 'node-22', + 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'installationId' => $installationId, 'providerRepositoryId' => $this->providerRepositoryId, @@ -820,12 +816,8 @@ final class VCSConsoleClientTest extends Scope ]); $this->assertEquals(404, $updatedSite['headers']['status-code']); } finally { - if ($project2Id !== null) { - $this->client->call(Client::METHOD_DELETE, '/projects/' . $project2Id, $consoleHeaders); - } - if ($teamId !== null) { - $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamId, $consoleHeaders); - } + $this->client->call(Client::METHOD_DELETE, '/projects/' . $project2Id, $consoleHeaders); + $this->client->call(Client::METHOD_DELETE, '/teams/' . $team['body']['$id'], $consoleHeaders); } } From 0a6c7e0d2ea6d9b1f9928753cbdc4eb50fbe5f9e Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 16 Jun 2026 14:34:21 +0530 Subject: [PATCH 12/15] Run CI on merged PRs (#12606) --- .github/workflows/ci.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96b579c006..c2bd7ea4a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,9 @@ env: on: pull_request: + push: + branches: + - 1.9.x workflow_dispatch: inputs: response_format: @@ -705,7 +708,7 @@ jobs: benchmark: name: Benchmark - if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request' || github.event_name == 'push' runs-on: ubuntu-latest needs: build permissions: @@ -747,9 +750,11 @@ jobs: - name: Prepare benchmark before id: benchmark_before_prepare continue-on-error: true + env: + BENCHMARK_BEFORE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }} run: | - git fetch --depth=1 origin ${{ github.event.pull_request.base.sha }} - git worktree add --detach /tmp/appwrite-benchmark-before ${{ github.event.pull_request.base.sha }} + git fetch --depth=1 origin "${BENCHMARK_BEFORE_SHA}" + git worktree add --detach /tmp/appwrite-benchmark-before "${BENCHMARK_BEFORE_SHA}" docker build \ --cache-from ${{ env.IMAGE }}:after \ --target development \ @@ -871,8 +876,8 @@ jobs: if: always() uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: - BENCHMARK_BASE_REF: ${{ github.event.pull_request.base.ref }} - BENCHMARK_HEAD_REF: ${{ github.event.pull_request.head.ref }} + BENCHMARK_BASE_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || github.event.before }} + BENCHMARK_HEAD_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }} with: script: | const comment = require('./.github/workflows/benchmark-comment.js'); From 2540732ac0e14976ef0715b213d9997f55c43072 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 16 Jun 2026 18:42:50 +0530 Subject: [PATCH 13/15] fix: bump utopia-php/vcs to 4.2.3 --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 97674ae904..484402325d 100644 --- a/composer.lock +++ b/composer.lock @@ -5130,16 +5130,16 @@ }, { "name": "utopia-php/vcs", - "version": "4.2.2", + "version": "4.2.3", "source": { "type": "git", "url": "https://github.com/utopia-php/vcs.git", - "reference": "bb42584d3efb95ff4eb241605bb15165c56974de" + "reference": "598cbd2793a5a6394493f1046743e75ec6544a57" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/vcs/zipball/bb42584d3efb95ff4eb241605bb15165c56974de", - "reference": "bb42584d3efb95ff4eb241605bb15165c56974de", + "url": "https://api.github.com/repos/utopia-php/vcs/zipball/598cbd2793a5a6394493f1046743e75ec6544a57", + "reference": "598cbd2793a5a6394493f1046743e75ec6544a57", "shasum": "" }, "require": { @@ -5173,9 +5173,9 @@ ], "support": { "issues": "https://github.com/utopia-php/vcs/issues", - "source": "https://github.com/utopia-php/vcs/tree/4.2.2" + "source": "https://github.com/utopia-php/vcs/tree/4.2.3" }, - "time": "2026-06-10T08:08:48+00:00" + "time": "2026-06-16T12:14:08+00:00" }, { "name": "utopia-php/websocket", From c38c8e1f4d8cd49ab1381fb4cb90a4ceb800a45f Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 17 Jun 2026 09:25:56 +0530 Subject: [PATCH 14/15] fix: refine impersonation security scheme definitions (#12610) Compact the X-Appwrite-Impersonate-User-{Id,Email,Phone} header descriptions to a short phrase matching the other security schemes (they previously carried a multi-sentence paragraph that rendered poorly in the docs). Mark the impersonation schemes with a new x-appwrite.optional flag. Location methods (downloads, previews, views, avatars) include these schemes so impersonation can pass through as a URL query param, but they are optional; the flag lets SDK doc generation skip them in examples instead of showing setImpersonateUserId('') as required auth. --- src/Appwrite/Platform/Tasks/Specs.php | 45 +++++++++++++++++++++------ 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Specs.php b/src/Appwrite/Platform/Tasks/Specs.php index bd2a03ecf0..e7f5167611 100644 --- a/src/Appwrite/Platform/Tasks/Specs.php +++ b/src/Appwrite/Platform/Tasks/Specs.php @@ -180,20 +180,29 @@ class Specs extends Action 'ImpersonateUserId' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Id', - 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by ID', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserEmail' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Email', - 'description' => 'Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by email', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserPhone' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Phone', - 'description' => 'Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by phone', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], ], APP_SDK_PLATFORM_SERVER => [ @@ -258,20 +267,29 @@ class Specs extends Action 'ImpersonateUserId' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Id', - 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by ID', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserEmail' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Email', - 'description' => 'Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by email', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserPhone' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Phone', - 'description' => 'Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by phone', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], ], APP_SDK_PLATFORM_CONSOLE => [ @@ -336,20 +354,29 @@ class Specs extends Action 'ImpersonateUserId' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Id', - 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by ID', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserEmail' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Email', - 'description' => 'Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by email', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserPhone' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Phone', - 'description' => 'Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by phone', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], ], ]; From 53b2dea1243d8c9aa82af7e5a43989588ad776f7 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 17 Jun 2026 13:23:44 +0530 Subject: [PATCH 15/15] Add batch execution upserts (#12611) --- src/Appwrite/Event/Message/Executions.php | 39 ++++++++++++++++++++ src/Appwrite/Event/Publisher/Execution.php | 3 +- src/Appwrite/Platform/Workers/Executions.php | 38 ++++++++++++++----- 3 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 src/Appwrite/Event/Message/Executions.php diff --git a/src/Appwrite/Event/Message/Executions.php b/src/Appwrite/Event/Message/Executions.php new file mode 100644 index 0000000000..b6fbf64b91 --- /dev/null +++ b/src/Appwrite/Event/Message/Executions.php @@ -0,0 +1,39 @@ + $executions + */ + public function __construct( + public readonly Document $project, + public readonly array $executions, + ) { + } + + public function toArray(): array + { + return [ + 'project' => $this->project->getArrayCopy(), + 'executions' => \array_map( + fn (Document $execution) => $execution->getArrayCopy(), + $this->executions + ), + ]; + } + + public static function fromArray(array $data): static + { + return new self( + project: new Document($data['project'] ?? []), + executions: \array_map( + fn (array $execution) => new Document($execution), + $data['executions'] ?? [] + ), + ); + } +} diff --git a/src/Appwrite/Event/Publisher/Execution.php b/src/Appwrite/Event/Publisher/Execution.php index 05ea28d540..60470fcb9d 100644 --- a/src/Appwrite/Event/Publisher/Execution.php +++ b/src/Appwrite/Event/Publisher/Execution.php @@ -3,6 +3,7 @@ namespace Appwrite\Event\Publisher; use Appwrite\Event\Message\Execution as ExecutionMessage; +use Appwrite\Event\Message\Executions as ExecutionsMessage; use Utopia\Queue\Publisher; use Utopia\Queue\Queue; @@ -15,7 +16,7 @@ readonly class Execution extends Base parent::__construct($publisher); } - public function enqueue(ExecutionMessage $message): string|bool + public function enqueue(ExecutionMessage|ExecutionsMessage $message): string|bool { return $this->publish($this->queue, $message); } diff --git a/src/Appwrite/Platform/Workers/Executions.php b/src/Appwrite/Platform/Workers/Executions.php index 8dbf10cae6..30b4a43a55 100644 --- a/src/Appwrite/Platform/Workers/Executions.php +++ b/src/Appwrite/Platform/Workers/Executions.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Workers; use Appwrite\Event\Message\Execution; +use Appwrite\Event\Message\Executions as ExecutionsMessage; use Exception; use Utopia\Database\Database; use Utopia\Platform\Action; @@ -11,6 +12,8 @@ use Utopia\Span\Span; class Executions extends Action { + private const int UPSERT_BATCH_SIZE = 100; + public static function getName(): string { return 'executions'; @@ -33,19 +36,36 @@ class Executions extends Action Message $message, Database $dbForProject, ): void { - $executionMessage = Execution::fromArray($message->getPayload()); - $execution = $executionMessage->execution; + $payload = $message->getPayload(); + $isBatch = isset($payload['executions']) && \is_array($payload['executions']); - if ($execution->isEmpty()) { - throw new Exception('Missing execution'); + if ($isBatch) { + $executionMessage = ExecutionsMessage::fromArray($payload); + $executions = \array_values(\array_filter( + $executionMessage->executions, + fn ($execution) => !$execution->isEmpty() + )); + } else { + $executionMessage = Execution::fromArray($payload); + $executions = [$executionMessage->execution]; + } + + if (empty($executions)) { + throw new Exception($isBatch ? 'Missing executions' : 'Missing execution'); } Span::add('project.id', $executionMessage->project->getId()); - Span::add('function.id', $execution->getAttribute('resourceId', '')); - Span::add('execution.id', $execution->getId()); - Span::add('deployment.id', $execution->getAttribute('deploymentId', '')); - Span::add('resource.type', $execution->getAttribute('resourceType', '')); - $dbForProject->upsertDocument('executions', $execution); + if ($isBatch) { + Span::add('executions.count', \count($executions)); + $dbForProject->upsertDocuments('executions', $executions, self::UPSERT_BATCH_SIZE); + } else { + $execution = $executions[0]; + Span::add('function.id', $execution->getAttribute('resourceId', '')); + Span::add('execution.id', $execution->getId()); + Span::add('deployment.id', $execution->getAttribute('deploymentId', '')); + Span::add('resource.type', $execution->getAttribute('resourceType', '')); + $dbForProject->upsertDocument('executions', $execution); + } } }