response format fix, smtp QA fixes

This commit is contained in:
Matej Bačo
2023-08-25 17:13:25 +02:00
parent 9fcfca78f8
commit 596e59f2cc
12 changed files with 182 additions and 63 deletions
+15 -2
View File
@@ -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()) {