diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index b3d233b23fb7..b6f9e62b392a 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -1092,6 +1092,7 @@ class AccountController extends BaseController $user->notify_viewed = Input::get('notify_viewed'); $user->notify_paid = Input::get('notify_paid'); $user->notify_approved = Input::get('notify_approved'); + $user->only_notify_owned = Input::get('only_notify_owned'); $user->slack_webhook_url = Input::get('slack_webhook_url'); $user->save(); @@ -1235,6 +1236,7 @@ class AccountController extends BaseController $user->notify_viewed = Input::get('notify_viewed'); $user->notify_paid = Input::get('notify_paid'); $user->notify_approved = Input::get('notify_approved'); + $user->only_notify_owned = Input::get('only_notify_owned'); } if ($user->google_2fa_secret && ! Input::get('enable_two_factor')) { diff --git a/app/Models/User.php b/app/Models/User.php index 6302e9b6dd4a..69cf746afd10 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -478,6 +478,28 @@ class User extends Authenticatable return $this; } + + public function ownsEntity($entity) + { + return $entity->user_id == $this->id; + } + + public function shouldNotify($invoice) + { + if (! $this->email || ! $this->confirmed) { + return false; + } + + if ($this->cannot('view', $invoice)) { + return false; + } + + if ($this->only_notify_owned && ! $this->ownsEntity($invoice)) { + return false; + } + + return true; + } } User::created(function ($user) diff --git a/app/Ninja/Mailers/UserMailer.php b/app/Ninja/Mailers/UserMailer.php index 9cd34e9455f3..881ab1b1a90b 100644 --- a/app/Ninja/Mailers/UserMailer.php +++ b/app/Ninja/Mailers/UserMailer.php @@ -76,7 +76,7 @@ class UserMailer extends Mailer Payment $payment = null, $notes = false ) { - if (! $user->email || $user->cannot('view', $invoice)) { + if (! $user->shouldNotify($invoice)) { return; } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index f27982b41d45..c23270a827ec 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2844,6 +2844,9 @@ $LANG = array( 'show_aging' => 'Show Aging', 'reference' => 'Reference', 'amount_paid' => 'Amount Paid', + 'send_notifications_for' => 'Send Notifications For', + 'all_invoices' => 'All Invoices', + 'my_invoices' => 'My Invoices', ); diff --git a/resources/views/accounts/partials/notifications.blade.php b/resources/views/accounts/partials/notifications.blade.php index 44bf09033e3a..018fcde8f29a 100644 --- a/resources/views/accounts/partials/notifications.blade.php +++ b/resources/views/accounts/partials/notifications.blade.php @@ -2,15 +2,25 @@ {{ Former::populateField('notify_viewed', intval(Auth::user()->notify_viewed)) }} {{ Former::populateField('notify_paid', intval(Auth::user()->notify_paid)) }} {{ Former::populateField('notify_approved', intval(Auth::user()->notify_approved)) }} +{{ Former::populateField('only_notify_owned', intval(Auth::user()->only_notify_owned)) }}