diff --git a/app/Infrastructure/Console/Commands/SendNotificationAboutBenefitsReportCreation.php b/app/Infrastructure/Console/Commands/SendNotificationAboutBenefitsReportCreation.php index 54c44582..b3c95291 100644 --- a/app/Infrastructure/Console/Commands/SendNotificationAboutBenefitsReportCreation.php +++ b/app/Infrastructure/Console/Commands/SendNotificationAboutBenefitsReportCreation.php @@ -5,9 +5,8 @@ namespace Toby\Infrastructure\Console\Commands; use Illuminate\Console\Command; -use Toby\Domain\Enums\Role; +use Spatie\Permission\Models\Permission; use Toby\Domain\Notifications\BenefitsReportCreationNotification; -use Toby\Eloquent\Models\User; class SendNotificationAboutBenefitsReportCreation extends Command { @@ -16,9 +15,7 @@ class SendNotificationAboutBenefitsReportCreation extends Command public function handle(): void { - $usersToNotify = User::query() - ->whereIn("role", [Role::AdministrativeApprover]) - ->get(); + $usersToNotify = Permission::findByName("receiveBenefitsReportCreationNotification")->users()->get(); foreach ($usersToNotify as $user) { $user->notify(new BenefitsReportCreationNotification()); 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/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 index 18fb7aab..4c29ed11 100644 --- a/tests/Unit/BenefitsReportCreationNotificationTest.php +++ b/tests/Unit/BenefitsReportCreationNotificationTest.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Support\Facades\Notification; use Tests\TestCase; -use Toby\Domain\Enums\Role; use Toby\Domain\Notifications\BenefitsReportCreationNotification; use Toby\Eloquent\Models\User; use Toby\Infrastructure\Console\Commands\SendNotificationAboutBenefitsReportCreation; @@ -20,19 +19,10 @@ public function testSendingNotificationAboutBenefitsReportCreation(): void { Notification::fake(); - $user = User::factory([ - "role" => Role::Employee, - ])->create(); - $technicalApprover = User::factory([ - "role" => Role::TechnicalApprover, - ])->create(); - $administrativeApprover = User::factory([ - "role" => Role::AdministrativeApprover, - ])->create(); - - $admin = User::factory([ - "role" => Role::Administrator, - ])->create(); + $user = User::factory()->employee()->create(); + $technicalApprover = User::factory()->technicalApprover()->create(); + $administrativeApprover = User::factory()->administrativeApprover()->create(); + $admin = User::factory()->admin()->create(); $this->artisan(SendNotificationAboutBenefitsReportCreation::class) ->execute();