#116 - integration with slack #129
@@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
45
app/Domain/DailySummaryRetriever.php
Normal file
@@ -0,0 +1,45 @@
|
||||
|
krzysztofrewak
commented
Review
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
krzysztofrewak
commented
Review
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
krzysztofrewak
commented
Review
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
krzysztofrewak
commented
Review
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
<?php
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
declare(strict_types=1);
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
namespace Toby\Domain;
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
use Illuminate\Support\Carbon;
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
use Illuminate\Support\Collection;
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
use Toby\Eloquent\Models\User;
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
use Toby\Eloquent\Models\Vacation;
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
class DailySummaryRetriever
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
{
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
public function __construct(
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
protected VacationTypeConfigRetriever $configRetriever,
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
) {}
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
public function getAbsences(Carbon $date): Collection
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
{
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
return Vacation::query()
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
->with(["user", "vacationRequest"])
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
->whereDate("date", $date)
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
->approved()
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
->whereTypes(VacationType::all()->filter(fn(VacationType $type) => $this->configRetriever->isVacation($type)))
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
->get();
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
}
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
public function getRemoteDays(Carbon $date): Collection
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
{
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
return Vacation::query()
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
->with(["user", "vacationRequest"])
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
->whereDate("date", $date)
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
->approved()
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
->whereTypes(VacationType::all()->filter(fn(VacationType $type) => !$this->configRetriever->isVacation($type)))
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
->get();
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
}
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
public function getBirthdays(Carbon $date): Collection
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
{
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
return User::query()
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
->whereRelation("profile", "birthday", $date)
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
->get();
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
}
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
}
|
||||
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => $this->configRetriever->isVacation($type)))
```
```suggestion
->whereTypes(VacationType::all()->filter(fn(VacationType $type): bool => !$this->configRetriever->isVacation($type)))
```
|
||||
42
app/Domain/Notifications/KeyHasBeenGivenNotification.php
Normal file
@@ -0,0 +1,42 @@
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
<?php
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
declare(strict_types=1);
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
namespace Toby\Domain\Notifications;
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
use Illuminate\Bus\Queueable;
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
class KeyHasBeenGivenNotification extends Notification
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
{
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
use Queueable;
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
public function __construct(
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
protected User $sender,
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
protected User $recipient,
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
) {}
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
public function via(): array
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
{
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
return ["slack"];
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
}
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
public function toSlack($notifiable): string
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
{
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
return __(":sender gives key no :key to :recipient", [
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
"sender" => $this->getName($this->sender),
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
"recipient" => $this->getName($this->recipient),
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
"key" => $notifiable->id,
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
]);
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
}
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
protected function getName(User $user): string
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
{
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
if ($user->profile->slack_id !== null) {
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
return "<@{$user->profile->slack_id}>";
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
}
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
return $user->profile->full_name;
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
}
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
}
|
||||
|
Maybe these Maybe these `"slack"` and other channels could be gathered somewhere and used as constants or enums?
|
||||
42
app/Domain/Notifications/KeyHasBeenTakenNotification.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class KeyHasBeenTakenNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
protected User $recipient,
|
||||
protected User $sender,
|
||||
) {}
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
return ["slack"];
|
||||
}
|
||||
|
||||
public function toSlack($notifiable): string
|
||||
{
|
||||
return __(":recipient takes key no :key from :sender", [
|
||||
"recipient" => $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;
|
||||
}
|
||||
}
|
||||
55
app/Domain/Slack/Controller.php
Normal file
@@ -0,0 +1,55 @@
|
||||
|
Please add return type here. Please add return type here.
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
<?php
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
declare(strict_types=1);
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
namespace Toby\Domain\Slack;
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
use Exception;
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
use Illuminate\Http\Request as IlluminateRequest;
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
use Illuminate\Http\Response as IlluminateResponse;
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
use Illuminate\Support\Collection;
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
use Spatie\SlashCommand\Attachment;
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
use Spatie\SlashCommand\Controller as SlackController;
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
use Spatie\SlashCommand\Exceptions\RequestCouldNotBeHandled;
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
use Spatie\SlashCommand\Exceptions\SlackSlashCommandException;
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
use Spatie\SlashCommand\Response;
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
class Controller extends SlackController
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
{
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
/**
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
* @throws RequestCouldNotBeHandled
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
*/
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
public function getResponse(IlluminateRequest $request): IlluminateResponse
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
{
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
$this->guardAgainstInvalidRequest($request);
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
$handler = $this->determineHandler();
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
try {
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
$response = $handler->handle($this->request);
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
} catch (SlackSlashCommandException $exception) {
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
$response = $exception->getResponse($this->request);
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
} catch (ValidationException $exception) {
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
$response = $this->prepareValidationResponse($exception);
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
} catch (Exception $exception) {
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
$response = $this->convertToResponse($exception);
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
}
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
return $response->getIlluminateResponse();
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
}
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
protected function prepareValidationResponse(ValidationException $exception): Response
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
{
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
$errors = (new Collection($exception->errors()))
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
->map(
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
fn(array $message) => Attachment::create()
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
->setColor("danger")
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
->setText($message[0]),
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
);
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
return Response::create($this->request)
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
->withText(":x: Komenda `/{$this->request->command} {$this->request->text}` jest niepoprawna:")
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
->withAttachments($errors->all());
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
}
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
}
|
||||
|
Please add return type here. Please add return type here.
@EwelinaLasowy , what do you think about word Komenda? :> @EwelinaLasowy , what do you think about word Komenda? :>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -5,70 +5,52 @@ declare(strict_types=1);
|
||||
```suggestion
$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);
```
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
namespace Toby\Domain\Slack\Handlers;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
use Spatie\SlashCommand\Attachment;
|
||||
use Spatie\SlashCommand\Request;
|
||||
use Spatie\SlashCommand\Response;
|
||||
use Spatie\SlashCommand\Handlers\SignatureHandler;
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
use Toby\Domain\VacationTypeConfigRetriever;
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
use Toby\Domain\DailySummaryRetriever;
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
use Toby\Domain\Slack\SignatureHandler;
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\Vacation;
|
||||
|
||||
class DailySummary extends SignatureHandler
|
||||
{
|
||||
protected $signature = "toby dzisiaj";
|
||||
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
protected $description = "Podsumowanie";
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
protected $description = "Codzienne podsumowanie";
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$configRetriever = app(VacationTypeConfigRetriever::class);
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
$dailySummaryRetriever = app()->make(DailySummaryRetriever::class);
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
|
||||
$now = Carbon::today();
|
||||
|
||||
/** @var Collection $absences */
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
$absences = Vacation::query()
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->with(["user", "vacationRequest"])
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->whereDate("date", $now)
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->approved()
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->whereTypes(VacationType::all()->filter(fn(VacationType $type) => $configRetriever->isVacation($type)))
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->get()
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
$absences = $dailySummaryRetriever->getAbsences($now)
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
|
||||
|
||||
/** @var Collection $remoteDays */
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
$remoteDays = Vacation::query()
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->with(["user", "vacationRequest"])
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->whereDate("date", $now)
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->approved()
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->whereTypes(VacationType::all()->filter(fn(VacationType $type) => !$configRetriever->isVacation($type)))
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->get()
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
$remoteDays = $dailySummaryRetriever->getRemoteDays($now)
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
|
||||
|
||||
$birthdays = User::query()
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->whereRelation("profile", "birthday", $now)
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->get()
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
$birthdays = $dailySummaryRetriever->getBirthdays($now)
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->map(fn(User $user) => $user->profile->full_name);
|
||||
|
||||
$absencesAttachment = Attachment::create()
|
||||
->setTitle("Nieobecności :palm_tree:")
|
||||
->setColor('#eab308')
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->setColor("#eab308")
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->setText($absences->isNotEmpty() ? $absences->implode("\n") : "Wszyscy dzisiaj pracują :muscle:");
|
||||
|
||||
$remoteAttachment = Attachment::create()
|
||||
->setTitle("Praca zdalna :house_with_garden:")
|
||||
->setColor('#d946ef')
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->setColor("#d946ef")
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->setText($remoteDays->isNotEmpty() ? $remoteDays->implode("\n") : "Wszyscy dzisiaj są w biurze :boom:");
|
||||
|
||||
$birthdayAttachment = Attachment::create()
|
||||
->setTitle("Urodziny :birthday:")
|
||||
->setColor('#3C5F97')
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->setColor("#3C5F97")
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->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)
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->displayResponseToEveryoneOnChannel();
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
->withAttachment($birthdayAttachment);
|
||||
```suggestion
$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);
```
What if we would have five more activities? Maybe this could be encapsulated somehow? What if we would have five more activities? Maybe this could be encapsulated somehow?
|
||||
}
|
||||
}
|
||||
@@ -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",
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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"),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Slack\Handlers;
|
||||
|
||||
use Spatie\SlashCommand\Request;
|
||||
use Spatie\SlashCommand\Response;
|
||||
use Spatie\SlashCommand\Handlers\SignatureHandler;
|
||||
|
||||
class SaySomething extends SignatureHandler
|
||||
{
|
||||
protected $signature = "toby powiedz {zdanie}";
|
||||
|
||||
protected $description = "Powiedz zdanie";
|
||||
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$sentence = $this->getArgument("zdanie");
|
||||
|
||||
return $this->respondToSlack($sentence)
|
||||
->displayResponseToEveryoneOnChannel();
|
||||
}
|
||||
}
|
||||
@@ -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",
|
||||
];
|
||||
}
|
||||
}
|
||||
26
app/Domain/Slack/SignatureHandler.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Slack;
|
||||
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Spatie\SlashCommand\Handlers\SignatureHandler as BaseSignatureHandler;
|
||||
|
||||
abstract class SignatureHandler extends BaseSignatureHandler
|
||||
{
|
||||
public function validate()
|
||||
{
|
||||
return Validator::validate($this->getArguments(), $this->getRules(), $this->getMessages());
|
||||
}
|
||||
|
||||
protected function getRules(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function getMessages(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
24
app/Domain/Slack/SlackUserExistsRule.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Slack;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Support\Str;
|
||||
use Toby\Eloquent\Models\Profile;
|
||||
|
||||
class SlackUserExistsRule implements Rule
|
||||
{
|
||||
public function passes($attribute, $value): bool
|
||||
{
|
||||
$slackId = Str::between($value, "<@", "|");
|
||||
|
||||
return Profile::query()->where("slack_id", $slackId)->exists();
|
||||
}
|
||||
|
||||
public function message(): string
|
||||
{
|
||||
return "Użytkownik :input nie istnieje w tobym";
|
||||
}
|
||||
}
|
||||
43
app/Domain/Slack/Traits/FindsUserBySlackId.php
Normal file
@@ -0,0 +1,43 @@
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
<?php
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
declare(strict_types=1);
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
namespace Toby\Domain\Slack\Traits;
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
use Illuminate\Support\Str;
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
use Toby\Domain\Slack\UserNotFoundException;
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
trait FindsUserBySlackId
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
{
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
protected function findUserBySlackId(string $slackId): ?User
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
{
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
$id = $this->prepareSlackIdFromString($slackId);
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
/** @var User $user */
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
$user = User::query()
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
->whereRelation("profile", "slack_id", $id)
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
->first();
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
return $user;
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
}
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
/**
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
* @throws UserNotFoundException
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
*/
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
protected function findUserBySlackIdOrFail(string $slackId): ?User
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
{
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
$user = $this->findUserBySlackId($slackId);
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
if (!$user) {
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
throw new UserNotFoundException("Użytkownik {$slackId} nie istnieje w tobym");
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
}
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
return $user;
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
}
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
protected function prepareSlackIdFromString(string $slackId): string
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
{
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
return Str::between($slackId, "<@", "|");
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
}
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
}
|
||||
|
Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387 Is it required here? https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Collection.php#L387
Yes. Yes.
`Return value is expected to be 'null|\Toby\Eloquent\Models\User', '\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object' returned `
|
||||
45
app/Domain/Slack/Traits/ListsHandlers.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Slack\Traits;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
use Spatie\SlashCommand\AttachmentField;
|
||||
use Spatie\SlashCommand\Handlers\SignatureHandler;
|
||||
use Spatie\SlashCommand\Handlers\SignatureParts;
|
||||
use Spatie\SlashCommand\HandlesSlashCommand;
|
||||
|
||||
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)
|
||||
->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();
|
||||
}
|
||||
}
|
||||
11
app/Domain/Slack/UserNotFoundException.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Slack;
|
||||
|
||||
use Spatie\SlashCommand\Exceptions\SlackSlashCommandException;
|
||||
|
||||
class UserNotFoundException extends SlackSlashCommandException
|
||||
{
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use Database\Factories\KeyFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@@ -16,6 +17,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
class Key extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use Notifiable;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
@@ -24,6 +26,11 @@ class Key extends Model
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function routeNotificationForSlack(): string
|
||||
{
|
||||
return config("services.slack.default_channel");
|
||||
}
|
||||
|
||||
protected static function newFactory(): KeyFactory
|
||||
{
|
||||
return KeyFactory::new();
|
||||
|
||||
@@ -7,11 +7,9 @@ namespace Toby\Infrastructure\Console\Commands;
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Spatie\SlashCommand\Attachment;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
use Toby\Domain\VacationTypeConfigRetriever;
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
use Toby\Domain\DailySummaryRetriever;
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
use Toby\Eloquent\Models\Holiday;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Eloquent\Models\Vacation;
|
||||
@@ -21,7 +19,7 @@ class SendDailySummaryToSlack extends Command
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
protected $signature = "toby:slack:daily-summary {--f|force}";
|
||||
protected $description = "Sent daily summary to slack";
|
||||
|
||||
public function handle(VacationTypeConfigRetriever $configRetriever): void
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
public function handle(DailySummaryRetriever $dailySummaryRetriever): void
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
{
|
||||
$now = Carbon::today();
|
||||
|
||||
@@ -29,42 +27,28 @@ class SendDailySummaryToSlack extends Command
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var Collection $absences */
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
$absences = Vacation::query()
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->with(["user", "vacationRequest"])
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->whereDate("date", $now)
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->approved()
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->whereTypes(VacationType::all()->filter(fn(VacationType $type) => $configRetriever->isVacation($type)))
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->get()
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
$absences = $dailySummaryRetriever->getAbsences($now)
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
|
||||
|
||||
/** @var Collection $remoteDays */
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
$remoteDays = Vacation::query()
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->with(["user", "vacationRequest"])
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->whereDate("date", $now)
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->approved()
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->whereTypes(VacationType::all()->filter(fn(VacationType $type) => !$configRetriever->isVacation($type)))
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->get()
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
$remoteDays = $dailySummaryRetriever->getRemoteDays($now)
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->map(fn(Vacation $vacation) => $vacation->user->profile->full_name);
|
||||
|
||||
$birthdays = User::query()
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->whereRelation("profile", "birthday", $now)
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->get()
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
$birthdays = $dailySummaryRetriever->getBirthdays($now)
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->map(fn(User $user) => $user->profile->full_name);
|
||||
|
||||
$absencesAttachment = Attachment::create()
|
||||
->setTitle("Nieobecności :palm_tree:")
|
||||
->setColor('#eab308')
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->setColor("#eab308")
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->setText($absences->isNotEmpty() ? $absences->implode("\n") : "Wszyscy dzisiaj pracują :muscle:");
|
||||
|
||||
$remoteAttachment = Attachment::create()
|
||||
->setTitle("Praca zdalna :house_with_garden:")
|
||||
->setColor('#d946ef')
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->setColor("#d946ef")
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->setText($remoteDays->isNotEmpty() ? $remoteDays->implode("\n") : "Wszyscy dzisiaj są w biurze :boom:");
|
||||
|
||||
$birthdayAttachment = Attachment::create()
|
||||
->setTitle("Urodziny :birthday:")
|
||||
->setColor('#3C5F97')
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->setColor("#3C5F97")
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->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
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
->post($url, [
|
||||
"channel" => config("services.slack.default_channel"),
|
||||
"text" => "Podsumowanie dla dnia {$now->toDisplayString()}",
|
||||
'attachments' => collect([$absencesAttachment, $remoteAttachment, $birthdayAttachment])->map(
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
fn(Attachment $attachment) => $attachment->toArray()
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
"attachments" => collect([$absencesAttachment, $remoteAttachment, $birthdayAttachment])->map(
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
fn(Attachment $attachment) => $attachment->toArray(),
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
)->toArray(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
These attachments are almost the same as somewhere above. There should be some abstraction for that. These attachments are almost the same as somewhere above. There should be some abstraction for that.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it. I think I would prefer to use camelCased model attributes. It's not for this PR, but please think about it.
|
||||
@@ -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()
|
||||
|
||||
@@ -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.", [
|
||||
|
||||
@@ -62,7 +62,8 @@
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"dont-discover": [
|
||||
"laravel/telescope"
|
||||
"laravel/telescope",
|
||||
"spatie/laravel-slack-slash-command"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
],
|
||||
];
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||