Fixes for mails

This commit is contained in:
David Bomba 2021-02-18 21:33:54 +11:00
parent 1d17b8c339
commit 8346875f88
13 changed files with 52 additions and 47 deletions

View File

@ -369,16 +369,21 @@ class UserController extends BaseController
*/ */
public function update(UpdateUserRequest $request, User $user) public function update(UpdateUserRequest $request, User $user)
{ {
$old_company_user = $user->company_user; $old_company_user = $user->company_user;
$old_user = $user; $old_user = json_encode($user);
$old_user_email = $user->getOriginal('email');
$new_email = $request->input('email'); $new_email = $request->input('email');
$new_user = $this->user_repo->save($request->all(), $user);
$new_user = $user->fresh();
$user = $this->user_repo->save($request->all(), $user);
$user = $user->fresh();
if ($old_user->email != $new_email) nlog($old_user);
UserEmailChanged::dispatch($new_user, $old_user, auth()->user()->company());
if ($old_user_email != $new_email)
UserEmailChanged::dispatch($new_user, json_decode($old_user), auth()->user()->company());
if( if(
strcasecmp($old_company_user->permissions, $user->company_user->permissions) != 0 || strcasecmp($old_company_user->permissions, $user->company_user->permissions) != 0 ||

View File

@ -80,6 +80,7 @@ class NinjaMailerJob implements ShouldQueue
} catch (\Exception $e) { } catch (\Exception $e) {
nlog("error failed with {$e->getMessage()}"); nlog("error failed with {$e->getMessage()}");
nlog($e);
if($this->nmo->entity) if($this->nmo->entity)
$this->entityEmailFailed($e->getMessage()); $this->entityEmailFailed($e->getMessage());
@ -120,7 +121,7 @@ class NinjaMailerJob implements ShouldQueue
switch ($this->nmo->settings->email_sending_method) { switch ($this->nmo->settings->email_sending_method) {
case 'default': case 'default':
config(['mail.driver' => config('mail.default')]); //config(['mail.driver' => config('mail.default')]);
break; break;
case 'gmail': case 'gmail':
$this->setGmailMailer(); $this->setGmailMailer();

View File

@ -44,7 +44,7 @@ class UserEmailChanged implements ShouldQueue
* @param string $old_email * @param string $old_email
* @param Company $company * @param Company $company
*/ */
public function __construct(User $new_user, User $old_user, Company $company) public function __construct(User $new_user, $old_user, Company $company)
{ {
$this->new_user = $new_user; $this->new_user = $new_user;
$this->old_user = $old_user; $this->old_user = $old_user;
@ -54,9 +54,10 @@ class UserEmailChanged implements ShouldQueue
public function handle() public function handle()
{ {
if ($this->company->is_disabled) { nlog("notifying user of email change");
if ($this->company->is_disabled)
return true; return true;
}
//Set DB //Set DB
MultiDB::setDb($this->company->db); MultiDB::setDb($this->company->db);
@ -91,8 +92,8 @@ class UserEmailChanged implements ShouldQueue
'title' => ctrans('texts.email_address_changed'), 'title' => ctrans('texts.email_address_changed'),
'message' => ctrans( 'message' => ctrans(
'texts.email_address_changed_message', 'texts.email_address_changed_message',
['old_email' => $this->old_email, ['old_email' => $this->old_user->email,
'new_email' => $this->new_email, 'new_email' => $this->new_user->email,
] ]
), ),
'url' => config('ninja.app_url'), 'url' => config('ninja.app_url'),

View File

@ -52,7 +52,7 @@ class CreditEmailedNotification implements ShouldQueue
foreach ($event->invitation->company->company_users as $company_user) { foreach ($event->invitation->company->company_users as $company_user) {
$user = $company_user->user; $user = $company_user->user;
$notification = new EntitySentNotification($event->invitation, 'credit'); // $notification = new EntitySentNotification($event->invitation, 'credit');
$methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'credit', ['all_notifications', 'credit_sent']); $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'credit', ['all_notifications', 'credit_sent']);
@ -66,9 +66,9 @@ class CreditEmailedNotification implements ShouldQueue
$first_notification_sent = false; $first_notification_sent = false;
} }
$notification->method = $methods; // $notification->method = $methods;
$user->notify($notification); // $user->notify($notification);
} }
} }
} }

View File

@ -57,7 +57,7 @@ class InvoiceEmailedNotification implements ShouldQueue
$user = $company_user->user; $user = $company_user->user;
/* This is only here to handle the alternate message channels - ie Slack */ /* This is only here to handle the alternate message channels - ie Slack */
$notification = new EntitySentNotification($event->invitation, 'invoice'); // $notification = new EntitySentNotification($event->invitation, 'invoice');
/* Returns an array of notification methods */ /* Returns an array of notification methods */
$methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'invoice', ['all_notifications', 'invoice_sent']); $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'invoice', ['all_notifications', 'invoice_sent']);
@ -76,10 +76,10 @@ class InvoiceEmailedNotification implements ShouldQueue
} }
/* Override the methods in the Notification Class */ /* Override the methods in the Notification Class */
$notification->method = $methods; // $notification->method = $methods;
/* Notify on the alternate channels */ // Notify on the alternate channels
$user->notify($notification); // $user->notify($notification);
} }
} }
} }

View File

@ -20,7 +20,7 @@ use App\Notifications\Admin\EntitySentNotification;
use App\Utils\Traits\Notifications\UserNotifies; use App\Utils\Traits\Notifications\UserNotifies;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
class InvoiceFailedEmailNotification implements ShouldQueue class InvoiceFailedEmailNotification
{ {
use UserNotifies; use UserNotifies;
@ -54,7 +54,7 @@ class InvoiceFailedEmailNotification implements ShouldQueue
foreach ($event->invitation->company->company_users as $company_user) { foreach ($event->invitation->company->company_users as $company_user) {
$user = $company_user->user; $user = $company_user->user;
$notification = new EntitySentNotification($event->invitation, 'invoice'); // $notification = new EntitySentNotification($event->invitation, 'invoice');
$methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'invoice', ['all_notifications', 'invoice_sent']); $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'invoice', ['all_notifications', 'invoice_sent']);
@ -68,9 +68,9 @@ class InvoiceFailedEmailNotification implements ShouldQueue
$first_notification_sent = false; $first_notification_sent = false;
} }
$notification->method = $methods; // $notification->method = $methods;
$user->notify($notification); // $user->notify($notification);
} }
} }
} }

View File

@ -47,7 +47,7 @@ class InvitationViewedListener implements ShouldQueue
$entity_name = lcfirst(class_basename($event->entity)); $entity_name = lcfirst(class_basename($event->entity));
$invitation = $event->invitation; $invitation = $event->invitation;
$notification = new EntityViewedNotification($invitation, $entity_name); // $notification = new EntityViewedNotification($invitation, $entity_name);
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer( (new EntityViewedObject($invitation, $entity_name))->build() ); $nmo->mailable = new NinjaMailer( (new EntityViewedObject($invitation, $entity_name))->build() );
@ -68,16 +68,16 @@ class InvitationViewedListener implements ShouldQueue
} }
$notification->method = $methods; // $notification->method = $methods;
$company_user->user->notify($notification); // $company_user->user->notify($notification);
} }
if (isset($invitation->company->slack_webhook_url)) { // if (isset($invitation->company->slack_webhook_url)) {
$notification->method = ['slack']; // $notification->method = ['slack'];
// Notification::route('slack', $invitation->company->slack_webhook_url) // Notification::route('slack', $invitation->company->slack_webhook_url)
// ->notify($notification); // ->notify($notification);
} // }
} }
} }

View File

@ -69,19 +69,19 @@ class PaymentNotification implements ShouldQueue
NinjaMailerJob::dispatch($nmo); NinjaMailerJob::dispatch($nmo);
} }
$notification = new NewPaymentNotification($payment, $payment->company); // $notification = new NewPaymentNotification($payment, $payment->company);
$notification->method = $methods; // $notification->method = $methods;
if ($user) { // if ($user) {
$user->notify($notification); // $user->notify($notification);
} // }
} }
/*Company Notifications*/ /*Company Notifications*/
if (isset($payment->company->slack_webhook_url)) { // if (isset($payment->company->slack_webhook_url)) {
Notification::route('slack', $payment->company->slack_webhook_url) // Notification::route('slack', $payment->company->slack_webhook_url)
->notify(new NewPaymentNotification($payment, $payment->company, true)); // ->notify(new NewPaymentNotification($payment, $payment->company, true));
} // }
/*Google Analytics Track Revenue*/ /*Google Analytics Track Revenue*/
if (isset($payment->company->google_analytics_key)) { if (isset($payment->company->google_analytics_key)) {

View File

@ -53,7 +53,7 @@ class QuoteEmailedNotification implements ShouldQueue
foreach ($event->invitation->company->company_users as $company_user) { foreach ($event->invitation->company->company_users as $company_user) {
$user = $company_user->user; $user = $company_user->user;
$notification = new EntitySentNotification($event->invitation, 'quote'); // $notification = new EntitySentNotification($event->invitation, 'quote');
$methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'quote', ['all_notifications', 'quote_sent']); $methods = $this->findUserNotificationTypes($event->invitation, $company_user, 'quote', ['all_notifications', 'quote_sent']);
@ -68,9 +68,9 @@ class QuoteEmailedNotification implements ShouldQueue
$first_notification_sent = false; $first_notification_sent = false;
} }
$notification->method = $methods; // $notification->method = $methods;
$user->notify($notification); // $user->notify($notification);
} }
} }
} }

View File

@ -131,6 +131,7 @@ class EntityFailedSendObject
'client' => $this->contact->present()->name(), 'client' => $this->contact->present()->name(),
'invoice' => $this->entity->number, 'invoice' => $this->entity->number,
'error' => $this->message, 'error' => $this->message,
'contact' => $this->contact->present()->name(),
] ]
), ),
'url' => $this->invitation->getAdminLink(), 'url' => $this->invitation->getAdminLink(),

View File

@ -22,10 +22,9 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
//@deprecated //@deprecated
class EntitySentNotification extends Notification implements ShouldQueue class EntitySentNotification extends Notification
{ {
//use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/** /**
* Create a new notification instance. * Create a new notification instance.
* *

View File

@ -21,9 +21,8 @@ use Illuminate\Notifications\Notification;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
class EntityViewedNotification extends Notification implements ShouldQueue class EntityViewedNotification extends Notification
{ {
//use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/** /**
* Create a new notification instance. * Create a new notification instance.

View File

@ -21,9 +21,8 @@ use Illuminate\Notifications\Notification;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
class NewPaymentNotification extends Notification implements ShouldQueue class NewPaymentNotification extends Notification
{ {
// use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/** /**
* Create a new notification instance. * Create a new notification instance.