Skip to content

Commit

Permalink
#235 - fix
Browse files Browse the repository at this point in the history
  • Loading branch information
EwelinaSkrzypacz committed Sep 26, 2023
1 parent 0e810e3 commit 481bb2e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions config/permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"receiveVacationRequestsSummaryNotification",
"receiveVacationRequestWaitsForApprovalNotification",
"receiveVacationRequestStatusChangedNotification",
"receiveBenefitsReportCreationNotification",
],
"permission_roles" => [
Role::Administrator->value => [
Expand Down Expand Up @@ -92,6 +93,7 @@
"receiveVacationRequestsSummaryNotification",
"receiveVacationRequestWaitsForApprovalNotification",
"receiveVacationRequestStatusChangedNotification",
"receiveBenefitsReportCreationNotification",
],
Role::TechnicalApprover->value => [
"manageTechnologies",
Expand Down
18 changes: 12 additions & 6 deletions database/seeders/PermissionsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
}
5 changes: 5 additions & 0 deletions resources/js/Composables/permissionInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions tests/Feature/PermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
18 changes: 4 additions & 14 deletions tests/Unit/BenefitsReportCreationNotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit 481bb2e

Please sign in to comment.