mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Notification types
This commit is contained in:
parent
71d643070b
commit
2b31b3bd8c
@ -13,6 +13,9 @@ namespace App\Http\Controllers\ClientPortal;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ClientPortal\ShowRecurringInvoiceRequest;
|
||||
use App\Jobs\Mail\NinjaMailer;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
use App\Mail\RecurringInvoice\ClientContactRequestCancellationObject;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Notifications\ClientContactRequestCancellation;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
@ -57,7 +60,11 @@ class RecurringInvoiceController extends Controller
|
||||
{
|
||||
//todo double check the user is able to request a cancellation
|
||||
//can add locale specific by chaining ->locale();
|
||||
$recurring_invoice->user->notify(new ClientContactRequestCancellation($recurring_invoice, auth()->user()));
|
||||
|
||||
$nmo = new NinjaMailerObject;
|
||||
$nmo->mailable = (new NinjaMailer((new ClientContactRequestCancellationObject($recurring_invoice, auth()->user()))->build()));
|
||||
|
||||
//$recurring_invoice->user->notify(new ClientContactRequestCancellation($recurring_invoice, auth()->user()));
|
||||
|
||||
return $this->render('recurring_invoices.cancellation.index', [
|
||||
'invoice' => $recurring_invoice,
|
||||
|
@ -32,7 +32,7 @@ class ClientContactRequestCancellationObject
|
||||
|
||||
$data = [
|
||||
'title' => ctrans('texts.new_signup'),
|
||||
'message' => ctrans('texts.new_signup_text', ['user' => $this->user->present()->name(), 'email' => $this->user->email, 'ip' => $this->user->ip]),
|
||||
'message' => ctrans('texts.recurring_cancellation_request_body', ['contact' => $this->client_contact->present()->name(), 'client' => $this->client_contact->client->present()->name(), 'invoice' => $this->recurring_invoice->number]),
|
||||
'url' => config('ninja.web_url'),
|
||||
'button' => ctrans('texts.account_login'),
|
||||
'signature' => $this->company->settings->email_signature,
|
||||
@ -42,7 +42,7 @@ class ClientContactRequestCancellationObject
|
||||
|
||||
|
||||
$mail_obj = new \stdClass;
|
||||
$mail_obj->subject = ctrans('texts.new_signup');
|
||||
$mail_obj->subject = ctrans('texts.recurring_cancellation_request', ['contact' => $this->client_contact->present()->name()]);
|
||||
$mail_obj->data = $data;
|
||||
$mail_obj->markdown = 'email.admin.generic';
|
||||
$mail_obj->tag = $this->company->company_key;
|
||||
|
@ -56,7 +56,7 @@ class ClientContactRequestCancellation extends Notification
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['mail', 'slack'];
|
||||
return ['slack'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,10 @@ namespace App\Utils\Traits\Notifications;
|
||||
|
||||
/**
|
||||
* Class UserNotifies.
|
||||
*
|
||||
* I think the term $required_permissions is confusing here, what
|
||||
* we are actually defining is the notifications available on the
|
||||
* user itself.
|
||||
*/
|
||||
trait UserNotifies
|
||||
{
|
||||
@ -74,10 +78,41 @@ trait UserNotifies
|
||||
$notifiable_methods = [];
|
||||
$notifications = $company_user->notifications;
|
||||
|
||||
//conditional to define whether the company user has the required notification for the MAIL notification TYPE
|
||||
if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect($required_permissions, ['all_user_notifications'])) >= 1 || count(array_intersect($required_permissions, ['all_notifications'])) >= 1) {
|
||||
array_push($notifiable_methods, 'mail');
|
||||
}
|
||||
|
||||
return $notifiable_methods;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a filtered collection of users with the
|
||||
* required notification - NOTE this is only implemented for
|
||||
* EMAIL notification types - we'll need to chain
|
||||
* additional types at a later stage.
|
||||
*/
|
||||
public function filterUsersByPermissions($company_users, $entity, array $required_notification)
|
||||
{
|
||||
|
||||
return $company_users->filter(function($company_user) use($required_notification, $entity){
|
||||
|
||||
return $this->checkNotificationExists($company_user, $entity, $required_notification)
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private function checkNotificationExists($company_user, $entity, $required_notification)
|
||||
{
|
||||
/* Always make sure we push the `all_notificaitons` into the mix */
|
||||
array_push($required_notification, 'all_notifications');
|
||||
|
||||
/* Selectively add the all_user if the user is associated with the entity */
|
||||
if ($entity->user_id == $company_user->_user_id || $entity->assigned_user_id == $company_user->user_id)
|
||||
array_push($required_notification, 'all_user_notifications');
|
||||
|
||||
|
||||
return count(array_intersect($required_notification, $company_user->notifications->email)) >= 1;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user