mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fix casts for permissions (#3467)
* Fix cast for permissions * Notification Types * Working on notification logic
This commit is contained in:
parent
35b2e9b5e1
commit
aad117a67d
@ -549,8 +549,6 @@ class CreateTestData extends Command
|
||||
$credit->service()->markSent()->save();
|
||||
$credit->service()->createInvitations();
|
||||
|
||||
event(new CreateCreditInvitation($credit));
|
||||
|
||||
}
|
||||
|
||||
private function createQuote($client)
|
||||
@ -561,8 +559,10 @@ class CreateTestData extends Command
|
||||
// }
|
||||
$faker = \Faker\Factory::create();
|
||||
|
||||
//$quote = QuoteFactory::create($client->company->id, $client->user->id);//stub the company and user_id
|
||||
$quote =factory(\App\Models\Quote::class)->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
|
||||
$quote->date = $faker->date();
|
||||
$quote->client_id = $client->id;
|
||||
|
||||
$quote->setRelation('client', $client);
|
||||
|
||||
@ -596,7 +596,6 @@ class CreateTestData extends Command
|
||||
$quote->service()->markSent()->save();
|
||||
$quote->service()->createInvitations();
|
||||
|
||||
CreateQuoteInvitations::dispatch($quote, $quote->company);
|
||||
}
|
||||
|
||||
private function buildLineItems($count = 1)
|
||||
|
@ -40,16 +40,58 @@ class InvitationViewedListener implements ShouldQueue
|
||||
|
||||
foreach($invitation->company->company_users as $company_user)
|
||||
{
|
||||
$notifiable_methods = [];
|
||||
|
||||
$notifications = $company_user->notifications;
|
||||
|
||||
$entity_viewed = "{$entity_name}_viewed";
|
||||
|
||||
/*** Check for Mail notifications***/
|
||||
$all_user_notifications = '';
|
||||
|
||||
if($event->entity->user_id == $company_user->user_id || $event->entity->assigned_user_id == $company_user->user_id)
|
||||
$all_user_notifications = "all_user_notifications";
|
||||
|
||||
$possible_permissions = [$entity_viewed, "all_notifications", $all_user_notifications];
|
||||
|
||||
$permission_count = array_intersect($possible_permissions, $notifications->email);
|
||||
|
||||
if(count($permission_count) >=1)
|
||||
array_push($notifiable_methods, 'mail');
|
||||
/*** Check for Mail notifications***/
|
||||
|
||||
|
||||
/*** Check for Slack notifications***/
|
||||
//@TODO when hillel implements this we can uncomment this.
|
||||
// $permission_count = array_intersect($possible_permissions, $notifications->slack);
|
||||
// if(count($permission_count) >=1)
|
||||
// array_push($notifiable_methods, 'slack');
|
||||
|
||||
/*** Check for Slack notifications***/
|
||||
|
||||
$notification->method = $notifiable_methods;
|
||||
|
||||
$company_user->user->notify($notification);
|
||||
}
|
||||
|
||||
if(isset($invitation->company->slack_webhook_url)){
|
||||
|
||||
$notification->is_system = true;
|
||||
$notification->method = ['slack'];
|
||||
|
||||
Notification::route('slack', $invitation->company->slack_webhook_url)
|
||||
->notify($notification);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function userNotificationArray($notifications)
|
||||
{
|
||||
$via_array = [];
|
||||
|
||||
if(stripos($this->company_user->permissions, ) !== false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class CompanyUser extends Pivot
|
||||
'deleted_at' => 'timestamp',
|
||||
'settings' => 'object',
|
||||
'notifications' => 'object',
|
||||
'permissions' => 'object',
|
||||
'permissions' => 'string',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
|
@ -301,8 +301,8 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
public function routeNotificationForSlack($notification)
|
||||
{
|
||||
|
||||
if($this->company())
|
||||
return $this->company()->slack_webhook_url;
|
||||
if($this->company_user->slack_webhook_url)
|
||||
return $this->company_user->slack_webhook_url;
|
||||
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ class EntityViewedNotification extends Notification implements ShouldQueue
|
||||
|
||||
protected $settings;
|
||||
|
||||
public $is_system;
|
||||
public $method;
|
||||
|
||||
protected $contact;
|
||||
|
||||
@ -55,7 +55,8 @@ class EntityViewedNotification extends Notification implements ShouldQueue
|
||||
public function via($notifiable)
|
||||
{
|
||||
|
||||
return $this->is_system ? ['slack'] : ['mail'];
|
||||
return $this->method;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,6 +19,28 @@ use Illuminate\Support\Facades\Notification;
|
||||
class NotificationService extends AbstractService
|
||||
{
|
||||
|
||||
const ALL = 'all_notifications';
|
||||
|
||||
const ALL_USER = 'all_user_notifications';
|
||||
|
||||
const PAYMENT_SUCCESS = 'payment_success';
|
||||
|
||||
const PAYMENT_FAILURE = 'payment_failure';
|
||||
|
||||
const INVOICE_SENT = 'invoice_sent';
|
||||
|
||||
const QUOTE_SENT = 'quote_sent';
|
||||
|
||||
const CREDIT_SENT = 'credit_sent';
|
||||
|
||||
const QUOTE_VIEWED = 'quote_viewed';
|
||||
|
||||
const INVOICE_VIEWED = 'invoice_viewed';
|
||||
|
||||
const CREDIT_VIEWED = 'credit_viewed';
|
||||
|
||||
const QUOTE_APPROVED = 'quote_approved';
|
||||
|
||||
public $company;
|
||||
|
||||
public $notification;
|
||||
|
@ -9,26 +9,29 @@ class MarkSent
|
||||
{
|
||||
private $client;
|
||||
|
||||
public function __construct($client)
|
||||
private $quote;
|
||||
|
||||
public function __construct($client, $quote)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->quote = $quote;
|
||||
}
|
||||
|
||||
public function run($quote)
|
||||
public function run()
|
||||
{
|
||||
|
||||
/* Return immediately if status is not draft */
|
||||
if ($quote->status_id != Quote::STATUS_DRAFT) {
|
||||
if ($this->quote->status_id != Quote::STATUS_DRAFT) {
|
||||
return $quote;
|
||||
}
|
||||
|
||||
$quote->markInvitationsSent();
|
||||
$this->quote->markInvitationsSent();
|
||||
|
||||
event(new QuoteWasMarkedSent($quote, $quote->company));
|
||||
event(new QuoteWasMarkedSent($this->quote, $this->quote->company));
|
||||
|
||||
$quote->service()->setStatus(Quote::STATUS_SENT)->applyNumber()->save();
|
||||
$this->quote->service()->setStatus(Quote::STATUS_SENT)->applyNumber()->save();
|
||||
|
||||
return $quote;
|
||||
return $this->quote;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -69,9 +69,9 @@ class QuoteService
|
||||
|
||||
public function markSent() :QuoteService
|
||||
{
|
||||
$mark_sent = new MarkSent($this->quote->client);
|
||||
$mark_sent = new MarkSent($this->quote->client, $this->quote);
|
||||
|
||||
$this->quote = $mark_sent->run($this->quote);
|
||||
$this->quote = $mark_sent->run();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user