mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Send email to all members of the org
This commit is contained in:
+5
-5
@@ -11,11 +11,11 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
Hi <strong><?php echo $this->getParam('user') ?></strong>,
|
||||
Hi <strong>{{user}}</strong>,
|
||||
<br /><br />
|
||||
Your webhook <strong><?php echo $this->getParam('webhook') ?></strong> on project <strong><?php echo $this->getParam('project') ?></strong> has been paused after <?php echo $this->getParam('attempts') ?> consecutive failures. <br />
|
||||
<p>Webhook Endpoint: <strong><?php echo $this->getParam('url') ?></strong></p>
|
||||
<p>Error: <strong><?php echo $this->getParam('error') ?></strong></p> <br />To restore your webhook's functionality and reset attempts, we suggest to follow the below steps:<br />
|
||||
Your webhook <strong>{{webhook}}</strong> on project <strong>{{project}}</strong> has been paused after {{attempts}} consecutive failures. <br />
|
||||
<p>Webhook Endpoint: {{url}}</strong></p>
|
||||
<p>Error: <strong>{{error}}</strong></p> <br />To restore your webhook's functionality and reset attempts, we suggest to follow the below steps:<br />
|
||||
<ol>
|
||||
<li>Examine the logs of both Appwrite Console and your webhook server to identify the issue.</li>
|
||||
<li>Investigate potential network issues and use webhook testing tools to verify expected behaviour.</li>
|
||||
@@ -28,7 +28,7 @@
|
||||
<table border="0" cellspacing="0" cellpadding="0" style="padding-top: 10px; padding-bottom: 10px; margin-top: 32px">
|
||||
<tr>
|
||||
<td style="border-radius: 8px; display: block; width: 100%;">
|
||||
<a class="mobile-full-width" rel="noopener" target="_blank" href="<?php echo $this->getParam('redirect') ?>" style="font-size: 14px; font-family: Inter; color: #ffffff; text-decoration: none; background-color: #FD366E; border-radius: 8px; padding: 9px 14px; border: 1px solid #FD366E; display: inline-block; text-align:center; box-sizing: border-box;">Webhook settings</a>
|
||||
<a class="mobile-full-width" rel="noopener" target="_blank" href="{{redirect}}" style="font-size: 14px; font-family: Inter; color: #ffffff; text-decoration: none; background-color: #FD366E; border-radius: 8px; padding: 9px 14px; border: 1px solid #FD366E; display: inline-block; text-align:center; box-sizing: border-box;">Webhook settings</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -9,6 +9,7 @@ use Exception;
|
||||
use Utopia\App;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Logger\Log;
|
||||
use Utopia\Platform\Action;
|
||||
use Utopia\Queue\Message;
|
||||
@@ -158,36 +159,34 @@ class Webhooks extends Action
|
||||
|
||||
if ($attempts >= self::MAX_FAILED_ATTEMPTS) {
|
||||
$webhook->setAttribute('enabled', false);
|
||||
|
||||
$teamId = $project->getAttribute('teamId');
|
||||
// Find all 'userId' for this teamId from memberships collection by using query in find method
|
||||
|
||||
$users = $dbForConsole->find('users');
|
||||
$userDetails = array_map(function ($user) {
|
||||
return [
|
||||
'name' => $user->getAttribute('name'),
|
||||
'email' => $user->getAttribute('email')
|
||||
];
|
||||
}, $users);
|
||||
$memberships = $dbForConsole->find('memberships', [
|
||||
Query::equal('teamInternalId', [$project->getAttribute('teamInternalId')]),
|
||||
Query::limit(APP_LIMIT_SUBQUERY)
|
||||
]);
|
||||
|
||||
$userIds = array_column(\array_map(fn ($membership) => $membership->getArrayCopy(), $memberships), 'userId');
|
||||
|
||||
$users = $dbForConsole->find('users', [
|
||||
Query::equal('$id', $userIds),
|
||||
]);
|
||||
|
||||
$protocol = App::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https';
|
||||
$hostname = App::getEnv('_APP_DOMAIN');
|
||||
$projectId = $project->getId();
|
||||
$webhookId = $webhook->getId();
|
||||
|
||||
$template = __DIR__ . '/../../../../app/config/locale/templates/email-webhook.phtml';
|
||||
$template = new View($template);
|
||||
$template = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-webhook-failed.tpl');
|
||||
|
||||
// $template->setParam('user', $user->getAttribute('name'));
|
||||
$template->setParam('webhook', $webhook->getAttribute('name'));
|
||||
$template->setParam('project', $project->getAttribute('name'));
|
||||
$template->setParam('url', $webhook->getAttribute('url'));
|
||||
$template->setParam('error', $curlError ?? 'The server returned ' . $statusCode . ' status code');
|
||||
$template->setParam('redirect', $protocol . '://' . $hostname . "/console/project-$projectId/settings/webhooks/$webhookId");
|
||||
$template->setParam('attempts', $attempts);
|
||||
$template->setParam('{{webhook}}', $webhook->getAttribute('name'));
|
||||
$template->setParam('{{project}}', $project->getAttribute('name'));
|
||||
$template->setParam('{{url}}', $webhook->getAttribute('url'));
|
||||
$template->setParam('{{error}}', $curlError ?? 'The server returned ' . $statusCode . ' status code');
|
||||
$template->setParam('{{redirect}}', $protocol . '://' . $hostname . "/console/project-$projectId/settings/webhooks/$webhookId");
|
||||
$template->setParam('{{attempts}}', $attempts);
|
||||
|
||||
$subject = 'Webhook deliveries have been paused';
|
||||
$body = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-base-branded.tpl');
|
||||
$body = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-base-styled.tpl');
|
||||
|
||||
$body
|
||||
->setParam('{{subject}}', $subject)
|
||||
@@ -198,9 +197,11 @@ class Webhooks extends Action
|
||||
->setSubject($subject)
|
||||
->setBody($body->render());
|
||||
|
||||
foreach ($userEmails as $userEmail) {
|
||||
foreach ($users as $user) {
|
||||
$queueForMails
|
||||
->setRecipient($userEmail)
|
||||
->setVariables(['user' => $user->getAttribute('name', '')])
|
||||
->setName($user->getAttribute('name', ''))
|
||||
->setRecipient($user->getAttribute('email'))
|
||||
->trigger();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user