Skip to content

Commit

Permalink
Merge branch 'main' into #231-add-new-tab-to-menu-about-benefits-report
Browse files Browse the repository at this point in the history
  • Loading branch information
EwelinaSkrzypacz committed Sep 26, 2023
2 parents c92bcfe + c71974d commit 2a37618
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 6 deletions.
42 changes: 42 additions & 0 deletions app/Domain/Notifications/BenefitsReportCreationNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Toby\Domain\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;

class BenefitsReportCreationNotification extends QueuedNotification
{
use Queueable;

public function via(): array
{
return [Channels::MAIL];
}

public function toMail(Notifiable $notifiable): MailMessage
{
$url = route("assigned-benefits.index");

return $this->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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Toby\Infrastructure\Console\Commands;

use Illuminate\Console\Command;
use Spatie\Permission\Models\Permission;
use Toby\Domain\Notifications\BenefitsReportCreationNotification;

class SendNotificationAboutBenefitsReportCreation extends Command
{
protected $signature = "toby:send-notification-about-benefits-report-creation";
protected $description = "Send notifications about benefits report creation.";

public function handle(): void
{
$usersToNotify = Permission::findByName("receiveBenefitsReportCreationNotification")->users()->get();

foreach ($usersToNotify as $user) {
$user->notify(new BenefitsReportCreationNotification());
}
}
}
5 changes: 5 additions & 0 deletions app/Infrastructure/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
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();
}
}
}
}
3 changes: 3 additions & 0 deletions lang/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
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
33 changes: 33 additions & 0 deletions tests/Unit/BenefitsReportCreationNotificationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Tests\Unit;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
use Toby\Domain\Notifications\BenefitsReportCreationNotification;
use Toby\Eloquent\Models\User;
use Toby\Infrastructure\Console\Commands\SendNotificationAboutBenefitsReportCreation;

class BenefitsReportCreationNotificationTest extends TestCase
{
use DatabaseMigrations;

public function testSendingNotificationAboutBenefitsReportCreation(): void
{
Notification::fake();

$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();

Notification::assertSentTo($administrativeApprover, BenefitsReportCreationNotification::class);
Notification::assertNotSentTo([$user, $technicalApprover, $admin], BenefitsReportCreationNotification::class);
}
}

0 comments on commit 2a37618

Please sign in to comment.