Merge branch '1.9.x' into fix/vcs-adapter-detection

This commit is contained in:
Harsh Mahajan authored and GitHub committed 2026-06-17 13:53:44 +05:30
commit 9a0c51b77b
27 files changed
+347 -49

No files matched your search

+10 -5
View File
@@ -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');
+4
View File
@@ -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,
+2 -2
View File
@@ -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: <<<EOT
Send a ping to project as part of onboarding.
EOT,
auth: [],
auth: [AuthType::ADMIN, AuthType::KEY, AuthType::JWT, AuthType::SESSION],
responses: [
new SDKResponse(
code: Response::STATUS_CODE_OK,
+11
View File
@@ -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';
+1 -1
View File
@@ -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.*",
Generated
+15 -14
View File
@@ -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",
@@ -5129,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": {
@@ -5172,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",
+1
View File
@@ -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,
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace Appwrite\Event\Message;
use Utopia\Database\Document;
final class Executions extends Base
{
/**
* @param array<Document> $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'] ?? []
),
);
}
}
+3
View File
@@ -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'] ?? '',
+2 -1
View File
@@ -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);
}
@@ -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,
@@ -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".');
}
@@ -182,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', '');
@@ -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';
@@ -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) {
@@ -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: [
@@ -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".');
}
@@ -182,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', '');
@@ -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,
+36 -9
View File
@@ -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,
],
],
],
];
@@ -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,
+29 -9
View File
@@ -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);
}
}
}
+17 -1
View File
@@ -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');
}
}
+45 -5
View File
@@ -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) {
@@ -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,
@@ -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', '')],
@@ -734,6 +734,112 @@ final class VCSConsoleClientTest extends Scope
], $this->getHeaders()));
}
public function testCrossProjectInstallationRejected(): void
{
$installationId = $this->setupInstallation();
$consoleHeaders = [
'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', $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 {
// 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']);
// 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']);
$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']);
// 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']);
$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
{
$installationId = $this->setupInstallation();
@@ -558,6 +558,7 @@ class ScriptedEmailAdapter extends EmailAdapter
*/
public function __construct(private readonly array $script = [])
{
parent::__construct();
}
public function getName(): string