From 01e88e65d661fba545440cc057bdf4ebdbb21a87 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 13 Feb 2024 15:16:37 +1300 Subject: [PATCH 1/2] Fix swapping options/credentials on create/update smtp provider --- app/controllers/api/messaging.php | 27 ++++++++++--------- .../e2e/Services/Messaging/MessagingBase.php | 23 +++++++++++++--- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 9b3e529e94..f325300c50 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -1204,6 +1204,7 @@ App::patch('/v1/messaging/providers/smtp/:providerId') ->param('password', '', new Text(0), 'Authentication password.', true) ->param('encryption', '', new WhiteList(['none', 'ssl', 'tls']), 'Encryption type. Can be \'ssl\' or \'tls\'', true) ->param('autoTLS', null, new Boolean(), 'Enable SMTP AutoTLS feature.', true) + ->param('mailer', '', new Text(0), 'The value to use for the X-Mailer header.', true) ->param('fromName', '', new Text(128), 'Sender Name.', true) ->param('fromEmail', '', new Email(), 'Sender email address.', true) ->param('replyToName', '', new Text(128), 'Name set in the Reply To field for the mail. Default value is Sender Name.', true) @@ -1212,16 +1213,14 @@ App::patch('/v1/messaging/providers/smtp/:providerId') ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $providerId, string $name, string $host, ?int $port, string $username, string $password, string $encryption, ?bool $autoTLS, string $fromName, string $fromEmail, string $replyToName, string $replyToEmail, ?bool $enabled, Event $queueForEvents, Database $dbForProject, Response $response) { + ->action(function (string $providerId, string $name, string $host, ?int $port, string $username, string $password, string $encryption, ?bool $autoTLS, string $mailer, string $fromName, string $fromEmail, string $replyToName, string $replyToEmail, ?bool $enabled, Event $queueForEvents, Database $dbForProject, Response $response) { $provider = $dbForProject->getDocument('providers', $providerId); if ($provider->isEmpty()) { throw new Exception(Exception::PROVIDER_NOT_FOUND); } - $providerAttr = $provider->getAttribute('provider'); - - if ($providerAttr !== 'smtp') { + if ($provider->getAttribute('provider') !== 'smtp') { throw new Exception(Exception::PROVIDER_INCORRECT_TYPE); } @@ -1231,6 +1230,18 @@ App::patch('/v1/messaging/providers/smtp/:providerId') $options = $provider->getAttribute('options'); + if (!empty($encryption)) { + $options['encryption'] = $encryption === 'none' ? '' : $encryption; + } + + if (!\is_null($autoTLS)) { + $options['autoTLS'] = $autoTLS; + } + + if (!empty($mailer)) { + $options['mailer'] = $mailer; + } + if (!empty($fromName)) { $options['fromName'] = $fromName; } @@ -1267,14 +1278,6 @@ App::patch('/v1/messaging/providers/smtp/:providerId') $credentials['password'] = $password; } - if (!empty($encryption)) { - $credentials['encryption'] = $encryption === 'none' ? '' : $encryption; - } - - if (!\is_null($autoTLS)) { - $credentials['autoTLS'] = $autoTLS; - } - $provider->setAttribute('credentials', $credentials); if (!\is_null($enabled)) { diff --git a/tests/e2e/Services/Messaging/MessagingBase.php b/tests/e2e/Services/Messaging/MessagingBase.php index 111f0294fc..1255f99fbf 100644 --- a/tests/e2e/Services/Messaging/MessagingBase.php +++ b/tests/e2e/Services/Messaging/MessagingBase.php @@ -177,14 +177,26 @@ trait MessagingBase 'bundleId' => 'my-bundleid', ], ]; - foreach (\array_keys($providersParams) as $index => $key) { - $response = $this->client->call(Client::METHOD_PATCH, '/messaging/providers/' . $key . '/' . $providers[$index]['$id'], [ + + foreach (\array_keys($providersParams) as $index => $name) { + $response = $this->client->call(Client::METHOD_PATCH, '/messaging/providers/' . $name . '/' . $providers[$index]['$id'], [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'], - ], $providersParams[$key]); + ], $providersParams[$name]); + $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals($providersParams[$key]['name'], $response['body']['name']); + $this->assertEquals($providersParams[$name]['name'], $response['body']['name']); + + if ($name === 'smtp') { + $this->assertArrayHasKey('encryption', $response['body']['options']); + $this->assertArrayHasKey('autoTLS', $response['body']['options']); + $this->assertArrayHasKey('mailer', $response['body']['options']); + $this->assertArrayNotHasKey('encryption', $response['body']['credentials']); + $this->assertArrayNotHasKey('autoTLS', $response['body']['credentials']); + $this->assertArrayNotHasKey('mailer', $response['body']['credentials']); + } + $providers[$index] = $response['body']; } @@ -199,10 +211,13 @@ trait MessagingBase 'isEuRegion' => true, 'enabled' => false, ]); + $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals('Mailgun2', $response['body']['name']); $this->assertEquals(false, $response['body']['enabled']); + $providers[1] = $response['body']; + return $providers; } From 1be56bf1183da944ee29bfeec060430d2e824917 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 13 Feb 2024 12:09:52 +0000 Subject: [PATCH 2/2] feat: new console --- Dockerfile | 2 +- app/console | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 968b0bb22a..2dcbbbb221 100755 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN composer install --ignore-platform-reqs --optimize-autoloader \ --no-plugins --no-scripts --prefer-dist \ `if [ "$TESTING" != "true" ]; then echo "--no-dev"; fi` -FROM --platform=$BUILDPLATFORM node:16.14.2-alpine3.15 as node +FROM --platform=$BUILDPLATFORM node:20.11.0-alpine3.19 as node COPY app/console /usr/local/src/console diff --git a/app/console b/app/console index 0a007a3b1b..01aa032dae 160000 --- a/app/console +++ b/app/console @@ -1 +1 @@ -Subproject commit 0a007a3b1b6eafc39dc19b7129f41643102f9676 +Subproject commit 01aa032daef600cc5e07f4be5019c2fbf8f3420b