mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for user notifications
This commit is contained in:
parent
dc1fe692a3
commit
94fa01091d
@ -20,6 +20,7 @@ use App\Mail\Admin\EntityNotificationMailer;
|
|||||||
use App\Mail\Admin\PaymentFailureObject;
|
use App\Mail\Admin\PaymentFailureObject;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use App\Models\Invoice;
|
||||||
use App\Models\PaymentHash;
|
use App\Models\PaymentHash;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Utils\Traits\Notifications\UserNotifies;
|
use App\Utils\Traits\Notifications\UserNotifies;
|
||||||
@ -75,17 +76,17 @@ class PaymentFailedMailer implements ShouldQueue
|
|||||||
|
|
||||||
$settings = $this->client->getMergedSettings();
|
$settings = $this->client->getMergedSettings();
|
||||||
$amount = 0;
|
$amount = 0;
|
||||||
|
$invoice = false;
|
||||||
|
|
||||||
if($this->payment_hash)
|
if($this->payment_hash){
|
||||||
$amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total;
|
$amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total;
|
||||||
|
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
|
||||||
|
}
|
||||||
|
|
||||||
//iterate through company_users
|
//iterate through company_users
|
||||||
$this->company->company_users->each(function ($company_user) use($amount, $settings){
|
$this->company->company_users->each(function ($company_user) use($amount, $settings, $invoice){
|
||||||
|
|
||||||
//determine if this user has the right permissions
|
$methods = $this->findUserEntityNotificationType($invoice ?: $this->client, $company_user, ['payment_failure_user', 'payment_failure_all', 'payment_failure', 'all_notifications']);
|
||||||
// $methods = $this->findCompanyUserNotificationType($company_user, ['payment_failure_all','payment_failure','all_notifications']);
|
|
||||||
|
|
||||||
$methods = $this->findUserEntityNotificationType($this->client, $company_user, ['payment_failure_user','payment_failure_all','payment_failure','all_notifications']);
|
|
||||||
|
|
||||||
//if mail is a method type -fire mail!!
|
//if mail is a method type -fire mail!!
|
||||||
if (($key = array_search('mail', $methods)) !== false) {
|
if (($key = array_search('mail', $methods)) !== false) {
|
||||||
|
@ -85,7 +85,7 @@ trait Utilities
|
|||||||
public function processUnsuccessfulPayment(Payment $_payment, $throw_exception = true)
|
public function processUnsuccessfulPayment(Payment $_payment, $throw_exception = true)
|
||||||
{
|
{
|
||||||
$this->getParent()->sendFailureMail($_payment->response_summary);
|
$this->getParent()->sendFailureMail($_payment->response_summary);
|
||||||
$this->getParent()->clientPaymentFailureMailer($_payment->status);
|
// $this->getParent()->clientPaymentFailureMailer($_payment->status);
|
||||||
|
|
||||||
$message = [
|
$message = [
|
||||||
'server_response' => $_payment,
|
'server_response' => $_payment,
|
||||||
|
@ -11,6 +11,11 @@
|
|||||||
|
|
||||||
namespace App\Utils\Traits\Notifications;
|
namespace App\Utils\Traits\Notifications;
|
||||||
|
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Payment;
|
||||||
|
use App\Models\Quote;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class UserNotifies.
|
* Class UserNotifies.
|
||||||
*
|
*
|
||||||
@ -31,7 +36,7 @@ trait UserNotifies
|
|||||||
|
|
||||||
//if a user owns this record or is assigned to it, they are attached the permission for notification.
|
//if a user owns this record or is assigned to it, they are attached the permission for notification.
|
||||||
if ($invitation->{$entity_name}->user_id == $company_user->_user_id || $invitation->{$entity_name}->assigned_user_id == $company_user->user_id) {
|
if ($invitation->{$entity_name}->user_id == $company_user->_user_id || $invitation->{$entity_name}->assigned_user_id == $company_user->user_id) {
|
||||||
array_push($required_permissions, 'all_user_notifications');
|
$required_permissions = $this->addSpecialUserPermissionForEntity($invitation->{$entity_name}, $required_permissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect(['all_user_notifications'], $notifications->email)) >= 1 || count(array_intersect(['all_notifications'],$notifications->email)) >= 1) {
|
if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect(['all_user_notifications'], $notifications->email)) >= 1 || count(array_intersect(['all_notifications'],$notifications->email)) >= 1) {
|
||||||
@ -58,17 +63,62 @@ trait UserNotifies
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($entity->user_id == $company_user->_user_id || $entity->assigned_user_id == $company_user->user_id) {
|
if ($entity->user_id == $company_user->_user_id || $entity->assigned_user_id == $company_user->user_id) {
|
||||||
array_push($required_permissions, 'all_user_notifications');
|
$required_permissions = $this->addSpecialUserPermissionForEntity($entity, $required_permissions);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$required_permissions = $this->removeSpecialUserPermissionForEntity($entity, $required_permissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect(['all_notifications'],$notifications->email)) >= 1) {
|
if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect(['all_notifications'],$notifications->email)) >= 1) {
|
||||||
array_push($notifiable_methods, 'mail');
|
array_push($notifiable_methods, 'mail');
|
||||||
}
|
}
|
||||||
|
|
||||||
nlog($notifiable_methods);
|
|
||||||
return $notifiable_methods;
|
return $notifiable_methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function addSpecialUserPermissionForEntity($entity, $required_permissions)
|
||||||
|
{
|
||||||
|
switch ($entity) {
|
||||||
|
case ($entity instanceof Payment || $entity instanceof Client): //we pass client also as this is the proxy for Payment Failures (ie, there is no payment)
|
||||||
|
return array_push($required_permissions, ["all_user_notifications","payment_failure_user","payment_success_user"]);
|
||||||
|
break;
|
||||||
|
case ($entity instanceof Invoice):
|
||||||
|
return array_push($required_permissions, ["all_user_notifications","invoice_created_user","invoice_sent_user","invoice_viewed_user","invoice_late_user"]);
|
||||||
|
break;
|
||||||
|
case ($entity instanceof Quote):
|
||||||
|
return array_push($required_permissions, ["all_user_notifications","quote_created_user","quote_sent_user","quote_viewed_user","quote_approved_user","quote_expired_user"]);
|
||||||
|
break;
|
||||||
|
case ($entity instanceof Credit):
|
||||||
|
return array_push($required_permissions, ["all_user_notifications","credit_created_user","credit_sent_user","credit_viewed_user"]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// code...
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function removeSpecialUserPermissionForEntity($entity, $required_permissions)
|
||||||
|
{
|
||||||
|
switch ($entity) {
|
||||||
|
case ($entity instanceof Payment || $entity instanceof Client): //we pass client also as this is the proxy for Payment Failures (ie, there is no payment)
|
||||||
|
return array_diff($required_permissions, ["all_user_notifications","payment_failure_user","payment_success_user"]);
|
||||||
|
break;
|
||||||
|
case ($entity instanceof Invoice):
|
||||||
|
return array_diff($required_permissions, ["all_user_notifications","invoice_created_user","invoice_sent_user","invoice_viewed_user","invoice_late_user"]);
|
||||||
|
break;
|
||||||
|
case ($entity instanceof Quote):
|
||||||
|
return array_diff($required_permissions, ["all_user_notifications","quote_created_user","quote_sent_user","quote_viewed_user","quote_approved_user","quote_expired_user"]);
|
||||||
|
break;
|
||||||
|
case ($entity instanceof Credit):
|
||||||
|
return array_diff($required_permissions, ["all_user_notifications","credit_created_user","credit_sent_user","credit_viewed_user"]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// code...
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function findCompanyUserNotificationType($company_user, $required_permissions) :array
|
public function findCompanyUserNotificationType($company_user, $required_permissions) :array
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user