diff --git a/app/Jobs/Account/CreateAccount.php b/app/Jobs/Account/CreateAccount.php index d45b0423fdbe..4dfe7e0bf2a1 100644 --- a/app/Jobs/Account/CreateAccount.php +++ b/app/Jobs/Account/CreateAccount.php @@ -114,9 +114,6 @@ class CreateAccount $spaa9f78->fresh(); - //todo implement SLACK notifications - //$sp035a66->notification(new NewAccountCreated($spaa9f78, $sp035a66))->ninja(); - if(Ninja::isHosted()) \Modules\Admin\Jobs\Account\NinjaUser::dispatch([], $sp035a66); diff --git a/app/Listeners/SendVerificationNotification.php b/app/Listeners/SendVerificationNotification.php index cec4f916b0cc..4f6beef409ee 100644 --- a/app/Listeners/SendVerificationNotification.php +++ b/app/Listeners/SendVerificationNotification.php @@ -17,7 +17,6 @@ use App\Jobs\Mail\NinjaMailerObject; use App\Libraries\MultiDB; use App\Mail\Admin\VerifyUserObject; use App\Mail\User\UserAdded; -use App\Notifications\Ninja\VerifyUser; use App\Utils\Ninja; use Exception; use Illuminate\Broadcasting\InteractsWithSockets; diff --git a/app/Models/Account.php b/app/Models/Account.php index 54766d341fa9..5301d90cbd7d 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -15,11 +15,13 @@ use App\Jobs\Mail\NinjaMailerJob; use App\Jobs\Mail\NinjaMailerObject; use App\Mail\Ninja\EmailQuotaExceeded; use App\Models\Presenters\AccountPresenter; +use App\Notifications\Ninja\EmailQuotaNotification; use App\Utils\Ninja; use App\Utils\Traits\MakesHash; use Carbon\Carbon; use DateTime; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; use Laracasts\Presenter\PresentableTrait; @@ -384,6 +386,10 @@ class Account extends BaseModel if(is_null(Cache::get("throttle_notified:{$this->key}"))) { + App::forgetInstance('translator'); + $t = app('translator'); + $t->replace(Ninja::transformTranslations($this->companies()->first()->settings)); + $nmo = new NinjaMailerObject; $nmo->mailable = new EmailQuotaExceeded($this->companies()->first()); $nmo->company = $this->companies()->first(); @@ -392,6 +398,9 @@ class Account extends BaseModel NinjaMailerJob::dispatch($nmo); Cache::put("throttle_notified:{$this->key}", true, 60 * 24); + + if(config('ninja.notification.slack')) + $this->companies()->first()->notification(new EmailQuotaNotification($this))->ninja(); } return true; diff --git a/app/Notifications/Ninja/EmailQuotaNotification.php b/app/Notifications/Ninja/EmailQuotaNotification.php new file mode 100644 index 000000000000..71c4b00644a0 --- /dev/null +++ b/app/Notifications/Ninja/EmailQuotaNotification.php @@ -0,0 +1,88 @@ +account = $account; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['slack']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return MailMessage + */ + public function toMail($notifiable) + { + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } + + public function toSlack($notifiable) + { + + $content = "Email quota exceeded by Account {$this->account->key} \n"; + + $owner = $this->account->companies()->first()->owner(); + + $content .= "Owner {$owner->present()->name() } | {$owner->email}"; + + return (new SlackMessage) + ->success() + ->from(ctrans('texts.notification_bot')) + ->image('https://app.invoiceninja.com/favicon.png') + ->content($content); + } +} diff --git a/config/ninja.php b/config/ninja.php index 16d0f9c9be73..1bbd2c67b14e 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -115,7 +115,7 @@ return [ //'fonts' => 'App\Models\Font', ], 'notification' => [ - 'slack' => env('SLACK_WEBHOOK_URL', ''), + 'slack' => env('SLACK_WEBHOOK_URL', false), 'mail' => env('HOSTED_EMAIL', ''), ], 'themes' => [