Added an administrator fallback banner to organisation join approval emails

This commit is contained in:
2022-11-14 16:54:52 +00:00
parent 5a0906eb43
commit c99a277e2a
2 changed files with 21 additions and 12 deletions

View File

@@ -1370,6 +1370,20 @@ class OrganisationMembersController extends SimpleController
{
$timeout = $this->ci->config['organisation.membership.timeout'];
$admin_fallback = false;
$recipientsQuery = $organisation->administrators();
if ($recipientsQuery->count() == 0) {
$admin_fallback = true;
$role = $this->ci->classMapper->getClassMapping('role')::where('slug', 'organisations-admin')->with('users')->first();
if ($role->users()->count() == 0) {
$role = $this->ci->classMapper->getClassMapping('role')::where('slug', 'site-admin')->with('users')->first();
}
$recipientsQuery = $role->users();
}
$recipients = $recipientsQuery->get();
// Create and send approval email
$message = new TwigMailMessage($this->ci->view, 'mail/organisation-membership-request.html.twig');
@@ -1379,20 +1393,9 @@ class OrganisationMembersController extends SimpleController
'organisation' => $organisation,
'token' => $token,
'approval_expiration' => ($timeout > 0 ? floor($timeout / 86400) . ' days' : false),
'admin_fallback' => $admin_fallback,
]);
$recipientsQuery = $organisation->administrators();
if ($recipientsQuery->count() == 0) {
$role = $this->ci->classMapper->getClassMapping('role')::where('slug', 'organisations-admin')->with('users')->first();
if ($role->users()->count() == 0) {
$role = $this->ci->classMapper->getClassMapping('role')::where('slug', 'site-admin')->with('users')->first();
}
$recipientsQuery = $role->users();
}
$recipients = $recipientsQuery->get();
foreach($recipients as $recipient) {
$message->addEmailRecipient(new EmailRecipient($recipient->email, $recipient->full_name));
$message->addParams([ 'recipient' => $recipient ]);