mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
response format fix, smtp QA fixes
This commit is contained in:
+11
-1
@@ -98,6 +98,11 @@ return [
|
||||
'description' => 'Usage stats is not configured. Please check the value of the _APP_USAGE_STATS environment variable of your Appwrite server.',
|
||||
'code' => 501,
|
||||
],
|
||||
Exception::GENERAL_NOT_IMPLEMENTED => [
|
||||
'name' => Exception::GENERAL_NOT_IMPLEMENTED,
|
||||
'description' => 'This method was not fully implemented yet. If you believe this is a mistake, please upgrade your Appwrite server version.',
|
||||
'code' => 405,
|
||||
],
|
||||
|
||||
/** User Errors */
|
||||
Exception::USER_COUNT_EXCEEDED => [
|
||||
@@ -666,9 +671,14 @@ return [
|
||||
'description' => 'Provided SMTP config is invalid. Please check the configured values and try again.',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::PROJECT_SMTP_CONFIG_NOT_FOUND => [
|
||||
'name' => Exception::PROJECT_SMTP_CONFIG_NOT_FOUND,
|
||||
'description' => 'SMTP configuration on project is missing. Please configure a custom SMTP server to enable custom email templates.',
|
||||
'code' => 404,
|
||||
],
|
||||
Exception::PROJECT_TEMPLATE_DEFAULT_DELETION => [
|
||||
'name' => Exception::PROJECT_TEMPLATE_DEFAULT_DELETION,
|
||||
'description' => 'The default template for the project cannot be deleted.',
|
||||
'description' => 'You can\'t delete default template. If you are trying to reset your template changes, you can ignore this error as it\'s already been reset.',
|
||||
'code' => 401,
|
||||
],
|
||||
Exception::WEBHOOK_NOT_FOUND => [
|
||||
|
||||
@@ -1098,9 +1098,20 @@ App::post('/v1/account/sessions/magic-url')
|
||||
$smtpEnabled = $project->getAttribute('smtp', [])['enabled'] ?? false;
|
||||
$customTemplate = $project->getAttribute('templates', [])['email.magicSession-' . $locale->default] ?? [];
|
||||
if ($smtpEnabled && !empty($customTemplate)) {
|
||||
$body = $customTemplate['message'] ?? $body;
|
||||
$body = Template::fromString($customTemplate['message'] ?? '');
|
||||
$subject = $customTemplate['subject'] ?? $subject;
|
||||
$from = $customTemplate['senderName'] ?? $from;
|
||||
|
||||
$smtp = $project->getAttribute('smtp', []);
|
||||
$mails
|
||||
->setSmtpHost($smtp['host'] ?? '')
|
||||
->setSmtpPort($smtp['port'] ?? '')
|
||||
->setSmtpUsername($smtp['username'] ?? '')
|
||||
->setSmtpPassword($smtp['password'] ?? '')
|
||||
->setSmtpSecure($smtp['secure'] ?? '')
|
||||
->setSmtpReplyTo($customTemplate['replyTo'] ?? '')
|
||||
->setSmtpSenderEmail($customTemplate['senderEmail'] ?? '')
|
||||
->setSmtpSenderName($customTemplate['senderName'] ?? '');
|
||||
}
|
||||
|
||||
$body
|
||||
@@ -2514,9 +2525,20 @@ App::post('/v1/account/recovery')
|
||||
$smtpEnabled = $project->getAttribute('smtp', [])['enabled'] ?? false;
|
||||
$customTemplate = $project->getAttribute('templates', [])['email.recovery-' . $locale->default] ?? [];
|
||||
if ($smtpEnabled && !empty($customTemplate)) {
|
||||
$body = $customTemplate['message'] ?? $body;
|
||||
$body = Template::fromString($customTemplate['message'] ?? '');
|
||||
$subject = $customTemplate['subject'] ?? $subject;
|
||||
$from = $customTemplate['senderName'] ?? $from;
|
||||
|
||||
$smtp = $project->getAttribute('smtp', []);
|
||||
$mails
|
||||
->setSmtpHost($smtp['host'] ?? '')
|
||||
->setSmtpPort($smtp['port'] ?? '')
|
||||
->setSmtpUsername($smtp['username'] ?? '')
|
||||
->setSmtpPassword($smtp['password'] ?? '')
|
||||
->setSmtpSecure($smtp['secure'] ?? '')
|
||||
->setSmtpReplyTo($customTemplate['replyTo'] ?? '')
|
||||
->setSmtpSenderEmail($customTemplate['senderEmail'] ?? '')
|
||||
->setSmtpSenderName($customTemplate['senderName'] ?? '');
|
||||
}
|
||||
|
||||
$body
|
||||
@@ -2724,9 +2746,20 @@ App::post('/v1/account/verification')
|
||||
$smtpEnabled = $project->getAttribute('smtp', [])['enabled'] ?? false;
|
||||
$customTemplate = $project->getAttribute('templates', [])['email.verification-' . $locale->default] ?? [];
|
||||
if ($smtpEnabled && !empty($customTemplate)) {
|
||||
$body = $customTemplate['message'] ?? $body;
|
||||
$body = Template::fromString($customTemplate['message'] ?? '');
|
||||
$subject = $customTemplate['subject'] ?? $subject;
|
||||
$from = $customTemplate['senderName'] ?? $from;
|
||||
|
||||
$smtp = $project->getAttribute('smtp', []);
|
||||
$mails
|
||||
->setSmtpHost($smtp['host'] ?? '')
|
||||
->setSmtpPort($smtp['port'] ?? '')
|
||||
->setSmtpUsername($smtp['username'] ?? '')
|
||||
->setSmtpPassword($smtp['password'] ?? '')
|
||||
->setSmtpSecure($smtp['secure'] ?? '')
|
||||
->setSmtpReplyTo($customTemplate['replyTo'] ?? '')
|
||||
->setSmtpSenderEmail($customTemplate['senderEmail'] ?? '')
|
||||
->setSmtpSenderName($customTemplate['senderName'] ?? '');
|
||||
}
|
||||
|
||||
$body
|
||||
|
||||
@@ -1556,10 +1556,10 @@ App::patch('/v1/projects/:projectId/smtp')
|
||||
$valid = $mail->SmtpConnect();
|
||||
|
||||
if (!$valid) {
|
||||
throw new Exception(Exception::GENERAL_SMTP_DISABLED);
|
||||
throw new Exception('Connection is not valid.');
|
||||
}
|
||||
} catch (Throwable $error) {
|
||||
throw new Exception(Exception::GENERAL_SMTP_DISABLED, 'Could not connect to SMTP server: ' . $error->getMessage());
|
||||
throw new Exception(Exception::PROJECT_SMTP_CONFIG_INVALID, 'Could not connect to SMTP server: ' . $error->getMessage());
|
||||
}
|
||||
|
||||
$smtp = [
|
||||
@@ -1594,6 +1594,8 @@ App::get('/v1/projects/:projectId/templates/sms/:type/:locale')
|
||||
->inject('dbForConsole')
|
||||
->action(function (string $projectId, string $type, string $locale, Response $response, Database $dbForConsole) {
|
||||
|
||||
throw new Exception(Exception::GENERAL_NOT_IMPLEMENTED);
|
||||
|
||||
$project = $dbForConsole->getDocument('projects', $projectId);
|
||||
|
||||
if ($project->isEmpty()) {
|
||||
@@ -1691,12 +1693,16 @@ App::patch('/v1/projects/:projectId/templates/sms/:type/:locale')
|
||||
->inject('dbForConsole')
|
||||
->action(function (string $projectId, string $type, string $locale, string $message, Response $response, Database $dbForConsole) {
|
||||
|
||||
throw new Exception(Exception::GENERAL_NOT_IMPLEMENTED);
|
||||
|
||||
$project = $dbForConsole->getDocument('projects', $projectId);
|
||||
|
||||
if ($project->isEmpty()) {
|
||||
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
||||
}
|
||||
|
||||
// TODO: Ensure SMS is enabled on project
|
||||
|
||||
$templates = $project->getAttribute('templates', []);
|
||||
$templates['sms.' . $type . '-' . $locale] = [
|
||||
'message' => $message
|
||||
@@ -1739,6 +1745,11 @@ App::patch('/v1/projects/:projectId/templates/email/:type/:locale')
|
||||
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
||||
}
|
||||
|
||||
$smtpEnabled = $project->getAttribute('smtp', [])['enabled'] ?? false;
|
||||
if(!$smtpEnabled) {
|
||||
throw new Exception(Exception::PROJECT_SMTP_CONFIG_NOT_FOUND);
|
||||
}
|
||||
|
||||
$templates = $project->getAttribute('templates', []);
|
||||
$templates['email.' . $type . '-' . $locale] = [
|
||||
'senderName' => $senderName,
|
||||
@@ -1778,6 +1789,8 @@ App::delete('/v1/projects/:projectId/templates/sms/:type/:locale')
|
||||
->inject('dbForConsole')
|
||||
->action(function (string $projectId, string $type, string $locale, Response $response, Database $dbForConsole) {
|
||||
|
||||
throw new Exception(Exception::GENERAL_NOT_IMPLEMENTED);
|
||||
|
||||
$project = $dbForConsole->getDocument('projects', $projectId);
|
||||
|
||||
if ($project->isEmpty()) {
|
||||
|
||||
@@ -550,9 +550,20 @@ App::post('/v1/teams/:teamId/memberships')
|
||||
$smtpEnabled = $project->getAttribute('smtp', [])['enabled'] ?? false;
|
||||
$customTemplate = $project->getAttribute('templates', [])['email.invitation-' . $locale->default] ?? [];
|
||||
if ($smtpEnabled && !empty($customTemplate)) {
|
||||
$body = $customTemplate['message'];
|
||||
$subject = $customTemplate['subject'];
|
||||
$from = $customTemplate['senderName'];
|
||||
$body = Template::fromString($customTemplate['message'] ?? '');
|
||||
$subject = $customTemplate['subject'] ?? $subject;
|
||||
$from = $customTemplate['senderName'] ?? $from;
|
||||
|
||||
$smtp = $project->getAttribute('smtp', []);
|
||||
$mails
|
||||
->setSmtpHost($smtp['host'] ?? '')
|
||||
->setSmtpPort($smtp['port'] ?? '')
|
||||
->setSmtpUsername($smtp['username'] ?? '')
|
||||
->setSmtpPassword($smtp['password'] ?? '')
|
||||
->setSmtpSecure($smtp['secure'] ?? '')
|
||||
->setSmtpReplyTo($customTemplate['replyTo'] ?? '')
|
||||
->setSmtpSenderEmail($customTemplate['senderEmail'] ?? '')
|
||||
->setSmtpSenderName($customTemplate['senderName'] ?? '');
|
||||
}
|
||||
|
||||
$body->setParam('{{owner}}', $user->getAttribute('name'));
|
||||
|
||||
@@ -6,7 +6,7 @@ use Utopia\Config\Config;
|
||||
|
||||
App::get('/versions')
|
||||
->desc('Get Version')
|
||||
->groups(['home'])
|
||||
->groups(['home', 'web'])
|
||||
->label('scope', 'public')
|
||||
->inject('response')
|
||||
->action(function (Response $response) {
|
||||
|
||||
@@ -48,12 +48,7 @@ class MailsV1 extends Worker
|
||||
$mail->clearAttachments();
|
||||
$mail->clearBCCs();
|
||||
$mail->clearCCs();
|
||||
|
||||
$mail->setFrom(App::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM), (empty($from) ? \urldecode(App::getEnv('_APP_SYSTEM_EMAIL_NAME', APP_NAME . ' Server')) : $from));
|
||||
$mail->addAddress($recipient, $name);
|
||||
if (isset($smtp['replyTo'])) {
|
||||
$mail->addReplyTo($smtp['replyTo']);
|
||||
}
|
||||
$mail->Subject = $subject;
|
||||
$mail->Body = $body;
|
||||
$mail->AltBody = \strip_tags($body);
|
||||
|
||||
Reference in New Issue
Block a user