From a802a78b0b40acd333214dafd27d32d06c18979f Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 12 May 2025 13:10:58 +0000 Subject: [PATCH 1/4] feat: plan based email logoUrl --- .../locale/templates/email-base-styled.tpl | 2 +- app/controllers/api/projects.php | 6 ++++-- app/init/constants.php | 1 + src/Appwrite/Platform/Workers/Certificates.php | 16 +++++++++++----- src/Appwrite/Platform/Workers/Webhooks.php | 16 +++++++++++----- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/app/config/locale/templates/email-base-styled.tpl b/app/config/locale/templates/email-base-styled.tpl index 4d6972389e..7add785b11 100644 --- a/app/config/locale/templates/email-base-styled.tpl +++ b/app/config/locale/templates/email-base-styled.tpl @@ -126,7 +126,7 @@ diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 839a51a764..a626c677c2 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -2139,7 +2139,8 @@ App::post('/v1/projects/:projectId/smtp/tests') ->inject('response') ->inject('dbForPlatform') ->inject('queueForMails') - ->action(function (string $projectId, array $emails, string $senderName, string $senderEmail, string $replyTo, string $host, int $port, string $username, string $password, string $secure, Response $response, Database $dbForPlatform, Mail $queueForMails) { + ->inject('plan') + ->action(function (string $projectId, array $emails, string $senderName, string $senderEmail, string $replyTo, string $host, int $port, string $username, string $password, string $secure, Response $response, Database $dbForPlatform, Mail $queueForMails, array $plan) { $project = $dbForPlatform->getDocument('projects', $projectId); if ($project->isEmpty()) { @@ -2152,7 +2153,8 @@ App::post('/v1/projects/:projectId/smtp/tests') $template = Template::fromFile(__DIR__ . '/../../config/locale/templates/email-smtp-test.tpl'); $template ->setParam('{{from}}', "{$senderName} ({$senderEmail})") - ->setParam('{{replyTo}}', "{$senderName} ({$replyToEmail})"); + ->setParam('{{replyTo}}', "{$senderName} ({$replyToEmail})") + ->setParam('{{logoUrl}}', $plan['logoUrl'] ?? APP_EMAIL_LOGO_URL); foreach ($emails as $email) { $queueForMails diff --git a/app/init/constants.php b/app/init/constants.php index 143bba29bd..6658048f07 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -6,6 +6,7 @@ const APP_NAME = 'Appwrite'; const APP_DOMAIN = 'appwrite.io'; const APP_EMAIL_TEAM = 'team@localhost.test'; // Default email address const APP_EMAIL_SECURITY = ''; // Default security email address +const APP_EMAIL_LOGO_URL = 'https://cloud.appwrite.io/images/mails/logo.png'; const APP_USERAGENT = APP_NAME . '-Server v%s. Please report abuse at %s'; const APP_MODE_DEFAULT = 'default'; const APP_MODE_ADMIN = 'admin'; diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index 15f9645bb0..ce7b5f3522 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -54,6 +54,7 @@ class Certificates extends Action ->inject('queueForRealtime') ->inject('log') ->inject('certificates') + ->inject('plan') ->callback([$this, 'action']); } @@ -80,7 +81,8 @@ class Certificates extends Action Func $queueForFunctions, Realtime $queueForRealtime, Log $log, - CertificatesAdapter $certificates + CertificatesAdapter $certificates, + array $plan ): void { $payload = $message->getPayload() ?? []; @@ -94,7 +96,7 @@ class Certificates extends Action $log->addTag('domain', $domain->get()); - $this->execute($domain, $dbForPlatform, $queueForMails, $queueForEvents, $queueForWebhooks, $queueForFunctions, $queueForRealtime, $log, $certificates, $skipRenewCheck); + $this->execute($domain, $dbForPlatform, $queueForMails, $queueForEvents, $queueForWebhooks, $queueForFunctions, $queueForRealtime, $log, $certificates, $skipRenewCheck, $plan); } /** @@ -106,6 +108,7 @@ class Certificates extends Action * @param Realtime $queueForRealtime * @param CertificatesAdapter $certificates * @param bool $skipRenewCheck + * @param array $plan * @return void * @throws Throwable * @throws \Utopia\Database\Exception @@ -120,7 +123,8 @@ class Certificates extends Action Realtime $queueForRealtime, Log $log, CertificatesAdapter $certificates, - bool $skipRenewCheck = false + bool $skipRenewCheck = false, + array $plan = [] ): void { /** * 1. Read arguments and validate domain @@ -202,7 +206,7 @@ class Certificates extends Action $certificate->setAttribute('renewDate', DateTime::now()); // Send email to security email - $this->notifyError($domain->get(), $e->getMessage(), $attempts, $queueForMails); + $this->notifyError($domain->get(), $e->getMessage(), $attempts, $queueForMails, $plan); throw $e; } finally { @@ -342,10 +346,11 @@ class Certificates extends Action * @param string $errorMessage Verbose error message * @param int $attempt How many times it failed already * @param Mail $queueForMails + * @param array $plan * @return void * @throws Exception */ - private function notifyError(string $domain, string $errorMessage, int $attempt, Mail $queueForMails): void + private function notifyError(string $domain, string $errorMessage, int $attempt, Mail $queueForMails, array $plan): void { // Log error into console Console::warning('Cannot renew domain (' . $domain . ') on attempt no. ' . $attempt . ' certificate: ' . $errorMessage); @@ -357,6 +362,7 @@ class Certificates extends Action $template->setParam('{{domain}}', $domain); $template->setParam('{{error}}', \nl2br($errorMessage)); $template->setParam('{{attempts}}', $attempt); + $template->setParam('{{logoUrl}}', $plan['logoUrl'] ?? APP_EMAIL_LOGO_URL); $body = $template->render(); $emailVariables = [ diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index b36f4cb67c..82a26f849c 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -37,6 +37,7 @@ class Webhooks extends Action ->inject('queueForMails') ->inject('queueForStatsUsage') ->inject('log') + ->inject('plan') ->callback([$this, 'action']); } @@ -45,11 +46,13 @@ class Webhooks extends Action * @param Document $project * @param Database $dbForPlatform * @param Mail $queueForMails + * @param StatsUsage $queueForStatsUsage * @param Log $log + * @param array $plan * @return void * @throws Exception */ - public function action(Message $message, Document $project, Database $dbForPlatform, Mail $queueForMails, StatsUsage $queueForStatsUsage, Log $log): void + public function action(Message $message, Document $project, Database $dbForPlatform, Mail $queueForMails, StatsUsage $queueForStatsUsage, Log $log, array $plan): void { $this->errors = []; $payload = $message->getPayload() ?? []; @@ -68,7 +71,7 @@ class Webhooks extends Action foreach ($project->getAttribute('webhooks', []) as $webhook) { if (array_intersect($webhook->getAttribute('events', []), $events)) { - $this->execute($events, $webhookPayload, $webhook, $user, $project, $dbForPlatform, $queueForMails, $queueForStatsUsage); + $this->execute($events, $webhookPayload, $webhook, $user, $project, $dbForPlatform, $queueForMails, $queueForStatsUsage, $plan); } } @@ -85,9 +88,10 @@ class Webhooks extends Action * @param Document $project * @param Database $dbForPlatform * @param Mail $queueForMails + * @param array $plan * @return void */ - private function execute(array $events, string $payload, Document $webhook, Document $user, Document $project, Database $dbForPlatform, Mail $queueForMails, StatsUsage $queueForStatsUsage): void + private function execute(array $events, string $payload, Document $webhook, Document $user, Document $project, Database $dbForPlatform, Mail $queueForMails, StatsUsage $queueForStatsUsage, array $plan): void { if ($webhook->getAttribute('enabled') !== true) { return; @@ -163,7 +167,7 @@ class Webhooks extends Action if ($attempts >= \intval(System::getEnv('_APP_WEBHOOK_MAX_FAILED_ATTEMPTS', '10'))) { $webhook->setAttribute('enabled', false); - $this->sendEmailAlert($attempts, $statusCode, $webhook, $project, $dbForPlatform, $queueForMails); + $this->sendEmailAlert($attempts, $statusCode, $webhook, $project, $dbForPlatform, $queueForMails, $plan); } $dbForPlatform->updateDocument('webhooks', $webhook->getId(), $webhook); @@ -198,9 +202,10 @@ class Webhooks extends Action * @param Document $project * @param Database $dbForPlatform * @param Mail $queueForMails + * @param array $plan * @return void */ - public function sendEmailAlert(int $attempts, mixed $statusCode, Document $webhook, Document $project, Database $dbForPlatform, Mail $queueForMails): void + public function sendEmailAlert(int $attempts, mixed $statusCode, Document $webhook, Document $project, Database $dbForPlatform, Mail $queueForMails, array $plan): void { $memberships = $dbForPlatform->find('memberships', [ Query::equal('teamInternalId', [$project->getAttribute('teamInternalId')]), @@ -224,6 +229,7 @@ class Webhooks extends Action $template->setParam('{{error}}', $curlError ?? 'The server returned ' . $statusCode . ' status code'); $template->setParam('{{path}}', "/console/project-$projectId/settings/webhooks/$webhookId"); $template->setParam('{{attempts}}', $attempts); + $template->setParam('{{logoUrl}}', $plan['logoUrl'] ?? APP_EMAIL_LOGO_URL); // TODO: Use setbodyTemplate once #7307 is merged $subject = 'Webhook deliveries have been paused'; From 980afc2eaf574c0c5ded696064c9c945b6fb0f0f Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 12 May 2025 13:20:59 +0000 Subject: [PATCH 2/4] chore: update social links --- app/config/locale/templates/email-base-styled.tpl | 10 +++++----- app/controllers/api/projects.php | 7 ++++++- app/init/constants.php | 3 +++ src/Appwrite/Platform/Workers/Certificates.php | 7 +++++++ src/Appwrite/Platform/Workers/Webhooks.php | 6 ++++++ 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/app/config/locale/templates/email-base-styled.tpl b/app/config/locale/templates/email-base-styled.tpl index 7add785b11..860e964672 100644 --- a/app/config/locale/templates/email-base-styled.tpl +++ b/app/config/locale/templates/email-base-styled.tpl @@ -164,7 +164,7 @@