From 7d12a1a1531d9ede1fc38779ea2e77493294e287 Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Thu, 21 Apr 2022 15:03:49 +0200
Subject: [PATCH 01/18] wip
---
app/Domain/Slack/GiveKeysTo.php | 49 +++++++
app/Domain/Slack/HomeOffice.php | 58 ++++++++
app/Domain/Slack/KeyList.php | 30 +++++
app/Domain/Slack/TakeKeysFrom.php | 49 +++++++
composer.json | 3 +-
composer.lock | 125 +++++++++++++++++-
config/app.php | 3 +-
config/laravel-slack-slash-command.php | 20 +++
..._add_slack_id_column_in_profiles_table.php | 23 ++++
9 files changed, 356 insertions(+), 4 deletions(-)
create mode 100644 app/Domain/Slack/GiveKeysTo.php
create mode 100644 app/Domain/Slack/HomeOffice.php
create mode 100644 app/Domain/Slack/KeyList.php
create mode 100644 app/Domain/Slack/TakeKeysFrom.php
create mode 100644 config/laravel-slack-slash-command.php
create mode 100644 database/migrations/2022_04_21_101027_add_slack_id_column_in_profiles_table.php
diff --git a/app/Domain/Slack/GiveKeysTo.php b/app/Domain/Slack/GiveKeysTo.php
new file mode 100644
index 0000000..c45597f
--- /dev/null
+++ b/app/Domain/Slack/GiveKeysTo.php
@@ -0,0 +1,49 @@
+getArgument('to');
+
+ $id = Str::between($to, "@", "|");
+
+ $authUser = $this->findUserBySlackId($request->userId);
+ $user = $this->findUserBySlackId($id);
+
+ /** @var Key $key */
+ $key = $authUser->keys()->first();
+
+ $key->user()->associate($user);
+
+ $key->save();
+
+ return $this->respondToSlack("<@{$authUser->profile->slack_id}> daje klucz nr {$key->id} użytkownikowi <@{$user->profile->slack_id}>")
+ ->displayResponseToEveryoneOnChannel();
+ }
+
+ protected function findUserBySlackId(string $slackId): User
+ {
+ /** @var User $user */
+ $user = User::query()
+ ->whereRelation("profile", "slack_id", $slackId)
+ ->first();
+
+ return $user;
+ }
+}
\ No newline at end of file
diff --git a/app/Domain/Slack/HomeOffice.php b/app/Domain/Slack/HomeOffice.php
new file mode 100644
index 0000000..bb0fe1e
--- /dev/null
+++ b/app/Domain/Slack/HomeOffice.php
@@ -0,0 +1,58 @@
+getDateFromArgument($this->getArgument('date'));
+ $user = $this->findUserBySlackId($request->userId);
+
+ $yearPeriod = YearPeriod::findByYear($date->year);
+
+ app(CreateAction::class)->execute([
+ "user_id" => $user->id,
+ "type" => VacationType::HomeOffice,
+ "from" => $date,
+ "to" => $date,
+ "year_period_id" => $yearPeriod->id,
+ "flow_skipped" => false,
+ ], $user);
+
+ return $this->respondToSlack("Praca zdalna dnia {$date->toDisplayString()} została utworzona pomyślnie");
+ }
+
+ protected function getDateFromArgument(string $argument): Carbon
+ {
+ return match ($argument) {
+ "dzisiaj" => Carbon::today(),
+ "jutro" => Carbon::tomorrow(),
+ default => Carbon::create($argument),
+ };
+ }
+
+ protected function findUserBySlackId(string $slackId): User
+ {
+ /** @var User $user */
+ $user = User::query()
+ ->whereRelation("profile", "slack_id", $slackId)
+ ->first();
+
+ return $user;
+ }
+}
\ No newline at end of file
diff --git a/app/Domain/Slack/KeyList.php b/app/Domain/Slack/KeyList.php
new file mode 100644
index 0000000..af1d2c5
--- /dev/null
+++ b/app/Domain/Slack/KeyList.php
@@ -0,0 +1,30 @@
+get() as $key) {
+ $temp[] = "Klucz nr {$key->id} - <@{$key->user->profile->slack_id}>";
+ }
+
+
+ return $this->respondToSlack(implode("\n", $temp))
+ ->displayResponseToEveryoneOnChannel();
+ }
+}
\ No newline at end of file
diff --git a/app/Domain/Slack/TakeKeysFrom.php b/app/Domain/Slack/TakeKeysFrom.php
new file mode 100644
index 0000000..31860ff
--- /dev/null
+++ b/app/Domain/Slack/TakeKeysFrom.php
@@ -0,0 +1,49 @@
+getArgument('from');
+
+ $id = Str::between($from, "@", "|");
+
+ $authUser = $this->findUserBySlackId($request->userId);
+ $user = $this->findUserBySlackId($id);
+
+ /** @var Key $key */
+ $key = $user->keys()->first();
+
+ $key->user()->associate($authUser);
+
+ $key->save();
+
+ return $this->respondToSlack("<@{$authUser->profile->slack_id}> zabiera klucz nr {$key->id} użytkownikowi <@{$user->profile->slack_id}>")
+ ->displayResponseToEveryoneOnChannel();
+ }
+
+ protected function findUserBySlackId(string $slackId): User
+ {
+ /** @var User $user */
+ $user = User::query()
+ ->whereRelation("profile", "slack_id", $slackId)
+ ->first();
+
+ return $user;
+ }
+}
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 82145dd..71cb14b 100644
--- a/composer.json
+++ b/composer.json
@@ -21,7 +21,8 @@
"maatwebsite/excel": "^3.1",
"rackbeat/laravel-ui-avatars": "^1.0",
"spatie/laravel-google-calendar": "^3.5",
- "spatie/laravel-model-states": "^2.1"
+ "spatie/laravel-model-states": "^2.1",
+ "spatie/laravel-slack-slash-command": "^1.11"
},
"require-dev": {
"blumilksoftware/codestyle": "^1.0.0",
diff --git a/composer.lock b/composer.lock
index 8dd0196..c61e264 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "414a1fc13e0731e59605248bd4e39de6",
+ "content-hash": "17caa1f146a96a76822006d13f440645",
"packages": [
{
"name": "asm89/stack-cors",
@@ -1910,6 +1910,62 @@
},
"time": "2022-04-05T15:07:51+00:00"
},
+ {
+ "name": "laravel/helpers",
+ "version": "v1.5.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/laravel/helpers.git",
+ "reference": "c28b0ccd799d58564c41a62395ac9511a1e72931"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/laravel/helpers/zipball/c28b0ccd799d58564c41a62395ac9511a1e72931",
+ "reference": "c28b0ccd799d58564c41a62395ac9511a1e72931",
+ "shasum": ""
+ },
+ "require": {
+ "illuminate/support": "~5.8.0|^6.0|^7.0|^8.0|^9.0",
+ "php": "^7.1.3|^8.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^7.0|^8.0|^9.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.x-dev"
+ }
+ },
+ "autoload": {
+ "files": [
+ "src/helpers.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Taylor Otwell",
+ "email": "taylor@laravel.com"
+ },
+ {
+ "name": "Dries Vints",
+ "email": "dries@laravel.com"
+ }
+ ],
+ "description": "Provides backwards compatibility for helpers in the latest Laravel release.",
+ "keywords": [
+ "helpers",
+ "laravel"
+ ],
+ "support": {
+ "source": "https://github.com/laravel/helpers/tree/v1.5.0"
+ },
+ "time": "2022-01-12T15:58:51+00:00"
+ },
{
"name": "laravel/sanctum",
"version": "v2.15.0",
@@ -5171,6 +5227,71 @@
],
"time": "2022-03-15T20:01:36+00:00"
},
+ {
+ "name": "spatie/laravel-slack-slash-command",
+ "version": "1.11.3",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/spatie/laravel-slack-slash-command.git",
+ "reference": "8e507653054ff08581b28d6ddf5bb4ce8c2e2335"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/spatie/laravel-slack-slash-command/zipball/8e507653054ff08581b28d6ddf5bb4ce8c2e2335",
+ "reference": "8e507653054ff08581b28d6ddf5bb4ce8c2e2335",
+ "shasum": ""
+ },
+ "require": {
+ "guzzlehttp/guzzle": "^7.0",
+ "illuminate/config": "~5.8.0|^6.0|^7.0|^8.0|^9.0",
+ "illuminate/queue": "~5.8.0|^6.0|^7.0|^8.0|^9.0",
+ "illuminate/routing": "~5.8.0|^6.0|^7.0|^8.0|^9.0",
+ "illuminate/support": "~5.8.0|^6.0|^7.0|^8.0|^9.0",
+ "laravel/helpers": "^1.0",
+ "php": "^7.3|^8.0"
+ },
+ "require-dev": {
+ "mockery/mockery": "^1.0",
+ "orchestra/testbench": "~3.8.0|^4.0|^5.0|^6.0|^7.0",
+ "phpunit/phpunit": "^9.2"
+ },
+ "type": "library",
+ "extra": {
+ "laravel": {
+ "providers": [
+ "Spatie\\SlashCommand\\SlashCommandServiceProvider"
+ ]
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Spatie\\SlashCommand\\": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Freek Van der Herten",
+ "email": "freek@spatie.be",
+ "homepage": "https://spatie.be",
+ "role": "Developer"
+ }
+ ],
+ "description": "Make a Laravel app respond to a slash command from Slack",
+ "homepage": "https://github.com/spatie/laravel-slack-slash-command",
+ "keywords": [
+ "laravel-slack",
+ "spatie"
+ ],
+ "support": {
+ "issues": "https://github.com/spatie/laravel-slack-slash-command/issues",
+ "source": "https://github.com/spatie/laravel-slack-slash-command/tree/1.11.3"
+ },
+ "time": "2022-02-09T07:58:01+00:00"
+ },
{
"name": "symfony/console",
"version": "v6.0.7",
@@ -10931,5 +11052,5 @@
"ext-redis": "*"
},
"platform-dev": [],
- "plugin-api-version": "2.1.0"
+ "plugin-api-version": "2.2.0"
}
diff --git a/config/app.php b/config/app.php
index a5d12a9..2c2ab89 100644
--- a/config/app.php
+++ b/config/app.php
@@ -37,12 +37,13 @@ return [
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
+ Barryvdh\DomPDF\ServiceProvider::class,
+ Spatie\SlashCommand\SlashCommandServiceProvider::class,
Toby\Architecture\Providers\AppServiceProvider::class,
Toby\Architecture\Providers\AuthServiceProvider::class,
Toby\Architecture\Providers\EventServiceProvider::class,
Toby\Architecture\Providers\RouteServiceProvider::class,
Toby\Architecture\Providers\TelescopeServiceProvider::class,
Toby\Architecture\Providers\ObserverServiceProvider::class,
- Barryvdh\DomPDF\ServiceProvider::class,
],
];
diff --git a/config/laravel-slack-slash-command.php b/config/laravel-slack-slash-command.php
new file mode 100644
index 0000000..f19d56c
--- /dev/null
+++ b/config/laravel-slack-slash-command.php
@@ -0,0 +1,20 @@
+ 'api/slack',
+ 'signing_secret' => env('SLACK_SIGNING_SECRET'),
+ 'verify_with_signing' => true,
+ 'handlers' => [
+ TakeKeysFrom::class,
+ GiveKeysTo::class,
+ KeyList::class,
+ HomeOffice::class,
+ Spatie\SlashCommand\Handlers\Help::class,
+ Spatie\SlashCommand\Handlers\CatchAll::class,
+ ],
+];
diff --git a/database/migrations/2022_04_21_101027_add_slack_id_column_in_profiles_table.php b/database/migrations/2022_04_21_101027_add_slack_id_column_in_profiles_table.php
new file mode 100644
index 0000000..2e9e345
--- /dev/null
+++ b/database/migrations/2022_04_21_101027_add_slack_id_column_in_profiles_table.php
@@ -0,0 +1,23 @@
+string("slack_id")->nullable();
+ });
+ }
+
+ public function down(): void
+ {
+ Schema::table("profiles", function (Blueprint $table): void {
+ $table->string("slack_id");
+ });
+ }
+};
--
2.52.0
From fad4290cc39ef952c8346ea1b1a3d54c888ec142 Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Fri, 22 Apr 2022 12:41:00 +0200
Subject: [PATCH 02/18] wip
---
.../Providers/AppServiceProvider.php | 11 +++
.../Actions/VacationRequest/CreateAction.php | 1 -
.../VacationRequestCreatedNotification.php | 20 ++--
...cationRequestStatusChangedNotification.php | 43 +++++---
...ionRequestWaitsForApprovalNotification.php | 12 ++-
app/Domain/Slack/Channels/SlackApiChannel.php | 25 +++++
app/Domain/Slack/Handlers/CatchAll.php | 51 ++++++++++
app/Domain/Slack/Handlers/DailySummary.php | 74 ++++++++++++++
.../Slack/{ => Handlers}/GiveKeysTo.php | 8 +-
app/Domain/Slack/Handlers/Help.php | 45 +++++++++
.../Slack/{ => Handlers}/HomeOffice.php | 11 ++-
app/Domain/Slack/Handlers/KeyList.php | 33 +++++++
app/Domain/Slack/Handlers/SaySomething.php | 24 +++++
.../Slack/{ => Handlers}/TakeKeysFrom.php | 8 +-
app/Domain/Slack/KeyList.php | 30 ------
app/Domain/VacationDaysCalculator.php | 3 +-
.../Rules/DoesNotExceedLimitRule.php | 2 +-
.../Rules/MinimumOneVacationDayRule.php | 2 +-
app/Eloquent/Models/Profile.php | 2 +
app/Eloquent/Models/User.php | 5 +
.../Commands/SendDailySummaryToSlack.php | 97 +++++++++++++++++++
.../Api/CalculateVacationDaysController.php | 2 +-
.../Http/Requests/UserRequest.php | 2 +
.../Http/Resources/UserFormDataResource.php | 1 +
config/app.php | 1 -
config/laravel-slack-slash-command.php | 20 ++--
config/services.php | 5 +
database/factories/ProfileFactory.php | 1 +
...nd_birthday_columns_in_profiles_table.php} | 4 +-
resources/js/Pages/Users/Create.vue | 24 +++++
resources/js/Pages/Users/Edit.vue | 24 +++++
resources/lang/pl.json | 4 +-
tests/Unit/SendDailySummaryToSlackTest.php | 82 ++++++++++++++++
33 files changed, 599 insertions(+), 78 deletions(-)
create mode 100644 app/Domain/Slack/Channels/SlackApiChannel.php
create mode 100644 app/Domain/Slack/Handlers/CatchAll.php
create mode 100644 app/Domain/Slack/Handlers/DailySummary.php
rename app/Domain/Slack/{ => Handlers}/GiveKeysTo.php (83%)
create mode 100644 app/Domain/Slack/Handlers/Help.php
rename app/Domain/Slack/{ => Handlers}/HomeOffice.php (79%)
create mode 100644 app/Domain/Slack/Handlers/KeyList.php
create mode 100644 app/Domain/Slack/Handlers/SaySomething.php
rename app/Domain/Slack/{ => Handlers}/TakeKeysFrom.php (83%)
delete mode 100644 app/Domain/Slack/KeyList.php
create mode 100644 app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
rename database/migrations/{2022_04_21_101027_add_slack_id_column_in_profiles_table.php => 2022_04_21_101027_add_slack_id_and_birthday_columns_in_profiles_table.php} (78%)
create mode 100644 tests/Unit/SendDailySummaryToSlackTest.php
diff --git a/app/Architecture/Providers/AppServiceProvider.php b/app/Architecture/Providers/AppServiceProvider.php
index ce611b9..37f7884 100644
--- a/app/Architecture/Providers/AppServiceProvider.php
+++ b/app/Architecture/Providers/AppServiceProvider.php
@@ -4,11 +4,22 @@ declare(strict_types=1);
namespace Toby\Architecture\Providers;
+use Illuminate\Contracts\Foundation\Application;
+use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\Carbon;
+use Illuminate\Support\Facades\Notification;
use Illuminate\Support\ServiceProvider;
+use Toby\Domain\Slack\Channels\SlackApiChannel;
class AppServiceProvider extends ServiceProvider
{
+ public function register()
+ {
+ Notification::resolved(function (ChannelManager $service) {
+ $service->extend("slack", fn(Application $app) => $app->make(SlackApiChannel::class));
+ });
+ }
+
public function boot(): void
{
Carbon::macro("toDisplayString", fn() => $this->translatedFormat("d.m.Y"));
diff --git a/app/Domain/Actions/VacationRequest/CreateAction.php b/app/Domain/Actions/VacationRequest/CreateAction.php
index 8a823e3..1bb8a7a 100644
--- a/app/Domain/Actions/VacationRequest/CreateAction.php
+++ b/app/Domain/Actions/VacationRequest/CreateAction.php
@@ -53,7 +53,6 @@ class CreateAction
$vacationRequest->save();
$days = $this->vacationDaysCalculator->calculateDays(
- $vacationRequest->yearPeriod,
$vacationRequest->from,
$vacationRequest->to,
);
diff --git a/app/Domain/Notifications/VacationRequestCreatedNotification.php b/app/Domain/Notifications/VacationRequestCreatedNotification.php
index d84d108..69198e7 100644
--- a/app/Domain/Notifications/VacationRequestCreatedNotification.php
+++ b/app/Domain/Notifications/VacationRequestCreatedNotification.php
@@ -20,7 +20,17 @@ class VacationRequestCreatedNotification extends Notification
public function via(): array
{
- return ["mail"];
+ return ["mail", "slack"];
+ }
+
+ public function toSlack(): string
+ {
+ $url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]);
+
+ return implode("\n", [
+ $this->buildDescription(),
+ "<${url}|Zobacz szczegóły>",
+ ]);
}
/**
@@ -80,18 +90,16 @@ class VacationRequestCreatedNotification extends Notification
protected function buildDescription(): string
{
$name = $this->vacationRequest->name;
- $appName = config("app.name");
if ($this->vacationRequest->creator()->is($this->vacationRequest->user)) {
- return __("The vacation request :title has been created correctly in the :appName.", [
+ return __("The vacation request :title for user :user has been created successfully.", [
+ "user" => $this->vacationRequest->user->profile->full_name,
"title" => $name,
- "appName" => $appName,
]);
}
- return __("The vacation request :title has been created correctly by user :creator on your behalf in the :appName.", [
+ return __("The vacation request :title has been created successfully by user :creator on your behalf.", [
"title" => $this->vacationRequest->name,
- "appName" => $appName,
"creator" => $this->vacationRequest->creator->profile->full_name,
]);
}
diff --git a/app/Domain/Notifications/VacationRequestStatusChangedNotification.php b/app/Domain/Notifications/VacationRequestStatusChangedNotification.php
index 11594a1..1cc8d7c 100644
--- a/app/Domain/Notifications/VacationRequestStatusChangedNotification.php
+++ b/app/Domain/Notifications/VacationRequestStatusChangedNotification.php
@@ -22,7 +22,17 @@ class VacationRequestStatusChangedNotification extends Notification
public function via(): array
{
- return ["mail"];
+ return ["mail", "slack"];
+ }
+
+ public function toSlack(): string
+ {
+ $url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]);
+
+ return implode("\n", [
+ $this->buildDescription(),
+ "<${url}|Zobacz szczegóły>",
+ ]);
}
/**
@@ -43,27 +53,17 @@ class VacationRequestStatusChangedNotification extends Notification
protected function buildMailMessage(string $url): MailMessage
{
$user = $this->user->profile->first_name;
- $title = $this->vacationRequest->name;
$type = $this->vacationRequest->type->label();
- $status = $this->vacationRequest->state->label();
$from = $this->vacationRequest->from->toDisplayString();
$to = $this->vacationRequest->to->toDisplayString();
$days = $this->vacationRequest->vacations()->count();
- $requester = $this->vacationRequest->user->profile->full_name;
return (new MailMessage())
->greeting(__("Hi :user!", [
"user" => $user,
]))
- ->subject(__("Vacation request :title has been :status", [
- "title" => $title,
- "status" => $status,
- ]))
- ->line(__("The vacation request :title from user :requester has been :status.", [
- "title" => $title,
- "requester" => $requester,
- "status" => $status,
- ]))
+ ->subject($this->buildSubject())
+ ->line($this->buildDescription())
->line(__("Vacation type: :type", [
"type" => $type,
]))
@@ -74,4 +74,21 @@ class VacationRequestStatusChangedNotification extends Notification
]))
->action(__("Click here for details"), $url);
}
+
+ protected function buildSubject(): string
+ {
+ return __("Vacation request :title has been :status", [
+ "title" => $this->vacationRequest->name,
+ "status" => $this->vacationRequest->state->label(),
+ ]);
+ }
+
+ protected function buildDescription(): string
+ {
+ return __("The vacation request :title from user :requester has been :status.", [
+ "title" => $this->vacationRequest->name,
+ "requester" => $this->vacationRequest->user->profile->full_name,
+ "status" => $this->vacationRequest->state->label(),
+ ]);
+ }
}
diff --git a/app/Domain/Notifications/VacationRequestWaitsForApprovalNotification.php b/app/Domain/Notifications/VacationRequestWaitsForApprovalNotification.php
index 109eef9..3f07a1d 100644
--- a/app/Domain/Notifications/VacationRequestWaitsForApprovalNotification.php
+++ b/app/Domain/Notifications/VacationRequestWaitsForApprovalNotification.php
@@ -23,7 +23,17 @@ class VacationRequestWaitsForApprovalNotification extends Notification
public function via(): array
{
- return ["mail"];
+ return ["mail", "slack"];
+ }
+
+ public function toSlack(): string
+ {
+ $url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]);
+
+ return implode("\n", [
+ $this->buildDescription(),
+ "<${url}|Zobacz szczegóły>",
+ ]);
}
/**
diff --git a/app/Domain/Slack/Channels/SlackApiChannel.php b/app/Domain/Slack/Channels/SlackApiChannel.php
new file mode 100644
index 0000000..6b40cb0
--- /dev/null
+++ b/app/Domain/Slack/Channels/SlackApiChannel.php
@@ -0,0 +1,25 @@
+routeNotificationFor('slack', $notification);
+
+ return Http::withToken(config("services.slack.client_token"))
+ ->post($url, [
+ "channel" => $channel,
+ "text" => $notification->toSlack(),
+ ]);
+ }
+}
\ No newline at end of file
diff --git a/app/Domain/Slack/Handlers/CatchAll.php b/app/Domain/Slack/Handlers/CatchAll.php
new file mode 100644
index 0000000..c38930f
--- /dev/null
+++ b/app/Domain/Slack/Handlers/CatchAll.php
@@ -0,0 +1,51 @@
+respondToSlack("Nie rozpoznaję tej komendy: `/{$request->command} {$request->text}`");
+
+ [$command] = explode(' ', $this->request->text ?? "");
+
+ $alternativeHandlers = $this->findAlternativeHandlers($command);
+
+ if ($alternativeHandlers->count()) {
+ $response->withAttachment($this->getCommandListAttachment($alternativeHandlers));
+ }
+
+ if ($this->containsHelpHandler($alternativeHandlers)) {
+ $response->withAttachment(Attachment::create()
+ ->setText("Aby wyświetlić wszystkie komendy, napisz: `/toby pomoc`")
+ );
+ }
+
+ return $response;
+ }
+
+ protected function getCommandListAttachment(Collection $handlers): Attachment
+ {
+ $attachmentFields = $handlers
+ ->map(function (SignatureHandler $handler) {
+ return AttachmentField::create($handler->getFullCommand(), $handler->getDescription());
+ })
+ ->all();
+
+ return Attachment::create()
+ ->setColor('warning')
+ ->setTitle('Czy miałeś na myśli:')
+ ->setFields($attachmentFields);
+ }
+}
\ No newline at end of file
diff --git a/app/Domain/Slack/Handlers/DailySummary.php b/app/Domain/Slack/Handlers/DailySummary.php
new file mode 100644
index 0000000..b3ae2be
--- /dev/null
+++ b/app/Domain/Slack/Handlers/DailySummary.php
@@ -0,0 +1,74 @@
+with(["user", "vacationRequest"])
+ ->whereDate("date", $now)
+ ->approved()
+ ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => $configRetriever->isVacation($type)))
+ ->get()
+ ->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
+
+ /** @var Collection $remoteDays */
+ $remoteDays = Vacation::query()
+ ->with(["user", "vacationRequest"])
+ ->whereDate("date", $now)
+ ->approved()
+ ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => !$configRetriever->isVacation($type)))
+ ->get()
+ ->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
+
+ $birthdays = User::query()
+ ->whereRelation("profile", "birthday", $now)
+ ->get()
+ ->map(fn(User $user) => $user->profile->full_name);
+
+ $absencesAttachment = Attachment::create()
+ ->setTitle("Nieobecności :palm_tree:")
+ ->setColor('#eab308')
+ ->setText($absences->isNotEmpty() ? $absences->implode("\n") : "Wszyscy dzisiaj pracują :muscle:");
+
+ $remoteAttachment = Attachment::create()
+ ->setTitle("Praca zdalna :house_with_garden:")
+ ->setColor('#d946ef')
+ ->setText($remoteDays->isNotEmpty() ? $remoteDays->implode("\n") : "Wszyscy dzisiaj są w biurze :boom:");
+
+ $birthdayAttachment = Attachment::create()
+ ->setTitle("Urodziny :birthday:")
+ ->setColor('#3C5F97')
+ ->setText($birthdays->isNotEmpty() ? $birthdays->implode("\n") : "Dzisiaj nikt nie ma urodzin :cry:");
+
+ return $this->respondToSlack("Podsumowanie dla dnia {$now->toDisplayString()}")
+ ->withAttachment($absencesAttachment)
+ ->withAttachment($remoteAttachment)
+ ->withAttachment($birthdayAttachment)
+ ->displayResponseToEveryoneOnChannel();
+ }
+}
\ No newline at end of file
diff --git a/app/Domain/Slack/GiveKeysTo.php b/app/Domain/Slack/Handlers/GiveKeysTo.php
similarity index 83%
rename from app/Domain/Slack/GiveKeysTo.php
rename to app/Domain/Slack/Handlers/GiveKeysTo.php
index c45597f..bfaf900 100644
--- a/app/Domain/Slack/GiveKeysTo.php
+++ b/app/Domain/Slack/Handlers/GiveKeysTo.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack;
+namespace Toby\Domain\Slack\Handlers;
use Illuminate\Support\Str;
use Spatie\SlashCommand\Request;
@@ -13,13 +13,13 @@ use Toby\Eloquent\Models\User;
class GiveKeysTo extends SignatureHandler
{
- protected $signature = "toby klucze:dla {to}";
+ protected $signature = "toby klucze:dla {użytkownik}";
- protected $description = "Daj klucze użytkownikowi {to}";
+ protected $description = "Daj klucze wskazanemu użytkownikowi";
public function handle(Request $request): Response
{
- $to = $this->getArgument('to');
+ $to = $this->getArgument('użytkownik');
$id = Str::between($to, "@", "|");
diff --git a/app/Domain/Slack/Handlers/Help.php b/app/Domain/Slack/Handlers/Help.php
new file mode 100644
index 0000000..45fc7bf
--- /dev/null
+++ b/app/Domain/Slack/Handlers/Help.php
@@ -0,0 +1,45 @@
+findAvailableHandlers();
+
+ return $this->displayListOfAllCommands($handlers);
+ }
+
+ protected function displayListOfAllCommands(Collection $handlers): Response
+ {
+ $attachmentFields = $handlers
+ ->sort(function (SignatureHandler $handlerA, SignatureHandler $handlerB) {
+ return strcmp($handlerA->getFullCommand(), $handlerB->getFullCommand());
+ })
+ ->map(function (SignatureHandler $handler) {
+ return AttachmentField::create("/{$handler->getSignature()}", $handler->getDescription());
+ })
+ ->all();
+
+ return $this->respondToSlack('Dostępne komendy')
+ ->withAttachment(
+ Attachment::create()
+ ->setColor('good')
+ ->setFields($attachmentFields)
+ );
+ }
+}
\ No newline at end of file
diff --git a/app/Domain/Slack/HomeOffice.php b/app/Domain/Slack/Handlers/HomeOffice.php
similarity index 79%
rename from app/Domain/Slack/HomeOffice.php
rename to app/Domain/Slack/Handlers/HomeOffice.php
index bb0fe1e..87270d8 100644
--- a/app/Domain/Slack/HomeOffice.php
+++ b/app/Domain/Slack/Handlers/HomeOffice.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack;
+namespace Toby\Domain\Slack\Handlers;
use Illuminate\Support\Carbon;
use Spatie\SlashCommand\Request;
@@ -15,12 +15,12 @@ use Toby\Eloquent\Models\YearPeriod;
class HomeOffice extends SignatureHandler
{
- protected $signature = "toby zdalnie {date=dzisiaj}";
- protected $description = "Praca zdalna {kiedy}";
+ protected $signature = "toby zdalnie {kiedy?}";
+ protected $description = "Pracuj zdalnie wybranego dnia (domyślnie dzisiaj)";
public function handle(Request $request): Response
{
- $date = $this->getDateFromArgument($this->getArgument('date'));
+ $date = $this->getDateFromArgument($this->getArgument('kiedy') ?? "dzisiaj");
$user = $this->findUserBySlackId($request->userId);
$yearPeriod = YearPeriod::findByYear($date->year);
@@ -34,7 +34,8 @@ class HomeOffice extends SignatureHandler
"flow_skipped" => false,
], $user);
- return $this->respondToSlack("Praca zdalna dnia {$date->toDisplayString()} została utworzona pomyślnie");
+ return $this->respondToSlack("Praca zdalna dnia {$date->toDisplayString()} została utworzona pomyślnie.")
+ ->displayResponseToEveryoneOnChannel();
}
protected function getDateFromArgument(string $argument): Carbon
diff --git a/app/Domain/Slack/Handlers/KeyList.php b/app/Domain/Slack/Handlers/KeyList.php
new file mode 100644
index 0000000..ac60a93
--- /dev/null
+++ b/app/Domain/Slack/Handlers/KeyList.php
@@ -0,0 +1,33 @@
+orderBy("id")
+ ->get()
+ ->map(fn(Key $key) => "Klucz nr {$key->id} - <@{$key->user->profile->slack_id}>");
+
+ return $this->respondToSlack("Lista kluczy")
+ ->withAttachment(
+ Attachment::create()
+ ->setColor('#3C5F97')
+ ->setText($keys->implode("\n"))
+ );
+ }
+}
\ No newline at end of file
diff --git a/app/Domain/Slack/Handlers/SaySomething.php b/app/Domain/Slack/Handlers/SaySomething.php
new file mode 100644
index 0000000..4099172
--- /dev/null
+++ b/app/Domain/Slack/Handlers/SaySomething.php
@@ -0,0 +1,24 @@
+getArgument("zdanie");
+
+ return $this->respondToSlack($sentence)
+ ->displayResponseToEveryoneOnChannel();
+ }
+}
\ No newline at end of file
diff --git a/app/Domain/Slack/TakeKeysFrom.php b/app/Domain/Slack/Handlers/TakeKeysFrom.php
similarity index 83%
rename from app/Domain/Slack/TakeKeysFrom.php
rename to app/Domain/Slack/Handlers/TakeKeysFrom.php
index 31860ff..eed3a89 100644
--- a/app/Domain/Slack/TakeKeysFrom.php
+++ b/app/Domain/Slack/Handlers/TakeKeysFrom.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack;
+namespace Toby\Domain\Slack\Handlers;
use Illuminate\Support\Str;
use Spatie\SlashCommand\Request;
@@ -13,13 +13,13 @@ use Toby\Eloquent\Models\User;
class TakeKeysFrom extends SignatureHandler
{
- protected $signature = "toby klucze:od {from}";
+ protected $signature = "toby klucze:od {użytkownik}";
- protected $description = "Zabierz klucze użytkownikowi {from}";
+ protected $description = "Zabierz klucze wskazanemu użytkownikowi";
public function handle(Request $request): Response
{
- $from = $this->getArgument('from');
+ $from = $this->getArgument("użytkownik");
$id = Str::between($from, "@", "|");
diff --git a/app/Domain/Slack/KeyList.php b/app/Domain/Slack/KeyList.php
deleted file mode 100644
index af1d2c5..0000000
--- a/app/Domain/Slack/KeyList.php
+++ /dev/null
@@ -1,30 +0,0 @@
-get() as $key) {
- $temp[] = "Klucz nr {$key->id} - <@{$key->user->profile->slack_id}>";
- }
-
-
- return $this->respondToSlack(implode("\n", $temp))
- ->displayResponseToEveryoneOnChannel();
- }
-}
\ No newline at end of file
diff --git a/app/Domain/VacationDaysCalculator.php b/app/Domain/VacationDaysCalculator.php
index 0e41a4a..2d3227e 100644
--- a/app/Domain/VacationDaysCalculator.php
+++ b/app/Domain/VacationDaysCalculator.php
@@ -11,9 +11,10 @@ use Toby\Eloquent\Models\YearPeriod;
class VacationDaysCalculator
{
- public function calculateDays(YearPeriod $yearPeriod, CarbonInterface $from, CarbonInterface $to): Collection
+ public function calculateDays(CarbonInterface $from, CarbonInterface $to): Collection
{
$period = CarbonPeriod::create($from, $to);
+ $yearPeriod = YearPeriod::findByYear($from->year);
$holidays = $yearPeriod->holidays()->pluck("date");
$validDays = new Collection();
diff --git a/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php b/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php
index 3fd5429..299e0a5 100644
--- a/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php
+++ b/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php
@@ -29,7 +29,7 @@ class DoesNotExceedLimitRule implements VacationRequestRule
$limit = $this->getUserVacationLimit($vacationRequest->user, $vacationRequest->yearPeriod);
$vacationDays = $this->getVacationDaysWithLimit($vacationRequest->user, $vacationRequest->yearPeriod);
- $estimatedDays = $this->vacationDaysCalculator->calculateDays($vacationRequest->yearPeriod, $vacationRequest->from, $vacationRequest->to)->count();
+ $estimatedDays = $this->vacationDaysCalculator->calculateDays($vacationRequest->from, $vacationRequest->to)->count();
return $limit >= ($vacationDays + $estimatedDays);
}
diff --git a/app/Domain/Validation/Rules/MinimumOneVacationDayRule.php b/app/Domain/Validation/Rules/MinimumOneVacationDayRule.php
index ae9f58b..4968d4d 100644
--- a/app/Domain/Validation/Rules/MinimumOneVacationDayRule.php
+++ b/app/Domain/Validation/Rules/MinimumOneVacationDayRule.php
@@ -16,7 +16,7 @@ class MinimumOneVacationDayRule implements VacationRequestRule
public function check(VacationRequest $vacationRequest): bool
{
return $this->vacationDaysCalculator
- ->calculateDays($vacationRequest->yearPeriod, $vacationRequest->from, $vacationRequest->to)
+ ->calculateDays($vacationRequest->from, $vacationRequest->to)
->isNotEmpty();
}
diff --git a/app/Eloquent/Models/Profile.php b/app/Eloquent/Models/Profile.php
index df237e9..84bbd7c 100644
--- a/app/Eloquent/Models/Profile.php
+++ b/app/Eloquent/Models/Profile.php
@@ -19,6 +19,7 @@ use Toby\Eloquent\Helpers\ColorGenerator;
* @property string $position
* @property EmploymentForm $employment_form
* @property Carbon $employment_date
+ * @property Carbon $birthday
*/
class Profile extends Model
{
@@ -32,6 +33,7 @@ class Profile extends Model
protected $casts = [
"employment_form" => EmploymentForm::class,
"employment_date" => "date",
+ "birthday" => "date",
];
public function user(): BelongsTo
diff --git a/app/Eloquent/Models/User.php b/app/Eloquent/Models/User.php
index 4bf2891..2518c95 100644
--- a/app/Eloquent/Models/User.php
+++ b/app/Eloquent/Models/User.php
@@ -125,6 +125,11 @@ class User extends Authenticatable
);
}
+ public function routeNotificationForSlack()
+ {
+ return $this->profile->slack_id;
+ }
+
protected static function newFactory(): UserFactory
{
return UserFactory::new();
diff --git a/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php b/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
new file mode 100644
index 0000000..3959be0
--- /dev/null
+++ b/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
@@ -0,0 +1,97 @@
+option("force") && !$this->shouldHandle($now)) {
+ return;
+ }
+
+ /** @var Collection $absences */
+ $absences = Vacation::query()
+ ->with(["user", "vacationRequest"])
+ ->whereDate("date", $now)
+ ->approved()
+ ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => $configRetriever->isVacation($type)))
+ ->get()
+ ->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
+
+ /** @var Collection $remoteDays */
+ $remoteDays = Vacation::query()
+ ->with(["user", "vacationRequest"])
+ ->whereDate("date", $now)
+ ->approved()
+ ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => !$configRetriever->isVacation($type)))
+ ->get()
+ ->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
+
+ $birthdays = User::query()
+ ->whereRelation("profile", "birthday", $now)
+ ->get()
+ ->map(fn(User $user) => $user->profile->full_name);
+
+ $absencesAttachment = Attachment::create()
+ ->setTitle("Nieobecności :palm_tree:")
+ ->setColor('#eab308')
+ ->setText($absences->isNotEmpty() ? $absences->implode("\n") : "Wszyscy dzisiaj pracują :muscle:");
+
+ $remoteAttachment = Attachment::create()
+ ->setTitle("Praca zdalna :house_with_garden:")
+ ->setColor('#d946ef')
+ ->setText($remoteDays->isNotEmpty() ? $remoteDays->implode("\n") : "Wszyscy dzisiaj są w biurze :boom:");
+
+ $birthdayAttachment = Attachment::create()
+ ->setTitle("Urodziny :birthday:")
+ ->setColor('#3C5F97')
+ ->setText($birthdays->isNotEmpty() ? $birthdays->implode("\n") : "Dzisiaj nikt nie ma urodzin :cry:");
+
+ $baseUrl = config("services.slack.url");
+ $url = "{$baseUrl}/chat.postMessage";
+
+ Http::withToken(config("services.slack.client_token"))
+ ->post($url, [
+ "channel" => config("services.slack.default_channel"),
+ "text" => "Podsumowanie dla dnia {$now->toDisplayString()}",
+ 'attachments' => collect([$absencesAttachment, $remoteAttachment, $birthdayAttachment])->map(
+ fn(Attachment $attachment) => $attachment->toArray()
+ )->toArray(),
+ ]);
+ }
+
+ protected function shouldHandle(CarbonInterface $day): bool
+ {
+ $holidays = Holiday::query()->whereDate("date", $day)->pluck("date");
+
+ if ($day->isWeekend()) {
+ return false;
+ }
+
+ if ($holidays->contains($day)) {
+ return false;
+ }
+
+ return true;
+ }
+}
diff --git a/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php b/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php
index c204be1..79b0bf9 100644
--- a/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php
+++ b/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php
@@ -14,7 +14,7 @@ class CalculateVacationDaysController extends Controller
{
public function __invoke(CalculateVacationDaysRequest $request, VacationDaysCalculator $calculator): JsonResponse
{
- $days = $calculator->calculateDays($request->yearPeriod(), $request->from(), $request->to());
+ $days = $calculator->calculateDays($request->from(), $request->to());
return new JsonResponse($days->map(fn(Carbon $day) => $day->toDateString())->all());
}
diff --git a/app/Infrastructure/Http/Requests/UserRequest.php b/app/Infrastructure/Http/Requests/UserRequest.php
index d3f094f..9319121 100644
--- a/app/Infrastructure/Http/Requests/UserRequest.php
+++ b/app/Infrastructure/Http/Requests/UserRequest.php
@@ -22,6 +22,7 @@ class UserRequest extends FormRequest
"position" => ["required"],
"employmentForm" => ["required", new Enum(EmploymentForm::class)],
"employmentDate" => ["required", "date_format:Y-m-d"],
+ "birthday" => ["nullable", "date_format:Y-m-d"],
];
}
@@ -41,6 +42,7 @@ class UserRequest extends FormRequest
"position" => $this->get("position"),
"employment_form" => $this->get("employmentForm"),
"employment_date" => $this->get("employmentDate"),
+ "birthday" => $this->get("birthday"),
];
}
}
diff --git a/app/Infrastructure/Http/Resources/UserFormDataResource.php b/app/Infrastructure/Http/Resources/UserFormDataResource.php
index 219a2c9..bade223 100644
--- a/app/Infrastructure/Http/Resources/UserFormDataResource.php
+++ b/app/Infrastructure/Http/Resources/UserFormDataResource.php
@@ -21,6 +21,7 @@ class UserFormDataResource extends JsonResource
"position" => $this->profile->position,
"employmentForm" => $this->profile->employment_form,
"employmentDate" => $this->profile->employment_date->toDateString(),
+ "birthday" => $this->profile->birthday->toDateString(),
];
}
}
diff --git a/config/app.php b/config/app.php
index 2c2ab89..6ef5b69 100644
--- a/config/app.php
+++ b/config/app.php
@@ -38,7 +38,6 @@ return [
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
Barryvdh\DomPDF\ServiceProvider::class,
- Spatie\SlashCommand\SlashCommandServiceProvider::class,
Toby\Architecture\Providers\AppServiceProvider::class,
Toby\Architecture\Providers\AuthServiceProvider::class,
Toby\Architecture\Providers\EventServiceProvider::class,
diff --git a/config/laravel-slack-slash-command.php b/config/laravel-slack-slash-command.php
index f19d56c..51ea7d4 100644
--- a/config/laravel-slack-slash-command.php
+++ b/config/laravel-slack-slash-command.php
@@ -1,9 +1,15 @@
'api/slack',
@@ -14,7 +20,9 @@ return [
GiveKeysTo::class,
KeyList::class,
HomeOffice::class,
- Spatie\SlashCommand\Handlers\Help::class,
- Spatie\SlashCommand\Handlers\CatchAll::class,
+ DailySummary::class,
+ SaySomething::class,
+ Help::class,
+ CatchAll::class
],
];
diff --git a/config/services.php b/config/services.php
index e535c9e..8940ddd 100644
--- a/config/services.php
+++ b/config/services.php
@@ -8,4 +8,9 @@ return [
"client_secret" => env("GOOGLE_CLIENT_SECRET"),
"redirect" => env("GOOGLE_REDIRECT"),
],
+ "slack" => [
+ "url" => "https://slack.com/api",
+ "client_token" => env("SLACK_CLIENT_TOKEN"),
+ "default_channel" => env("SLACK_DEFAULT_CHANNEL"),
+ ],
];
diff --git a/database/factories/ProfileFactory.php b/database/factories/ProfileFactory.php
index 706df10..ba96c86 100644
--- a/database/factories/ProfileFactory.php
+++ b/database/factories/ProfileFactory.php
@@ -23,6 +23,7 @@ class ProfileFactory extends Factory
"employment_form" => $this->faker->randomElement(EmploymentForm::cases()),
"position" => $this->faker->jobTitle(),
"employment_date" => Carbon::createFromInterface($this->faker->dateTimeBetween("2020-10-27"))->toDateString(),
+ "birthday" => Carbon::createFromInterface($this->faker->dateTimeBetween("1970-01-01", "1998-01-01"))->toDateString(),
];
}
}
diff --git a/database/migrations/2022_04_21_101027_add_slack_id_column_in_profiles_table.php b/database/migrations/2022_04_21_101027_add_slack_id_and_birthday_columns_in_profiles_table.php
similarity index 78%
rename from database/migrations/2022_04_21_101027_add_slack_id_column_in_profiles_table.php
rename to database/migrations/2022_04_21_101027_add_slack_id_and_birthday_columns_in_profiles_table.php
index 2e9e345..893b4ef 100644
--- a/database/migrations/2022_04_21_101027_add_slack_id_column_in_profiles_table.php
+++ b/database/migrations/2022_04_21_101027_add_slack_id_and_birthday_columns_in_profiles_table.php
@@ -11,13 +11,15 @@ return new class() extends Migration {
{
Schema::table("profiles", function (Blueprint $table): void {
$table->string("slack_id")->nullable();
+ $table->date("birthday")->nullable();
});
}
public function down(): void
{
Schema::table("profiles", function (Blueprint $table): void {
- $table->string("slack_id");
+ $table->dropColumn("slack_id");
+ $table->dropColumn("birthday");
});
}
};
diff --git a/resources/js/Pages/Users/Create.vue b/resources/js/Pages/Users/Create.vue
index 4959b47..9335a1d 100644
--- a/resources/js/Pages/Users/Create.vue
+++ b/resources/js/Pages/Users/Create.vue
@@ -234,6 +234,29 @@
+
+
+
+
+
+ {{ form.errors.birthday }}
+
+
+
+
+
+
+
+
+ {{ form.errors.birthday }}
+
+
+
form.value === props.user.employmentForm),
employmentDate: props.user.employmentDate,
+ birthday: props.user.birthday,
})
function editUser() {
diff --git a/resources/lang/pl.json b/resources/lang/pl.json
index d792d41..f755a40 100644
--- a/resources/lang/pl.json
+++ b/resources/lang/pl.json
@@ -56,7 +56,7 @@
"All rights reserved.": "Wszelkie prawa zastrzeżone",
"Show vacation request": "Pokaż wniosek",
"Vacation request :title has been created" : "Wniosek :title został utworzony",
- "The vacation request :title has been created correctly in the :appName.": "W systemie :appName został poprawnie utworzony wniosek urlopowy :title.",
+ "The vacation request :title from user :requester has been created sucessfully.": "Wniosek :title użytkownika :requester został utworzony pomyślnie.",
"Vacation type: :type": "Rodzaj wniosku: :type",
"From :from to :to (number of days: :days)": "Od :from do :to (liczba dni: :days)",
"Click here for details": "Kliknij, aby zobaczyć szczegóły",
@@ -67,7 +67,7 @@
"Vacation request :title has been :status": "Wniosek :title został :status",
"The vacation request :title from user :requester has been :status.": "Wniosek urlopowy :title użytkownika :requester został :status.",
"Vacation request :title has been created on your behalf": "Wniosek urlopowy :title został utworzony w Twoim imieniu",
- "The vacation request :title has been created correctly by user :creator on your behalf in the :appName.": "W systemie :appName został poprawnie utworzony wniosek urlopowy :title w Twoim imieniu przez użytkownika :creator.",
+ "The vacation request :title has been created successfully by user :creator on your behalf.": "Wniosek urlopowy :title został pomyślnie utworzony w Twoim imieniu przez użytkownika :creator.",
"Key no :number has been created.": "Klucz nr :number został utworzony.",
"Key no :number has been deleted.": "Klucz nr :number został usunięty.",
"Key no :number has been taken from :user.": "Klucz nr :number został zabrany użytkownikowi :user.",
diff --git a/tests/Unit/SendDailySummaryToSlackTest.php b/tests/Unit/SendDailySummaryToSlackTest.php
new file mode 100644
index 0000000..68cac03
--- /dev/null
+++ b/tests/Unit/SendDailySummaryToSlackTest.php
@@ -0,0 +1,82 @@
+createCurrentYearPeriod();
+ }
+
+ public function testCommandSendsMessageToSlackIfWeekday(): void
+ {
+ $weekDay = Carbon::create(2022, 4, 22);
+ $this->assertTrue($weekDay->isWeekday());
+
+ $this->travelTo($weekDay);
+
+ $this->artisan(SendDailySummaryToSlack::class)
+ ->execute();
+
+ Http::assertSentCount(1);
+ }
+
+ public function testCommandDoesntSendIfIsWeekend(): void
+ {
+ $weekend = Carbon::create(2022, 4, 23);
+ $this->assertTrue($weekend->isWeekend());
+
+ $this->travelTo($weekend);
+
+ $this->artisan(SendDailySummaryToSlack::class)
+ ->execute();
+
+ Http::assertNothingSent();
+ }
+
+ public function testCommandDoesntSendIfIsHoliday(): void
+ {
+ $holiday = Holiday::factory(["date" => Carbon::create(2022, 4, 22)])->create();
+
+ $this->assertDatabaseHas("holidays", [
+ "date" => $holiday->date->toDateString(),
+ ]);
+
+ $this->travelTo(Carbon::create(2022, 4, 22));
+
+ $this->artisan(SendDailySummaryToSlack::class)
+ ->execute();
+
+ Http::assertNothingSent();
+ }
+
+ public function testCommandForceSendsMessageEvenIsWeekendOrHoliday(): void
+ {
+ $weekend = Carbon::create(2022, 4, 23);
+ $this->assertTrue($weekend->isWeekend());
+
+ $this->travelTo($weekend);
+
+ $this->artisan(SendDailySummaryToSlack::class, ["--force" => true])
+ ->execute();
+
+ Http::assertSentCount(1);
+ }
+}
\ No newline at end of file
--
2.52.0
From 26f248a3f110da37645549993ea842040c934a7f Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Fri, 22 Apr 2022 13:01:58 +0200
Subject: [PATCH 03/18] wip
---
tests/Unit/SendDailySummaryToSlackTest.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/Unit/SendDailySummaryToSlackTest.php b/tests/Unit/SendDailySummaryToSlackTest.php
index 68cac03..75a2c05 100644
--- a/tests/Unit/SendDailySummaryToSlackTest.php
+++ b/tests/Unit/SendDailySummaryToSlackTest.php
@@ -38,7 +38,7 @@ class SendDailySummaryToSlackTest extends TestCase
Http::assertSentCount(1);
}
- public function testCommandDoesntSendIfIsWeekend(): void
+ public function testCommandDoesntSendIfWeekend(): void
{
$weekend = Carbon::create(2022, 4, 23);
$this->assertTrue($weekend->isWeekend());
@@ -51,7 +51,7 @@ class SendDailySummaryToSlackTest extends TestCase
Http::assertNothingSent();
}
- public function testCommandDoesntSendIfIsHoliday(): void
+ public function testCommandDoesntSendIfHoliday(): void
{
$holiday = Holiday::factory(["date" => Carbon::create(2022, 4, 22)])->create();
--
2.52.0
From 2a75534c529d990a235a2018526e2d090447d27f Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Fri, 22 Apr 2022 14:06:39 +0200
Subject: [PATCH 04/18] wip
---
.../Http/Requests/UserRequest.php | 2 ++
.../Http/Resources/UserFormDataResource.php | 1 +
resources/js/Pages/Users/Create.vue | 24 +++++++++++++++++++
resources/js/Pages/Users/Edit.vue | 24 +++++++++++++++++++
4 files changed, 51 insertions(+)
diff --git a/app/Infrastructure/Http/Requests/UserRequest.php b/app/Infrastructure/Http/Requests/UserRequest.php
index 9319121..8b74657 100644
--- a/app/Infrastructure/Http/Requests/UserRequest.php
+++ b/app/Infrastructure/Http/Requests/UserRequest.php
@@ -23,6 +23,7 @@ class UserRequest extends FormRequest
"employmentForm" => ["required", new Enum(EmploymentForm::class)],
"employmentDate" => ["required", "date_format:Y-m-d"],
"birthday" => ["nullable", "date_format:Y-m-d"],
+ "slackId" => [],
];
}
@@ -43,6 +44,7 @@ class UserRequest extends FormRequest
"employment_form" => $this->get("employmentForm"),
"employment_date" => $this->get("employmentDate"),
"birthday" => $this->get("birthday"),
+ "slack_id" => $this->get("slackId"),
];
}
}
diff --git a/app/Infrastructure/Http/Resources/UserFormDataResource.php b/app/Infrastructure/Http/Resources/UserFormDataResource.php
index bade223..ff85794 100644
--- a/app/Infrastructure/Http/Resources/UserFormDataResource.php
+++ b/app/Infrastructure/Http/Resources/UserFormDataResource.php
@@ -22,6 +22,7 @@ class UserFormDataResource extends JsonResource
"employmentForm" => $this->profile->employment_form,
"employmentDate" => $this->profile->employment_date->toDateString(),
"birthday" => $this->profile->birthday->toDateString(),
+ "slackId" => $this->profile->slack_id,
];
}
}
diff --git a/resources/js/Pages/Users/Create.vue b/resources/js/Pages/Users/Create.vue
index 9335a1d..5caadf9 100644
--- a/resources/js/Pages/Users/Create.vue
+++ b/resources/js/Pages/Users/Create.vue
@@ -234,6 +234,29 @@
+
+
+
+
+
+ {{ form.errors.slackId }}
+
+
+
+
+
+
+
+
+ {{ form.errors.slackId }}
+
+
+
form.value === props.user.employmentForm),
employmentDate: props.user.employmentDate,
birthday: props.user.birthday,
+ slackId: props.user.slackId,
})
function editUser() {
--
2.52.0
From 851a52fe32967eef4eb86328adb7fa32ebdeac2e Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Fri, 22 Apr 2022 14:15:09 +0200
Subject: [PATCH 05/18] fix
---
app/Domain/Notifications/VacationRequestCreatedNotification.php | 2 +-
app/Infrastructure/Http/Resources/UserFormDataResource.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/Domain/Notifications/VacationRequestCreatedNotification.php b/app/Domain/Notifications/VacationRequestCreatedNotification.php
index 69198e7..d8f819e 100644
--- a/app/Domain/Notifications/VacationRequestCreatedNotification.php
+++ b/app/Domain/Notifications/VacationRequestCreatedNotification.php
@@ -92,7 +92,7 @@ class VacationRequestCreatedNotification extends Notification
$name = $this->vacationRequest->name;
if ($this->vacationRequest->creator()->is($this->vacationRequest->user)) {
- return __("The vacation request :title for user :user has been created successfully.", [
+ return __("The vacation request :title from user :user has been created successfully.", [
"user" => $this->vacationRequest->user->profile->full_name,
"title" => $name,
]);
diff --git a/app/Infrastructure/Http/Resources/UserFormDataResource.php b/app/Infrastructure/Http/Resources/UserFormDataResource.php
index ff85794..83fd4e9 100644
--- a/app/Infrastructure/Http/Resources/UserFormDataResource.php
+++ b/app/Infrastructure/Http/Resources/UserFormDataResource.php
@@ -21,7 +21,7 @@ class UserFormDataResource extends JsonResource
"position" => $this->profile->position,
"employmentForm" => $this->profile->employment_form,
"employmentDate" => $this->profile->employment_date->toDateString(),
- "birthday" => $this->profile->birthday->toDateString(),
+ "birthday" => $this->profile->birthday?->toDateString(),
"slackId" => $this->profile->slack_id,
];
}
--
2.52.0
From 25816cc47ae710b990db9e1211ce063f724b9e9d Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Mon, 25 Apr 2022 13:23:49 +0200
Subject: [PATCH 06/18] wip
---
.../Providers/AppServiceProvider.php | 6 +-
app/Domain/DailySummaryRetriever.php | 45 ++++++++++++++
.../KeyHasBeenGivenNotification.php | 42 +++++++++++++
.../KeyHasBeenTakenNotification.php | 42 +++++++++++++
app/Domain/Slack/Controller.php | 55 +++++++++++++++++
app/Domain/Slack/Handlers/CatchAll.php | 52 ++++++----------
app/Domain/Slack/Handlers/DailySummary.php | 40 ++++---------
app/Domain/Slack/Handlers/GiveKeysTo.php | 59 +++++++++++++------
app/Domain/Slack/Handlers/Help.php | 33 ++++-------
app/Domain/Slack/Handlers/HomeOffice.php | 39 ++++--------
app/Domain/Slack/Handlers/KeyList.php | 9 ++-
app/Domain/Slack/Handlers/SaySomething.php | 24 --------
app/Domain/Slack/Handlers/TakeKeysFrom.php | 56 ++++++++++++------
app/Domain/Slack/SignatureHandler.php | 26 ++++++++
.../Slack/{Channels => }/SlackApiChannel.php | 6 +-
app/Domain/Slack/SlackUserExistsRule.php | 24 ++++++++
.../Slack/Traits/FindsUserBySlackId.php | 43 ++++++++++++++
app/Domain/Slack/Traits/ListsHandlers.php | 45 ++++++++++++++
app/Domain/Slack/UserNotFoundException.php | 11 ++++
app/Eloquent/Models/Key.php | 7 +++
.../Commands/SendDailySummaryToSlack.php | 36 ++++-------
.../Http/Controllers/DashboardController.php | 19 ++----
.../Http/Controllers/KeysController.php | 6 ++
composer.json | 3 +-
config/laravel-slack-slash-command.php | 11 ++--
resources/lang/pl.json | 20 ++++---
routes/api.php | 3 +
tests/Feature/KeyTest.php | 8 +++
28 files changed, 531 insertions(+), 239 deletions(-)
create mode 100644 app/Domain/DailySummaryRetriever.php
create mode 100644 app/Domain/Notifications/KeyHasBeenGivenNotification.php
create mode 100644 app/Domain/Notifications/KeyHasBeenTakenNotification.php
create mode 100644 app/Domain/Slack/Controller.php
delete mode 100644 app/Domain/Slack/Handlers/SaySomething.php
create mode 100644 app/Domain/Slack/SignatureHandler.php
rename app/Domain/Slack/{Channels => }/SlackApiChannel.php (77%)
create mode 100644 app/Domain/Slack/SlackUserExistsRule.php
create mode 100644 app/Domain/Slack/Traits/FindsUserBySlackId.php
create mode 100644 app/Domain/Slack/Traits/ListsHandlers.php
create mode 100644 app/Domain/Slack/UserNotFoundException.php
diff --git a/app/Architecture/Providers/AppServiceProvider.php b/app/Architecture/Providers/AppServiceProvider.php
index 37f7884..094200f 100644
--- a/app/Architecture/Providers/AppServiceProvider.php
+++ b/app/Architecture/Providers/AppServiceProvider.php
@@ -9,13 +9,13 @@ use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\ServiceProvider;
-use Toby\Domain\Slack\Channels\SlackApiChannel;
+use Toby\Domain\Slack\SlackApiChannel;
class AppServiceProvider extends ServiceProvider
{
- public function register()
+ public function register(): void
{
- Notification::resolved(function (ChannelManager $service) {
+ Notification::resolved(function (ChannelManager $service): void {
$service->extend("slack", fn(Application $app) => $app->make(SlackApiChannel::class));
});
}
diff --git a/app/Domain/DailySummaryRetriever.php b/app/Domain/DailySummaryRetriever.php
new file mode 100644
index 0000000..465cdb4
--- /dev/null
+++ b/app/Domain/DailySummaryRetriever.php
@@ -0,0 +1,45 @@
+with(["user", "vacationRequest"])
+ ->whereDate("date", $date)
+ ->approved()
+ ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => $this->configRetriever->isVacation($type)))
+ ->get();
+ }
+
+ public function getRemoteDays(Carbon $date): Collection
+ {
+ return Vacation::query()
+ ->with(["user", "vacationRequest"])
+ ->whereDate("date", $date)
+ ->approved()
+ ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => !$this->configRetriever->isVacation($type)))
+ ->get();
+ }
+
+ public function getBirthdays(Carbon $date): Collection
+ {
+ return User::query()
+ ->whereRelation("profile", "birthday", $date)
+ ->get();
+ }
+}
diff --git a/app/Domain/Notifications/KeyHasBeenGivenNotification.php b/app/Domain/Notifications/KeyHasBeenGivenNotification.php
new file mode 100644
index 0000000..84bf706
--- /dev/null
+++ b/app/Domain/Notifications/KeyHasBeenGivenNotification.php
@@ -0,0 +1,42 @@
+ $this->getName($this->sender),
+ "recipient" => $this->getName($this->recipient),
+ "key" => $notifiable->id,
+ ]);
+ }
+
+ protected function getName(User $user): string
+ {
+ if ($user->profile->slack_id !== null) {
+ return "<@{$user->profile->slack_id}>";
+ }
+
+ return $user->profile->full_name;
+ }
+}
diff --git a/app/Domain/Notifications/KeyHasBeenTakenNotification.php b/app/Domain/Notifications/KeyHasBeenTakenNotification.php
new file mode 100644
index 0000000..d22467d
--- /dev/null
+++ b/app/Domain/Notifications/KeyHasBeenTakenNotification.php
@@ -0,0 +1,42 @@
+ $this->getName($this->recipient),
+ "sender" => $this->getName($this->sender),
+ "key" => $notifiable->id,
+ ]);
+ }
+
+ protected function getName(User $user): string
+ {
+ if ($user->profile->slack_id !== null) {
+ return "<@{$user->profile->slack_id}>";
+ }
+
+ return $user->profile->full_name;
+ }
+}
diff --git a/app/Domain/Slack/Controller.php b/app/Domain/Slack/Controller.php
new file mode 100644
index 0000000..78cb4de
--- /dev/null
+++ b/app/Domain/Slack/Controller.php
@@ -0,0 +1,55 @@
+guardAgainstInvalidRequest($request);
+
+ $handler = $this->determineHandler();
+
+ try {
+ $response = $handler->handle($this->request);
+ } catch (SlackSlashCommandException $exception) {
+ $response = $exception->getResponse($this->request);
+ } catch (ValidationException $exception) {
+ $response = $this->prepareValidationResponse($exception);
+ } catch (Exception $exception) {
+ $response = $this->convertToResponse($exception);
+ }
+
+ return $response->getIlluminateResponse();
+ }
+
+ protected function prepareValidationResponse(ValidationException $exception): Response
+ {
+ $errors = (new Collection($exception->errors()))
+ ->map(
+ fn(array $message) => Attachment::create()
+ ->setColor("danger")
+ ->setText($message[0]),
+ );
+
+ return Response::create($this->request)
+ ->withText(":x: Komenda `/{$this->request->command} {$this->request->text}` jest niepoprawna:")
+ ->withAttachments($errors->all());
+ }
+}
\ No newline at end of file
diff --git a/app/Domain/Slack/Handlers/CatchAll.php b/app/Domain/Slack/Handlers/CatchAll.php
index c38930f..a2516b5 100644
--- a/app/Domain/Slack/Handlers/CatchAll.php
+++ b/app/Domain/Slack/Handlers/CatchAll.php
@@ -4,48 +4,32 @@ declare(strict_types=1);
namespace Toby\Domain\Slack\Handlers;
-use Illuminate\Support\Collection;
use Spatie\SlashCommand\Attachment;
-use Spatie\SlashCommand\AttachmentField;
-use Spatie\SlashCommand\Handlers\CatchAll as BaseCatchAllHandler;
-use Spatie\SlashCommand\Handlers\SignatureHandler;
+use Spatie\SlashCommand\Handlers\BaseHandler;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
+use Toby\Domain\Slack\Traits\ListsHandlers;
-class CatchAll extends BaseCatchAllHandler
+class CatchAll extends BaseHandler
{
+ use ListsHandlers;
+
+ public function canHandle(Request $request): bool
+ {
+ return true;
+ }
+
public function handle(Request $request): Response
{
- $response = $this->respondToSlack("Nie rozpoznaję tej komendy: `/{$request->command} {$request->text}`");
+ $handlers = $this->findAvailableHandlers();
+ $attachmentFields = $this->mapHandlersToAttachments($handlers);
- [$command] = explode(' ', $this->request->text ?? "");
-
- $alternativeHandlers = $this->findAlternativeHandlers($command);
-
- if ($alternativeHandlers->count()) {
- $response->withAttachment($this->getCommandListAttachment($alternativeHandlers));
- }
-
- if ($this->containsHelpHandler($alternativeHandlers)) {
- $response->withAttachment(Attachment::create()
- ->setText("Aby wyświetlić wszystkie komendy, napisz: `/toby pomoc`")
+ return $this->respondToSlack(":x: Nie rozpoznaję tej komendy. Lista wszystkich komend:")
+ ->withAttachment(
+ Attachment::create()
+ ->setColor("danger")
+ ->useMarkdown()
+ ->setFields($attachmentFields),
);
- }
-
- return $response;
- }
-
- protected function getCommandListAttachment(Collection $handlers): Attachment
- {
- $attachmentFields = $handlers
- ->map(function (SignatureHandler $handler) {
- return AttachmentField::create($handler->getFullCommand(), $handler->getDescription());
- })
- ->all();
-
- return Attachment::create()
- ->setColor('warning')
- ->setTitle('Czy miałeś na myśli:')
- ->setFields($attachmentFields);
}
}
\ No newline at end of file
diff --git a/app/Domain/Slack/Handlers/DailySummary.php b/app/Domain/Slack/Handlers/DailySummary.php
index b3ae2be..af62bb8 100644
--- a/app/Domain/Slack/Handlers/DailySummary.php
+++ b/app/Domain/Slack/Handlers/DailySummary.php
@@ -5,70 +5,52 @@ declare(strict_types=1);
namespace Toby\Domain\Slack\Handlers;
use Illuminate\Support\Carbon;
-use Illuminate\Support\Collection;
use Spatie\SlashCommand\Attachment;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
-use Spatie\SlashCommand\Handlers\SignatureHandler;
-use Toby\Domain\Enums\VacationType;
-use Toby\Domain\VacationTypeConfigRetriever;
+use Toby\Domain\DailySummaryRetriever;
+use Toby\Domain\Slack\SignatureHandler;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\Vacation;
class DailySummary extends SignatureHandler
{
protected $signature = "toby dzisiaj";
-
- protected $description = "Podsumowanie";
+ protected $description = "Codzienne podsumowanie";
public function handle(Request $request): Response
{
- $configRetriever = app(VacationTypeConfigRetriever::class);
+ $dailySummaryRetriever = app()->make(DailySummaryRetriever::class);
$now = Carbon::today();
- /** @var Collection $absences */
- $absences = Vacation::query()
- ->with(["user", "vacationRequest"])
- ->whereDate("date", $now)
- ->approved()
- ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => $configRetriever->isVacation($type)))
- ->get()
+ $absences = $dailySummaryRetriever->getAbsences($now)
->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
- /** @var Collection $remoteDays */
- $remoteDays = Vacation::query()
- ->with(["user", "vacationRequest"])
- ->whereDate("date", $now)
- ->approved()
- ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => !$configRetriever->isVacation($type)))
- ->get()
+ $remoteDays = $dailySummaryRetriever->getRemoteDays($now)
->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
- $birthdays = User::query()
- ->whereRelation("profile", "birthday", $now)
- ->get()
+ $birthdays = $dailySummaryRetriever->getBirthdays($now)
->map(fn(User $user) => $user->profile->full_name);
$absencesAttachment = Attachment::create()
->setTitle("Nieobecności :palm_tree:")
- ->setColor('#eab308')
+ ->setColor("#eab308")
->setText($absences->isNotEmpty() ? $absences->implode("\n") : "Wszyscy dzisiaj pracują :muscle:");
$remoteAttachment = Attachment::create()
->setTitle("Praca zdalna :house_with_garden:")
- ->setColor('#d946ef')
+ ->setColor("#d946ef")
->setText($remoteDays->isNotEmpty() ? $remoteDays->implode("\n") : "Wszyscy dzisiaj są w biurze :boom:");
$birthdayAttachment = Attachment::create()
->setTitle("Urodziny :birthday:")
- ->setColor('#3C5F97')
+ ->setColor("#3C5F97")
->setText($birthdays->isNotEmpty() ? $birthdays->implode("\n") : "Dzisiaj nikt nie ma urodzin :cry:");
return $this->respondToSlack("Podsumowanie dla dnia {$now->toDisplayString()}")
->withAttachment($absencesAttachment)
->withAttachment($remoteAttachment)
- ->withAttachment($birthdayAttachment)
- ->displayResponseToEveryoneOnChannel();
+ ->withAttachment($birthdayAttachment);
}
}
\ No newline at end of file
diff --git a/app/Domain/Slack/Handlers/GiveKeysTo.php b/app/Domain/Slack/Handlers/GiveKeysTo.php
index bfaf900..049551e 100644
--- a/app/Domain/Slack/Handlers/GiveKeysTo.php
+++ b/app/Domain/Slack/Handlers/GiveKeysTo.php
@@ -4,46 +4,69 @@ declare(strict_types=1);
namespace Toby\Domain\Slack\Handlers;
-use Illuminate\Support\Str;
+use Illuminate\Validation\ValidationException;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
-use Spatie\SlashCommand\Handlers\SignatureHandler;
+use Toby\Domain\Notifications\KeyHasBeenGivenNotification;
+use Toby\Domain\Slack\SignatureHandler;
+use Toby\Domain\Slack\SlackUserExistsRule;
+use Toby\Domain\Slack\Traits\FindsUserBySlackId;
+use Toby\Domain\Slack\UserNotFoundException;
use Toby\Eloquent\Models\Key;
-use Toby\Eloquent\Models\User;
class GiveKeysTo extends SignatureHandler
{
- protected $signature = "toby klucze:dla {użytkownik}";
+ use FindsUserBySlackId;
- protected $description = "Daj klucze wskazanemu użytkownikowi";
+ protected $signature = "toby klucze:dla {user}";
+ protected $description = "Przekaż klucze wskazanemu użytkownikowi";
+ /**
+ * @throws UserNotFoundException
+ * @throws ValidationException
+ */
public function handle(Request $request): Response
{
- $to = $this->getArgument('użytkownik');
+ ["user" => $from] = $this->validate();
- $id = Str::between($to, "@", "|");
-
- $authUser = $this->findUserBySlackId($request->userId);
- $user = $this->findUserBySlackId($id);
+ $authUser = $this->findUserBySlackIdOrFail($request->userId);
+ $user = $this->findUserBySlackId($from);
/** @var Key $key */
$key = $authUser->keys()->first();
+ if (!$key) {
+ throw ValidationException::withMessages(["key" => "Nie masz żadnego klucza do przekazania"]);
+ }
+
+ if ($user->is($authUser)) {
+ throw ValidationException::withMessages([
+ "key" => "Nie możesz przekazać sobie kluczy :dzban:",
+ ]);
+ }
+
$key->user()->associate($user);
$key->save();
- return $this->respondToSlack("<@{$authUser->profile->slack_id}> daje klucz nr {$key->id} użytkownikowi <@{$user->profile->slack_id}>")
- ->displayResponseToEveryoneOnChannel();
+ $key->notify(new KeyHasBeenGivenNotification($authUser, $user));
+
+ return $this->respondToSlack(
+ ":white_check_mark: Klucz nr {$key->id} został przekazany użytkownikowi <@{$user->profile->slack_id}>",
+ );
}
- protected function findUserBySlackId(string $slackId): User
+ protected function getRules(): array
{
- /** @var User $user */
- $user = User::query()
- ->whereRelation("profile", "slack_id", $slackId)
- ->first();
+ return [
+ "user" => ["required", new SlackUserExistsRule()],
+ ];
+ }
- return $user;
+ protected function getMessages(): array
+ {
+ return [
+ "user.required" => "Musisz podać użytkownika, któremu chcesz przekazać klucze",
+ ];
}
}
\ No newline at end of file
diff --git a/app/Domain/Slack/Handlers/Help.php b/app/Domain/Slack/Handlers/Help.php
index 45fc7bf..1407c50 100644
--- a/app/Domain/Slack/Handlers/Help.php
+++ b/app/Domain/Slack/Handlers/Help.php
@@ -4,42 +4,31 @@ declare(strict_types=1);
namespace Toby\Domain\Slack\Handlers;
-use Illuminate\Support\Collection;
use Spatie\SlashCommand\Attachment;
-use Spatie\SlashCommand\AttachmentField;
-use Spatie\SlashCommand\Handlers\Help as BaseHelpHandler;
-use Spatie\SlashCommand\Handlers\SignatureHandler;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
+use Toby\Domain\Slack\SignatureHandler;
+use Toby\Domain\Slack\Traits\ListsHandlers;
-class Help extends BaseHelpHandler
+class Help extends SignatureHandler
{
+ use ListsHandlers;
+
protected $signature = "toby pomoc";
- protected $description = "Wyświetl wszystkie dostępne komendy tobiego";
+ protected $description = "Wyświetl wszystkie dostępne komendy";
public function handle(Request $request): Response
{
$handlers = $this->findAvailableHandlers();
- return $this->displayListOfAllCommands($handlers);
- }
+ $attachmentFields = $this->mapHandlersToAttachments($handlers);
- protected function displayListOfAllCommands(Collection $handlers): Response
- {
- $attachmentFields = $handlers
- ->sort(function (SignatureHandler $handlerA, SignatureHandler $handlerB) {
- return strcmp($handlerA->getFullCommand(), $handlerB->getFullCommand());
- })
- ->map(function (SignatureHandler $handler) {
- return AttachmentField::create("/{$handler->getSignature()}", $handler->getDescription());
- })
- ->all();
-
- return $this->respondToSlack('Dostępne komendy')
+ return $this->respondToSlack("Dostępne komendy:")
->withAttachment(
Attachment::create()
- ->setColor('good')
- ->setFields($attachmentFields)
+ ->setColor("good")
+ ->useMarkdown()
+ ->setFields($attachmentFields),
);
}
}
\ No newline at end of file
diff --git a/app/Domain/Slack/Handlers/HomeOffice.php b/app/Domain/Slack/Handlers/HomeOffice.php
index 87270d8..437cff0 100644
--- a/app/Domain/Slack/Handlers/HomeOffice.php
+++ b/app/Domain/Slack/Handlers/HomeOffice.php
@@ -7,22 +7,31 @@ namespace Toby\Domain\Slack\Handlers;
use Illuminate\Support\Carbon;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
-use Spatie\SlashCommand\Handlers\SignatureHandler;
use Toby\Domain\Actions\VacationRequest\CreateAction;
use Toby\Domain\Enums\VacationType;
+use Toby\Domain\Slack\SignatureHandler;
+use Toby\Domain\Slack\Traits\FindsUserBySlackId;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\YearPeriod;
class HomeOffice extends SignatureHandler
{
- protected $signature = "toby zdalnie {kiedy?}";
- protected $description = "Pracuj zdalnie wybranego dnia (domyślnie dzisiaj)";
+ use FindsUserBySlackId;
+
+ protected $signature = "toby zdalnie";
+ protected $description = "Pracuj dzisiaj zdalnie";
public function handle(Request $request): Response
{
- $date = $this->getDateFromArgument($this->getArgument('kiedy') ?? "dzisiaj");
$user = $this->findUserBySlackId($request->userId);
+ $this->createRemoteday($user, Carbon::today());
+
+ return $this->respondToSlack(":white_check_mark: Pracujesz dzisiaj zdalnie");
+ }
+
+ protected function createRemoteday(User $user, Carbon $date): void
+ {
$yearPeriod = YearPeriod::findByYear($date->year);
app(CreateAction::class)->execute([
@@ -33,27 +42,5 @@ class HomeOffice extends SignatureHandler
"year_period_id" => $yearPeriod->id,
"flow_skipped" => false,
], $user);
-
- return $this->respondToSlack("Praca zdalna dnia {$date->toDisplayString()} została utworzona pomyślnie.")
- ->displayResponseToEveryoneOnChannel();
- }
-
- protected function getDateFromArgument(string $argument): Carbon
- {
- return match ($argument) {
- "dzisiaj" => Carbon::today(),
- "jutro" => Carbon::tomorrow(),
- default => Carbon::create($argument),
- };
- }
-
- protected function findUserBySlackId(string $slackId): User
- {
- /** @var User $user */
- $user = User::query()
- ->whereRelation("profile", "slack_id", $slackId)
- ->first();
-
- return $user;
}
}
\ No newline at end of file
diff --git a/app/Domain/Slack/Handlers/KeyList.php b/app/Domain/Slack/Handlers/KeyList.php
index ac60a93..70ed4a7 100644
--- a/app/Domain/Slack/Handlers/KeyList.php
+++ b/app/Domain/Slack/Handlers/KeyList.php
@@ -7,13 +7,12 @@ namespace Toby\Domain\Slack\Handlers;
use Spatie\SlashCommand\Attachment;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
-use Spatie\SlashCommand\Handlers\SignatureHandler;
+use Toby\Domain\Slack\SignatureHandler;
use Toby\Eloquent\Models\Key;
class KeyList extends SignatureHandler
{
protected $signature = "toby klucze";
-
protected $description = "Lista wszystkich kluczy";
public function handle(Request $request): Response
@@ -23,11 +22,11 @@ class KeyList extends SignatureHandler
->get()
->map(fn(Key $key) => "Klucz nr {$key->id} - <@{$key->user->profile->slack_id}>");
- return $this->respondToSlack("Lista kluczy")
+ return $this->respondToSlack("Lista kluczy :key:")
->withAttachment(
Attachment::create()
- ->setColor('#3C5F97')
- ->setText($keys->implode("\n"))
+ ->setColor("#3C5F97")
+ ->setText($keys->isNotEmpty() ? $keys->implode("\n") : "Nie ma żadnych kluczy w tobym"),
);
}
}
\ No newline at end of file
diff --git a/app/Domain/Slack/Handlers/SaySomething.php b/app/Domain/Slack/Handlers/SaySomething.php
deleted file mode 100644
index 4099172..0000000
--- a/app/Domain/Slack/Handlers/SaySomething.php
+++ /dev/null
@@ -1,24 +0,0 @@
-getArgument("zdanie");
-
- return $this->respondToSlack($sentence)
- ->displayResponseToEveryoneOnChannel();
- }
-}
\ No newline at end of file
diff --git a/app/Domain/Slack/Handlers/TakeKeysFrom.php b/app/Domain/Slack/Handlers/TakeKeysFrom.php
index eed3a89..de6aa85 100644
--- a/app/Domain/Slack/Handlers/TakeKeysFrom.php
+++ b/app/Domain/Slack/Handlers/TakeKeysFrom.php
@@ -4,46 +4,68 @@ declare(strict_types=1);
namespace Toby\Domain\Slack\Handlers;
-use Illuminate\Support\Str;
+use Illuminate\Validation\ValidationException;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
-use Spatie\SlashCommand\Handlers\SignatureHandler;
+use Toby\Domain\Notifications\KeyHasBeenTakenNotification;
+use Toby\Domain\Slack\SignatureHandler;
+use Toby\Domain\Slack\SlackUserExistsRule;
+use Toby\Domain\Slack\Traits\FindsUserBySlackId;
+use Toby\Domain\Slack\UserNotFoundException;
use Toby\Eloquent\Models\Key;
-use Toby\Eloquent\Models\User;
class TakeKeysFrom extends SignatureHandler
{
- protected $signature = "toby klucze:od {użytkownik}";
+ use FindsUserBySlackId;
+ protected $signature = "toby klucze:od {user}";
protected $description = "Zabierz klucze wskazanemu użytkownikowi";
+ /**
+ * @throws UserNotFoundException|ValidationException
+ */
public function handle(Request $request): Response
{
- $from = $this->getArgument("użytkownik");
+ ["user" => $from] = $this->validate();
- $id = Str::between($from, "@", "|");
-
- $authUser = $this->findUserBySlackId($request->userId);
- $user = $this->findUserBySlackId($id);
+ $authUser = $this->findUserBySlackIdOrFail($request->userId);
+ $user = $this->findUserBySlackId($from);
/** @var Key $key */
$key = $user->keys()->first();
+ if (!$key) {
+ throw ValidationException::withMessages([
+ "key" => "Użytkownik <@{$user->profile->slack_id}> nie ma żadnych kluczy",
+ ]);
+ }
+
+ if ($key->user()->is($authUser)) {
+ throw ValidationException::withMessages([
+ "key" => "Nie możesz zabrać sobie kluczy :dzban:",
+ ]);
+ }
+
$key->user()->associate($authUser);
$key->save();
- return $this->respondToSlack("<@{$authUser->profile->slack_id}> zabiera klucz nr {$key->id} użytkownikowi <@{$user->profile->slack_id}>")
- ->displayResponseToEveryoneOnChannel();
+ $key->notify(new KeyHasBeenTakenNotification($authUser, $user));
+
+ return $this->respondToSlack(":white_check_mark: Klucz nr {$key->id} został zabrany użytkownikowi <@{$user->profile->slack_id}>");
}
- protected function findUserBySlackId(string $slackId): User
+ protected function getRules(): array
{
- /** @var User $user */
- $user = User::query()
- ->whereRelation("profile", "slack_id", $slackId)
- ->first();
+ return [
+ "user" => ["required", new SlackUserExistsRule()],
+ ];
+ }
- return $user;
+ protected function getMessages(): array
+ {
+ return [
+ "user.required" => "Musisz podać użytkownika, któremu chcesz zabrać klucze",
+ ];
}
}
\ No newline at end of file
diff --git a/app/Domain/Slack/SignatureHandler.php b/app/Domain/Slack/SignatureHandler.php
new file mode 100644
index 0000000..b7d4ddf
--- /dev/null
+++ b/app/Domain/Slack/SignatureHandler.php
@@ -0,0 +1,26 @@
+getArguments(), $this->getRules(), $this->getMessages());
+ }
+
+ protected function getRules(): array
+ {
+ return [];
+ }
+
+ protected function getMessages(): array
+ {
+ return [];
+ }
+}
\ No newline at end of file
diff --git a/app/Domain/Slack/Channels/SlackApiChannel.php b/app/Domain/Slack/SlackApiChannel.php
similarity index 77%
rename from app/Domain/Slack/Channels/SlackApiChannel.php
rename to app/Domain/Slack/SlackApiChannel.php
index 6b40cb0..9b66640 100644
--- a/app/Domain/Slack/Channels/SlackApiChannel.php
+++ b/app/Domain/Slack/SlackApiChannel.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack\Channels;
+namespace Toby\Domain\Slack;
use Illuminate\Http\Client\Response;
use Illuminate\Notifications\Notification;
@@ -14,12 +14,12 @@ class SlackApiChannel
{
$baseUrl = config("services.slack.url");
$url = "{$baseUrl}/chat.postMessage";
- $channel = $notifiable->routeNotificationFor('slack', $notification);
+ $channel = $notifiable->routeNotificationFor("slack", $notification);
return Http::withToken(config("services.slack.client_token"))
->post($url, [
"channel" => $channel,
- "text" => $notification->toSlack(),
+ "text" => $notification->toSlack($notifiable),
]);
}
}
\ No newline at end of file
diff --git a/app/Domain/Slack/SlackUserExistsRule.php b/app/Domain/Slack/SlackUserExistsRule.php
new file mode 100644
index 0000000..f0176ba
--- /dev/null
+++ b/app/Domain/Slack/SlackUserExistsRule.php
@@ -0,0 +1,24 @@
+where("slack_id", $slackId)->exists();
+ }
+
+ public function message(): string
+ {
+ return "Użytkownik :input nie istnieje w tobym";
+ }
+}
\ No newline at end of file
diff --git a/app/Domain/Slack/Traits/FindsUserBySlackId.php b/app/Domain/Slack/Traits/FindsUserBySlackId.php
new file mode 100644
index 0000000..15514f9
--- /dev/null
+++ b/app/Domain/Slack/Traits/FindsUserBySlackId.php
@@ -0,0 +1,43 @@
+prepareSlackIdFromString($slackId);
+
+ /** @var User $user */
+ $user = User::query()
+ ->whereRelation("profile", "slack_id", $id)
+ ->first();
+
+ return $user;
+ }
+
+ /**
+ * @throws UserNotFoundException
+ */
+ protected function findUserBySlackIdOrFail(string $slackId): ?User
+ {
+ $user = $this->findUserBySlackId($slackId);
+
+ if (!$user) {
+ throw new UserNotFoundException("Użytkownik {$slackId} nie istnieje w tobym");
+ }
+
+ return $user;
+ }
+
+ protected function prepareSlackIdFromString(string $slackId): string
+ {
+ return Str::between($slackId, "<@", "|");
+ }
+}
\ No newline at end of file
diff --git a/app/Domain/Slack/Traits/ListsHandlers.php b/app/Domain/Slack/Traits/ListsHandlers.php
new file mode 100644
index 0000000..08895f9
--- /dev/null
+++ b/app/Domain/Slack/Traits/ListsHandlers.php
@@ -0,0 +1,45 @@
+map(fn(string $handlerClassName) => new $handlerClassName($this->request))
+ ->filter(fn(HandlesSlashCommand $handler) => $handler instanceof SignatureHandler)
+ ->filter(function (SignatureHandler $handler) {
+ $signatureParts = new SignatureParts($handler->getSignature());
+
+ return Str::is($signatureParts->getSlashCommandName(), $this->request->command);
+ });
+ }
+
+ protected function mapHandlersToAttachments(Collection $handlers): array
+ {
+ return $handlers
+ ->sort(
+ fn(SignatureHandler $handlerA, SignatureHandler $handlerB) => strcmp(
+ $handlerA->getFullCommand(),
+ $handlerB->getFullCommand(),
+ ),
+ )
+ ->map(
+ fn(SignatureHandler $handler) => AttachmentField::create(
+ $handler->getDescription(),
+ "`/{$handler->getSignature()}`",
+ ),
+ )
+ ->all();
+ }
+}
\ No newline at end of file
diff --git a/app/Domain/Slack/UserNotFoundException.php b/app/Domain/Slack/UserNotFoundException.php
new file mode 100644
index 0000000..1d60d66
--- /dev/null
+++ b/app/Domain/Slack/UserNotFoundException.php
@@ -0,0 +1,11 @@
+belongsTo(User::class);
}
+ public function routeNotificationForSlack(): string
+ {
+ return config("services.slack.default_channel");
+ }
+
protected static function newFactory(): KeyFactory
{
return KeyFactory::new();
diff --git a/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php b/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
index 3959be0..c487c1f 100644
--- a/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
+++ b/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
@@ -7,11 +7,9 @@ namespace Toby\Infrastructure\Console\Commands;
use Carbon\CarbonInterface;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
-use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;
use Spatie\SlashCommand\Attachment;
-use Toby\Domain\Enums\VacationType;
-use Toby\Domain\VacationTypeConfigRetriever;
+use Toby\Domain\DailySummaryRetriever;
use Toby\Eloquent\Models\Holiday;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\Vacation;
@@ -21,7 +19,7 @@ class SendDailySummaryToSlack extends Command
protected $signature = "toby:slack:daily-summary {--f|force}";
protected $description = "Sent daily summary to slack";
- public function handle(VacationTypeConfigRetriever $configRetriever): void
+ public function handle(DailySummaryRetriever $dailySummaryRetriever): void
{
$now = Carbon::today();
@@ -29,42 +27,28 @@ class SendDailySummaryToSlack extends Command
return;
}
- /** @var Collection $absences */
- $absences = Vacation::query()
- ->with(["user", "vacationRequest"])
- ->whereDate("date", $now)
- ->approved()
- ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => $configRetriever->isVacation($type)))
- ->get()
+ $absences = $dailySummaryRetriever->getAbsences($now)
->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
- /** @var Collection $remoteDays */
- $remoteDays = Vacation::query()
- ->with(["user", "vacationRequest"])
- ->whereDate("date", $now)
- ->approved()
- ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => !$configRetriever->isVacation($type)))
- ->get()
+ $remoteDays = $dailySummaryRetriever->getRemoteDays($now)
->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
- $birthdays = User::query()
- ->whereRelation("profile", "birthday", $now)
- ->get()
+ $birthdays = $dailySummaryRetriever->getBirthdays($now)
->map(fn(User $user) => $user->profile->full_name);
$absencesAttachment = Attachment::create()
->setTitle("Nieobecności :palm_tree:")
- ->setColor('#eab308')
+ ->setColor("#eab308")
->setText($absences->isNotEmpty() ? $absences->implode("\n") : "Wszyscy dzisiaj pracują :muscle:");
$remoteAttachment = Attachment::create()
->setTitle("Praca zdalna :house_with_garden:")
- ->setColor('#d946ef')
+ ->setColor("#d946ef")
->setText($remoteDays->isNotEmpty() ? $remoteDays->implode("\n") : "Wszyscy dzisiaj są w biurze :boom:");
$birthdayAttachment = Attachment::create()
->setTitle("Urodziny :birthday:")
- ->setColor('#3C5F97')
+ ->setColor("#3C5F97")
->setText($birthdays->isNotEmpty() ? $birthdays->implode("\n") : "Dzisiaj nikt nie ma urodzin :cry:");
$baseUrl = config("services.slack.url");
@@ -74,8 +58,8 @@ class SendDailySummaryToSlack extends Command
->post($url, [
"channel" => config("services.slack.default_channel"),
"text" => "Podsumowanie dla dnia {$now->toDisplayString()}",
- 'attachments' => collect([$absencesAttachment, $remoteAttachment, $birthdayAttachment])->map(
- fn(Attachment $attachment) => $attachment->toArray()
+ "attachments" => collect([$absencesAttachment, $remoteAttachment, $birthdayAttachment])->map(
+ fn(Attachment $attachment) => $attachment->toArray(),
)->toArray(),
]);
}
diff --git a/app/Infrastructure/Http/Controllers/DashboardController.php b/app/Infrastructure/Http/Controllers/DashboardController.php
index 33bf1aa..9f164a9 100644
--- a/app/Infrastructure/Http/Controllers/DashboardController.php
+++ b/app/Infrastructure/Http/Controllers/DashboardController.php
@@ -7,12 +7,11 @@ namespace Toby\Infrastructure\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Inertia\Response;
-use Toby\Domain\Enums\VacationType;
+use Toby\Domain\DailySummaryRetriever;
use Toby\Domain\UserVacationStatsRetriever;
use Toby\Domain\VacationRequestStatesRetriever;
use Toby\Domain\VacationTypeConfigRetriever;
use Toby\Eloquent\Helpers\YearPeriodRetriever;
-use Toby\Eloquent\Models\Vacation;
use Toby\Eloquent\Models\VacationRequest;
use Toby\Infrastructure\Http\Resources\HolidayResource;
use Toby\Infrastructure\Http\Resources\VacationRequestResource;
@@ -25,24 +24,14 @@ class DashboardController extends Controller
YearPeriodRetriever $yearPeriodRetriever,
UserVacationStatsRetriever $vacationStatsRetriever,
VacationTypeConfigRetriever $configRetriever,
+ DailySummaryRetriever $dailySummaryRetriever,
): Response {
$user = $request->user();
$now = Carbon::now();
$yearPeriod = $yearPeriodRetriever->selected();
- $absences = Vacation::query()
- ->with(["user", "vacationRequest"])
- ->whereDate("date", $now)
- ->approved()
- ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => $configRetriever->isVacation($type)))
- ->get();
-
- $remoteDays = Vacation::query()
- ->with(["user", "vacationRequest"])
- ->whereDate("date", $now)
- ->approved()
- ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => !$configRetriever->isVacation($type)))
- ->get();
+ $absences = $dailySummaryRetriever->getAbsences($now);
+ $remoteDays = $dailySummaryRetriever->getRemoteDays($now);
if ($user->can("listAll", VacationRequest::class)) {
$vacationRequests = $yearPeriod->vacationRequests()
diff --git a/app/Infrastructure/Http/Controllers/KeysController.php b/app/Infrastructure/Http/Controllers/KeysController.php
index 096e540..d71c177 100644
--- a/app/Infrastructure/Http/Controllers/KeysController.php
+++ b/app/Infrastructure/Http/Controllers/KeysController.php
@@ -8,6 +8,8 @@ use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\Request;
use Inertia\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
+use Toby\Domain\Notifications\KeyHasBeenGivenNotification;
+use Toby\Domain\Notifications\KeyHasBeenTakenNotification;
use Toby\Eloquent\Models\Key;
use Toby\Eloquent\Models\User;
use Toby\Infrastructure\Http\Requests\GiveKeyRequest;
@@ -60,6 +62,8 @@ class KeysController extends Controller
$key->save();
+ $key->notify(new KeyHasBeenTakenNotification($request->user(), $previousUser));
+
return redirect()
->back()
->with("success", __("Key no :number has been taken from :user.", [
@@ -81,6 +85,8 @@ class KeysController extends Controller
$key->save();
+ $key->notify(new KeyHasBeenGivenNotification($request->user(), $recipient));
+
return redirect()
->back()
->with("success", __("Key no :number has been given to :user.", [
diff --git a/composer.json b/composer.json
index 71cb14b..36d9d98 100644
--- a/composer.json
+++ b/composer.json
@@ -62,7 +62,8 @@
"extra": {
"laravel": {
"dont-discover": [
- "laravel/telescope"
+ "laravel/telescope",
+ "spatie/laravel-slack-slash-command"
]
}
},
diff --git a/config/laravel-slack-slash-command.php b/config/laravel-slack-slash-command.php
index 51ea7d4..23eb170 100644
--- a/config/laravel-slack-slash-command.php
+++ b/config/laravel-slack-slash-command.php
@@ -8,21 +8,18 @@ use Toby\Domain\Slack\Handlers\GiveKeysTo;
use Toby\Domain\Slack\Handlers\Help;
use Toby\Domain\Slack\Handlers\HomeOffice;
use Toby\Domain\Slack\Handlers\KeyList;
-use Toby\Domain\Slack\Handlers\SaySomething;
use Toby\Domain\Slack\Handlers\TakeKeysFrom;
return [
- 'url' => 'api/slack',
- 'signing_secret' => env('SLACK_SIGNING_SECRET'),
- 'verify_with_signing' => true,
- 'handlers' => [
+ "signing_secret" => env("SLACK_SIGNING_SECRET"),
+ "verify_with_signing" => true,
+ "handlers" => [
TakeKeysFrom::class,
GiveKeysTo::class,
KeyList::class,
HomeOffice::class,
DailySummary::class,
- SaySomething::class,
Help::class,
- CatchAll::class
+ CatchAll::class,
],
];
diff --git a/resources/lang/pl.json b/resources/lang/pl.json
index f755a40..192ce08 100644
--- a/resources/lang/pl.json
+++ b/resources/lang/pl.json
@@ -23,11 +23,11 @@
"cancelled": "anulowany",
"rejected": "odrzucony",
"approved": "zatwierdzony",
- "You have pending vacation request in this range.": "Masz oczekujący wniosek urlopowy w tym zakresie dat.",
- "You have approved vacation request in this range.": "Masz zaakceptowany wniosek urlopowy w tym zakresie dat.",
+ "You have pending vacation request in this range.": "Masz oczekujący wniosek w tym zakresie dat.",
+ "You have approved vacation request in this range.": "Masz zaakceptowany wniosek w tym zakresie dat.",
"Vacation limit has been exceeded.": "Limit urlopu został przekroczony.",
"Vacation needs minimum one day.": "Urlop musi być co najmniej na jeden dzień.",
- "The vacation request cannot be created at the turn of the year.": "Wniosek urlopowy nie może zostać złożony na przełomie roku.",
+ "The vacation request cannot be created at the turn of the year.": "Wniosek nie może zostać złożony na przełomie roku.",
"User has been created.": "Użytkownik został utworzony.",
"User has been updated.": "Użytkownik został zaktualizowany.",
"User has been deleted.": "Użytkownik został usunięty.",
@@ -37,11 +37,11 @@
"Holiday has been deleted.": "Dzień wolny został usunięty.",
"Selected year period has been changed.": "Wybrany rok został zmieniony.",
"Vacation limits have been updated.": "Limity urlopów zostały zaktualizowane.",
- "Vacation request has been created.": "Wniosek urlopowy został utworzony.",
- "Vacation request has been accepted.": "Wniosek urlopowy został zaakceptowany.",
- "Vacation request has been approved.": "Wniosek urlopowy został zatwierdzony.",
- "Vacation request has been rejected.": "Wniosek urlopowy został odrzucony.",
- "Vacation request has been cancelled.": "Wniosek urlopowy został anulowany.",
+ "Vacation request has been created.": "Wniosek został utworzony.",
+ "Vacation request has been accepted.": "Wniosek został zaakceptowany.",
+ "Vacation request has been approved.": "Wniosek został zatwierdzony.",
+ "Vacation request has been rejected.": "Wniosek został odrzucony.",
+ "Vacation request has been cancelled.": "Wniosek został anulowany.",
"Sum:": "Suma:",
"Date": "Data",
"Day of week": "Dzień tygodnia",
@@ -71,5 +71,7 @@
"Key no :number has been created.": "Klucz nr :number został utworzony.",
"Key no :number has been deleted.": "Klucz nr :number został usunięty.",
"Key no :number has been taken from :user.": "Klucz nr :number został zabrany użytkownikowi :user.",
- "Key no :number has been given to :user.": "Klucz nr :number został przekazany użytkownikowi :user."
+ "Key no :number has been given to :user.": "Klucz nr :number został przekazany użytkownikowi :user.",
+ ":sender gives key no :key to :recipient": ":sender przekazuje klucz nr :key :recipient",
+ ":recipient takes key no :key from :sender": ":recipient zabiera klucz nr :key :sender"
}
diff --git a/routes/api.php b/routes/api.php
index d76094c..9d8bace 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -3,11 +3,14 @@
declare(strict_types=1);
use Illuminate\Support\Facades\Route;
+use Toby\Domain\Slack\Controller as SlackController;
use Toby\Infrastructure\Http\Controllers\Api\CalculateUserUnavailableDaysController;
use Toby\Infrastructure\Http\Controllers\Api\CalculateUserVacationStatsController;
use Toby\Infrastructure\Http\Controllers\Api\CalculateVacationDaysController;
use Toby\Infrastructure\Http\Controllers\Api\GetAvailableVacationTypesController;
+Route::post("slack", [SlackController::class, "getResponse"]);
+
Route::middleware("auth:sanctum")->group(function (): void {
Route::post("vacation/calculate-days", CalculateVacationDaysController::class);
Route::post("vacation/calculate-stats", CalculateUserVacationStatsController::class);
diff --git a/tests/Feature/KeyTest.php b/tests/Feature/KeyTest.php
index e9c3ddc..2b1c329 100644
--- a/tests/Feature/KeyTest.php
+++ b/tests/Feature/KeyTest.php
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseMigrations;
+use Illuminate\Support\Facades\Notification;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\FeatureTestCase;
use Toby\Eloquent\Models\Key;
@@ -14,6 +15,13 @@ class KeyTest extends FeatureTestCase
{
use DatabaseMigrations;
+ protected function setUp(): void
+ {
+ parent::setUp();
+
+ Notification::fake();
+ }
+
public function testUserCanSeeKeyList(): void
{
Key::factory()->count(10)->create();
--
2.52.0
From 54faa3460cd82560cf251469893bf5e6ca785585 Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Mon, 25 Apr 2022 13:31:57 +0200
Subject: [PATCH 07/18] wip
---
app/Architecture/Providers/AppServiceProvider.php | 2 +-
app/Domain/Slack/{ => Channels}/SlackApiChannel.php | 2 +-
app/Domain/Slack/{ => Exceptions}/UserNotFoundException.php | 2 +-
app/Domain/Slack/Handlers/DailySummary.php | 1 -
app/Domain/Slack/Handlers/GiveKeysTo.php | 5 ++---
app/Domain/Slack/Handlers/Help.php | 1 -
app/Domain/Slack/Handlers/HomeOffice.php | 1 -
app/Domain/Slack/Handlers/KeyList.php | 1 -
app/Domain/Slack/{ => Handlers}/SignatureHandler.php | 2 +-
app/Domain/Slack/Handlers/TakeKeysFrom.php | 5 ++---
app/Domain/Slack/{ => Rules}/SlackUserExistsRule.php | 2 +-
app/Domain/Slack/Traits/FindsUserBySlackId.php | 2 +-
12 files changed, 10 insertions(+), 16 deletions(-)
rename app/Domain/Slack/{ => Channels}/SlackApiChannel.php (94%)
rename app/Domain/Slack/{ => Exceptions}/UserNotFoundException.php (80%)
rename app/Domain/Slack/{ => Handlers}/SignatureHandler.php (93%)
rename app/Domain/Slack/{ => Rules}/SlackUserExistsRule.php (93%)
diff --git a/app/Architecture/Providers/AppServiceProvider.php b/app/Architecture/Providers/AppServiceProvider.php
index 094200f..bd8659f 100644
--- a/app/Architecture/Providers/AppServiceProvider.php
+++ b/app/Architecture/Providers/AppServiceProvider.php
@@ -9,7 +9,7 @@ use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\ServiceProvider;
-use Toby\Domain\Slack\SlackApiChannel;
+use Toby\Domain\Slack\Channels\SlackApiChannel;
class AppServiceProvider extends ServiceProvider
{
diff --git a/app/Domain/Slack/SlackApiChannel.php b/app/Domain/Slack/Channels/SlackApiChannel.php
similarity index 94%
rename from app/Domain/Slack/SlackApiChannel.php
rename to app/Domain/Slack/Channels/SlackApiChannel.php
index 9b66640..55c28ab 100644
--- a/app/Domain/Slack/SlackApiChannel.php
+++ b/app/Domain/Slack/Channels/SlackApiChannel.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack;
+namespace Toby\Domain\Slack\Channels;
use Illuminate\Http\Client\Response;
use Illuminate\Notifications\Notification;
diff --git a/app/Domain/Slack/UserNotFoundException.php b/app/Domain/Slack/Exceptions/UserNotFoundException.php
similarity index 80%
rename from app/Domain/Slack/UserNotFoundException.php
rename to app/Domain/Slack/Exceptions/UserNotFoundException.php
index 1d60d66..3bccfc9 100644
--- a/app/Domain/Slack/UserNotFoundException.php
+++ b/app/Domain/Slack/Exceptions/UserNotFoundException.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack;
+namespace Toby\Domain\Slack\Exceptions;
use Spatie\SlashCommand\Exceptions\SlackSlashCommandException;
diff --git a/app/Domain/Slack/Handlers/DailySummary.php b/app/Domain/Slack/Handlers/DailySummary.php
index af62bb8..6eb6905 100644
--- a/app/Domain/Slack/Handlers/DailySummary.php
+++ b/app/Domain/Slack/Handlers/DailySummary.php
@@ -9,7 +9,6 @@ use Spatie\SlashCommand\Attachment;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
use Toby\Domain\DailySummaryRetriever;
-use Toby\Domain\Slack\SignatureHandler;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\Vacation;
diff --git a/app/Domain/Slack/Handlers/GiveKeysTo.php b/app/Domain/Slack/Handlers/GiveKeysTo.php
index 049551e..51c1cf3 100644
--- a/app/Domain/Slack/Handlers/GiveKeysTo.php
+++ b/app/Domain/Slack/Handlers/GiveKeysTo.php
@@ -8,10 +8,9 @@ use Illuminate\Validation\ValidationException;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
use Toby\Domain\Notifications\KeyHasBeenGivenNotification;
-use Toby\Domain\Slack\SignatureHandler;
-use Toby\Domain\Slack\SlackUserExistsRule;
+use Toby\Domain\Slack\Exceptions\UserNotFoundException;
+use Toby\Domain\Slack\Rules\SlackUserExistsRule;
use Toby\Domain\Slack\Traits\FindsUserBySlackId;
-use Toby\Domain\Slack\UserNotFoundException;
use Toby\Eloquent\Models\Key;
class GiveKeysTo extends SignatureHandler
diff --git a/app/Domain/Slack/Handlers/Help.php b/app/Domain/Slack/Handlers/Help.php
index 1407c50..0df9fb8 100644
--- a/app/Domain/Slack/Handlers/Help.php
+++ b/app/Domain/Slack/Handlers/Help.php
@@ -7,7 +7,6 @@ namespace Toby\Domain\Slack\Handlers;
use Spatie\SlashCommand\Attachment;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
-use Toby\Domain\Slack\SignatureHandler;
use Toby\Domain\Slack\Traits\ListsHandlers;
class Help extends SignatureHandler
diff --git a/app/Domain/Slack/Handlers/HomeOffice.php b/app/Domain/Slack/Handlers/HomeOffice.php
index 437cff0..1586eb4 100644
--- a/app/Domain/Slack/Handlers/HomeOffice.php
+++ b/app/Domain/Slack/Handlers/HomeOffice.php
@@ -9,7 +9,6 @@ use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
use Toby\Domain\Actions\VacationRequest\CreateAction;
use Toby\Domain\Enums\VacationType;
-use Toby\Domain\Slack\SignatureHandler;
use Toby\Domain\Slack\Traits\FindsUserBySlackId;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\YearPeriod;
diff --git a/app/Domain/Slack/Handlers/KeyList.php b/app/Domain/Slack/Handlers/KeyList.php
index 70ed4a7..c13cf21 100644
--- a/app/Domain/Slack/Handlers/KeyList.php
+++ b/app/Domain/Slack/Handlers/KeyList.php
@@ -7,7 +7,6 @@ namespace Toby\Domain\Slack\Handlers;
use Spatie\SlashCommand\Attachment;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
-use Toby\Domain\Slack\SignatureHandler;
use Toby\Eloquent\Models\Key;
class KeyList extends SignatureHandler
diff --git a/app/Domain/Slack/SignatureHandler.php b/app/Domain/Slack/Handlers/SignatureHandler.php
similarity index 93%
rename from app/Domain/Slack/SignatureHandler.php
rename to app/Domain/Slack/Handlers/SignatureHandler.php
index b7d4ddf..5cbf12f 100644
--- a/app/Domain/Slack/SignatureHandler.php
+++ b/app/Domain/Slack/Handlers/SignatureHandler.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack;
+namespace Toby\Domain\Slack\Handlers;
use Illuminate\Support\Facades\Validator;
use Spatie\SlashCommand\Handlers\SignatureHandler as BaseSignatureHandler;
diff --git a/app/Domain/Slack/Handlers/TakeKeysFrom.php b/app/Domain/Slack/Handlers/TakeKeysFrom.php
index de6aa85..9801026 100644
--- a/app/Domain/Slack/Handlers/TakeKeysFrom.php
+++ b/app/Domain/Slack/Handlers/TakeKeysFrom.php
@@ -8,10 +8,9 @@ use Illuminate\Validation\ValidationException;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
use Toby\Domain\Notifications\KeyHasBeenTakenNotification;
-use Toby\Domain\Slack\SignatureHandler;
-use Toby\Domain\Slack\SlackUserExistsRule;
+use Toby\Domain\Slack\Exceptions\UserNotFoundException;
+use Toby\Domain\Slack\Rules\SlackUserExistsRule;
use Toby\Domain\Slack\Traits\FindsUserBySlackId;
-use Toby\Domain\Slack\UserNotFoundException;
use Toby\Eloquent\Models\Key;
class TakeKeysFrom extends SignatureHandler
diff --git a/app/Domain/Slack/SlackUserExistsRule.php b/app/Domain/Slack/Rules/SlackUserExistsRule.php
similarity index 93%
rename from app/Domain/Slack/SlackUserExistsRule.php
rename to app/Domain/Slack/Rules/SlackUserExistsRule.php
index f0176ba..fcdc3d3 100644
--- a/app/Domain/Slack/SlackUserExistsRule.php
+++ b/app/Domain/Slack/Rules/SlackUserExistsRule.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack;
+namespace Toby\Domain\Slack\Rules;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Str;
diff --git a/app/Domain/Slack/Traits/FindsUserBySlackId.php b/app/Domain/Slack/Traits/FindsUserBySlackId.php
index 15514f9..b48a07b 100644
--- a/app/Domain/Slack/Traits/FindsUserBySlackId.php
+++ b/app/Domain/Slack/Traits/FindsUserBySlackId.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace Toby\Domain\Slack\Traits;
use Illuminate\Support\Str;
-use Toby\Domain\Slack\UserNotFoundException;
+use Toby\Domain\Slack\Exceptions\UserNotFoundException;
use Toby\Eloquent\Models\User;
trait FindsUserBySlackId
--
2.52.0
From 160eb5f94b376d4fbb977683cf0b06486a4e8b20 Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Mon, 25 Apr 2022 13:36:40 +0200
Subject: [PATCH 08/18] fix
---
app/Domain/Slack/Channels/SlackApiChannel.php | 2 +-
app/Domain/Slack/Controller.php | 2 +-
app/Domain/Slack/Exceptions/UserNotFoundException.php | 2 +-
app/Domain/Slack/Handlers/CatchAll.php | 2 +-
app/Domain/Slack/Handlers/DailySummary.php | 2 +-
app/Domain/Slack/Handlers/GiveKeysTo.php | 2 +-
app/Domain/Slack/Handlers/Help.php | 2 +-
app/Domain/Slack/Handlers/HomeOffice.php | 2 +-
app/Domain/Slack/Handlers/KeyList.php | 2 +-
app/Domain/Slack/Handlers/SignatureHandler.php | 2 +-
app/Domain/Slack/Handlers/TakeKeysFrom.php | 2 +-
app/Domain/Slack/Rules/SlackUserExistsRule.php | 2 +-
app/Domain/Slack/Traits/FindsUserBySlackId.php | 2 +-
app/Domain/Slack/Traits/ListsHandlers.php | 2 +-
14 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/app/Domain/Slack/Channels/SlackApiChannel.php b/app/Domain/Slack/Channels/SlackApiChannel.php
index 55c28ab..2741e09 100644
--- a/app/Domain/Slack/Channels/SlackApiChannel.php
+++ b/app/Domain/Slack/Channels/SlackApiChannel.php
@@ -22,4 +22,4 @@ class SlackApiChannel
"text" => $notification->toSlack($notifiable),
]);
}
-}
\ No newline at end of file
+}
diff --git a/app/Domain/Slack/Controller.php b/app/Domain/Slack/Controller.php
index 78cb4de..616f048 100644
--- a/app/Domain/Slack/Controller.php
+++ b/app/Domain/Slack/Controller.php
@@ -52,4 +52,4 @@ class Controller extends SlackController
->withText(":x: Komenda `/{$this->request->command} {$this->request->text}` jest niepoprawna:")
->withAttachments($errors->all());
}
-}
\ No newline at end of file
+}
diff --git a/app/Domain/Slack/Exceptions/UserNotFoundException.php b/app/Domain/Slack/Exceptions/UserNotFoundException.php
index 3bccfc9..925e6fb 100644
--- a/app/Domain/Slack/Exceptions/UserNotFoundException.php
+++ b/app/Domain/Slack/Exceptions/UserNotFoundException.php
@@ -8,4 +8,4 @@ use Spatie\SlashCommand\Exceptions\SlackSlashCommandException;
class UserNotFoundException extends SlackSlashCommandException
{
-}
\ No newline at end of file
+}
diff --git a/app/Domain/Slack/Handlers/CatchAll.php b/app/Domain/Slack/Handlers/CatchAll.php
index a2516b5..faeaf7e 100644
--- a/app/Domain/Slack/Handlers/CatchAll.php
+++ b/app/Domain/Slack/Handlers/CatchAll.php
@@ -32,4 +32,4 @@ class CatchAll extends BaseHandler
->setFields($attachmentFields),
);
}
-}
\ No newline at end of file
+}
diff --git a/app/Domain/Slack/Handlers/DailySummary.php b/app/Domain/Slack/Handlers/DailySummary.php
index 6eb6905..07dd420 100644
--- a/app/Domain/Slack/Handlers/DailySummary.php
+++ b/app/Domain/Slack/Handlers/DailySummary.php
@@ -52,4 +52,4 @@ class DailySummary extends SignatureHandler
->withAttachment($remoteAttachment)
->withAttachment($birthdayAttachment);
}
-}
\ No newline at end of file
+}
diff --git a/app/Domain/Slack/Handlers/GiveKeysTo.php b/app/Domain/Slack/Handlers/GiveKeysTo.php
index 51c1cf3..0ecb587 100644
--- a/app/Domain/Slack/Handlers/GiveKeysTo.php
+++ b/app/Domain/Slack/Handlers/GiveKeysTo.php
@@ -68,4 +68,4 @@ class GiveKeysTo extends SignatureHandler
"user.required" => "Musisz podać użytkownika, któremu chcesz przekazać klucze",
];
}
-}
\ No newline at end of file
+}
diff --git a/app/Domain/Slack/Handlers/Help.php b/app/Domain/Slack/Handlers/Help.php
index 0df9fb8..a46d9d1 100644
--- a/app/Domain/Slack/Handlers/Help.php
+++ b/app/Domain/Slack/Handlers/Help.php
@@ -30,4 +30,4 @@ class Help extends SignatureHandler
->setFields($attachmentFields),
);
}
-}
\ No newline at end of file
+}
diff --git a/app/Domain/Slack/Handlers/HomeOffice.php b/app/Domain/Slack/Handlers/HomeOffice.php
index 1586eb4..5a4cd34 100644
--- a/app/Domain/Slack/Handlers/HomeOffice.php
+++ b/app/Domain/Slack/Handlers/HomeOffice.php
@@ -42,4 +42,4 @@ class HomeOffice extends SignatureHandler
"flow_skipped" => false,
], $user);
}
-}
\ No newline at end of file
+}
diff --git a/app/Domain/Slack/Handlers/KeyList.php b/app/Domain/Slack/Handlers/KeyList.php
index c13cf21..7a8adef 100644
--- a/app/Domain/Slack/Handlers/KeyList.php
+++ b/app/Domain/Slack/Handlers/KeyList.php
@@ -28,4 +28,4 @@ class KeyList extends SignatureHandler
->setText($keys->isNotEmpty() ? $keys->implode("\n") : "Nie ma żadnych kluczy w tobym"),
);
}
-}
\ No newline at end of file
+}
diff --git a/app/Domain/Slack/Handlers/SignatureHandler.php b/app/Domain/Slack/Handlers/SignatureHandler.php
index 5cbf12f..626a561 100644
--- a/app/Domain/Slack/Handlers/SignatureHandler.php
+++ b/app/Domain/Slack/Handlers/SignatureHandler.php
@@ -23,4 +23,4 @@ abstract class SignatureHandler extends BaseSignatureHandler
{
return [];
}
-}
\ No newline at end of file
+}
diff --git a/app/Domain/Slack/Handlers/TakeKeysFrom.php b/app/Domain/Slack/Handlers/TakeKeysFrom.php
index 9801026..e8ac558 100644
--- a/app/Domain/Slack/Handlers/TakeKeysFrom.php
+++ b/app/Domain/Slack/Handlers/TakeKeysFrom.php
@@ -67,4 +67,4 @@ class TakeKeysFrom extends SignatureHandler
"user.required" => "Musisz podać użytkownika, któremu chcesz zabrać klucze",
];
}
-}
\ No newline at end of file
+}
diff --git a/app/Domain/Slack/Rules/SlackUserExistsRule.php b/app/Domain/Slack/Rules/SlackUserExistsRule.php
index fcdc3d3..aeb8fe7 100644
--- a/app/Domain/Slack/Rules/SlackUserExistsRule.php
+++ b/app/Domain/Slack/Rules/SlackUserExistsRule.php
@@ -21,4 +21,4 @@ class SlackUserExistsRule implements Rule
{
return "Użytkownik :input nie istnieje w tobym";
}
-}
\ No newline at end of file
+}
diff --git a/app/Domain/Slack/Traits/FindsUserBySlackId.php b/app/Domain/Slack/Traits/FindsUserBySlackId.php
index b48a07b..0502c3f 100644
--- a/app/Domain/Slack/Traits/FindsUserBySlackId.php
+++ b/app/Domain/Slack/Traits/FindsUserBySlackId.php
@@ -40,4 +40,4 @@ trait FindsUserBySlackId
{
return Str::between($slackId, "<@", "|");
}
-}
\ No newline at end of file
+}
diff --git a/app/Domain/Slack/Traits/ListsHandlers.php b/app/Domain/Slack/Traits/ListsHandlers.php
index 08895f9..aa8e331 100644
--- a/app/Domain/Slack/Traits/ListsHandlers.php
+++ b/app/Domain/Slack/Traits/ListsHandlers.php
@@ -42,4 +42,4 @@ trait ListsHandlers
)
->all();
}
-}
\ No newline at end of file
+}
--
2.52.0
From ae2ff139613ce2a8fdb894e7e7737e23390d301a Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Mon, 25 Apr 2022 13:53:22 +0200
Subject: [PATCH 09/18] fix
---
composer.lock | 277 +++++++++++++++++++++++++-------------------------
1 file changed, 141 insertions(+), 136 deletions(-)
diff --git a/composer.lock b/composer.lock
index c61e264..d04d59e 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "17caa1f146a96a76822006d13f440645",
+ "content-hash": "24a1b3a5dd7c4d4f50d521dda4b6654e",
"packages": [
{
"name": "asm89/stack-cors",
@@ -815,23 +815,23 @@
},
{
"name": "firebase/php-jwt",
- "version": "v5.5.1",
+ "version": "v6.1.2",
"source": {
"type": "git",
"url": "https://github.com/firebase/php-jwt.git",
- "reference": "83b609028194aa042ea33b5af2d41a7427de80e6"
+ "reference": "c297139da7c6873dbd67cbd1093f09ec0bbd0c50"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/firebase/php-jwt/zipball/83b609028194aa042ea33b5af2d41a7427de80e6",
- "reference": "83b609028194aa042ea33b5af2d41a7427de80e6",
+ "url": "https://api.github.com/repos/firebase/php-jwt/zipball/c297139da7c6873dbd67cbd1093f09ec0bbd0c50",
+ "reference": "c297139da7c6873dbd67cbd1093f09ec0bbd0c50",
"shasum": ""
},
"require": {
- "php": ">=5.3.0"
+ "php": "^7.1||^8.0"
},
"require-dev": {
- "phpunit/phpunit": ">=4.8 <=9"
+ "phpunit/phpunit": "^7.5||9.5"
},
"suggest": {
"paragonie/sodium_compat": "Support EdDSA (Ed25519) signatures when libsodium is not present"
@@ -866,9 +866,9 @@
],
"support": {
"issues": "https://github.com/firebase/php-jwt/issues",
- "source": "https://github.com/firebase/php-jwt/tree/v5.5.1"
+ "source": "https://github.com/firebase/php-jwt/tree/v6.1.2"
},
- "time": "2021-11-08T20:18:51+00:00"
+ "time": "2022-04-21T14:37:18+00:00"
},
{
"name": "fruitcake/laravel-cors",
@@ -1022,16 +1022,16 @@
},
{
"name": "google/apiclient",
- "version": "v2.12.2",
+ "version": "v2.12.4",
"source": {
"type": "git",
"url": "https://github.com/googleapis/google-api-php-client.git",
- "reference": "a18b0e1ef5618523c607c01a41ec137c7f9af3b1"
+ "reference": "702eed9ae7022ba20dc7118c8161060cb50ee9f8"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/googleapis/google-api-php-client/zipball/a18b0e1ef5618523c607c01a41ec137c7f9af3b1",
- "reference": "a18b0e1ef5618523c607c01a41ec137c7f9af3b1",
+ "url": "https://api.github.com/repos/googleapis/google-api-php-client/zipball/702eed9ae7022ba20dc7118c8161060cb50ee9f8",
+ "reference": "702eed9ae7022ba20dc7118c8161060cb50ee9f8",
"shasum": ""
},
"require": {
@@ -1087,22 +1087,22 @@
],
"support": {
"issues": "https://github.com/googleapis/google-api-php-client/issues",
- "source": "https://github.com/googleapis/google-api-php-client/tree/v2.12.2"
+ "source": "https://github.com/googleapis/google-api-php-client/tree/v2.12.4"
},
- "time": "2022-04-05T16:19:05+00:00"
+ "time": "2022-04-20T16:44:03+00:00"
},
{
"name": "google/apiclient-services",
- "version": "v0.242.0",
+ "version": "v0.246.0",
"source": {
"type": "git",
"url": "https://github.com/googleapis/google-api-php-client-services.git",
- "reference": "73d4c0ed4b241e7396699e0ee1d1cdebabac25e8"
+ "reference": "33aef1ccce34799a1124c39951fed8ad0b16aced"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/73d4c0ed4b241e7396699e0ee1d1cdebabac25e8",
- "reference": "73d4c0ed4b241e7396699e0ee1d1cdebabac25e8",
+ "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/33aef1ccce34799a1124c39951fed8ad0b16aced",
+ "reference": "33aef1ccce34799a1124c39951fed8ad0b16aced",
"shasum": ""
},
"require": {
@@ -1131,30 +1131,30 @@
],
"support": {
"issues": "https://github.com/googleapis/google-api-php-client-services/issues",
- "source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.242.0"
+ "source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.246.0"
},
- "time": "2022-04-03T01:24:10+00:00"
+ "time": "2022-04-24T00:58:37+00:00"
},
{
"name": "google/auth",
- "version": "v1.19.0",
+ "version": "v1.21.0",
"source": {
"type": "git",
"url": "https://github.com/googleapis/google-auth-library-php.git",
- "reference": "31e5d24d5fa0eaf6adc7e596292dc4732f4b60c5"
+ "reference": "73392bad2eb6852eea9084b6bbdec752515cb849"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/googleapis/google-auth-library-php/zipball/31e5d24d5fa0eaf6adc7e596292dc4732f4b60c5",
- "reference": "31e5d24d5fa0eaf6adc7e596292dc4732f4b60c5",
+ "url": "https://api.github.com/repos/googleapis/google-auth-library-php/zipball/73392bad2eb6852eea9084b6bbdec752515cb849",
+ "reference": "73392bad2eb6852eea9084b6bbdec752515cb849",
"shasum": ""
},
"require": {
- "firebase/php-jwt": "~5.0",
+ "firebase/php-jwt": "^5.5||^6.0",
"guzzlehttp/guzzle": "^6.2.1|^7.0",
"guzzlehttp/psr7": "^1.7|^2.0",
- "php": ">=5.6",
- "psr/cache": "^1.0|^2.0",
+ "php": "^7.1||^8.0",
+ "psr/cache": "^1.0|^2.0|^3.0",
"psr/http-message": "^1.0"
},
"require-dev": {
@@ -1162,7 +1162,7 @@
"kelvinmo/simplejwt": "^0.2.5|^0.5.1",
"phpseclib/phpseclib": "^2.0.31",
"phpspec/prophecy-phpunit": "^1.1",
- "phpunit/phpunit": "^5.7||^8.5.13",
+ "phpunit/phpunit": "^7.5||^8.5",
"sebastian/comparator": ">=1.2.3",
"squizlabs/php_codesniffer": "^3.5"
},
@@ -1189,9 +1189,9 @@
"support": {
"docs": "https://googleapis.github.io/google-auth-library-php/main/",
"issues": "https://github.com/googleapis/google-auth-library-php/issues",
- "source": "https://github.com/googleapis/google-auth-library-php/tree/v1.19.0"
+ "source": "https://github.com/googleapis/google-auth-library-php/tree/v1.21.0"
},
- "time": "2022-03-24T21:22:45+00:00"
+ "time": "2022-04-13T20:35:52+00:00"
},
{
"name": "graham-campbell/result-type",
@@ -1733,16 +1733,16 @@
},
{
"name": "laravel/framework",
- "version": "v9.7.0",
+ "version": "v9.9.0",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
- "reference": "54c9696ee3e558ab29317ed6e0cb16bb9db5aad4"
+ "reference": "4d5a07640891b772188d7737348886a0222737d8"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/laravel/framework/zipball/54c9696ee3e558ab29317ed6e0cb16bb9db5aad4",
- "reference": "54c9696ee3e558ab29317ed6e0cb16bb9db5aad4",
+ "url": "https://api.github.com/repos/laravel/framework/zipball/4d5a07640891b772188d7737348886a0222737d8",
+ "reference": "4d5a07640891b772188d7737348886a0222737d8",
"shasum": ""
},
"require": {
@@ -1908,7 +1908,7 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2022-04-05T15:07:51+00:00"
+ "time": "2022-04-19T15:01:23+00:00"
},
{
"name": "laravel/helpers",
@@ -1968,16 +1968,16 @@
},
{
"name": "laravel/sanctum",
- "version": "v2.15.0",
+ "version": "v2.15.1",
"source": {
"type": "git",
"url": "https://github.com/laravel/sanctum.git",
- "reference": "5be160413b6f37dcf8758663edeab12d0e806f56"
+ "reference": "31fbe6f85aee080c4dc2f9b03dc6dd5d0ee72473"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/laravel/sanctum/zipball/5be160413b6f37dcf8758663edeab12d0e806f56",
- "reference": "5be160413b6f37dcf8758663edeab12d0e806f56",
+ "url": "https://api.github.com/repos/laravel/sanctum/zipball/31fbe6f85aee080c4dc2f9b03dc6dd5d0ee72473",
+ "reference": "31fbe6f85aee080c4dc2f9b03dc6dd5d0ee72473",
"shasum": ""
},
"require": {
@@ -2029,7 +2029,7 @@
"issues": "https://github.com/laravel/sanctum/issues",
"source": "https://github.com/laravel/sanctum"
},
- "time": "2022-03-28T13:53:05+00:00"
+ "time": "2022-04-08T13:39:49+00:00"
},
{
"name": "laravel/serializable-closure",
@@ -2161,16 +2161,16 @@
},
{
"name": "laravel/telescope",
- "version": "v4.8.2",
+ "version": "v4.8.3",
"source": {
"type": "git",
"url": "https://github.com/laravel/telescope.git",
- "reference": "88e3ded3e1fc301a82403820b2f68ec5a9e092e3"
+ "reference": "bb23d58161032c8745d38348452afcbcd8adfc78"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/laravel/telescope/zipball/88e3ded3e1fc301a82403820b2f68ec5a9e092e3",
- "reference": "88e3ded3e1fc301a82403820b2f68ec5a9e092e3",
+ "url": "https://api.github.com/repos/laravel/telescope/zipball/bb23d58161032c8745d38348452afcbcd8adfc78",
+ "reference": "bb23d58161032c8745d38348452afcbcd8adfc78",
"shasum": ""
},
"require": {
@@ -2223,9 +2223,9 @@
],
"support": {
"issues": "https://github.com/laravel/telescope/issues",
- "source": "https://github.com/laravel/telescope/tree/v4.8.2"
+ "source": "https://github.com/laravel/telescope/tree/v4.8.3"
},
- "time": "2022-04-01T14:27:12+00:00"
+ "time": "2022-04-11T14:29:02+00:00"
},
{
"name": "laravel/tinker",
@@ -2460,16 +2460,16 @@
},
{
"name": "league/commonmark",
- "version": "2.2.3",
+ "version": "2.3.0",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/commonmark.git",
- "reference": "47b015bc4e50fd4438c1ffef6139a1fb65d2ab71"
+ "reference": "32a49eb2b38fe5e5c417ab748a45d0beaab97955"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/47b015bc4e50fd4438c1ffef6139a1fb65d2ab71",
- "reference": "47b015bc4e50fd4438c1ffef6139a1fb65d2ab71",
+ "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/32a49eb2b38fe5e5c417ab748a45d0beaab97955",
+ "reference": "32a49eb2b38fe5e5c417ab748a45d0beaab97955",
"shasum": ""
},
"require": {
@@ -2478,17 +2478,19 @@
"php": "^7.4 || ^8.0",
"psr/event-dispatcher": "^1.0",
"symfony/deprecation-contracts": "^2.1 || ^3.0",
- "symfony/polyfill-php80": "^1.15"
+ "symfony/polyfill-php80": "^1.16"
},
"require-dev": {
"cebe/markdown": "^1.0",
"commonmark/cmark": "0.30.0",
"commonmark/commonmark.js": "0.30.0",
"composer/package-versions-deprecated": "^1.8",
+ "embed/embed": "^4.4",
"erusev/parsedown": "^1.0",
"ext-json": "*",
"github/gfm": "0.29.0",
"michelf/php-markdown": "^1.4",
+ "nyholm/psr7": "^1.5",
"phpstan/phpstan": "^0.12.88 || ^1.0.0",
"phpunit/phpunit": "^9.5.5",
"scrutinizer/ocular": "^1.8.1",
@@ -2503,7 +2505,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "2.3-dev"
+ "dev-main": "2.4-dev"
}
},
"autoload": {
@@ -2560,7 +2562,7 @@
"type": "tidelift"
}
],
- "time": "2022-02-26T21:24:45+00:00"
+ "time": "2022-04-07T22:37:05+00:00"
},
{
"name": "league/config",
@@ -2646,16 +2648,16 @@
},
{
"name": "league/flysystem",
- "version": "3.0.14",
+ "version": "3.0.17",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/flysystem.git",
- "reference": "46a5450352540e89cb8e7eb20c58b5b4aae481f6"
+ "reference": "29eb78cac0be0c22237c5e0f6f98234d97037d79"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/46a5450352540e89cb8e7eb20c58b5b4aae481f6",
- "reference": "46a5450352540e89cb8e7eb20c58b5b4aae481f6",
+ "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/29eb78cac0be0c22237c5e0f6f98234d97037d79",
+ "reference": "29eb78cac0be0c22237c5e0f6f98234d97037d79",
"shasum": ""
},
"require": {
@@ -2716,7 +2718,7 @@
],
"support": {
"issues": "https://github.com/thephpleague/flysystem/issues",
- "source": "https://github.com/thephpleague/flysystem/tree/3.0.14"
+ "source": "https://github.com/thephpleague/flysystem/tree/3.0.17"
},
"funding": [
{
@@ -2732,20 +2734,20 @@
"type": "tidelift"
}
],
- "time": "2022-04-06T18:17:37+00:00"
+ "time": "2022-04-14T14:57:13+00:00"
},
{
"name": "league/mime-type-detection",
- "version": "1.9.0",
+ "version": "1.11.0",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/mime-type-detection.git",
- "reference": "aa70e813a6ad3d1558fc927863d47309b4c23e69"
+ "reference": "ff6248ea87a9f116e78edd6002e39e5128a0d4dd"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/aa70e813a6ad3d1558fc927863d47309b4c23e69",
- "reference": "aa70e813a6ad3d1558fc927863d47309b4c23e69",
+ "url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/ff6248ea87a9f116e78edd6002e39e5128a0d4dd",
+ "reference": "ff6248ea87a9f116e78edd6002e39e5128a0d4dd",
"shasum": ""
},
"require": {
@@ -2776,7 +2778,7 @@
"description": "Mime-type detection for Flysystem",
"support": {
"issues": "https://github.com/thephpleague/mime-type-detection/issues",
- "source": "https://github.com/thephpleague/mime-type-detection/tree/1.9.0"
+ "source": "https://github.com/thephpleague/mime-type-detection/tree/1.11.0"
},
"funding": [
{
@@ -2788,20 +2790,20 @@
"type": "tidelift"
}
],
- "time": "2021-11-21T11:48:40+00:00"
+ "time": "2022-04-17T13:12:02+00:00"
},
{
"name": "league/oauth1-client",
- "version": "v1.10.0",
+ "version": "v1.10.1",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/oauth1-client.git",
- "reference": "88dd16b0cff68eb9167bfc849707d2c40ad91ddc"
+ "reference": "d6365b901b5c287dd41f143033315e2f777e1167"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/thephpleague/oauth1-client/zipball/88dd16b0cff68eb9167bfc849707d2c40ad91ddc",
- "reference": "88dd16b0cff68eb9167bfc849707d2c40ad91ddc",
+ "url": "https://api.github.com/repos/thephpleague/oauth1-client/zipball/d6365b901b5c287dd41f143033315e2f777e1167",
+ "reference": "d6365b901b5c287dd41f143033315e2f777e1167",
"shasum": ""
},
"require": {
@@ -2862,22 +2864,22 @@
],
"support": {
"issues": "https://github.com/thephpleague/oauth1-client/issues",
- "source": "https://github.com/thephpleague/oauth1-client/tree/v1.10.0"
+ "source": "https://github.com/thephpleague/oauth1-client/tree/v1.10.1"
},
- "time": "2021-08-15T23:05:49+00:00"
+ "time": "2022-04-15T14:02:14+00:00"
},
{
"name": "maatwebsite/excel",
- "version": "3.1.38",
+ "version": "3.1.39",
"source": {
"type": "git",
"url": "https://github.com/SpartnerNL/Laravel-Excel.git",
- "reference": "dff132ce4d30b19863f4e84de1613fca99604992"
+ "reference": "5165334de44c6f7788a5818a1d019aa71a43e092"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/SpartnerNL/Laravel-Excel/zipball/dff132ce4d30b19863f4e84de1613fca99604992",
- "reference": "dff132ce4d30b19863f4e84de1613fca99604992",
+ "url": "https://api.github.com/repos/SpartnerNL/Laravel-Excel/zipball/5165334de44c6f7788a5818a1d019aa71a43e092",
+ "reference": "5165334de44c6f7788a5818a1d019aa71a43e092",
"shasum": ""
},
"require": {
@@ -2930,7 +2932,7 @@
],
"support": {
"issues": "https://github.com/SpartnerNL/Laravel-Excel/issues",
- "source": "https://github.com/SpartnerNL/Laravel-Excel/tree/3.1.38"
+ "source": "https://github.com/SpartnerNL/Laravel-Excel/tree/3.1.39"
},
"funding": [
{
@@ -2942,7 +2944,7 @@
"type": "github"
}
],
- "time": "2022-03-24T16:00:29+00:00"
+ "time": "2022-04-23T11:44:18+00:00"
},
{
"name": "maennchen/zipstream-php",
@@ -3174,16 +3176,16 @@
},
{
"name": "monolog/monolog",
- "version": "2.4.0",
+ "version": "2.5.0",
"source": {
"type": "git",
"url": "https://github.com/Seldaek/monolog.git",
- "reference": "d7fd7450628561ba697b7097d86db72662f54aef"
+ "reference": "4192345e260f1d51b365536199744b987e160edc"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/Seldaek/monolog/zipball/d7fd7450628561ba697b7097d86db72662f54aef",
- "reference": "d7fd7450628561ba697b7097d86db72662f54aef",
+ "url": "https://api.github.com/repos/Seldaek/monolog/zipball/4192345e260f1d51b365536199744b987e160edc",
+ "reference": "4192345e260f1d51b365536199744b987e160edc",
"shasum": ""
},
"require": {
@@ -3257,7 +3259,7 @@
],
"support": {
"issues": "https://github.com/Seldaek/monolog/issues",
- "source": "https://github.com/Seldaek/monolog/tree/2.4.0"
+ "source": "https://github.com/Seldaek/monolog/tree/2.5.0"
},
"funding": [
{
@@ -3269,7 +3271,7 @@
"type": "tidelift"
}
],
- "time": "2022-03-14T12:44:37+00:00"
+ "time": "2022-04-08T15:43:54+00:00"
},
{
"name": "myclabs/php-enum",
@@ -3912,16 +3914,16 @@
},
{
"name": "phpoffice/phpspreadsheet",
- "version": "1.22.0",
+ "version": "1.23.0",
"source": {
"type": "git",
"url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
- "reference": "3a9e29b4f386a08a151a33578e80ef1747037a48"
+ "reference": "21e4cf62699eebf007db28775f7d1554e612ed9e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/3a9e29b4f386a08a151a33578e80ef1747037a48",
- "reference": "3a9e29b4f386a08a151a33578e80ef1747037a48",
+ "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/21e4cf62699eebf007db28775f7d1554e612ed9e",
+ "reference": "21e4cf62699eebf007db28775f7d1554e612ed9e",
"shasum": ""
},
"require": {
@@ -3945,7 +3947,7 @@
"php": "^7.3 || ^8.0",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
- "psr/simple-cache": "^1.0"
+ "psr/simple-cache": "^1.0 || ^2.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "dev-master",
@@ -4010,9 +4012,9 @@
],
"support": {
"issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues",
- "source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/1.22.0"
+ "source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/1.23.0"
},
- "time": "2022-02-18T12:57:07+00:00"
+ "time": "2022-04-24T13:53:10+00:00"
},
{
"name": "phpoption/phpoption",
@@ -4196,16 +4198,16 @@
},
{
"name": "psr/cache",
- "version": "2.0.0",
+ "version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/cache.git",
- "reference": "213f9dbc5b9bfbc4f8db86d2838dc968752ce13b"
+ "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/php-fig/cache/zipball/213f9dbc5b9bfbc4f8db86d2838dc968752ce13b",
- "reference": "213f9dbc5b9bfbc4f8db86d2838dc968752ce13b",
+ "url": "https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
+ "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
"shasum": ""
},
"require": {
@@ -4239,9 +4241,9 @@
"psr-6"
],
"support": {
- "source": "https://github.com/php-fig/cache/tree/2.0.0"
+ "source": "https://github.com/php-fig/cache/tree/3.0.0"
},
- "time": "2021-02-03T23:23:37+00:00"
+ "time": "2021-02-03T23:26:27+00:00"
},
{
"name": "psr/container",
@@ -4558,25 +4560,25 @@
},
{
"name": "psr/simple-cache",
- "version": "1.0.1",
+ "version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/simple-cache.git",
- "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b"
+ "reference": "8707bf3cea6f710bf6ef05491234e3ab06f6432a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b",
- "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b",
+ "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/8707bf3cea6f710bf6ef05491234e3ab06f6432a",
+ "reference": "8707bf3cea6f710bf6ef05491234e3ab06f6432a",
"shasum": ""
},
"require": {
- "php": ">=5.3.0"
+ "php": ">=8.0.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.0.x-dev"
+ "dev-master": "2.0.x-dev"
}
},
"autoload": {
@@ -4591,7 +4593,7 @@
"authors": [
{
"name": "PHP-FIG",
- "homepage": "http://www.php-fig.org/"
+ "homepage": "https://www.php-fig.org/"
}
],
"description": "Common interfaces for simple caching",
@@ -4603,9 +4605,9 @@
"simple-cache"
],
"support": {
- "source": "https://github.com/php-fig/simple-cache/tree/master"
+ "source": "https://github.com/php-fig/simple-cache/tree/2.0.0"
},
- "time": "2017-10-23T01:57:42+00:00"
+ "time": "2021-10-29T13:22:09+00:00"
},
{
"name": "psy/psysh",
@@ -5096,16 +5098,16 @@
},
{
"name": "spatie/laravel-model-states",
- "version": "2.2.0",
+ "version": "2.3.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-model-states.git",
- "reference": "7b31a63c0bd8b33d7dc5e12e6b16d2535d9b31a8"
+ "reference": "bfa12486558952eca4d6c81d4dd803b83f065297"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/spatie/laravel-model-states/zipball/7b31a63c0bd8b33d7dc5e12e6b16d2535d9b31a8",
- "reference": "7b31a63c0bd8b33d7dc5e12e6b16d2535d9b31a8",
+ "url": "https://api.github.com/repos/spatie/laravel-model-states/zipball/bfa12486558952eca4d6c81d4dd803b83f065297",
+ "reference": "bfa12486558952eca4d6c81d4dd803b83f065297",
"shasum": ""
},
"require": {
@@ -5154,7 +5156,7 @@
"state"
],
"support": {
- "source": "https://github.com/spatie/laravel-model-states/tree/2.2.0"
+ "source": "https://github.com/spatie/laravel-model-states/tree/2.3.0"
},
"funding": [
{
@@ -5166,7 +5168,7 @@
"type": "github"
}
],
- "time": "2022-03-03T11:22:16+00:00"
+ "time": "2022-04-21T12:09:37+00:00"
},
{
"name": "spatie/laravel-package-tools",
@@ -7650,21 +7652,21 @@
"packages-dev": [
{
"name": "blumilksoftware/codestyle",
- "version": "v1.0.1",
+ "version": "v1.1.0",
"source": {
"type": "git",
"url": "https://github.com/blumilksoftware/codestyle.git",
- "reference": "e86ebcd5175bc435d9c8d4f83bf201a6f5a9fc60"
+ "reference": "3f2248859562afe7d7b2b16aa25e83dc73236fcc"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/blumilksoftware/codestyle/zipball/e86ebcd5175bc435d9c8d4f83bf201a6f5a9fc60",
- "reference": "e86ebcd5175bc435d9c8d4f83bf201a6f5a9fc60",
+ "url": "https://api.github.com/repos/blumilksoftware/codestyle/zipball/3f2248859562afe7d7b2b16aa25e83dc73236fcc",
+ "reference": "3f2248859562afe7d7b2b16aa25e83dc73236fcc",
"shasum": ""
},
"require": {
"friendsofphp/php-cs-fixer": "^3.8.0",
- "kubawerlos/php-cs-fixer-custom-fixers": "^3.7",
+ "kubawerlos/php-cs-fixer-custom-fixers": "^3.10.1",
"php": "^8.0"
},
"require-dev": {
@@ -7672,6 +7674,9 @@
"phpunit/phpunit": "^9.5",
"symfony/console": "^6.0"
},
+ "bin": [
+ "bin/codestyle"
+ ],
"type": "library",
"autoload": {
"psr-4": {
@@ -7691,9 +7696,9 @@
"description": "Blumilk codestyle configurator",
"support": {
"issues": "https://github.com/blumilksoftware/codestyle/issues",
- "source": "https://github.com/blumilksoftware/codestyle/tree/v1.0.1"
+ "source": "https://github.com/blumilksoftware/codestyle/tree/v1.1.0"
},
- "time": "2022-04-04T06:25:21+00:00"
+ "time": "2022-04-25T06:04:51+00:00"
},
{
"name": "composer/pcre",
@@ -8383,16 +8388,16 @@
},
{
"name": "laravel/dusk",
- "version": "v6.22.3",
+ "version": "v6.23.0",
"source": {
"type": "git",
"url": "https://github.com/laravel/dusk.git",
- "reference": "f42844d5a7eace45d199d276bb2bc23fec788256"
+ "reference": "98901d49176977c96330fd8c2ca5460eee50a246"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/laravel/dusk/zipball/f42844d5a7eace45d199d276bb2bc23fec788256",
- "reference": "f42844d5a7eace45d199d276bb2bc23fec788256",
+ "url": "https://api.github.com/repos/laravel/dusk/zipball/98901d49176977c96330fd8c2ca5460eee50a246",
+ "reference": "98901d49176977c96330fd8c2ca5460eee50a246",
"shasum": ""
},
"require": {
@@ -8450,9 +8455,9 @@
],
"support": {
"issues": "https://github.com/laravel/dusk/issues",
- "source": "https://github.com/laravel/dusk/tree/v6.22.3"
+ "source": "https://github.com/laravel/dusk/tree/v6.23.0"
},
- "time": "2022-04-04T15:12:34+00:00"
+ "time": "2022-04-11T18:55:12+00:00"
},
{
"name": "mockery/mockery",
@@ -10640,16 +10645,16 @@
},
{
"name": "spatie/ignition",
- "version": "1.2.7",
+ "version": "1.2.9",
"source": {
"type": "git",
"url": "https://github.com/spatie/ignition.git",
- "reference": "2f059cf42b48f7c522efbba1c05ad59fc2c1a3f2"
+ "reference": "db25202fab2d5c14613b8914a1bb374998bbf870"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/spatie/ignition/zipball/2f059cf42b48f7c522efbba1c05ad59fc2c1a3f2",
- "reference": "2f059cf42b48f7c522efbba1c05ad59fc2c1a3f2",
+ "url": "https://api.github.com/repos/spatie/ignition/zipball/db25202fab2d5c14613b8914a1bb374998bbf870",
+ "reference": "db25202fab2d5c14613b8914a1bb374998bbf870",
"shasum": ""
},
"require": {
@@ -10706,20 +10711,20 @@
"type": "github"
}
],
- "time": "2022-03-29T08:48:34+00:00"
+ "time": "2022-04-23T20:37:21+00:00"
},
{
"name": "spatie/laravel-ignition",
- "version": "1.2.0",
+ "version": "1.2.2",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-ignition.git",
- "reference": "2b54c8c66f2d280f25e15064ebe3d5e3eda19820"
+ "reference": "924d1ae878874ad0bb49f63b69a9af759a34ee78"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/spatie/laravel-ignition/zipball/2b54c8c66f2d280f25e15064ebe3d5e3eda19820",
- "reference": "2b54c8c66f2d280f25e15064ebe3d5e3eda19820",
+ "url": "https://api.github.com/repos/spatie/laravel-ignition/zipball/924d1ae878874ad0bb49f63b69a9af759a34ee78",
+ "reference": "924d1ae878874ad0bb49f63b69a9af759a34ee78",
"shasum": ""
},
"require": {
@@ -10796,7 +10801,7 @@
"type": "github"
}
],
- "time": "2022-04-01T21:01:58+00:00"
+ "time": "2022-04-14T18:04:51+00:00"
},
{
"name": "symfony/filesystem",
@@ -11052,5 +11057,5 @@
"ext-redis": "*"
},
"platform-dev": [],
- "plugin-api-version": "2.2.0"
+ "plugin-api-version": "2.1.0"
}
--
2.52.0
From 54ca728880d088e53618dfc2002ff399084d3a43 Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Mon, 25 Apr 2022 13:56:36 +0200
Subject: [PATCH 10/18] cs fix
---
app/Architecture/ExceptionHandler.php | 1 -
.../VacationRequestWaitsForApprovalNotification.php | 1 -
app/Domain/Validation/Rules/VacationRequestRule.php | 1 +
app/Eloquent/Models/Holiday.php | 1 -
app/Eloquent/Models/Profile.php | 2 --
app/Eloquent/Models/User.php | 3 ---
app/Eloquent/Models/VacationRequest.php | 1 -
app/Eloquent/Models/VacationRequestActivity.php | 1 -
app/Infrastructure/Http/Kernel.php | 2 --
tests/Unit/SendDailySummaryToSlackTest.php | 2 +-
10 files changed, 2 insertions(+), 13 deletions(-)
diff --git a/app/Architecture/ExceptionHandler.php b/app/Architecture/ExceptionHandler.php
index b286bd1..a43fcab 100644
--- a/app/Architecture/ExceptionHandler.php
+++ b/app/Architecture/ExceptionHandler.php
@@ -16,7 +16,6 @@ class ExceptionHandler extends Handler
"password",
"password_confirmation",
];
-
protected array $handleByInertia = [
Response::HTTP_INTERNAL_SERVER_ERROR,
Response::HTTP_SERVICE_UNAVAILABLE,
diff --git a/app/Domain/Notifications/VacationRequestWaitsForApprovalNotification.php b/app/Domain/Notifications/VacationRequestWaitsForApprovalNotification.php
index 3f07a1d..4496317 100644
--- a/app/Domain/Notifications/VacationRequestWaitsForApprovalNotification.php
+++ b/app/Domain/Notifications/VacationRequestWaitsForApprovalNotification.php
@@ -109,4 +109,3 @@ class VacationRequestWaitsForApprovalNotification extends Notification
]);
}
}
-
diff --git a/app/Domain/Validation/Rules/VacationRequestRule.php b/app/Domain/Validation/Rules/VacationRequestRule.php
index 07af8d2..f7e3c6d 100644
--- a/app/Domain/Validation/Rules/VacationRequestRule.php
+++ b/app/Domain/Validation/Rules/VacationRequestRule.php
@@ -9,5 +9,6 @@ use Toby\Eloquent\Models\VacationRequest;
interface VacationRequestRule
{
public function check(VacationRequest $vacationRequest): bool;
+
public function errorMessage(): string;
}
diff --git a/app/Eloquent/Models/Holiday.php b/app/Eloquent/Models/Holiday.php
index be8ae49..466065c 100644
--- a/app/Eloquent/Models/Holiday.php
+++ b/app/Eloquent/Models/Holiday.php
@@ -21,7 +21,6 @@ class Holiday extends Model
use HasFactory;
protected $guarded = [];
-
protected $casts = [
"date" => "date",
];
diff --git a/app/Eloquent/Models/Profile.php b/app/Eloquent/Models/Profile.php
index 84bbd7c..a64b272 100644
--- a/app/Eloquent/Models/Profile.php
+++ b/app/Eloquent/Models/Profile.php
@@ -27,9 +27,7 @@ class Profile extends Model
use HasAvatar;
protected $primaryKey = "user_id";
-
protected $guarded = [];
-
protected $casts = [
"employment_form" => EmploymentForm::class,
"employment_date" => "date",
diff --git a/app/Eloquent/Models/User.php b/app/Eloquent/Models/User.php
index 2518c95..51689d0 100644
--- a/app/Eloquent/Models/User.php
+++ b/app/Eloquent/Models/User.php
@@ -33,18 +33,15 @@ class User extends Authenticatable
use SoftDeletes;
protected $guarded = [];
-
protected $casts = [
"role" => Role::class,
"last_active_at" => "datetime",
"employment_form" => EmploymentForm::class,
"employment_date" => "date",
];
-
protected $hidden = [
"remember_token",
];
-
protected $with = [
"profile",
];
diff --git a/app/Eloquent/Models/VacationRequest.php b/app/Eloquent/Models/VacationRequest.php
index 46bd084..97f94b7 100644
--- a/app/Eloquent/Models/VacationRequest.php
+++ b/app/Eloquent/Models/VacationRequest.php
@@ -41,7 +41,6 @@ class VacationRequest extends Model
use HasStates;
protected $guarded = [];
-
protected $casts = [
"type" => VacationType::class,
"state" => VacationRequestState::class,
diff --git a/app/Eloquent/Models/VacationRequestActivity.php b/app/Eloquent/Models/VacationRequestActivity.php
index 942bb96..2064e9e 100644
--- a/app/Eloquent/Models/VacationRequestActivity.php
+++ b/app/Eloquent/Models/VacationRequestActivity.php
@@ -22,7 +22,6 @@ class VacationRequestActivity extends Model
use HasFactory;
protected $guarded = [];
-
protected $casts = [
"from" => VacationRequestState::class,
"to" => VacationRequestState::class,
diff --git a/app/Infrastructure/Http/Kernel.php b/app/Infrastructure/Http/Kernel.php
index 5c6a238..5b1e42f 100644
--- a/app/Infrastructure/Http/Kernel.php
+++ b/app/Infrastructure/Http/Kernel.php
@@ -40,7 +40,6 @@ class Kernel extends HttpKernel
TrimStrings::class,
ConvertEmptyStringsToNull::class,
];
-
protected $middlewareGroups = [
"web" => [
EncryptCookies::class,
@@ -58,7 +57,6 @@ class Kernel extends HttpKernel
SubstituteBindings::class,
],
];
-
protected $routeMiddleware = [
"auth" => Authenticate::class,
"auth.basic" => AuthenticateWithBasicAuth::class,
diff --git a/tests/Unit/SendDailySummaryToSlackTest.php b/tests/Unit/SendDailySummaryToSlackTest.php
index 75a2c05..96014e2 100644
--- a/tests/Unit/SendDailySummaryToSlackTest.php
+++ b/tests/Unit/SendDailySummaryToSlackTest.php
@@ -79,4 +79,4 @@ class SendDailySummaryToSlackTest extends TestCase
Http::assertSentCount(1);
}
-}
\ No newline at end of file
+}
--
2.52.0
From ae1f6e066b0d0a5680e616df6a69c0ac038e645a Mon Sep 17 00:00:00 2001
From: EwelinaLasowy
Date: Mon, 25 Apr 2022 15:23:42 +0200
Subject: [PATCH 11/18] #116 - fix
---
app/Domain/Slack/Handlers/DailySummary.php | 2 +-
app/Domain/Slack/Handlers/KeyList.php | 2 +-
app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php | 2 +-
resources/lang/pl.json | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/app/Domain/Slack/Handlers/DailySummary.php b/app/Domain/Slack/Handlers/DailySummary.php
index 07dd420..64895fe 100644
--- a/app/Domain/Slack/Handlers/DailySummary.php
+++ b/app/Domain/Slack/Handlers/DailySummary.php
@@ -44,7 +44,7 @@ class DailySummary extends SignatureHandler
$birthdayAttachment = Attachment::create()
->setTitle("Urodziny :birthday:")
- ->setColor("#3C5F97")
+ ->setColor("#3c5f97")
->setText($birthdays->isNotEmpty() ? $birthdays->implode("\n") : "Dzisiaj nikt nie ma urodzin :cry:");
return $this->respondToSlack("Podsumowanie dla dnia {$now->toDisplayString()}")
diff --git a/app/Domain/Slack/Handlers/KeyList.php b/app/Domain/Slack/Handlers/KeyList.php
index 7a8adef..9d71bc1 100644
--- a/app/Domain/Slack/Handlers/KeyList.php
+++ b/app/Domain/Slack/Handlers/KeyList.php
@@ -24,7 +24,7 @@ class KeyList extends SignatureHandler
return $this->respondToSlack("Lista kluczy :key:")
->withAttachment(
Attachment::create()
- ->setColor("#3C5F97")
+ ->setColor("#3c5f97")
->setText($keys->isNotEmpty() ? $keys->implode("\n") : "Nie ma żadnych kluczy w tobym"),
);
}
diff --git a/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php b/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
index c487c1f..1630a5b 100644
--- a/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
+++ b/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
@@ -48,7 +48,7 @@ class SendDailySummaryToSlack extends Command
$birthdayAttachment = Attachment::create()
->setTitle("Urodziny :birthday:")
- ->setColor("#3C5F97")
+ ->setColor("#3c5f97")
->setText($birthdays->isNotEmpty() ? $birthdays->implode("\n") : "Dzisiaj nikt nie ma urodzin :cry:");
$baseUrl = config("services.slack.url");
diff --git a/resources/lang/pl.json b/resources/lang/pl.json
index 192ce08..8485773 100644
--- a/resources/lang/pl.json
+++ b/resources/lang/pl.json
@@ -56,7 +56,7 @@
"All rights reserved.": "Wszelkie prawa zastrzeżone",
"Show vacation request": "Pokaż wniosek",
"Vacation request :title has been created" : "Wniosek :title został utworzony",
- "The vacation request :title from user :requester has been created sucessfully.": "Wniosek :title użytkownika :requester został utworzony pomyślnie.",
+ "The vacation request :title from user :requester has been created successfully.": "Wniosek :title użytkownika :requester został utworzony pomyślnie.",
"Vacation type: :type": "Rodzaj wniosku: :type",
"From :from to :to (number of days: :days)": "Od :from do :to (liczba dni: :days)",
"Click here for details": "Kliknij, aby zobaczyć szczegóły",
--
2.52.0
From 4ecabeba0d59fe7bfcc1c2458f0b25b65ceda3bf Mon Sep 17 00:00:00 2001
From: EwelinaLasowy
Date: Tue, 26 Apr 2022 08:49:32 +0200
Subject: [PATCH 12/18] #116 - changed home-office icon
---
app/Domain/Slack/Handlers/DailySummary.php | 4 ++--
.../Console/Commands/SendDailySummaryToSlack.php | 2 +-
resources/js/Composables/vacationTypeInfo.js | 12 ++++++------
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/app/Domain/Slack/Handlers/DailySummary.php b/app/Domain/Slack/Handlers/DailySummary.php
index 64895fe..c69334f 100644
--- a/app/Domain/Slack/Handlers/DailySummary.php
+++ b/app/Domain/Slack/Handlers/DailySummary.php
@@ -33,13 +33,13 @@ class DailySummary extends SignatureHandler
->map(fn(User $user) => $user->profile->full_name);
$absencesAttachment = Attachment::create()
- ->setTitle("Nieobecności :palm_tree:")
+ ->setTitle("Nieobecności :sunny:")
->setColor("#eab308")
->setText($absences->isNotEmpty() ? $absences->implode("\n") : "Wszyscy dzisiaj pracują :muscle:");
$remoteAttachment = Attachment::create()
->setTitle("Praca zdalna :house_with_garden:")
- ->setColor("#d946ef")
+ ->setColor("#527aba")
->setText($remoteDays->isNotEmpty() ? $remoteDays->implode("\n") : "Wszyscy dzisiaj są w biurze :boom:");
$birthdayAttachment = Attachment::create()
diff --git a/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php b/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
index 1630a5b..2d57e98 100644
--- a/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
+++ b/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
@@ -43,7 +43,7 @@ class SendDailySummaryToSlack extends Command
$remoteAttachment = Attachment::create()
->setTitle("Praca zdalna :house_with_garden:")
- ->setColor("#d946ef")
+ ->setColor("#527aba")
->setText($remoteDays->isNotEmpty() ? $remoteDays->implode("\n") : "Wszyscy dzisiaj są w biurze :boom:");
$birthdayAttachment = Attachment::create()
diff --git a/resources/js/Composables/vacationTypeInfo.js b/resources/js/Composables/vacationTypeInfo.js
index 3ed7591..65ec983 100644
--- a/resources/js/Composables/vacationTypeInfo.js
+++ b/resources/js/Composables/vacationTypeInfo.js
@@ -8,7 +8,7 @@ import HandHeartOutlineIcon from 'vue-material-design-icons/HandHeartOutline.vue
import CalendarCheckIcon from 'vue-material-design-icons/CalendarCheck.vue'
import MedicalBagIcon from 'vue-material-design-icons/MedicalBag.vue'
import CalendarRemoveIcon from 'vue-material-design-icons/CalendarRemove.vue'
-import LaptopIcon from 'vue-material-design-icons/Laptop.vue'
+import HomeCityIcon from 'vue-material-design-icons/HomeCity.vue'
const types = [
{
@@ -43,8 +43,8 @@ const types = [
text: 'Urlop szkoleniowy',
value: 'training_vacation',
icon: HumanMaleBoardIcon,
- color: 'text-blumilk-500',
- border: 'border-blumilk-500',
+ color: 'text-indigo-500',
+ border: 'border-indigo-500',
},
{
text: 'Urlop bezpłatny',
@@ -84,9 +84,9 @@ const types = [
{
text: 'Praca zdalna',
value: 'home_office',
- icon: LaptopIcon,
- color: 'text-fuchsia-500',
- border: 'border-fuchsia-500',
+ icon: HomeCityIcon,
+ color: 'text-blumilk-500',
+ border: 'border-blumilk-500',
},
]
--
2.52.0
From cbfc2b0c45921fe3c97bc8283557157cdfecbe16 Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Tue, 26 Apr 2022 10:35:11 +0200
Subject: [PATCH 13/18] Apply suggestions from code review
Co-authored-by: Krzysztof Rewak
---
app/Domain/DailySummaryRetriever.php | 4 ++--
app/Domain/Slack/Handlers/DailySummary.php | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/app/Domain/DailySummaryRetriever.php b/app/Domain/DailySummaryRetriever.php
index 465cdb4..4049738 100644
--- a/app/Domain/DailySummaryRetriever.php
+++ b/app/Domain/DailySummaryRetriever.php
@@ -22,7 +22,7 @@ class DailySummaryRetriever
->with(["user", "vacationRequest"])
->whereDate("date", $date)
->approved()
- ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => $this->configRetriever->isVacation($type)))
+ ->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
->get();
}
@@ -32,7 +32,7 @@ class DailySummaryRetriever
->with(["user", "vacationRequest"])
->whereDate("date", $date)
->approved()
- ->whereTypes(VacationType::all()->filter(fn(VacationType $type) => !$this->configRetriever->isVacation($type)))
+ ->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
->get();
}
diff --git a/app/Domain/Slack/Handlers/DailySummary.php b/app/Domain/Slack/Handlers/DailySummary.php
index c69334f..8a33f80 100644
--- a/app/Domain/Slack/Handlers/DailySummary.php
+++ b/app/Domain/Slack/Handlers/DailySummary.php
@@ -24,13 +24,13 @@ class DailySummary extends SignatureHandler
$now = Carbon::today();
$absences = $dailySummaryRetriever->getAbsences($now)
- ->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
+ ->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name);
$remoteDays = $dailySummaryRetriever->getRemoteDays($now)
- ->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
+ ->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name);
$birthdays = $dailySummaryRetriever->getBirthdays($now)
- ->map(fn(User $user) => $user->profile->full_name);
+ ->map(fn(User $user): string => $user->profile->full_name);
$absencesAttachment = Attachment::create()
->setTitle("Nieobecności :sunny:")
--
2.52.0
From 7f5e462e4db0b22671add4ef0a3934b90cf05e82 Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Tue, 26 Apr 2022 12:46:18 +0200
Subject: [PATCH 14/18] #116 - cr fix
---
.../Providers/AppServiceProvider.php | 6 +-
.../Providers/AuthServiceProvider.php | 10 +--
.../Providers/RouteServiceProvider.php | 2 +-
app/Domain/CalendarGenerator.php | 2 +-
app/Domain/DailySummaryRetriever.php | 8 ++-
app/Domain/Enums/EmploymentForm.php | 2 +-
app/Domain/Enums/Role.php | 2 +-
app/Domain/Enums/VacationType.php | 2 +-
app/Domain/Notifications/Channels.php | 11 +++
.../KeyHasBeenGivenNotification.php | 4 +-
.../KeyHasBeenTakenNotification.php | 4 +-
app/Domain/Notifications/Notifiable.php | 10 +++
.../VacationRequestCreatedNotification.php | 2 +-
...cationRequestStatusChangedNotification.php | 2 +-
...ionRequestWaitsForApprovalNotification.php | 2 +-
app/Domain/PolishHolidaysRetriever.php | 2 +-
app/Domain/Slack/Channels/SlackApiChannel.php | 25 -------
app/Domain/Slack/Handlers/DailySummary.php | 55 ---------------
app/Domain/TimesheetExport.php | 2 +-
app/Domain/TimesheetPerUserSheet.php | 4 +-
app/Domain/UserVacationStatsRetriever.php | 8 +--
.../Rules/DoesNotExceedLimitRule.php | 2 +-
.../Rules/VacationTypeCanBeSelected.php | 2 +-
app/Eloquent/Helpers/YearPeriodRetriever.php | 2 +-
app/Eloquent/Models/Key.php | 3 +-
app/Eloquent/Models/User.php | 5 +-
.../Commands/SendDailySummaryToSlack.php | 68 +++++++++----------
.../Api/CalculateVacationDaysController.php | 2 +-
.../GetAvailableVacationTypesController.php | 4 +-
.../Http/Controllers/TimesheetController.php | 6 +-
.../Controllers/VacationLimitController.php | 2 +-
.../Http/Middleware/HandleInertiaRequests.php | 4 +-
.../Slack/Channels/SlackApiChannel.php | 36 ++++++++++
.../Slack/Controller.php | 11 +--
.../Slack/Elements/AbsencesAttachment.php | 22 ++++++
.../Slack/Elements/Attachment.php | 12 ++++
.../Slack/Elements/BirthdaysAttachment.php | 22 ++++++
.../Slack/Elements/KeysAttachment.php | 21 ++++++
.../Slack/Elements/ListAttachment.php | 36 ++++++++++
.../Slack/Elements/RemotesAttachment.php | 22 ++++++
.../Exceptions/UserNotFoundException.php | 2 +-
.../Slack/Handlers/CatchAll.php | 8 +--
.../Slack/Handlers/DailySummary.php | 36 ++++++++++
.../Slack/Handlers/GiveKeysTo.php | 8 +--
.../Slack/Handlers/Help.php | 10 +--
.../Slack/Handlers/HomeOffice.php | 4 +-
.../Slack/Handlers/KeyList.php | 13 ++--
.../Slack/Handlers/SignatureHandler.php | 2 +-
.../Slack/Handlers/TakeKeysFrom.php | 8 +--
.../Slack/Rules/SlackUserExistsRule.php | 2 +-
.../Slack/Traits/FindsUserBySlackId.php | 4 +-
.../Slack/Traits/ListsHandlers.php | 11 +--
config/laravel-slack-slash-command.php | 15 ++--
routes/api.php | 2 +-
54 files changed, 361 insertions(+), 211 deletions(-)
create mode 100644 app/Domain/Notifications/Channels.php
create mode 100644 app/Domain/Notifications/Notifiable.php
delete mode 100644 app/Domain/Slack/Channels/SlackApiChannel.php
delete mode 100644 app/Domain/Slack/Handlers/DailySummary.php
create mode 100644 app/Infrastructure/Slack/Channels/SlackApiChannel.php
rename app/{Domain => Infrastructure}/Slack/Controller.php (80%)
create mode 100644 app/Infrastructure/Slack/Elements/AbsencesAttachment.php
create mode 100644 app/Infrastructure/Slack/Elements/Attachment.php
create mode 100644 app/Infrastructure/Slack/Elements/BirthdaysAttachment.php
create mode 100644 app/Infrastructure/Slack/Elements/KeysAttachment.php
create mode 100644 app/Infrastructure/Slack/Elements/ListAttachment.php
create mode 100644 app/Infrastructure/Slack/Elements/RemotesAttachment.php
rename app/{Domain => Infrastructure}/Slack/Exceptions/UserNotFoundException.php (77%)
rename app/{Domain => Infrastructure}/Slack/Handlers/CatchAll.php (73%)
create mode 100644 app/Infrastructure/Slack/Handlers/DailySummary.php
rename app/{Domain => Infrastructure}/Slack/Handlers/GiveKeysTo.php (88%)
rename app/{Domain => Infrastructure}/Slack/Handlers/Help.php (68%)
rename app/{Domain => Infrastructure}/Slack/Handlers/HomeOffice.php (91%)
rename app/{Domain => Infrastructure}/Slack/Handlers/KeyList.php (51%)
rename app/{Domain => Infrastructure}/Slack/Handlers/SignatureHandler.php (91%)
rename app/{Domain => Infrastructure}/Slack/Handlers/TakeKeysFrom.php (88%)
rename app/{Domain => Infrastructure}/Slack/Rules/SlackUserExistsRule.php (91%)
rename app/{Domain => Infrastructure}/Slack/Traits/FindsUserBySlackId.php (89%)
rename app/{Domain => Infrastructure}/Slack/Traits/ListsHandlers.php (74%)
diff --git a/app/Architecture/Providers/AppServiceProvider.php b/app/Architecture/Providers/AppServiceProvider.php
index bd8659f..fbfe920 100644
--- a/app/Architecture/Providers/AppServiceProvider.php
+++ b/app/Architecture/Providers/AppServiceProvider.php
@@ -9,19 +9,19 @@ use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\ServiceProvider;
-use Toby\Domain\Slack\Channels\SlackApiChannel;
+use Toby\Infrastructure\Slack\Channels\SlackApiChannel;
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
Notification::resolved(function (ChannelManager $service): void {
- $service->extend("slack", fn(Application $app) => $app->make(SlackApiChannel::class));
+ $service->extend("slack", fn(Application $app): SlackApiChannel => $app->make(SlackApiChannel::class));
});
}
public function boot(): void
{
- Carbon::macro("toDisplayString", fn() => $this->translatedFormat("d.m.Y"));
+ Carbon::macro("toDisplayString", fn(): string => $this->translatedFormat("d.m.Y"));
}
}
diff --git a/app/Architecture/Providers/AuthServiceProvider.php b/app/Architecture/Providers/AuthServiceProvider.php
index cb5b112..62d21c7 100644
--- a/app/Architecture/Providers/AuthServiceProvider.php
+++ b/app/Architecture/Providers/AuthServiceProvider.php
@@ -30,10 +30,10 @@ class AuthServiceProvider extends ServiceProvider
}
});
- Gate::define("manageUsers", fn(User $user) => $user->role === Role::AdministrativeApprover);
- Gate::define("manageHolidays", fn(User $user) => $user->role === Role::AdministrativeApprover);
- Gate::define("manageVacationLimits", fn(User $user) => $user->role === Role::AdministrativeApprover);
- Gate::define("generateTimesheet", fn(User $user) => $user->role === Role::AdministrativeApprover);
- Gate::define("listMonthlyUsage", fn(User $user) => $user->role === Role::AdministrativeApprover);
+ Gate::define("manageUsers", fn(User $user): bool => $user->role === Role::AdministrativeApprover);
+ Gate::define("manageHolidays", fn(User $user): bool => $user->role === Role::AdministrativeApprover);
+ Gate::define("manageVacationLimits", fn(User $user): bool => $user->role === Role::AdministrativeApprover);
+ Gate::define("generateTimesheet", fn(User $user): bool => $user->role === Role::AdministrativeApprover);
+ Gate::define("listMonthlyUsage", fn(User $user): bool => $user->role === Role::AdministrativeApprover);
}
}
diff --git a/app/Architecture/Providers/RouteServiceProvider.php b/app/Architecture/Providers/RouteServiceProvider.php
index 2412290..ffd9a41 100644
--- a/app/Architecture/Providers/RouteServiceProvider.php
+++ b/app/Architecture/Providers/RouteServiceProvider.php
@@ -28,6 +28,6 @@ class RouteServiceProvider extends ServiceProvider
protected function configureRateLimiting(): void
{
- RateLimiter::for("api", fn(Request $request) => Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip()));
+ RateLimiter::for("api", fn(Request $request): Limit => Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip()));
}
}
diff --git a/app/Domain/CalendarGenerator.php b/app/Domain/CalendarGenerator.php
index 30d42b7..b1c6c0f 100644
--- a/app/Domain/CalendarGenerator.php
+++ b/app/Domain/CalendarGenerator.php
@@ -57,6 +57,6 @@ class CalendarGenerator
->approved()
->with("vacationRequest")
->get()
- ->groupBy(fn(Vacation $vacation) => $vacation->date->toDateString());
+ ->groupBy(fn(Vacation $vacation): string => $vacation->date->toDateString());
}
}
diff --git a/app/Domain/DailySummaryRetriever.php b/app/Domain/DailySummaryRetriever.php
index 4049738..a2482ef 100644
--- a/app/Domain/DailySummaryRetriever.php
+++ b/app/Domain/DailySummaryRetriever.php
@@ -22,7 +22,9 @@ class DailySummaryRetriever
->with(["user", "vacationRequest"])
->whereDate("date", $date)
->approved()
- ->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
+ ->whereTypes(
+ VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)),
+ )
->get();
}
@@ -32,7 +34,9 @@ class DailySummaryRetriever
->with(["user", "vacationRequest"])
->whereDate("date", $date)
->approved()
- ->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
+ ->whereTypes(
+ VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)),
+ )
->get();
}
diff --git a/app/Domain/Enums/EmploymentForm.php b/app/Domain/Enums/EmploymentForm.php
index daf671d..c3d1767 100644
--- a/app/Domain/Enums/EmploymentForm.php
+++ b/app/Domain/Enums/EmploymentForm.php
@@ -21,7 +21,7 @@ enum EmploymentForm: string
$cases = collect(EmploymentForm::cases());
return $cases->map(
- fn(EmploymentForm $enum) => [
+ fn(EmploymentForm $enum): array => [
"label" => $enum->label(),
"value" => $enum->value,
],
diff --git a/app/Domain/Enums/Role.php b/app/Domain/Enums/Role.php
index f4be8b9..bd2485c 100644
--- a/app/Domain/Enums/Role.php
+++ b/app/Domain/Enums/Role.php
@@ -21,7 +21,7 @@ enum Role: string
$cases = collect(Role::cases());
return $cases->map(
- fn(Role $enum) => [
+ fn(Role $enum): array => [
"label" => $enum->label(),
"value" => $enum->value,
],
diff --git a/app/Domain/Enums/VacationType.php b/app/Domain/Enums/VacationType.php
index a93ca3d..7940107 100644
--- a/app/Domain/Enums/VacationType.php
+++ b/app/Domain/Enums/VacationType.php
@@ -30,7 +30,7 @@ enum VacationType: string
$cases = VacationType::all();
return $cases->map(
- fn(VacationType $enum) => [
+ fn(VacationType $enum): array => [
"label" => $enum->label(),
"value" => $enum->value,
],
diff --git a/app/Domain/Notifications/Channels.php b/app/Domain/Notifications/Channels.php
new file mode 100644
index 0000000..e9c23e2
--- /dev/null
+++ b/app/Domain/Notifications/Channels.php
@@ -0,0 +1,11 @@
+ $this->getName($this->sender),
diff --git a/app/Domain/Notifications/KeyHasBeenTakenNotification.php b/app/Domain/Notifications/KeyHasBeenTakenNotification.php
index d22467d..71e8b7b 100644
--- a/app/Domain/Notifications/KeyHasBeenTakenNotification.php
+++ b/app/Domain/Notifications/KeyHasBeenTakenNotification.php
@@ -19,10 +19,10 @@ class KeyHasBeenTakenNotification extends Notification
public function via(): array
{
- return ["slack"];
+ return [Channels::SLACK];
}
- public function toSlack($notifiable): string
+ public function toSlack(Notifiable $notifiable): string
{
return __(":recipient takes key no :key from :sender", [
"recipient" => $this->getName($this->recipient),
diff --git a/app/Domain/Notifications/Notifiable.php b/app/Domain/Notifications/Notifiable.php
new file mode 100644
index 0000000..b23e554
--- /dev/null
+++ b/app/Domain/Notifications/Notifiable.php
@@ -0,0 +1,10 @@
+map(fn(Holiday $holiday) => [
+ return collect($holidays)->map(fn(Holiday $holiday): array => [
"name" => $holiday->getName([static::LANG_KEY]),
"date" => Carbon::createFromTimestamp($holiday->getTimestamp()),
])->values();
diff --git a/app/Domain/Slack/Channels/SlackApiChannel.php b/app/Domain/Slack/Channels/SlackApiChannel.php
deleted file mode 100644
index 2741e09..0000000
--- a/app/Domain/Slack/Channels/SlackApiChannel.php
+++ /dev/null
@@ -1,25 +0,0 @@
-routeNotificationFor("slack", $notification);
-
- return Http::withToken(config("services.slack.client_token"))
- ->post($url, [
- "channel" => $channel,
- "text" => $notification->toSlack($notifiable),
- ]);
- }
-}
diff --git a/app/Domain/Slack/Handlers/DailySummary.php b/app/Domain/Slack/Handlers/DailySummary.php
deleted file mode 100644
index 8a33f80..0000000
--- a/app/Domain/Slack/Handlers/DailySummary.php
+++ /dev/null
@@ -1,55 +0,0 @@
-make(DailySummaryRetriever::class);
-
- $now = Carbon::today();
-
- $absences = $dailySummaryRetriever->getAbsences($now)
- ->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name);
-
- $remoteDays = $dailySummaryRetriever->getRemoteDays($now)
- ->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name);
-
- $birthdays = $dailySummaryRetriever->getBirthdays($now)
- ->map(fn(User $user): string => $user->profile->full_name);
-
- $absencesAttachment = Attachment::create()
- ->setTitle("Nieobecności :sunny:")
- ->setColor("#eab308")
- ->setText($absences->isNotEmpty() ? $absences->implode("\n") : "Wszyscy dzisiaj pracują :muscle:");
-
- $remoteAttachment = Attachment::create()
- ->setTitle("Praca zdalna :house_with_garden:")
- ->setColor("#527aba")
- ->setText($remoteDays->isNotEmpty() ? $remoteDays->implode("\n") : "Wszyscy dzisiaj są w biurze :boom:");
-
- $birthdayAttachment = Attachment::create()
- ->setTitle("Urodziny :birthday:")
- ->setColor("#3c5f97")
- ->setText($birthdays->isNotEmpty() ? $birthdays->implode("\n") : "Dzisiaj nikt nie ma urodzin :cry:");
-
- return $this->respondToSlack("Podsumowanie dla dnia {$now->toDisplayString()}")
- ->withAttachment($absencesAttachment)
- ->withAttachment($remoteAttachment)
- ->withAttachment($birthdayAttachment);
- }
-}
diff --git a/app/Domain/TimesheetExport.php b/app/Domain/TimesheetExport.php
index 8d764d0..47c258d 100644
--- a/app/Domain/TimesheetExport.php
+++ b/app/Domain/TimesheetExport.php
@@ -18,7 +18,7 @@ class TimesheetExport implements WithMultipleSheets
public function sheets(): array
{
return $this->users
- ->map(fn(User $user) => new TimesheetPerUserSheet($user, $this->month, $this->types))
+ ->map(fn(User $user): TimesheetPerUserSheet => new TimesheetPerUserSheet($user, $this->month, $this->types))
->toArray();
}
diff --git a/app/Domain/TimesheetPerUserSheet.php b/app/Domain/TimesheetPerUserSheet.php
index 8547a5e..891ca34 100644
--- a/app/Domain/TimesheetPerUserSheet.php
+++ b/app/Domain/TimesheetPerUserSheet.php
@@ -193,8 +193,8 @@ class TimesheetPerUserSheet implements WithTitle, WithHeadings, WithEvents, With
->get()
->groupBy(
[
- fn(Vacation $vacation) => $vacation->date->toDateString(),
- fn(Vacation $vacation) => $vacation->vacationRequest->type->value,
+ fn(Vacation $vacation): string => $vacation->date->toDateString(),
+ fn(Vacation $vacation): string => $vacation->vacationRequest->type->value,
],
);
}
diff --git a/app/Domain/UserVacationStatsRetriever.php b/app/Domain/UserVacationStatsRetriever.php
index 7c11a29..42fdf50 100644
--- a/app/Domain/UserVacationStatsRetriever.php
+++ b/app/Domain/UserVacationStatsRetriever.php
@@ -42,8 +42,8 @@ class UserVacationStatsRetriever
->states(VacationRequestStatesRetriever::successStates()),
)
->get()
- ->groupBy(fn(Vacation $vacation) => strtolower($vacation->date->englishMonth))
- ->map(fn(Collection $items) => $items->count());
+ ->groupBy(fn(Vacation $vacation): string => strtolower($vacation->date->englishMonth))
+ ->map(fn(Collection $items): int => $items->count());
}
public function getPendingVacationDays(User $user, YearPeriod $yearPeriod): int
@@ -107,13 +107,13 @@ class UserVacationStatsRetriever
{
$types = VacationType::all();
- return $types->filter(fn(VacationType $type) => $this->configRetriever->hasLimit($type));
+ return $types->filter(fn(VacationType $type): bool => $this->configRetriever->hasLimit($type));
}
protected function getNotLimitableVacationTypes(): Collection
{
$types = VacationType::all();
- return $types->filter(fn(VacationType $type) => !$this->configRetriever->hasLimit($type));
+ return $types->filter(fn(VacationType $type): bool => !$this->configRetriever->hasLimit($type));
}
}
diff --git a/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php b/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php
index 299e0a5..3b53892 100644
--- a/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php
+++ b/app/Domain/Validation/Rules/DoesNotExceedLimitRule.php
@@ -64,6 +64,6 @@ class DoesNotExceedLimitRule implements VacationRequestRule
{
$types = VacationType::all();
- return $types->filter(fn(VacationType $type) => $this->configRetriever->hasLimit($type));
+ return $types->filter(fn(VacationType $type): bool => $this->configRetriever->hasLimit($type));
}
}
diff --git a/app/Domain/Validation/Rules/VacationTypeCanBeSelected.php b/app/Domain/Validation/Rules/VacationTypeCanBeSelected.php
index 2a7050f..a62d675 100644
--- a/app/Domain/Validation/Rules/VacationTypeCanBeSelected.php
+++ b/app/Domain/Validation/Rules/VacationTypeCanBeSelected.php
@@ -19,7 +19,7 @@ class VacationTypeCanBeSelected implements VacationRequestRule
$employmentForm = $vacationRequest->user->profile->employment_form;
$availableTypes = VacationType::all()
- ->filter(fn(VacationType $type) => $this->configRetriever->isAvailableFor($type, $employmentForm));
+ ->filter(fn(VacationType $type): bool => $this->configRetriever->isAvailableFor($type, $employmentForm));
return $availableTypes->contains($vacationRequest->type);
}
diff --git a/app/Eloquent/Helpers/YearPeriodRetriever.php b/app/Eloquent/Helpers/YearPeriodRetriever.php
index cf512cb..d248501 100644
--- a/app/Eloquent/Helpers/YearPeriodRetriever.php
+++ b/app/Eloquent/Helpers/YearPeriodRetriever.php
@@ -35,7 +35,7 @@ class YearPeriodRetriever
$years = YearPeriod::all();
- $navigation = $years->map(fn(YearPeriod $yearPeriod) => $this->toNavigation($yearPeriod));
+ $navigation = $years->map(fn(YearPeriod $yearPeriod): array => $this->toNavigation($yearPeriod));
return [
"current" => $this->toNavigation($current),
diff --git a/app/Eloquent/Models/Key.php b/app/Eloquent/Models/Key.php
index 3b02a68..cb7fc6f 100644
--- a/app/Eloquent/Models/Key.php
+++ b/app/Eloquent/Models/Key.php
@@ -9,12 +9,13 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Notifications\Notifiable;
+use Toby\Domain\Notifications\Notifiable as NotifiableInterface;
/**
* @property int $id
* @property User $user
*/
-class Key extends Model
+class Key extends Model implements NotifiableInterface
{
use HasFactory;
use Notifiable;
diff --git a/app/Eloquent/Models/User.php b/app/Eloquent/Models/User.php
index 51689d0..dcd3941 100644
--- a/app/Eloquent/Models/User.php
+++ b/app/Eloquent/Models/User.php
@@ -15,6 +15,7 @@ use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Collection;
use Toby\Domain\Enums\EmploymentForm;
use Toby\Domain\Enums\Role;
+use Toby\Domain\Notifications\Notifiable as NotifiableInterface;
/**
* @property int $id
@@ -26,7 +27,7 @@ use Toby\Domain\Enums\Role;
* @property Collection $vacationRequests
* @property Collection $vacations
*/
-class User extends Authenticatable
+class User extends Authenticatable implements NotifiableInterface
{
use HasFactory;
use Notifiable;
@@ -99,7 +100,7 @@ class User extends Authenticatable
->where("email", "ILIKE", "%{$text}%")
->orWhereRelation(
"profile",
- fn(Builder $query) => $query
+ fn(Builder $query): Builder => $query
->where("first_name", "ILIKE", "%{$text}%")
->orWhere("last_name", "ILIKE", "%{$text}%"),
);
diff --git a/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php b/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
index 2d57e98..139ddb2 100644
--- a/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
+++ b/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
@@ -7,12 +7,13 @@ namespace Toby\Infrastructure\Console\Commands;
use Carbon\CarbonInterface;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
+use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;
-use Spatie\SlashCommand\Attachment;
use Toby\Domain\DailySummaryRetriever;
use Toby\Eloquent\Models\Holiday;
-use Toby\Eloquent\Models\User;
-use Toby\Eloquent\Models\Vacation;
+use Toby\Infrastructure\Slack\Elements\AbsencesAttachment;
+use Toby\Infrastructure\Slack\Elements\BirthdaysAttachment;
+use Toby\Infrastructure\Slack\Elements\RemotesAttachment;
class SendDailySummaryToSlack extends Command
{
@@ -27,40 +28,17 @@ class SendDailySummaryToSlack extends Command
return;
}
- $absences = $dailySummaryRetriever->getAbsences($now)
- ->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
+ $attachments = new Collection([
+ new AbsencesAttachment($dailySummaryRetriever->getAbsences($now)),
+ new RemotesAttachment($dailySummaryRetriever->getRemoteDays($now)),
+ new BirthdaysAttachment($dailySummaryRetriever->getBirthdays($now)),
+ ]);
- $remoteDays = $dailySummaryRetriever->getRemoteDays($now)
- ->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
-
- $birthdays = $dailySummaryRetriever->getBirthdays($now)
- ->map(fn(User $user) => $user->profile->full_name);
-
- $absencesAttachment = Attachment::create()
- ->setTitle("Nieobecności :palm_tree:")
- ->setColor("#eab308")
- ->setText($absences->isNotEmpty() ? $absences->implode("\n") : "Wszyscy dzisiaj pracują :muscle:");
-
- $remoteAttachment = Attachment::create()
- ->setTitle("Praca zdalna :house_with_garden:")
- ->setColor("#527aba")
- ->setText($remoteDays->isNotEmpty() ? $remoteDays->implode("\n") : "Wszyscy dzisiaj są w biurze :boom:");
-
- $birthdayAttachment = Attachment::create()
- ->setTitle("Urodziny :birthday:")
- ->setColor("#3c5f97")
- ->setText($birthdays->isNotEmpty() ? $birthdays->implode("\n") : "Dzisiaj nikt nie ma urodzin :cry:");
-
- $baseUrl = config("services.slack.url");
- $url = "{$baseUrl}/chat.postMessage";
-
- Http::withToken(config("services.slack.client_token"))
- ->post($url, [
- "channel" => config("services.slack.default_channel"),
+ Http::withToken($this->getSlackClientToken())
+ ->post($this->getUrl(), [
+ "channel" => $this->getSlackChannel(),
"text" => "Podsumowanie dla dnia {$now->toDisplayString()}",
- "attachments" => collect([$absencesAttachment, $remoteAttachment, $birthdayAttachment])->map(
- fn(Attachment $attachment) => $attachment->toArray(),
- )->toArray(),
+ "attachments" => $attachments,
]);
}
@@ -78,4 +56,24 @@ class SendDailySummaryToSlack extends Command
return true;
}
+
+ protected function getUrl(): string
+ {
+ return "{$this->getSlackBaseUrl()}/chat.postMessage";
+ }
+
+ protected function getSlackBaseUrl(): string
+ {
+ return config("services.slack.url");
+ }
+
+ protected function getSlackClientToken(): string
+ {
+ return config("services.slack.client_token");
+ }
+
+ protected function getSlackChannel(): string
+ {
+ return config("services.slack.default_channel");
+ }
}
diff --git a/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php b/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php
index 79b0bf9..3f3caa5 100644
--- a/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php
+++ b/app/Infrastructure/Http/Controllers/Api/CalculateVacationDaysController.php
@@ -16,6 +16,6 @@ class CalculateVacationDaysController extends Controller
{
$days = $calculator->calculateDays($request->from(), $request->to());
- return new JsonResponse($days->map(fn(Carbon $day) => $day->toDateString())->all());
+ return new JsonResponse($days->map(fn(Carbon $day): string => $day->toDateString())->all());
}
}
diff --git a/app/Infrastructure/Http/Controllers/Api/GetAvailableVacationTypesController.php b/app/Infrastructure/Http/Controllers/Api/GetAvailableVacationTypesController.php
index 22a5f33..48a92a2 100644
--- a/app/Infrastructure/Http/Controllers/Api/GetAvailableVacationTypesController.php
+++ b/app/Infrastructure/Http/Controllers/Api/GetAvailableVacationTypesController.php
@@ -21,8 +21,8 @@ class GetAvailableVacationTypesController extends Controller
$user = User::query()->find($request->get("user"));
$types = VacationType::all()
- ->filter(fn(VacationType $type) => $configRetriever->isAvailableFor($type, $user->profile->employment_form))
- ->map(fn(VacationType $type) => [
+ ->filter(fn(VacationType $type): bool => $configRetriever->isAvailableFor($type, $user->profile->employment_form))
+ ->map(fn(VacationType $type): array => [
"label" => $type->label(),
"value" => $type->value,
])
diff --git a/app/Infrastructure/Http/Controllers/TimesheetController.php b/app/Infrastructure/Http/Controllers/TimesheetController.php
index 16af5f6..2404889 100644
--- a/app/Infrastructure/Http/Controllers/TimesheetController.php
+++ b/app/Infrastructure/Http/Controllers/TimesheetController.php
@@ -35,8 +35,10 @@ class TimesheetController extends Controller
$types = VacationType::all()
->filter(
- fn(VacationType $type) => $configRetriever->isAvailableFor($type, EmploymentForm::EmploymentContract)
- && $configRetriever->isVacation($type),
+ fn(VacationType $type): bool => $configRetriever->isAvailableFor(
+ $type,
+ EmploymentForm::EmploymentContract,
+ ) && $configRetriever->isVacation($type),
);
$filename = "{$carbonMonth->translatedFormat("F Y")}.xlsx";
diff --git a/app/Infrastructure/Http/Controllers/VacationLimitController.php b/app/Infrastructure/Http/Controllers/VacationLimitController.php
index 29c333e..31a7d80 100644
--- a/app/Infrastructure/Http/Controllers/VacationLimitController.php
+++ b/app/Infrastructure/Http/Controllers/VacationLimitController.php
@@ -30,7 +30,7 @@ class VacationLimitController extends Controller
->sortBy(fn(VacationLimit $limit): string => "{$limit->user->profile->last_name} {$limit->user->profile->first_name}")
->values();
- $limitsResource = $limits->map(fn(VacationLimit $limit) => [
+ $limitsResource = $limits->map(fn(VacationLimit $limit): array => [
"id" => $limit->id,
"user" => new UserResource($limit->user),
"hasVacation" => $limit->hasVacation(),
diff --git a/app/Infrastructure/Http/Middleware/HandleInertiaRequests.php b/app/Infrastructure/Http/Middleware/HandleInertiaRequests.php
index 7344b7f..15cb0dd 100644
--- a/app/Infrastructure/Http/Middleware/HandleInertiaRequests.php
+++ b/app/Infrastructure/Http/Middleware/HandleInertiaRequests.php
@@ -32,7 +32,7 @@ class HandleInertiaRequests extends Middleware
{
$user = $request->user();
- return fn() => [
+ return fn(): array => [
"user" => $user ? new UserResource($user) : null,
"can" => [
"manageVacationLimits" => $user ? $user->can("manageVacationLimits") : false,
@@ -45,7 +45,7 @@ class HandleInertiaRequests extends Middleware
protected function getFlashData(Request $request): Closure
{
- return fn() => [
+ return fn(): array => [
"success" => $request->session()->get("success"),
"error" => $request->session()->get("error"),
"info" => $request->session()->get("info"),
diff --git a/app/Infrastructure/Slack/Channels/SlackApiChannel.php b/app/Infrastructure/Slack/Channels/SlackApiChannel.php
new file mode 100644
index 0000000..d790555
--- /dev/null
+++ b/app/Infrastructure/Slack/Channels/SlackApiChannel.php
@@ -0,0 +1,36 @@
+getBaseUrl();
+ $url = "{$baseUrl}/chat.postMessage";
+ $channel = $notifiable->routeNotificationFor("slack", $notification);
+
+ return Http::withToken($this->getClientToken())
+ ->post($url, [
+ "channel" => $channel,
+ "text" => $notification->toSlack($notifiable),
+ ]);
+ }
+
+ protected function getClientToken(): string
+ {
+ return config("services.slack.client_token");
+ }
+
+ protected function getBaseUrl(): string
+ {
+ return config("services.slack.url");
+ }
+}
diff --git a/app/Domain/Slack/Controller.php b/app/Infrastructure/Slack/Controller.php
similarity index 80%
rename from app/Domain/Slack/Controller.php
rename to app/Infrastructure/Slack/Controller.php
index 616f048..60eaaa5 100644
--- a/app/Domain/Slack/Controller.php
+++ b/app/Infrastructure/Slack/Controller.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack;
+namespace Toby\Infrastructure\Slack;
use Exception;
use Illuminate\Http\Request as IlluminateRequest;
@@ -11,6 +11,7 @@ use Illuminate\Support\Collection;
use Illuminate\Validation\ValidationException;
use Spatie\SlashCommand\Attachment;
use Spatie\SlashCommand\Controller as SlackController;
+use Spatie\SlashCommand\Exceptions\InvalidRequest;
use Spatie\SlashCommand\Exceptions\RequestCouldNotBeHandled;
use Spatie\SlashCommand\Exceptions\SlackSlashCommandException;
use Spatie\SlashCommand\Response;
@@ -18,11 +19,11 @@ use Spatie\SlashCommand\Response;
class Controller extends SlackController
{
/**
- * @throws RequestCouldNotBeHandled
+ * @throws InvalidRequest|RequestCouldNotBeHandled
*/
public function getResponse(IlluminateRequest $request): IlluminateResponse
{
- $this->guardAgainstInvalidRequest($request);
+ $this->verifyWithSigning($request);
$handler = $this->determineHandler();
@@ -43,13 +44,13 @@ class Controller extends SlackController
{
$errors = (new Collection($exception->errors()))
->map(
- fn(array $message) => Attachment::create()
+ fn(array $message): Attachment => Attachment::create()
->setColor("danger")
->setText($message[0]),
);
return Response::create($this->request)
- ->withText(":x: Komenda `/{$this->request->command} {$this->request->text}` jest niepoprawna:")
+ ->withText(":x: Polecenie `/{$this->request->command} {$this->request->text}` jest niepoprawna:")
->withAttachments($errors->all());
}
}
diff --git a/app/Infrastructure/Slack/Elements/AbsencesAttachment.php b/app/Infrastructure/Slack/Elements/AbsencesAttachment.php
new file mode 100644
index 0000000..ae00273
--- /dev/null
+++ b/app/Infrastructure/Slack/Elements/AbsencesAttachment.php
@@ -0,0 +1,22 @@
+setTitle("Nieobecności :palm_tree:")
+ ->setColor("#eab308")
+ ->setItems($absences->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name))
+ ->setEmptyText("Wszyscy dzisiaj pracują :muscle:");
+ }
+}
\ No newline at end of file
diff --git a/app/Infrastructure/Slack/Elements/Attachment.php b/app/Infrastructure/Slack/Elements/Attachment.php
new file mode 100644
index 0000000..fe6a342
--- /dev/null
+++ b/app/Infrastructure/Slack/Elements/Attachment.php
@@ -0,0 +1,12 @@
+setTitle("Urodziny :birthday:")
+ ->setColor("#3c5f97")
+ ->setItems($birthdays->map(fn(User $user): string => $user->profile->full_name))
+ ->setEmptyText("Dzisiaj nikt nie ma urodzin :cry:");
+ }
+}
\ No newline at end of file
diff --git a/app/Infrastructure/Slack/Elements/KeysAttachment.php b/app/Infrastructure/Slack/Elements/KeysAttachment.php
new file mode 100644
index 0000000..6702a66
--- /dev/null
+++ b/app/Infrastructure/Slack/Elements/KeysAttachment.php
@@ -0,0 +1,21 @@
+setColor("#3c5f97")
+ ->setItems($keys->map(fn(Key $key): string => "Klucz nr {$key->id} - <@{$key->user->profile->slack_id}>"))
+ ->setEmptyText("Nie ma żadnych kluczy w tobym");
+ }
+}
\ No newline at end of file
diff --git a/app/Infrastructure/Slack/Elements/ListAttachment.php b/app/Infrastructure/Slack/Elements/ListAttachment.php
new file mode 100644
index 0000000..bccaf7a
--- /dev/null
+++ b/app/Infrastructure/Slack/Elements/ListAttachment.php
@@ -0,0 +1,36 @@
+items = $items;
+
+ return $this;
+ }
+
+ public function setEmptyText(string $emptyText): static
+ {
+ $this->emptyText = $emptyText;
+
+ return $this;
+ }
+
+ public function toArray(): array
+ {
+ $fields = parent::toArray();
+
+ return array_merge($fields, [
+ "text" => $this->items->isNotEmpty() ? $this->items->implode("\n") : $this->emptyText,
+ ]);
+ }
+}
\ No newline at end of file
diff --git a/app/Infrastructure/Slack/Elements/RemotesAttachment.php b/app/Infrastructure/Slack/Elements/RemotesAttachment.php
new file mode 100644
index 0000000..2b91f44
--- /dev/null
+++ b/app/Infrastructure/Slack/Elements/RemotesAttachment.php
@@ -0,0 +1,22 @@
+setTitle("Praca zdalna :house_with_garden:")
+ ->setColor("#527aba")
+ ->setItems($remoteDays->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name))
+ ->setEmptyText("Wszyscy dzisiaj są w biurze :boom:");
+ }
+}
\ No newline at end of file
diff --git a/app/Domain/Slack/Exceptions/UserNotFoundException.php b/app/Infrastructure/Slack/Exceptions/UserNotFoundException.php
similarity index 77%
rename from app/Domain/Slack/Exceptions/UserNotFoundException.php
rename to app/Infrastructure/Slack/Exceptions/UserNotFoundException.php
index 925e6fb..94a3948 100644
--- a/app/Domain/Slack/Exceptions/UserNotFoundException.php
+++ b/app/Infrastructure/Slack/Exceptions/UserNotFoundException.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack\Exceptions;
+namespace Toby\Infrastructure\Slack\Exceptions;
use Spatie\SlashCommand\Exceptions\SlackSlashCommandException;
diff --git a/app/Domain/Slack/Handlers/CatchAll.php b/app/Infrastructure/Slack/Handlers/CatchAll.php
similarity index 73%
rename from app/Domain/Slack/Handlers/CatchAll.php
rename to app/Infrastructure/Slack/Handlers/CatchAll.php
index faeaf7e..ce94256 100644
--- a/app/Domain/Slack/Handlers/CatchAll.php
+++ b/app/Infrastructure/Slack/Handlers/CatchAll.php
@@ -2,13 +2,13 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack\Handlers;
+namespace Toby\Infrastructure\Slack\Handlers;
-use Spatie\SlashCommand\Attachment;
use Spatie\SlashCommand\Handlers\BaseHandler;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
-use Toby\Domain\Slack\Traits\ListsHandlers;
+use Toby\Infrastructure\Slack\Elements\Attachment;
+use Toby\Infrastructure\Slack\Traits\ListsHandlers;
class CatchAll extends BaseHandler
{
@@ -24,7 +24,7 @@ class CatchAll extends BaseHandler
$handlers = $this->findAvailableHandlers();
$attachmentFields = $this->mapHandlersToAttachments($handlers);
- return $this->respondToSlack(":x: Nie rozpoznaję tej komendy. Lista wszystkich komend:")
+ return $this->respondToSlack(":x: Nie rozpoznaję polecenia. Lista wszystkich poleceń:")
->withAttachment(
Attachment::create()
->setColor("danger")
diff --git a/app/Infrastructure/Slack/Handlers/DailySummary.php b/app/Infrastructure/Slack/Handlers/DailySummary.php
new file mode 100644
index 0000000..5a941ee
--- /dev/null
+++ b/app/Infrastructure/Slack/Handlers/DailySummary.php
@@ -0,0 +1,36 @@
+make(DailySummaryRetriever::class);
+
+ $now = Carbon::today();
+
+ $attachments = new Collection([
+ new AbsencesAttachment($dailySummaryRetriever->getAbsences($now)),
+ new RemotesAttachment($dailySummaryRetriever->getRemoteDays($now)),
+ new BirthdaysAttachment($dailySummaryRetriever->getBirthdays($now)),
+ ]);
+
+ return $this->respondToSlack("Podsumowanie dla dnia {$now->toDisplayString()}")
+ ->withAttachments($attachments->all());
+ }
+}
diff --git a/app/Domain/Slack/Handlers/GiveKeysTo.php b/app/Infrastructure/Slack/Handlers/GiveKeysTo.php
similarity index 88%
rename from app/Domain/Slack/Handlers/GiveKeysTo.php
rename to app/Infrastructure/Slack/Handlers/GiveKeysTo.php
index 0ecb587..7925844 100644
--- a/app/Domain/Slack/Handlers/GiveKeysTo.php
+++ b/app/Infrastructure/Slack/Handlers/GiveKeysTo.php
@@ -2,16 +2,16 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack\Handlers;
+namespace Toby\Infrastructure\Slack\Handlers;
use Illuminate\Validation\ValidationException;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
use Toby\Domain\Notifications\KeyHasBeenGivenNotification;
-use Toby\Domain\Slack\Exceptions\UserNotFoundException;
-use Toby\Domain\Slack\Rules\SlackUserExistsRule;
-use Toby\Domain\Slack\Traits\FindsUserBySlackId;
use Toby\Eloquent\Models\Key;
+use Toby\Infrastructure\Slack\Exceptions\UserNotFoundException;
+use Toby\Infrastructure\Slack\Rules\SlackUserExistsRule;
+use Toby\Infrastructure\Slack\Traits\FindsUserBySlackId;
class GiveKeysTo extends SignatureHandler
{
diff --git a/app/Domain/Slack/Handlers/Help.php b/app/Infrastructure/Slack/Handlers/Help.php
similarity index 68%
rename from app/Domain/Slack/Handlers/Help.php
rename to app/Infrastructure/Slack/Handlers/Help.php
index a46d9d1..e5e7ca2 100644
--- a/app/Domain/Slack/Handlers/Help.php
+++ b/app/Infrastructure/Slack/Handlers/Help.php
@@ -2,19 +2,19 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack\Handlers;
+namespace Toby\Infrastructure\Slack\Handlers;
-use Spatie\SlashCommand\Attachment;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
-use Toby\Domain\Slack\Traits\ListsHandlers;
+use Toby\Infrastructure\Slack\Elements\Attachment;
+use Toby\Infrastructure\Slack\Traits\ListsHandlers;
class Help extends SignatureHandler
{
use ListsHandlers;
protected $signature = "toby pomoc";
- protected $description = "Wyświetl wszystkie dostępne komendy";
+ protected $description = "Wyświetl wszystkie dostępne polecenia";
public function handle(Request $request): Response
{
@@ -22,7 +22,7 @@ class Help extends SignatureHandler
$attachmentFields = $this->mapHandlersToAttachments($handlers);
- return $this->respondToSlack("Dostępne komendy:")
+ return $this->respondToSlack("Dostępne polecenia:")
->withAttachment(
Attachment::create()
->setColor("good")
diff --git a/app/Domain/Slack/Handlers/HomeOffice.php b/app/Infrastructure/Slack/Handlers/HomeOffice.php
similarity index 91%
rename from app/Domain/Slack/Handlers/HomeOffice.php
rename to app/Infrastructure/Slack/Handlers/HomeOffice.php
index 5a4cd34..7674539 100644
--- a/app/Domain/Slack/Handlers/HomeOffice.php
+++ b/app/Infrastructure/Slack/Handlers/HomeOffice.php
@@ -2,16 +2,16 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack\Handlers;
+namespace Toby\Infrastructure\Slack\Handlers;
use Illuminate\Support\Carbon;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
use Toby\Domain\Actions\VacationRequest\CreateAction;
use Toby\Domain\Enums\VacationType;
-use Toby\Domain\Slack\Traits\FindsUserBySlackId;
use Toby\Eloquent\Models\User;
use Toby\Eloquent\Models\YearPeriod;
+use Toby\Infrastructure\Slack\Traits\FindsUserBySlackId;
class HomeOffice extends SignatureHandler
{
diff --git a/app/Domain/Slack/Handlers/KeyList.php b/app/Infrastructure/Slack/Handlers/KeyList.php
similarity index 51%
rename from app/Domain/Slack/Handlers/KeyList.php
rename to app/Infrastructure/Slack/Handlers/KeyList.php
index 9d71bc1..87ef123 100644
--- a/app/Domain/Slack/Handlers/KeyList.php
+++ b/app/Infrastructure/Slack/Handlers/KeyList.php
@@ -2,12 +2,12 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack\Handlers;
+namespace Toby\Infrastructure\Slack\Handlers;
-use Spatie\SlashCommand\Attachment;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
use Toby\Eloquent\Models\Key;
+use Toby\Infrastructure\Slack\Elements\KeysAttachment;
class KeyList extends SignatureHandler
{
@@ -18,14 +18,9 @@ class KeyList extends SignatureHandler
{
$keys = Key::query()
->orderBy("id")
- ->get()
- ->map(fn(Key $key) => "Klucz nr {$key->id} - <@{$key->user->profile->slack_id}>");
+ ->get();
return $this->respondToSlack("Lista kluczy :key:")
- ->withAttachment(
- Attachment::create()
- ->setColor("#3c5f97")
- ->setText($keys->isNotEmpty() ? $keys->implode("\n") : "Nie ma żadnych kluczy w tobym"),
- );
+ ->withAttachment(new KeysAttachment($keys));
}
}
diff --git a/app/Domain/Slack/Handlers/SignatureHandler.php b/app/Infrastructure/Slack/Handlers/SignatureHandler.php
similarity index 91%
rename from app/Domain/Slack/Handlers/SignatureHandler.php
rename to app/Infrastructure/Slack/Handlers/SignatureHandler.php
index 626a561..56af5da 100644
--- a/app/Domain/Slack/Handlers/SignatureHandler.php
+++ b/app/Infrastructure/Slack/Handlers/SignatureHandler.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack\Handlers;
+namespace Toby\Infrastructure\Slack\Handlers;
use Illuminate\Support\Facades\Validator;
use Spatie\SlashCommand\Handlers\SignatureHandler as BaseSignatureHandler;
diff --git a/app/Domain/Slack/Handlers/TakeKeysFrom.php b/app/Infrastructure/Slack/Handlers/TakeKeysFrom.php
similarity index 88%
rename from app/Domain/Slack/Handlers/TakeKeysFrom.php
rename to app/Infrastructure/Slack/Handlers/TakeKeysFrom.php
index e8ac558..5d89eed 100644
--- a/app/Domain/Slack/Handlers/TakeKeysFrom.php
+++ b/app/Infrastructure/Slack/Handlers/TakeKeysFrom.php
@@ -2,16 +2,16 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack\Handlers;
+namespace Toby\Infrastructure\Slack\Handlers;
use Illuminate\Validation\ValidationException;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
use Toby\Domain\Notifications\KeyHasBeenTakenNotification;
-use Toby\Domain\Slack\Exceptions\UserNotFoundException;
-use Toby\Domain\Slack\Rules\SlackUserExistsRule;
-use Toby\Domain\Slack\Traits\FindsUserBySlackId;
use Toby\Eloquent\Models\Key;
+use Toby\Infrastructure\Slack\Exceptions\UserNotFoundException;
+use Toby\Infrastructure\Slack\Rules\SlackUserExistsRule;
+use Toby\Infrastructure\Slack\Traits\FindsUserBySlackId;
class TakeKeysFrom extends SignatureHandler
{
diff --git a/app/Domain/Slack/Rules/SlackUserExistsRule.php b/app/Infrastructure/Slack/Rules/SlackUserExistsRule.php
similarity index 91%
rename from app/Domain/Slack/Rules/SlackUserExistsRule.php
rename to app/Infrastructure/Slack/Rules/SlackUserExistsRule.php
index aeb8fe7..500c295 100644
--- a/app/Domain/Slack/Rules/SlackUserExistsRule.php
+++ b/app/Infrastructure/Slack/Rules/SlackUserExistsRule.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack\Rules;
+namespace Toby\Infrastructure\Slack\Rules;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Str;
diff --git a/app/Domain/Slack/Traits/FindsUserBySlackId.php b/app/Infrastructure/Slack/Traits/FindsUserBySlackId.php
similarity index 89%
rename from app/Domain/Slack/Traits/FindsUserBySlackId.php
rename to app/Infrastructure/Slack/Traits/FindsUserBySlackId.php
index 0502c3f..b3f1bae 100644
--- a/app/Domain/Slack/Traits/FindsUserBySlackId.php
+++ b/app/Infrastructure/Slack/Traits/FindsUserBySlackId.php
@@ -2,11 +2,11 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack\Traits;
+namespace Toby\Infrastructure\Slack\Traits;
use Illuminate\Support\Str;
-use Toby\Domain\Slack\Exceptions\UserNotFoundException;
use Toby\Eloquent\Models\User;
+use Toby\Infrastructure\Slack\Exceptions\UserNotFoundException;
trait FindsUserBySlackId
{
diff --git a/app/Domain/Slack/Traits/ListsHandlers.php b/app/Infrastructure/Slack/Traits/ListsHandlers.php
similarity index 74%
rename from app/Domain/Slack/Traits/ListsHandlers.php
rename to app/Infrastructure/Slack/Traits/ListsHandlers.php
index aa8e331..0ec2d1f 100644
--- a/app/Domain/Slack/Traits/ListsHandlers.php
+++ b/app/Infrastructure/Slack/Traits/ListsHandlers.php
@@ -2,11 +2,12 @@
declare(strict_types=1);
-namespace Toby\Domain\Slack\Traits;
+namespace Toby\Infrastructure\Slack\Traits;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Spatie\SlashCommand\AttachmentField;
+use Spatie\SlashCommand\Handlers\BaseHandler;
use Spatie\SlashCommand\Handlers\SignatureHandler;
use Spatie\SlashCommand\Handlers\SignatureParts;
use Spatie\SlashCommand\HandlesSlashCommand;
@@ -16,8 +17,8 @@ trait ListsHandlers
protected function findAvailableHandlers(): Collection
{
return collect(config("laravel-slack-slash-command.handlers"))
- ->map(fn(string $handlerClassName) => new $handlerClassName($this->request))
- ->filter(fn(HandlesSlashCommand $handler) => $handler instanceof SignatureHandler)
+ ->map(fn(string $handlerClassName): BaseHandler => new $handlerClassName($this->request))
+ ->filter(fn(HandlesSlashCommand $handler): bool => $handler instanceof SignatureHandler)
->filter(function (SignatureHandler $handler) {
$signatureParts = new SignatureParts($handler->getSignature());
@@ -29,13 +30,13 @@ trait ListsHandlers
{
return $handlers
->sort(
- fn(SignatureHandler $handlerA, SignatureHandler $handlerB) => strcmp(
+ fn(SignatureHandler $handlerA, SignatureHandler $handlerB): int => strcmp(
$handlerA->getFullCommand(),
$handlerB->getFullCommand(),
),
)
->map(
- fn(SignatureHandler $handler) => AttachmentField::create(
+ fn(SignatureHandler $handler): AttachmentField => AttachmentField::create(
$handler->getDescription(),
"`/{$handler->getSignature()}`",
),
diff --git a/config/laravel-slack-slash-command.php b/config/laravel-slack-slash-command.php
index 23eb170..b4f8cfb 100644
--- a/config/laravel-slack-slash-command.php
+++ b/config/laravel-slack-slash-command.php
@@ -2,17 +2,16 @@
declare(strict_types=1);
-use Toby\Domain\Slack\Handlers\CatchAll;
-use Toby\Domain\Slack\Handlers\DailySummary;
-use Toby\Domain\Slack\Handlers\GiveKeysTo;
-use Toby\Domain\Slack\Handlers\Help;
-use Toby\Domain\Slack\Handlers\HomeOffice;
-use Toby\Domain\Slack\Handlers\KeyList;
-use Toby\Domain\Slack\Handlers\TakeKeysFrom;
+use Toby\Infrastructure\Slack\Handlers\CatchAll;
+use Toby\Infrastructure\Slack\Handlers\DailySummary;
+use Toby\Infrastructure\Slack\Handlers\GiveKeysTo;
+use Toby\Infrastructure\Slack\Handlers\Help;
+use Toby\Infrastructure\Slack\Handlers\HomeOffice;
+use Toby\Infrastructure\Slack\Handlers\KeyList;
+use Toby\Infrastructure\Slack\Handlers\TakeKeysFrom;
return [
"signing_secret" => env("SLACK_SIGNING_SECRET"),
- "verify_with_signing" => true,
"handlers" => [
TakeKeysFrom::class,
GiveKeysTo::class,
diff --git a/routes/api.php b/routes/api.php
index 9d8bace..3220d19 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -3,11 +3,11 @@
declare(strict_types=1);
use Illuminate\Support\Facades\Route;
-use Toby\Domain\Slack\Controller as SlackController;
use Toby\Infrastructure\Http\Controllers\Api\CalculateUserUnavailableDaysController;
use Toby\Infrastructure\Http\Controllers\Api\CalculateUserVacationStatsController;
use Toby\Infrastructure\Http\Controllers\Api\CalculateVacationDaysController;
use Toby\Infrastructure\Http\Controllers\Api\GetAvailableVacationTypesController;
+use Toby\Infrastructure\Slack\Controller as SlackController;
Route::post("slack", [SlackController::class, "getResponse"]);
--
2.52.0
From f95739ecb1273d94f5ad4caa83525ba3078c0a8d Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Tue, 26 Apr 2022 12:50:39 +0200
Subject: [PATCH 15/18] #116 - cs fix
---
app/Domain/Notifications/Channels.php | 2 +-
app/Domain/Notifications/Notifiable.php | 2 +-
app/Infrastructure/Slack/Elements/AbsencesAttachment.php | 2 +-
app/Infrastructure/Slack/Elements/Attachment.php | 2 +-
app/Infrastructure/Slack/Elements/BirthdaysAttachment.php | 2 +-
app/Infrastructure/Slack/Elements/KeysAttachment.php | 2 +-
app/Infrastructure/Slack/Elements/ListAttachment.php | 2 +-
app/Infrastructure/Slack/Elements/RemotesAttachment.php | 2 +-
8 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/app/Domain/Notifications/Channels.php b/app/Domain/Notifications/Channels.php
index e9c23e2..b12d14b 100644
--- a/app/Domain/Notifications/Channels.php
+++ b/app/Domain/Notifications/Channels.php
@@ -8,4 +8,4 @@ class Channels
{
public const MAIL = "mail";
public const SLACK = "slack";
-}
\ No newline at end of file
+}
diff --git a/app/Domain/Notifications/Notifiable.php b/app/Domain/Notifications/Notifiable.php
index b23e554..99fef2f 100644
--- a/app/Domain/Notifications/Notifiable.php
+++ b/app/Domain/Notifications/Notifiable.php
@@ -7,4 +7,4 @@ namespace Toby\Domain\Notifications;
interface Notifiable
{
public function notify($instance);
-}
\ No newline at end of file
+}
diff --git a/app/Infrastructure/Slack/Elements/AbsencesAttachment.php b/app/Infrastructure/Slack/Elements/AbsencesAttachment.php
index ae00273..3f34fac 100644
--- a/app/Infrastructure/Slack/Elements/AbsencesAttachment.php
+++ b/app/Infrastructure/Slack/Elements/AbsencesAttachment.php
@@ -19,4 +19,4 @@ class AbsencesAttachment extends ListAttachment
->setItems($absences->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name))
->setEmptyText("Wszyscy dzisiaj pracują :muscle:");
}
-}
\ No newline at end of file
+}
diff --git a/app/Infrastructure/Slack/Elements/Attachment.php b/app/Infrastructure/Slack/Elements/Attachment.php
index fe6a342..9b223ec 100644
--- a/app/Infrastructure/Slack/Elements/Attachment.php
+++ b/app/Infrastructure/Slack/Elements/Attachment.php
@@ -9,4 +9,4 @@ use Spatie\SlashCommand\Attachment as BaseAttachment;
class Attachment extends BaseAttachment implements Arrayable
{
-}
\ No newline at end of file
+}
diff --git a/app/Infrastructure/Slack/Elements/BirthdaysAttachment.php b/app/Infrastructure/Slack/Elements/BirthdaysAttachment.php
index 13aa219..860885d 100644
--- a/app/Infrastructure/Slack/Elements/BirthdaysAttachment.php
+++ b/app/Infrastructure/Slack/Elements/BirthdaysAttachment.php
@@ -19,4 +19,4 @@ class BirthdaysAttachment extends ListAttachment
->setItems($birthdays->map(fn(User $user): string => $user->profile->full_name))
->setEmptyText("Dzisiaj nikt nie ma urodzin :cry:");
}
-}
\ No newline at end of file
+}
diff --git a/app/Infrastructure/Slack/Elements/KeysAttachment.php b/app/Infrastructure/Slack/Elements/KeysAttachment.php
index 6702a66..80819d3 100644
--- a/app/Infrastructure/Slack/Elements/KeysAttachment.php
+++ b/app/Infrastructure/Slack/Elements/KeysAttachment.php
@@ -18,4 +18,4 @@ class KeysAttachment extends ListAttachment
->setItems($keys->map(fn(Key $key): string => "Klucz nr {$key->id} - <@{$key->user->profile->slack_id}>"))
->setEmptyText("Nie ma żadnych kluczy w tobym");
}
-}
\ No newline at end of file
+}
diff --git a/app/Infrastructure/Slack/Elements/ListAttachment.php b/app/Infrastructure/Slack/Elements/ListAttachment.php
index bccaf7a..3e3dfab 100644
--- a/app/Infrastructure/Slack/Elements/ListAttachment.php
+++ b/app/Infrastructure/Slack/Elements/ListAttachment.php
@@ -33,4 +33,4 @@ class ListAttachment extends Attachment
"text" => $this->items->isNotEmpty() ? $this->items->implode("\n") : $this->emptyText,
]);
}
-}
\ No newline at end of file
+}
diff --git a/app/Infrastructure/Slack/Elements/RemotesAttachment.php b/app/Infrastructure/Slack/Elements/RemotesAttachment.php
index 2b91f44..2f39ad4 100644
--- a/app/Infrastructure/Slack/Elements/RemotesAttachment.php
+++ b/app/Infrastructure/Slack/Elements/RemotesAttachment.php
@@ -19,4 +19,4 @@ class RemotesAttachment extends ListAttachment
->setItems($remoteDays->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name))
->setEmptyText("Wszyscy dzisiaj są w biurze :boom:");
}
-}
\ No newline at end of file
+}
--
2.52.0
From 8726b81a667c405da225aa19894f5f2c9d5880fd Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Tue, 26 Apr 2022 12:56:35 +0200
Subject: [PATCH 16/18] #116 - cs fix
---
.../Console/Commands/SendDailySummaryToSlack.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php b/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
index 139ddb2..1c2a5b6 100644
--- a/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
+++ b/app/Infrastructure/Console/Commands/SendDailySummaryToSlack.php
@@ -62,17 +62,17 @@ class SendDailySummaryToSlack extends Command
return "{$this->getSlackBaseUrl()}/chat.postMessage";
}
- protected function getSlackBaseUrl(): string
+ protected function getSlackBaseUrl(): ?string
{
return config("services.slack.url");
}
- protected function getSlackClientToken(): string
+ protected function getSlackClientToken(): ?string
{
return config("services.slack.client_token");
}
- protected function getSlackChannel(): string
+ protected function getSlackChannel(): ?string
{
return config("services.slack.default_channel");
}
--
2.52.0
From 83e003ddbb3d8c84a0a29deaab6b480f1d774a89 Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Tue, 26 Apr 2022 14:24:29 +0200
Subject: [PATCH 17/18] Apply suggestions from code review
Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>
---
app/Infrastructure/Slack/Controller.php | 2 +-
tests/Unit/SendDailySummaryToSlackTest.php | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/app/Infrastructure/Slack/Controller.php b/app/Infrastructure/Slack/Controller.php
index 60eaaa5..a3467bb 100644
--- a/app/Infrastructure/Slack/Controller.php
+++ b/app/Infrastructure/Slack/Controller.php
@@ -50,7 +50,7 @@ class Controller extends SlackController
);
return Response::create($this->request)
- ->withText(":x: Polecenie `/{$this->request->command} {$this->request->text}` jest niepoprawna:")
+ ->withText(":x: Polecenie `/{$this->request->command} {$this->request->text}` jest niepoprawne:")
->withAttachments($errors->all());
}
}
diff --git a/tests/Unit/SendDailySummaryToSlackTest.php b/tests/Unit/SendDailySummaryToSlackTest.php
index 96014e2..93be6bf 100644
--- a/tests/Unit/SendDailySummaryToSlackTest.php
+++ b/tests/Unit/SendDailySummaryToSlackTest.php
@@ -38,7 +38,7 @@ class SendDailySummaryToSlackTest extends TestCase
Http::assertSentCount(1);
}
- public function testCommandDoesntSendIfWeekend(): void
+ public function testCommandDoesntSendMessageIfWeekend(): void
{
$weekend = Carbon::create(2022, 4, 23);
$this->assertTrue($weekend->isWeekend());
@@ -51,7 +51,7 @@ class SendDailySummaryToSlackTest extends TestCase
Http::assertNothingSent();
}
- public function testCommandDoesntSendIfHoliday(): void
+ public function testCommandDoesntSendMessageIfHoliday(): void
{
$holiday = Holiday::factory(["date" => Carbon::create(2022, 4, 22)])->create();
--
2.52.0
From 20fc0f841a4b86c914a3201da66a76f4b6087e10 Mon Sep 17 00:00:00 2001
From: Adrian Hopek
Date: Wed, 27 Apr 2022 09:30:30 +0200
Subject: [PATCH 18/18] #5 - bump codestyle
---
composer.lock | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/composer.lock b/composer.lock
index d04d59e..498daa4 100644
--- a/composer.lock
+++ b/composer.lock
@@ -11057,5 +11057,5 @@
"ext-redis": "*"
},
"platform-dev": [],
- "plugin-api-version": "2.1.0"
+ "plugin-api-version": "2.2.0"
}
--
2.52.0