From c71974db2b9dafd5a5804c78f0a3f7bec42e01e8 Mon Sep 17 00:00:00 2001 From: Ewelina Skrzypacz <56546832+EwelinaSkrzypacz@users.noreply.github.com> Date: Tue, 26 Sep 2023 08:13:52 +0200 Subject: [PATCH] #235 - e-mail notification for administrative approval to fill benefits (#344) * #235 - wip * Update app/Domain/Notifications/BenefitsReportCreationNotification.php Co-authored-by: Krzysztof Rewak * #235 - fix --------- Co-authored-by: Krzysztof Rewak --- .../BenefitsReportCreationNotification.php | 42 +++++++++++++++++++ ...otificationAboutBenefitsReportCreation.php | 24 +++++++++++ app/Infrastructure/Console/Kernel.php | 5 +++ config/permission.php | 2 + database/seeders/PermissionsSeeder.php | 18 +++++--- lang/pl.json | 3 ++ resources/js/Composables/permissionInfo.js | 5 +++ tests/Feature/PermissionTest.php | 3 ++ ...BenefitsReportCreationNotificationTest.php | 33 +++++++++++++++ 9 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 app/Domain/Notifications/BenefitsReportCreationNotification.php create mode 100644 app/Infrastructure/Console/Commands/SendNotificationAboutBenefitsReportCreation.php create mode 100644 tests/Unit/BenefitsReportCreationNotificationTest.php diff --git a/app/Domain/Notifications/BenefitsReportCreationNotification.php b/app/Domain/Notifications/BenefitsReportCreationNotification.php new file mode 100644 index 00000000..068f7a72 --- /dev/null +++ b/app/Domain/Notifications/BenefitsReportCreationNotification.php @@ -0,0 +1,42 @@ +buildMailMessage($notifiable, $url); + } + + protected function buildMailMessage(Notifiable $notifiable, string $url): MailMessage + { + $user = $notifiable->profile->first_name; + + $message = (new MailMessage()) + ->greeting( + __("Hi :user!", [ + "user" => $user, + ]), + ) + ->subject(__("Reminder to create benefit report")) + ->line(__("This message is a reminder to create a report for benefits for this month. If a report has already been created, please ignore this message.")); + + return $message + ->action(__("Benefits reports"), $url); + } +} diff --git a/app/Infrastructure/Console/Commands/SendNotificationAboutBenefitsReportCreation.php b/app/Infrastructure/Console/Commands/SendNotificationAboutBenefitsReportCreation.php new file mode 100644 index 00000000..b3c95291 --- /dev/null +++ b/app/Infrastructure/Console/Commands/SendNotificationAboutBenefitsReportCreation.php @@ -0,0 +1,24 @@ +users()->get(); + + foreach ($usersToNotify as $user) { + $user->notify(new BenefitsReportCreationNotification()); + } + } +} diff --git a/app/Infrastructure/Console/Kernel.php b/app/Infrastructure/Console/Kernel.php index 504f6cbc..62d2c536 100644 --- a/app/Infrastructure/Console/Kernel.php +++ b/app/Infrastructure/Console/Kernel.php @@ -11,6 +11,7 @@ use Psr\Container\NotFoundExceptionInterface; use Toby\Infrastructure\Console\Commands\Database\BackupPostgresDatabase; use Toby\Infrastructure\Console\Commands\SendDailySummaryToSlack; +use Toby\Infrastructure\Console\Commands\SendNotificationAboutBenefitsReportCreation; use Toby\Infrastructure\Console\Commands\SendNotificationAboutUpcomingAndOverdueMedicalExams; use Toby\Infrastructure\Console\Commands\SendNotificationAboutUpcomingAndOverdueOhsTraining; use Toby\Infrastructure\Console\Commands\SendVacationRequestSummariesToApprovers; @@ -48,6 +49,10 @@ protected function schedule(Schedule $schedule): void ->monthlyOn(1, "08:00") ->onOneServer(); + $schedule->command(SendNotificationAboutBenefitsReportCreation::class) + ->lastDayOfMonth("08:00") + ->onOneServer(); + $schedule->job(CheckYearPeriod::class) ->yearlyOn(1, 1, "01:00") ->onOneServer(); diff --git a/config/permission.php b/config/permission.php index 5bcbf041..0420acb2 100644 --- a/config/permission.php +++ b/config/permission.php @@ -52,6 +52,7 @@ "receiveVacationRequestsSummaryNotification", "receiveVacationRequestWaitsForApprovalNotification", "receiveVacationRequestStatusChangedNotification", + "receiveBenefitsReportCreationNotification", ], "permission_roles" => [ Role::Administrator->value => [ @@ -92,6 +93,7 @@ "receiveVacationRequestsSummaryNotification", "receiveVacationRequestWaitsForApprovalNotification", "receiveVacationRequestStatusChangedNotification", + "receiveBenefitsReportCreationNotification", ], Role::TechnicalApprover->value => [ "manageTechnologies", diff --git a/database/seeders/PermissionsSeeder.php b/database/seeders/PermissionsSeeder.php index 6c7d27b5..2b523570 100644 --- a/database/seeders/PermissionsSeeder.php +++ b/database/seeders/PermissionsSeeder.php @@ -11,12 +11,18 @@ class PermissionsSeeder extends Seeder { public function run(): void { - foreach (config("permission.permissions") as $permission) { - Permission::create( - [ - "name" => $permission, - ], - ); + $configPermissions = config("permission.permissions"); + + foreach ($configPermissions as $permission) { + Permission::findOrCreate($permission, "web"); + } + + $permissions = Permission::all(); + + foreach ($permissions as $permission) { + if (!in_array($permission->name, $configPermissions, true)) { + $permission->delete(); + } } } } diff --git a/lang/pl.json b/lang/pl.json index 461729cc..8f418658 100644 --- a/lang/pl.json +++ b/lang/pl.json @@ -146,6 +146,9 @@ "Below is a list of employees with upcoming OHS training:": "Poniżej znajduje się lista pracowników ze zbliżającym się terminem szkolenia BHP:", "The deadline for OHS training for some employees has passed.": "Termin szkolenia BHP dla części pracowników minął.", "Below is a list of employees with overdue OHS training:": "Poniżej znajduje się lista pracowników z przeterminowanym szkoleniem BHP:", + "Reminder to create benefit report": "Przypomnienie o utworzeniu raportu benefitów", + "This message is a reminder to create a report for benefits for this month. If a report has already been created, please ignore this message.": "Ta wiadomość jest przypomnieniem o utworzeniu raportu dla benefitów za obecny miesiąc. Jeśli raport już został utworzony, zignoruj tę wiadomość.", + "Benefits reports": "Raporty benefitów", "Take the keys from the office.": "Weź klucze z biura.", "There are no keys in the office.": "W biurze nie ma kluczy.", ":white_check_mark: Key no. :number has been taken from the office": ":white_check_mark: Klucz nr :number został zabrany z biura", diff --git a/resources/js/Composables/permissionInfo.js b/resources/js/Composables/permissionInfo.js index 0c1e81fe..a02c0921 100644 --- a/resources/js/Composables/permissionInfo.js +++ b/resources/js/Composables/permissionInfo.js @@ -79,6 +79,11 @@ const permissionsInfo = [ 'value': 'receiveUpcomingAndOverdueOhsTrainingNotification', 'section': 'Powiadomienia', }, + { + 'name': 'Tworzenie raportu benefitów', + 'value': 'receiveBenefitsReportCreationNotification', + 'section': 'Powiadomienia', + }, { 'name': 'Podsumowania wniosków urlopowych', 'value': 'receiveVacationRequestsSummaryNotification', diff --git a/tests/Feature/PermissionTest.php b/tests/Feature/PermissionTest.php index 7f578a4a..9d152a3c 100644 --- a/tests/Feature/PermissionTest.php +++ b/tests/Feature/PermissionTest.php @@ -42,6 +42,7 @@ public function testAdminCanSeeEditEmployeePermissionsForm(): void ->where("skipRequestFlow", false) ->where("receiveUpcomingAndOverdueMedicalExamsNotification", false) ->where("receiveUpcomingAndOverdueOhsTrainingNotification", false) + ->where("receiveBenefitsReportCreationNotification", false) ->where("receiveVacationRequestsSummaryNotification", false) ->where("receiveVacationRequestWaitsForApprovalNotification", false) ->where("receiveVacationRequestStatusChangedNotification", false), @@ -78,6 +79,7 @@ public function testAdminCanSeeEditTechnicalApproverPermissionsForm(): void ->where("skipRequestFlow", false) ->where("receiveUpcomingAndOverdueMedicalExamsNotification", false) ->where("receiveUpcomingAndOverdueOhsTrainingNotification", false) + ->where("receiveBenefitsReportCreationNotification", false) ->where("receiveVacationRequestsSummaryNotification", true) ->where("receiveVacationRequestWaitsForApprovalNotification", true) ->where("receiveVacationRequestStatusChangedNotification", true), @@ -114,6 +116,7 @@ public function testAdminCanSeeEditAdministrativeApproverPermissionsForm(): void ->where("skipRequestFlow", true) ->where("receiveUpcomingAndOverdueMedicalExamsNotification", true) ->where("receiveUpcomingAndOverdueOhsTrainingNotification", true) + ->where("receiveBenefitsReportCreationNotification", true) ->where("receiveVacationRequestsSummaryNotification", true) ->where("receiveVacationRequestWaitsForApprovalNotification", true) ->where("receiveVacationRequestStatusChangedNotification", true), diff --git a/tests/Unit/BenefitsReportCreationNotificationTest.php b/tests/Unit/BenefitsReportCreationNotificationTest.php new file mode 100644 index 00000000..4c29ed11 --- /dev/null +++ b/tests/Unit/BenefitsReportCreationNotificationTest.php @@ -0,0 +1,33 @@ +employee()->create(); + $technicalApprover = User::factory()->technicalApprover()->create(); + $administrativeApprover = User::factory()->administrativeApprover()->create(); + $admin = User::factory()->admin()->create(); + + $this->artisan(SendNotificationAboutBenefitsReportCreation::class) + ->execute(); + + Notification::assertSentTo($administrativeApprover, BenefitsReportCreationNotification::class); + Notification::assertNotSentTo([$user, $technicalApprover, $admin], BenefitsReportCreationNotification::class); + } +}