Skip to content

Commit

Permalink
feature/organisation-sign-up-form-notifications (#252)
Browse files Browse the repository at this point in the history
* Added emails for new org sign up form

* Updated naming

* Added emails and tests for approve and reject

* Fixed recursion bug

* Linted code

* Using latst version of grokzen/redis-cluster

* Refactored

* Extracted redis cluster discovery IP for only mac envs
  • Loading branch information
matthew-inamdar authored Sep 6, 2019
1 parent d83c4b8 commit 7dfdbf8
Show file tree
Hide file tree
Showing 18 changed files with 678 additions and 165 deletions.
3 changes: 3 additions & 0 deletions app/Emails/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ abstract protected function getReplyTo(): ?string;
*/
abstract public function getContent(): string;

/**
* Send the email.
*/
public function send()
{
$this->handle(resolve(EmailSender::class));
Expand Down
40 changes: 40 additions & 0 deletions app/Emails/OrganisationSignUpFormApproved/NotifySubmitterEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Emails\OrganisationSignUpFormApproved;

use App\Emails\Email;

class NotifySubmitterEmail extends Email
{
/**
* @return string
*/
protected function getTemplateId(): string
{
return config('ck.notifications_template_ids.organisation_sign_up_form_approved.notify_submitter.email');
}

/**
* @return string|null
*/
protected function getReference(): ?string
{
return null;
}

/**
* @return string|null
*/
protected function getReplyTo(): ?string
{
return null;
}

/**
* @return string
*/
public function getContent(): string
{
return 'Pending to be sent. Content will be filled once sent.';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Emails\OrganisationSignUpFormReceived;

use App\Emails\Email;

class NotifyGlobalAdminEmail extends Email
{
/**
* @return string
*/
protected function getTemplateId(): string
{
return config('ck.notifications_template_ids.organisation_sign_up_form_received.notify_global_admin.email');
}

/**
* @return string|null
*/
protected function getReference(): ?string
{
return null;
}

/**
* @return string|null
*/
protected function getReplyTo(): ?string
{
return null;
}

/**
* @return string
*/
public function getContent(): string
{
return 'Pending to be sent. Content will be filled once sent.';
}
}
40 changes: 40 additions & 0 deletions app/Emails/OrganisationSignUpFormReceived/NotifySubmitterEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Emails\OrganisationSignUpFormReceived;

use App\Emails\Email;

class NotifySubmitterEmail extends Email
{
/**
* @return string
*/
protected function getTemplateId(): string
{
return config('ck.notifications_template_ids.organisation_sign_up_form_received.notify_submitter.email');
}

/**
* @return string|null
*/
protected function getReference(): ?string
{
return null;
}

/**
* @return string|null
*/
protected function getReplyTo(): ?string
{
return null;
}

/**
* @return string
*/
public function getContent(): string
{
return 'Pending to be sent. Content will be filled once sent.';
}
}
40 changes: 40 additions & 0 deletions app/Emails/OrganisationSignUpFormRejected/NotifySubmitterEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Emails\OrganisationSignUpFormRejected;

use App\Emails\Email;

class NotifySubmitterEmail extends Email
{
/**
* @return string
*/
protected function getTemplateId(): string
{
return config('ck.notifications_template_ids.organisation_sign_up_form_rejected.notify_submitter.email');
}

/**
* @return string|null
*/
protected function getReference(): ?string
{
return null;
}

/**
* @return string|null
*/
protected function getReplyTo(): ?string
{
return null;
}

/**
* @return string
*/
public function getContent(): string
{
return 'Pending to be sent. Content will be filled once sent.';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NotifyGlobalAdminEmail extends Email
*/
protected function getTemplateId(): string
{
return config('ck.notifications_template_ids.update_request_submitted.notify_global_admin.email');
return config('ck.notifications_template_ids.update_request_received.notify_global_admin.email');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Emails/UpdateRequestReceived/NotifySubmitterEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NotifySubmitterEmail extends Email
*/
protected function getTemplateId(): string
{
return config('ck.notifications_template_ids.update_request_submitted.notify_submitter.email');
return config('ck.notifications_template_ids.update_request_received.notify_submitter.email');
}

/**
Expand Down
74 changes: 52 additions & 22 deletions app/Listeners/Notifications/UpdateRequestApproved.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

namespace App\Listeners\Notifications;

use App\Emails\UpdateRequestApproved\NotifySubmitterEmail;
use App\Events\EndpointHit;
use App\Models\Audit;
use App\Models\Location;
use App\Models\Notification;
use App\Models\Organisation;
use App\Models\Service;
use App\Models\ServiceLocation;
use App\Models\UpdateRequest;
use App\UpdateRequest\OrganisationSignUpForm;
use Illuminate\Support\Arr;

class UpdateRequestApproved
{
/**
* Handle the event.
*
* @param EndpointHit $event
* @throws \Exception
*/
public function handle(EndpointHit $event)
{
Expand All @@ -29,39 +32,66 @@ public function handle(EndpointHit $event)
$updateRequest = $event->getModel();

if ($updateRequest->isExisting()) {
$this->notifySubmitter($updateRequest);
$this->notifySubmitterForExisting($updateRequest);
}

if ($updateRequest->isNew()) {
$this->notifySubmitterForNew($updateRequest);
}
}

/**
* @param \App\Models\UpdateRequest $updateRequest
* @throws \Exception
*/
protected function notifySubmitter(UpdateRequest $updateRequest)
protected function notifySubmitterForExisting(UpdateRequest $updateRequest)
{
$resourceName = null;
$resourceType = null;
if ($updateRequest->updateable instanceof Location) {
$resourceName = $updateRequest->updateable->address_line_1;
$resourceName = 'N/A';
$resourceType = 'N/A';
if ($updateRequest->getUpdateable() instanceof Location) {
$resourceName = $updateRequest->getUpdateable()->address_line_1;
$resourceType = 'location';
} elseif ($updateRequest->updateable instanceof Service) {
$resourceName = $updateRequest->updateable->name;
} elseif ($updateRequest->getUpdateable() instanceof Service) {
$resourceName = $updateRequest->getUpdateable()->name;
$resourceType = 'service';
} elseif ($updateRequest->updateable instanceof ServiceLocation) {
$resourceName = $updateRequest->updateable->name ?? $updateRequest->updateable->location->address_line_1;
} elseif ($updateRequest->getUpdateable() instanceof ServiceLocation) {
$resourceName = $updateRequest->getUpdateable()->name ?? $updateRequest->getUpdateable()->location->address_line_1;
$resourceType = 'service location';
} elseif ($updateRequest->updateable instanceof Organisation) {
$resourceName = $updateRequest->updateable->name;
} elseif ($updateRequest->getUpdateable() instanceof Organisation) {
$resourceName = $updateRequest->getUpdateable()->name;
$resourceType = 'organisation';
} else {
$resourceName = 'N/A';
$resourceType = 'N/A';
}

$updateRequest->user->sendEmail(new NotifySubmitterEmail($updateRequest->user->email, [
'SUBMITTER_NAME' => $updateRequest->user->first_name,
'RESOURCE_NAME' => $resourceName,
'RESOURCE_TYPE' => $resourceType,
'REQUEST_DATE' => $updateRequest->created_at->format('j/n/Y'),
]));
$updateRequest->user->sendEmail(
new \App\Emails\UpdateRequestApproved\NotifySubmitterEmail(
$updateRequest->user->email,
[
'SUBMITTER_NAME' => $updateRequest->user->first_name,
'RESOURCE_NAME' => $resourceName,
'RESOURCE_TYPE' => $resourceType,
'REQUEST_DATE' => $updateRequest->created_at->format('j/n/Y'),
]
)
);
}

/**
* @param \App\Models\UpdateRequest $updateRequest
* @throws \Exception
*/
protected function notifySubmitterForNew(UpdateRequest $updateRequest)
{
if ($updateRequest->getUpdateable() instanceof OrganisationSignUpForm) {
Notification::sendEmail(
new \App\Emails\OrganisationSignUpFormApproved\NotifySubmitterEmail(
Arr::get($updateRequest->data, 'user.email'),
[
'SUBMITTER_NAME' => Arr::get($updateRequest->data, 'user.first_name'),
'ORGANISATION_NAME' => Arr::get($updateRequest->data, 'organisation.name'),
'REQUEST_DATE' => $updateRequest->created_at->format('j/n/Y'),
]
)
);
}
}
}
Loading

0 comments on commit 7dfdbf8

Please sign in to comment.