diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php index 5eee625b0a..8a3506eb13 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Labels/Update.php @@ -32,7 +32,7 @@ class Update extends Action ->desc('Update project labels') ->groups(['api', 'project']) ->label('scope', 'project.write') - ->label('event', 'project.labels.update') + // ->label('event', 'project.labels.update') ->label('audits.event', 'project.labels.update') ->label('audits.resource', 'project.labels/{response.$id}') ->label('sdk', new Method( diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php index 820c0be287..736865f299 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Update.php @@ -40,7 +40,7 @@ class Update extends Action ->desc('Update project SMTP configuration') ->groups(['api', 'project']) ->label('scope', 'project.write') - ->label('event', 'project.smtp.update') + // ->label('event', 'project.smtp.update') ->label('audits.event', 'project.smtp.update') ->label('audits.resource', 'project.smtp/{response.$id}') ->label('sdk', new Method( @@ -106,11 +106,13 @@ class Update extends Action // Backwards compatibility $smtp['replyToEmail'] = $smtp['replyToEmail'] ?? $smtp['replyTo'] ?? ''; - // Ensure required fields are set - $requiredKeys = ['host', 'port', 'senderEmail']; - foreach ($requiredKeys as $key) { - if (empty($smtp[$key])) { - throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, '"' . $key . '" is required. Please provide a value.'); + if (($smtp['enabled'] ?? false) === true) { + // Ensure required fields are set + $requiredKeys = ['host', 'port', 'senderEmail']; + foreach ($requiredKeys as $key) { + if (empty($smtp[$key])) { + throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Param "' . $key . '" is not optional.'); + } } } diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Get.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Get.php index 1843c556d4..02ba431775 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Get.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Get.php @@ -78,16 +78,16 @@ class Get extends Action $defaultMessage = $this->getDefaultMessage($templateId, $localeObj); // Apply defaults if needed - if (\is_null($template['message'])) { + if (\is_null($template['message'] ?? null)) { $template['message'] = $defaultMessage; } - if (\is_null($template['subject'])) { + if (\is_null($template['subject'] ?? null)) { $template['subject'] = $defaultSubject; } // Backwards compatibility - if (!\is_null($template['replyTo'])) { + if (!\is_null($template['replyTo'] ?? null)) { $template['replyToEmail'] = $template['replyToEmail'] ?? $template['replyTo'] ?? ''; } diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Update.php index c4a96d3c3c..ef93abf683 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Templates/Email/Update.php @@ -58,12 +58,12 @@ class Update extends Action )) ->param('templateId', '', new WhiteList(Config::getParam('locale-templates')['email'] ?? [], true), 'Custom email template type. Can be one of: '.\implode(', ', Config::getParam('locale-templates')['email'] ?? [])) ->param('locale', '', fn ($localeCodes) => new WhiteList($localeCodes), 'Custom email template locale. If left empty, the fallback locale (en) will be used.', optional: true, injections: ['localeCodes']) - ->param('subject', null, new Nullable(new Text(255)), 'Subject of the email template. Can be up to 255 characters.') - ->param('message', null, new Nullable(new Text(10485760)), 'Plain or HTML body of the email template message. Can be up to 10MB of content.') - ->param('senderName', null, new Nullable(new Text(255, 0)), 'Name of the email sender.', true) - ->param('senderEmail', null, new Nullable(new Email()), 'Email of the sender.', true) - ->param('replyToEmail', null, new Nullable(new Email()), 'Reply to email.', true) - ->param('replyToName', null, new Nullable(new Text(255, 0)), 'Reply to name.', true) + ->param('subject', null, new Nullable(new Text(255)), 'Subject of the email template. Can be up to 255 characters.', optional: true) + ->param('message', null, new Nullable(new Text(10485760)), 'Plain or HTML body of the email template message. Can be up to 10MB of content.', optional: true) + ->param('senderName', null, new Nullable(new Text(255, 0)), 'Name of the email sender.', optional: true) + ->param('senderEmail', null, new Nullable(new Email()), 'Email of the sender.', optional: true) + ->param('replyToEmail', null, new Nullable(new Email()), 'Reply to email.', optional: true) + ->param('replyToName', null, new Nullable(new Text(255, 0)), 'Reply to name.', optional: true) ->inject('response') ->inject('queueForEvents') ->inject('dbForPlatform') @@ -108,7 +108,9 @@ class Update extends Action } // Backwards compatibility - $template['replyToEmail'] = $template['replyToEmail'] ?? $template['replyTo'] ?? ''; + if (!\is_null($template['replyTo'] ?? null)) { + $template['replyToEmail'] = $template['replyToEmail'] ?? $template['replyTo'] ?? ''; + } // Ensure required fields are set $requiredKeys = ['subject', 'message']; diff --git a/tests/e2e/Services/Project/TemplatesBase.php b/tests/e2e/Services/Project/TemplatesBase.php index efdc3e4579..72a14210a5 100644 --- a/tests/e2e/Services/Project/TemplatesBase.php +++ b/tests/e2e/Services/Project/TemplatesBase.php @@ -550,7 +550,7 @@ trait TemplatesBase public function testUpdateEmailTemplateBlockedWhenSMTPDisabled(): void { // Custom templates only make sense alongside a custom SMTP configuration. - $this->client->call( + $response = $this->client->call( Client::METHOD_PATCH, '/project/smtp', \array_merge([ @@ -560,6 +560,9 @@ trait TemplatesBase ['enabled' => false], ); + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame(false, $response['body']['smtpEnabled']); + try { $response = $this->updateEmailTemplate( templateId: 'verification',