From 0a26c46b1eb1216ff0ab52c986958c6817f8fe62 Mon Sep 17 00:00:00 2001 From: IGORnvk Date: Sun, 29 Sep 2024 20:15:43 +0200 Subject: [PATCH 1/8] Notify speakers and crew members when presentation is updated --- app/Events/PresentationRolesNotified.php | 37 ++++++++++++ .../HandlePresentationRolesNotified.php | 43 ++++++++++++++ .../Presentation/EditPresentationModal.php | 5 ++ app/Mail/PresentationUpdatedMailable.php | 56 +++++++++++++++++++ .../emails/presentation-updated.blade.php | 22 ++++++++ 5 files changed, 163 insertions(+) create mode 100644 app/Events/PresentationRolesNotified.php create mode 100644 app/Listeners/HandlePresentationRolesNotified.php create mode 100644 app/Mail/PresentationUpdatedMailable.php create mode 100644 resources/views/emails/presentation-updated.blade.php diff --git a/app/Events/PresentationRolesNotified.php b/app/Events/PresentationRolesNotified.php new file mode 100644 index 00000000..9854f3dc --- /dev/null +++ b/app/Events/PresentationRolesNotified.php @@ -0,0 +1,37 @@ + + */ + public function broadcastOn(): array + { + return [ + new PrivateChannel('channel-name'), + ]; + } +} diff --git a/app/Listeners/HandlePresentationRolesNotified.php b/app/Listeners/HandlePresentationRolesNotified.php new file mode 100644 index 00000000..e91456b3 --- /dev/null +++ b/app/Listeners/HandlePresentationRolesNotified.php @@ -0,0 +1,43 @@ +presentation->is_approved) { + return; + } + + $users = collect(); + if ($event->receiver == 'crew') { + $users = User::role(['event organizer', 'speakers supervisor'])->get(); + } else if ($event->receiver == 'speaker') { + $users = $event->presentation->speakers; + } + + // Send emails to the users + foreach ($users as $user) { + Mail::to($user->email)->send(new PresentationUpdatedMailable($user, $event->presentation)); + } + } +} diff --git a/app/Livewire/Presentation/EditPresentationModal.php b/app/Livewire/Presentation/EditPresentationModal.php index d5b1dad4..ea6cf89e 100644 --- a/app/Livewire/Presentation/EditPresentationModal.php +++ b/app/Livewire/Presentation/EditPresentationModal.php @@ -2,6 +2,7 @@ namespace App\Livewire\Presentation; +use App\Events\PresentationRolesNotified; use App\Livewire\Forms\PresentationForm; use App\Models\Presentation; use Illuminate\Http\RedirectResponse; @@ -38,9 +39,13 @@ public function save() $this->form->update(); if (Auth::user()->presenter_of) { + PresentationRolesNotified::dispatch('crew', $this->presentation); + return redirect(route('presentations.show', $this->presentation)) ->with('status', 'Presentation successfully updated.'); } else { + PresentationRolesNotified::dispatch('speaker', $this->presentation); + return redirect(route('moderator.presentations.show', $this->presentation)) ->with('status', 'Presentation successfully updated.'); } diff --git a/app/Mail/PresentationUpdatedMailable.php b/app/Mail/PresentationUpdatedMailable.php new file mode 100644 index 00000000..1ecc01c0 --- /dev/null +++ b/app/Mail/PresentationUpdatedMailable.php @@ -0,0 +1,56 @@ + + */ + public function attachments(): array + { + return []; + } +} diff --git a/resources/views/emails/presentation-updated.blade.php b/resources/views/emails/presentation-updated.blade.php new file mode 100644 index 00000000..ed19102d --- /dev/null +++ b/resources/views/emails/presentation-updated.blade.php @@ -0,0 +1,22 @@ +@component('mail::message') +Dear {{ $user->name }} + +'{{ $presentation->name }}' details were updated by +@if($user->isPresenterOf($presentation)) +our crew. + +@component('mail::button', ['url' => route('presentations.show', $presentation)]) + Log in to see details +@endcomponent +@elseif($user->is_crew) +the speaker. + +@component('mail::button', ['url' => route('moderator.presentations.show', $presentation)]) + Log in to see details +@endcomponent +@endif + +Kind regards, + +We are in IT together conference team +@endcomponent From eeb8f2277a82975daf8ae9e0cfbbbe19d1aae0ed Mon Sep 17 00:00:00 2001 From: IGORnvk Date: Sun, 29 Sep 2024 22:06:05 +0200 Subject: [PATCH 2/8] Notify users when company details are changed --- app/Events/CompanyRolesNotified.php | 38 +++++++++++++ app/Listeners/HandleCompanyRolesNotified.php | 43 +++++++++++++++ app/Livewire/Company/EditCompanyModal.php | 5 ++ app/Mail/CompanyUpdatedMailable.php | 55 +++++++++++++++++++ .../views/emails/company-updated.blade.php | 22 ++++++++ 5 files changed, 163 insertions(+) create mode 100644 app/Events/CompanyRolesNotified.php create mode 100644 app/Listeners/HandleCompanyRolesNotified.php create mode 100644 app/Mail/CompanyUpdatedMailable.php create mode 100644 resources/views/emails/company-updated.blade.php diff --git a/app/Events/CompanyRolesNotified.php b/app/Events/CompanyRolesNotified.php new file mode 100644 index 00000000..90bc42df --- /dev/null +++ b/app/Events/CompanyRolesNotified.php @@ -0,0 +1,38 @@ + + */ + public function broadcastOn(): array + { + return [ + new PrivateChannel('channel-name'), + ]; + } +} diff --git a/app/Listeners/HandleCompanyRolesNotified.php b/app/Listeners/HandleCompanyRolesNotified.php new file mode 100644 index 00000000..d32f12a2 --- /dev/null +++ b/app/Listeners/HandleCompanyRolesNotified.php @@ -0,0 +1,43 @@ +company->is_approved) { + return; + } + + $users = collect(); + if ($event->receiver == 'crew') { + $users = User::role(['event organizer', 'assistant organizer'])->get(); + } else if ($event->receiver == 'representative') { + $users->push($event->company->representative); + } + + // Send emails to the users + foreach ($users as $user) { + Mail::to($user->email)->send(new CompanyUpdatedMailable($user, $event->company)); + } + } +} diff --git a/app/Livewire/Company/EditCompanyModal.php b/app/Livewire/Company/EditCompanyModal.php index 53575f20..d5421138 100644 --- a/app/Livewire/Company/EditCompanyModal.php +++ b/app/Livewire/Company/EditCompanyModal.php @@ -2,6 +2,7 @@ namespace App\Livewire\Company; +use App\Events\CompanyRolesNotified; use App\Livewire\Forms\CompanyForm; use App\Models\Company; use Illuminate\Contracts\Foundation\Application; @@ -42,9 +43,13 @@ public function save() $this->form->update(); if (Auth::user()->id == $this->company->representative->id) { + CompanyRolesNotified::dispatch('crew', $this->company); + return redirect(route('company.details')) ->with('status', 'Company successfully updated.'); } else { + CompanyRolesNotified::dispatch('representative', $this->company); + return redirect(route('moderator.companies.show', $this->company)) ->with('status', 'Company successfully updated.'); } diff --git a/app/Mail/CompanyUpdatedMailable.php b/app/Mail/CompanyUpdatedMailable.php new file mode 100644 index 00000000..98e07daa --- /dev/null +++ b/app/Mail/CompanyUpdatedMailable.php @@ -0,0 +1,55 @@ + + */ + public function attachments(): array + { + return []; + } +} diff --git a/resources/views/emails/company-updated.blade.php b/resources/views/emails/company-updated.blade.php new file mode 100644 index 00000000..62ec7006 --- /dev/null +++ b/resources/views/emails/company-updated.blade.php @@ -0,0 +1,22 @@ +@component('mail::message') +Dear {{ $user->name }} + +'{{ $company->name }}' details were updated by +@if($user->isMemberOf($company)) +our crew. + +@component('mail::button', ['url' => route('company.details', $company)]) + Log in to see details +@endcomponent +@elseif($user->is_crew) +the company representative. + +@component('mail::button', ['url' => route('moderator.companies.show', $company)]) + Log in to see details +@endcomponent +@endif + +Kind regards, + +We are in IT together conference team +@endcomponent From ac2c4800e7b6fff6e17592f251fbcb946cedfb3b Mon Sep 17 00:00:00 2001 From: IGORnvk Date: Sun, 29 Sep 2024 22:06:34 +0200 Subject: [PATCH 3/8] Fix presentation notifications --- app/Listeners/HandlePresentationRolesNotified.php | 2 +- app/Mail/PresentationUpdatedMailable.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Listeners/HandlePresentationRolesNotified.php b/app/Listeners/HandlePresentationRolesNotified.php index e91456b3..d6e44433 100644 --- a/app/Listeners/HandlePresentationRolesNotified.php +++ b/app/Listeners/HandlePresentationRolesNotified.php @@ -30,7 +30,7 @@ public function handle(PresentationRolesNotified $event): void $users = collect(); if ($event->receiver == 'crew') { - $users = User::role(['event organizer', 'speakers supervisor'])->get(); + $users = User::role(['event organizer', 'speakers supervisor', 'assistant organizer'])->get(); } else if ($event->receiver == 'speaker') { $users = $event->presentation->speakers; } diff --git a/app/Mail/PresentationUpdatedMailable.php b/app/Mail/PresentationUpdatedMailable.php index 1ecc01c0..88877b0e 100644 --- a/app/Mail/PresentationUpdatedMailable.php +++ b/app/Mail/PresentationUpdatedMailable.php @@ -20,7 +20,7 @@ class PresentationUpdatedMailable extends Mailable * Create a new message instance. */ public function __construct( - public User|Authenticatable $user, + public User $user, public Presentation $presentation, ) {} From ac8e952b2b7453bf6e62708fe6485cd5f7b74551 Mon Sep 17 00:00:00 2001 From: IGORnvk Date: Mon, 14 Oct 2024 20:46:07 +0200 Subject: [PATCH 4/8] Use global role name --- app/Listeners/HandleCompanyRolesNotified.php | 2 +- app/Livewire/Company/EditCompanyModal.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Listeners/HandleCompanyRolesNotified.php b/app/Listeners/HandleCompanyRolesNotified.php index d32f12a2..720cf187 100644 --- a/app/Listeners/HandleCompanyRolesNotified.php +++ b/app/Listeners/HandleCompanyRolesNotified.php @@ -31,7 +31,7 @@ public function handle(CompanyRolesNotified $event): void $users = collect(); if ($event->receiver == 'crew') { $users = User::role(['event organizer', 'assistant organizer'])->get(); - } else if ($event->receiver == 'representative') { + } else if ($event->receiver == 'company representative') { $users->push($event->company->representative); } diff --git a/app/Livewire/Company/EditCompanyModal.php b/app/Livewire/Company/EditCompanyModal.php index d5421138..5ee44533 100644 --- a/app/Livewire/Company/EditCompanyModal.php +++ b/app/Livewire/Company/EditCompanyModal.php @@ -48,7 +48,7 @@ public function save() return redirect(route('company.details')) ->with('status', 'Company successfully updated.'); } else { - CompanyRolesNotified::dispatch('representative', $this->company); + CompanyRolesNotified::dispatch('company representative', $this->company); return redirect(route('moderator.companies.show', $this->company)) ->with('status', 'Company successfully updated.'); From d291f1e6ec1b35fb83467b66432adc231e914023 Mon Sep 17 00:00:00 2001 From: IGORnvk Date: Wed, 16 Oct 2024 21:31:51 +0200 Subject: [PATCH 5/8] Prevent notifications for unchanged models --- app/Livewire/Company/EditCompanyModal.php | 8 ++++++-- .../Presentation/EditPresentationModal.php | 8 ++++++-- app/Models/Company.php | 19 +++++++++++++++++++ app/Models/Presentation.php | 16 ++++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/app/Livewire/Company/EditCompanyModal.php b/app/Livewire/Company/EditCompanyModal.php index 5ee44533..f5a2cb79 100644 --- a/app/Livewire/Company/EditCompanyModal.php +++ b/app/Livewire/Company/EditCompanyModal.php @@ -43,12 +43,16 @@ public function save() $this->form->update(); if (Auth::user()->id == $this->company->representative->id) { - CompanyRolesNotified::dispatch('crew', $this->company); + if (!$this->company->isSameCompany($this->form->company)) { + CompanyRolesNotified::dispatch('crew', $this->company); + } return redirect(route('company.details')) ->with('status', 'Company successfully updated.'); } else { - CompanyRolesNotified::dispatch('company representative', $this->company); + if (!$this->company->isSameCompany($this->form->company)) { + CompanyRolesNotified::dispatch('company representative', $this->company); + } return redirect(route('moderator.companies.show', $this->company)) ->with('status', 'Company successfully updated.'); diff --git a/app/Livewire/Presentation/EditPresentationModal.php b/app/Livewire/Presentation/EditPresentationModal.php index ea6cf89e..1d1acf25 100644 --- a/app/Livewire/Presentation/EditPresentationModal.php +++ b/app/Livewire/Presentation/EditPresentationModal.php @@ -39,12 +39,16 @@ public function save() $this->form->update(); if (Auth::user()->presenter_of) { - PresentationRolesNotified::dispatch('crew', $this->presentation); + if (!$this->presentation->isSamePresentation($this->form->presentation)) { + PresentationRolesNotified::dispatch('crew', $this->presentation); + } return redirect(route('presentations.show', $this->presentation)) ->with('status', 'Presentation successfully updated.'); } else { - PresentationRolesNotified::dispatch('speaker', $this->presentation); + if (!$this->presentation->isSamePresentation($this->form->presentation)) { + PresentationRolesNotified::dispatch('speaker', $this->presentation); + } return redirect(route('moderator.presentations.show', $this->presentation)) ->with('status', 'Presentation successfully updated.'); diff --git a/app/Models/Company.php b/app/Models/Company.php index 963b1e08..fff4ed98 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -252,4 +252,23 @@ public function handleSponsorshipApproval(bool $isApproved): void $this->enableLogging(); } } + + /** + * Determine whether the passed model instance is the same as the calling one + * + * @param Company $company + * @return bool + */ + public function isSameCompany(Company $company): bool + { + return $this->is($company) && + $this->name == $company->name && + $this->description == $company->description && + $this->website == $company->website && + $this->phone_number == $company->phone_number && + $this->postcode == $company->postcode && + $this->house_number == $company->house_number && + $this->street == $company->street && + $this->city == $company->city; + } } diff --git a/app/Models/Presentation.php b/app/Models/Presentation.php index 27870dfe..bb40c011 100644 --- a/app/Models/Presentation.php +++ b/app/Models/Presentation.php @@ -285,4 +285,20 @@ public function isScheduled(): Attribute get: fn() => !is_null($this->start) && !is_null($this->room_id) && !is_null($this->timeslot_id) ); } + + /** + * Determine whether the passed model instance is the same as the calling one + * + * @param Presentation $presentation + * @return bool + */ + public function isSamePresentation(Presentation $presentation): bool + { + return $this->is($presentation) && + $this->name == $presentation->name && + $this->description == $presentation->description && + $this->type == $presentation->type && + $this->max_participants == $presentation->max_participants && + $this->difficulty->id == $presentation->difficulty->id; + } } From 30c6e53f831011472c5d888a1d0a9e131765e08b Mon Sep 17 00:00:00 2001 From: IGORnvk Date: Wed, 16 Oct 2024 21:56:35 +0200 Subject: [PATCH 6/8] Fix phpcs --- app/Events/CompanyRolesNotified.php | 3 ++- app/Events/PresentationRolesNotified.php | 3 ++- app/Mail/CompanyUpdatedMailable.php | 3 ++- app/Mail/PresentationUpdatedMailable.php | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/Events/CompanyRolesNotified.php b/app/Events/CompanyRolesNotified.php index 90bc42df..2c0c3668 100644 --- a/app/Events/CompanyRolesNotified.php +++ b/app/Events/CompanyRolesNotified.php @@ -22,7 +22,8 @@ class CompanyRolesNotified public function __construct( public string $receiver, public Company $company, - ) {} + ) { + } /** * Get the channels the event should broadcast on. diff --git a/app/Events/PresentationRolesNotified.php b/app/Events/PresentationRolesNotified.php index 9854f3dc..65930e55 100644 --- a/app/Events/PresentationRolesNotified.php +++ b/app/Events/PresentationRolesNotified.php @@ -21,7 +21,8 @@ class PresentationRolesNotified public function __construct( public string $receiver, public Presentation $presentation, - ) {} + ) { + } /** * Get the channels the event should broadcast on. diff --git a/app/Mail/CompanyUpdatedMailable.php b/app/Mail/CompanyUpdatedMailable.php index 98e07daa..7ba5e197 100644 --- a/app/Mail/CompanyUpdatedMailable.php +++ b/app/Mail/CompanyUpdatedMailable.php @@ -21,7 +21,8 @@ class CompanyUpdatedMailable extends Mailable public function __construct( public User $user, public Company $company, - ) {} + ) { + } /** * Get the message envelope. diff --git a/app/Mail/PresentationUpdatedMailable.php b/app/Mail/PresentationUpdatedMailable.php index 88877b0e..36d7d247 100644 --- a/app/Mail/PresentationUpdatedMailable.php +++ b/app/Mail/PresentationUpdatedMailable.php @@ -22,7 +22,8 @@ class PresentationUpdatedMailable extends Mailable public function __construct( public User $user, public Presentation $presentation, - ) {} + ) { + } /** * Get the message envelope. From 7aba6d66d71d0c693959eb1c8cc81bb8af065be9 Mon Sep 17 00:00:00 2001 From: IGORnvk Date: Sun, 20 Oct 2024 14:22:29 +0200 Subject: [PATCH 7/8] Add logic for deleted presentation/company --- app/Events/CompanyRolesNotified.php | 2 + app/Events/PresentationRolesNotified.php | 1 + .../Controllers/Crew/CompanyController.php | 6 +- .../Crew/PresentationController.php | 4 ++ app/Listeners/HandleCompanyRolesNotified.php | 2 +- .../HandlePresentationRolesNotified.php | 2 +- app/Livewire/Company/EditCompanyModal.php | 5 +- app/Mail/CompanyDeletedMailable.php | 56 +++++++++++++++++++ app/Mail/PresentationDeletedMailable.php | 56 +++++++++++++++++++ .../views/emails/company-deleted.blade.php | 9 +++ .../emails/presentation-deleted.blade.php | 9 +++ 11 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 app/Mail/CompanyDeletedMailable.php create mode 100644 app/Mail/PresentationDeletedMailable.php create mode 100644 resources/views/emails/company-deleted.blade.php create mode 100644 resources/views/emails/presentation-deleted.blade.php diff --git a/app/Events/CompanyRolesNotified.php b/app/Events/CompanyRolesNotified.php index 2c0c3668..dd0188f2 100644 --- a/app/Events/CompanyRolesNotified.php +++ b/app/Events/CompanyRolesNotified.php @@ -10,6 +10,7 @@ use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; class CompanyRolesNotified @@ -22,6 +23,7 @@ class CompanyRolesNotified public function __construct( public string $receiver, public Company $company, + public string $emailTemplate, ) { } diff --git a/app/Events/PresentationRolesNotified.php b/app/Events/PresentationRolesNotified.php index 65930e55..8d90150b 100644 --- a/app/Events/PresentationRolesNotified.php +++ b/app/Events/PresentationRolesNotified.php @@ -21,6 +21,7 @@ class PresentationRolesNotified public function __construct( public string $receiver, public Presentation $presentation, + public string $emailTemplate, ) { } diff --git a/app/Http/Controllers/Crew/CompanyController.php b/app/Http/Controllers/Crew/CompanyController.php index 8ec69b4c..dbd3d9d5 100644 --- a/app/Http/Controllers/Crew/CompanyController.php +++ b/app/Http/Controllers/Crew/CompanyController.php @@ -2,8 +2,10 @@ namespace App\Http\Controllers\Crew; +use App\Events\CompanyRolesNotified; use App\Http\Controllers\Controller; use App\Mail\CompanyApprovedMailable; +use App\Mail\CompanyDeletedMailable; use App\Mail\CompanyDisapprovedMailable; use App\Mail\CompanyRepInvitation; use App\Models\Company; @@ -136,6 +138,8 @@ public function destroy(Company $company) abort(403); } + CompanyRolesNotified::dispatch('company representative', $company, CompanyDeletedMailable::class); + foreach ($company->users as $user) { $user->syncRoles(Role::findByName('participant', 'web')); } @@ -203,7 +207,7 @@ private function createCompanyWithNewUser($input) 'email' => $input['rep_new_email'], 'role' => 'company representative', ]); - + Mail::to($input['rep_new_email'])->send(new CompanyRepInvitation($invitation)); return $company; diff --git a/app/Http/Controllers/Crew/PresentationController.php b/app/Http/Controllers/Crew/PresentationController.php index c9bfa079..0f1b5d47 100644 --- a/app/Http/Controllers/Crew/PresentationController.php +++ b/app/Http/Controllers/Crew/PresentationController.php @@ -2,9 +2,11 @@ namespace App\Http\Controllers\Crew; +use App\Events\PresentationRolesNotified; use App\Http\Controllers\Controller; use App\Http\Requests\StorePresentationRequest; use App\Mail\PresentationApprovedMailable; +use App\Mail\PresentationDeletedMailable; use App\Mail\PresentationDisapprovedMailable; use App\Models\Company; use App\Models\Presentation; @@ -145,6 +147,8 @@ public function destroy(Presentation $presentation) abort(403); } + PresentationRolesNotified::dispatch('speaker', $presentation, PresentationDeletedMailable::class); + $presentation->delete(); return redirect(route('moderator.presentations.index')) diff --git a/app/Listeners/HandleCompanyRolesNotified.php b/app/Listeners/HandleCompanyRolesNotified.php index 720cf187..532f9db4 100644 --- a/app/Listeners/HandleCompanyRolesNotified.php +++ b/app/Listeners/HandleCompanyRolesNotified.php @@ -37,7 +37,7 @@ public function handle(CompanyRolesNotified $event): void // Send emails to the users foreach ($users as $user) { - Mail::to($user->email)->send(new CompanyUpdatedMailable($user, $event->company)); + Mail::to($user->email)->send(new $event->emailTemplate($user, $event->company)); } } } diff --git a/app/Listeners/HandlePresentationRolesNotified.php b/app/Listeners/HandlePresentationRolesNotified.php index d6e44433..187639c7 100644 --- a/app/Listeners/HandlePresentationRolesNotified.php +++ b/app/Listeners/HandlePresentationRolesNotified.php @@ -37,7 +37,7 @@ public function handle(PresentationRolesNotified $event): void // Send emails to the users foreach ($users as $user) { - Mail::to($user->email)->send(new PresentationUpdatedMailable($user, $event->presentation)); + Mail::to($user->email)->send(new $event->emailTemplate($user, $event->presentation)); } } } diff --git a/app/Livewire/Company/EditCompanyModal.php b/app/Livewire/Company/EditCompanyModal.php index f5a2cb79..0e6eba7d 100644 --- a/app/Livewire/Company/EditCompanyModal.php +++ b/app/Livewire/Company/EditCompanyModal.php @@ -4,6 +4,7 @@ use App\Events\CompanyRolesNotified; use App\Livewire\Forms\CompanyForm; +use App\Mail\CompanyUpdatedMailable; use App\Models\Company; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\View; @@ -44,14 +45,14 @@ public function save() if (Auth::user()->id == $this->company->representative->id) { if (!$this->company->isSameCompany($this->form->company)) { - CompanyRolesNotified::dispatch('crew', $this->company); + CompanyRolesNotified::dispatch('crew', $this->company, CompanyUpdatedMailable::class); } return redirect(route('company.details')) ->with('status', 'Company successfully updated.'); } else { if (!$this->company->isSameCompany($this->form->company)) { - CompanyRolesNotified::dispatch('company representative', $this->company); + CompanyRolesNotified::dispatch('company representative', $this->company, CompanyUpdatedMailable::class); } return redirect(route('moderator.companies.show', $this->company)) diff --git a/app/Mail/CompanyDeletedMailable.php b/app/Mail/CompanyDeletedMailable.php new file mode 100644 index 00000000..9ef38ea1 --- /dev/null +++ b/app/Mail/CompanyDeletedMailable.php @@ -0,0 +1,56 @@ + + */ + public function attachments(): array + { + return []; + } +} diff --git a/app/Mail/PresentationDeletedMailable.php b/app/Mail/PresentationDeletedMailable.php new file mode 100644 index 00000000..6813e6d9 --- /dev/null +++ b/app/Mail/PresentationDeletedMailable.php @@ -0,0 +1,56 @@ + + */ + public function attachments(): array + { + return []; + } +} diff --git a/resources/views/emails/company-deleted.blade.php b/resources/views/emails/company-deleted.blade.php new file mode 100644 index 00000000..0b47de47 --- /dev/null +++ b/resources/views/emails/company-deleted.blade.php @@ -0,0 +1,9 @@ +@component('mail::message') +Dear {{ $user->name }} + +Your company '{{ $company->name }}' was deleted by our crew. If you think this is a mistake, please contact us at: info@weareinittogether.com + +Kind regards, + +We are in IT together conference team +@endcomponent diff --git a/resources/views/emails/presentation-deleted.blade.php b/resources/views/emails/presentation-deleted.blade.php new file mode 100644 index 00000000..884315b9 --- /dev/null +++ b/resources/views/emails/presentation-deleted.blade.php @@ -0,0 +1,9 @@ +@component('mail::message') +Dear {{ $user->name }} + +Your presentation '{{ $presentation->name }}' was deleted by our crew. If you think this is a mistake, please contact us at: info@weareinittogether.com + +Kind regards, + +We are in IT together conference team +@endcomponent From 30ed06f516cf105610ca4f5a0b0e80fbef9ff0f4 Mon Sep 17 00:00:00 2001 From: IGORnvk Date: Sun, 20 Oct 2024 19:44:49 +0200 Subject: [PATCH 8/8] Switched to jobs instead of events --- app/Events/CompanyRolesNotified.php | 41 --------------- app/Events/PresentationRolesNotified.php | 39 -------------- .../Controllers/Crew/CompanyController.php | 3 +- .../Crew/PresentationController.php | 4 +- app/Jobs/NotifyCompanyRoles.php | 51 +++++++++++++++++++ app/Jobs/NotifyPresentationRoles.php | 49 ++++++++++++++++++ app/Listeners/HandleCompanyRolesNotified.php | 43 ---------------- .../HandlePresentationRolesNotified.php | 43 ---------------- app/Livewire/Company/EditCompanyModal.php | 6 +-- .../Presentation/EditPresentationModal.php | 7 +-- .../views/emails/company-updated.blade.php | 2 +- .../emails/presentation-updated.blade.php | 2 +- 12 files changed, 113 insertions(+), 177 deletions(-) delete mode 100644 app/Events/CompanyRolesNotified.php delete mode 100644 app/Events/PresentationRolesNotified.php create mode 100644 app/Jobs/NotifyCompanyRoles.php create mode 100644 app/Jobs/NotifyPresentationRoles.php delete mode 100644 app/Listeners/HandleCompanyRolesNotified.php delete mode 100644 app/Listeners/HandlePresentationRolesNotified.php diff --git a/app/Events/CompanyRolesNotified.php b/app/Events/CompanyRolesNotified.php deleted file mode 100644 index dd0188f2..00000000 --- a/app/Events/CompanyRolesNotified.php +++ /dev/null @@ -1,41 +0,0 @@ - - */ - public function broadcastOn(): array - { - return [ - new PrivateChannel('channel-name'), - ]; - } -} diff --git a/app/Events/PresentationRolesNotified.php b/app/Events/PresentationRolesNotified.php deleted file mode 100644 index 8d90150b..00000000 --- a/app/Events/PresentationRolesNotified.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ - public function broadcastOn(): array - { - return [ - new PrivateChannel('channel-name'), - ]; - } -} diff --git a/app/Http/Controllers/Crew/CompanyController.php b/app/Http/Controllers/Crew/CompanyController.php index dbd3d9d5..8a3a2b1f 100644 --- a/app/Http/Controllers/Crew/CompanyController.php +++ b/app/Http/Controllers/Crew/CompanyController.php @@ -4,6 +4,7 @@ use App\Events\CompanyRolesNotified; use App\Http\Controllers\Controller; +use App\Jobs\NotifyCompanyRoles; use App\Mail\CompanyApprovedMailable; use App\Mail\CompanyDeletedMailable; use App\Mail\CompanyDisapprovedMailable; @@ -138,7 +139,7 @@ public function destroy(Company $company) abort(403); } - CompanyRolesNotified::dispatch('company representative', $company, CompanyDeletedMailable::class); + NotifyCompanyRoles::dispatchSync('company representative', $company, CompanyDeletedMailable::class); foreach ($company->users as $user) { $user->syncRoles(Role::findByName('participant', 'web')); diff --git a/app/Http/Controllers/Crew/PresentationController.php b/app/Http/Controllers/Crew/PresentationController.php index 0f1b5d47..378b22fe 100644 --- a/app/Http/Controllers/Crew/PresentationController.php +++ b/app/Http/Controllers/Crew/PresentationController.php @@ -2,9 +2,9 @@ namespace App\Http\Controllers\Crew; -use App\Events\PresentationRolesNotified; use App\Http\Controllers\Controller; use App\Http\Requests\StorePresentationRequest; +use App\Jobs\NotifyPresentationRoles; use App\Mail\PresentationApprovedMailable; use App\Mail\PresentationDeletedMailable; use App\Mail\PresentationDisapprovedMailable; @@ -147,7 +147,7 @@ public function destroy(Presentation $presentation) abort(403); } - PresentationRolesNotified::dispatch('speaker', $presentation, PresentationDeletedMailable::class); + NotifyPresentationRoles::dispatch('speaker', $presentation, PresentationDeletedMailable::class); $presentation->delete(); diff --git a/app/Jobs/NotifyCompanyRoles.php b/app/Jobs/NotifyCompanyRoles.php new file mode 100644 index 00000000..58493462 --- /dev/null +++ b/app/Jobs/NotifyCompanyRoles.php @@ -0,0 +1,51 @@ +company->is_approved) { + return; + } + + $users = collect(); + if ($this->receiver == 'crew') { + $users = User::role(['event organizer', 'assistant organizer'])->get(); + } else if ($this->receiver == 'company representative') { + if ($representative = $this->company->representative) { + $users->push($representative); + } + } + + // Send emails to the users + foreach ($users as $user) { + Mail::to($user->email)->send(new $this->emailTemplate($user, $this->company)); + } + } +} diff --git a/app/Jobs/NotifyPresentationRoles.php b/app/Jobs/NotifyPresentationRoles.php new file mode 100644 index 00000000..5d2ac072 --- /dev/null +++ b/app/Jobs/NotifyPresentationRoles.php @@ -0,0 +1,49 @@ +presentation->is_approved) { + return; + } + + $users = collect(); + if ($this->receiver == 'crew') { + $users = User::role(['event organizer', 'speakers supervisor', 'assistant organizer'])->get(); + } else if ($this->receiver == 'speaker') { + $users = $this->presentation->speakers; + } + + // Send emails to the users + foreach ($users as $user) { + Mail::to($user->email)->send(new $this->emailTemplate($user, $this->presentation)); + } + } +} diff --git a/app/Listeners/HandleCompanyRolesNotified.php b/app/Listeners/HandleCompanyRolesNotified.php deleted file mode 100644 index 532f9db4..00000000 --- a/app/Listeners/HandleCompanyRolesNotified.php +++ /dev/null @@ -1,43 +0,0 @@ -company->is_approved) { - return; - } - - $users = collect(); - if ($event->receiver == 'crew') { - $users = User::role(['event organizer', 'assistant organizer'])->get(); - } else if ($event->receiver == 'company representative') { - $users->push($event->company->representative); - } - - // Send emails to the users - foreach ($users as $user) { - Mail::to($user->email)->send(new $event->emailTemplate($user, $event->company)); - } - } -} diff --git a/app/Listeners/HandlePresentationRolesNotified.php b/app/Listeners/HandlePresentationRolesNotified.php deleted file mode 100644 index 187639c7..00000000 --- a/app/Listeners/HandlePresentationRolesNotified.php +++ /dev/null @@ -1,43 +0,0 @@ -presentation->is_approved) { - return; - } - - $users = collect(); - if ($event->receiver == 'crew') { - $users = User::role(['event organizer', 'speakers supervisor', 'assistant organizer'])->get(); - } else if ($event->receiver == 'speaker') { - $users = $event->presentation->speakers; - } - - // Send emails to the users - foreach ($users as $user) { - Mail::to($user->email)->send(new $event->emailTemplate($user, $event->presentation)); - } - } -} diff --git a/app/Livewire/Company/EditCompanyModal.php b/app/Livewire/Company/EditCompanyModal.php index 0e6eba7d..98543f4f 100644 --- a/app/Livewire/Company/EditCompanyModal.php +++ b/app/Livewire/Company/EditCompanyModal.php @@ -2,7 +2,7 @@ namespace App\Livewire\Company; -use App\Events\CompanyRolesNotified; +use App\Jobs\NotifyCompanyRoles; use App\Livewire\Forms\CompanyForm; use App\Mail\CompanyUpdatedMailable; use App\Models\Company; @@ -45,14 +45,14 @@ public function save() if (Auth::user()->id == $this->company->representative->id) { if (!$this->company->isSameCompany($this->form->company)) { - CompanyRolesNotified::dispatch('crew', $this->company, CompanyUpdatedMailable::class); + NotifyCompanyRoles::dispatch('crew', $this->company, CompanyUpdatedMailable::class); } return redirect(route('company.details')) ->with('status', 'Company successfully updated.'); } else { if (!$this->company->isSameCompany($this->form->company)) { - CompanyRolesNotified::dispatch('company representative', $this->company, CompanyUpdatedMailable::class); + NotifyCompanyRoles::dispatch('company representative', $this->company, CompanyUpdatedMailable::class); } return redirect(route('moderator.companies.show', $this->company)) diff --git a/app/Livewire/Presentation/EditPresentationModal.php b/app/Livewire/Presentation/EditPresentationModal.php index 1d1acf25..e6b64799 100644 --- a/app/Livewire/Presentation/EditPresentationModal.php +++ b/app/Livewire/Presentation/EditPresentationModal.php @@ -2,8 +2,9 @@ namespace App\Livewire\Presentation; -use App\Events\PresentationRolesNotified; +use App\Jobs\NotifyPresentationRoles; use App\Livewire\Forms\PresentationForm; +use App\Mail\PresentationUpdatedMailable; use App\Models\Presentation; use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Auth; @@ -40,14 +41,14 @@ public function save() if (Auth::user()->presenter_of) { if (!$this->presentation->isSamePresentation($this->form->presentation)) { - PresentationRolesNotified::dispatch('crew', $this->presentation); + NotifyPresentationRoles::dispatch('crew', $this->presentation, PresentationUpdatedMailable::class); } return redirect(route('presentations.show', $this->presentation)) ->with('status', 'Presentation successfully updated.'); } else { if (!$this->presentation->isSamePresentation($this->form->presentation)) { - PresentationRolesNotified::dispatch('speaker', $this->presentation); + NotifyPresentationRoles::dispatch('speaker', $this->presentation, PresentationUpdatedMailable::class); } return redirect(route('moderator.presentations.show', $this->presentation)) diff --git a/resources/views/emails/company-updated.blade.php b/resources/views/emails/company-updated.blade.php index 62ec7006..d9016c44 100644 --- a/resources/views/emails/company-updated.blade.php +++ b/resources/views/emails/company-updated.blade.php @@ -1,7 +1,7 @@ @component('mail::message') Dear {{ $user->name }} -'{{ $company->name }}' details were updated by +Your company '{{ $company->name }}' details were updated by @if($user->isMemberOf($company)) our crew. diff --git a/resources/views/emails/presentation-updated.blade.php b/resources/views/emails/presentation-updated.blade.php index ed19102d..eba5b819 100644 --- a/resources/views/emails/presentation-updated.blade.php +++ b/resources/views/emails/presentation-updated.blade.php @@ -1,7 +1,7 @@ @component('mail::message') Dear {{ $user->name }} -'{{ $presentation->name }}' details were updated by +Your presentation '{{ $presentation->name }}' details were updated by @if($user->isPresenterOf($presentation)) our crew.