Skip to content

Commit

Permalink
Merge pull request #199 from ploi-deploy/notifications-per-project
Browse files Browse the repository at this point in the history
Allow notifications per project
  • Loading branch information
Cannonb4ll authored Feb 13, 2023
2 parents 74340b5 + a8b78b5 commit d3afa64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/Filament/Pages/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Filament\Pages;

use App\Models\Board;
use App\Models\Project;
use Closure;
use Filament\Forms\Components\Textarea;
use Storage;
Expand Down Expand Up @@ -200,7 +201,7 @@ protected function getFormSchema(): array
Tabs\Tab::make('Notifications')
->schema([
Repeater::make('send_notifications_to')
->columns(3)
->columns(4)
->schema([
Select::make('type')
->default('email')
Expand All @@ -210,6 +211,10 @@ protected function getFormSchema(): array
'discord' => 'Discord',
'slack' => 'Slack'
]),
Select::make('projects')
->multiple()
->helperText('Optionally select projects to trigger for, if you do not select a project it will always notify on new events')
->options(Project::pluck('title', 'id')),
TextInput::make('name')->label(function ($get) {
return match ($get('type')) {
'email' => 'Name receiver',
Expand Down
9 changes: 9 additions & 0 deletions app/Observers/ItemObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Observers;

use App\Models\Project;
use Mail;
use App\Models\Item;
use App\Models\User;
Expand All @@ -24,6 +25,14 @@ public function created(Item $item)
continue;
}

if (
isset($receiver['projects']) &&
Project::whereIn('id', $receiver['projects'])->count() &&
!in_array($item->project_id, $receiver['projects'])
) {
continue;
}

match ($receiver['type']) {
'email' => Mail::to($receiver['webhook'])->send(new ItemHasBeenCreatedEmail($receiver, $item)),
'discord', 'slack' => dispatch(new SendWebhookForNewItemJob($item, $receiver)),
Expand Down

0 comments on commit d3afa64

Please sign in to comment.