wip
This commit is contained in:
parent
d60dc75f99
commit
7d12a1a153
49
app/Domain/Slack/GiveKeysTo.php
Normal file
49
app/Domain/Slack/GiveKeysTo.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Toby\Domain\Slack;
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Spatie\SlashCommand\Request;
|
||||||
|
use Spatie\SlashCommand\Response;
|
||||||
|
use Spatie\SlashCommand\Handlers\SignatureHandler;
|
||||||
|
use Toby\Eloquent\Models\Key;
|
||||||
|
use Toby\Eloquent\Models\User;
|
||||||
|
|
||||||
|
class GiveKeysTo extends SignatureHandler
|
||||||
|
{
|
||||||
|
protected $signature = "toby klucze:dla {to}";
|
||||||
|
|
||||||
|
protected $description = "Daj klucze użytkownikowi {to}";
|
||||||
|
|
||||||
|
public function handle(Request $request): Response
|
||||||
|
{
|
||||||
|
$to = $this->getArgument('to');
|
||||||
|
|
||||||
|
$id = Str::between($to, "@", "|");
|
||||||
|
|
||||||
|
$authUser = $this->findUserBySlackId($request->userId);
|
||||||
|
$user = $this->findUserBySlackId($id);
|
||||||
|
|
||||||
|
/** @var Key $key */
|
||||||
|
$key = $authUser->keys()->first();
|
||||||
|
|
||||||
|
$key->user()->associate($user);
|
||||||
|
|
||||||
|
$key->save();
|
||||||
|
|
||||||
|
return $this->respondToSlack("<@{$authUser->profile->slack_id}> daje klucz nr {$key->id} użytkownikowi <@{$user->profile->slack_id}>")
|
||||||
|
->displayResponseToEveryoneOnChannel();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function findUserBySlackId(string $slackId): User
|
||||||
|
{
|
||||||
|
/** @var User $user */
|
||||||
|
$user = User::query()
|
||||||
|
->whereRelation("profile", "slack_id", $slackId)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
}
|
58
app/Domain/Slack/HomeOffice.php
Normal file
58
app/Domain/Slack/HomeOffice.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Toby\Domain\Slack;
|
||||||
|
|
||||||
|
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\Eloquent\Models\User;
|
||||||
|
use Toby\Eloquent\Models\YearPeriod;
|
||||||
|
|
||||||
|
class HomeOffice extends SignatureHandler
|
||||||
|
{
|
||||||
|
protected $signature = "toby zdalnie {date=dzisiaj}";
|
||||||
|
protected $description = "Praca zdalna {kiedy}";
|
||||||
|
|
||||||
|
public function handle(Request $request): Response
|
||||||
|
{
|
||||||
|
$date = $this->getDateFromArgument($this->getArgument('date'));
|
||||||
|
$user = $this->findUserBySlackId($request->userId);
|
||||||
|
|
||||||
|
$yearPeriod = YearPeriod::findByYear($date->year);
|
||||||
|
|
||||||
|
app(CreateAction::class)->execute([
|
||||||
|
"user_id" => $user->id,
|
||||||
|
"type" => VacationType::HomeOffice,
|
||||||
|
"from" => $date,
|
||||||
|
"to" => $date,
|
||||||
|
"year_period_id" => $yearPeriod->id,
|
||||||
|
"flow_skipped" => false,
|
||||||
|
], $user);
|
||||||
|
|
||||||
|
return $this->respondToSlack("Praca zdalna dnia {$date->toDisplayString()} została utworzona pomyślnie");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getDateFromArgument(string $argument): Carbon
|
||||||
|
{
|
||||||
|
return match ($argument) {
|
||||||
|
"dzisiaj" => Carbon::today(),
|
||||||
|
"jutro" => Carbon::tomorrow(),
|
||||||
|
default => Carbon::create($argument),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function findUserBySlackId(string $slackId): User
|
||||||
|
{
|
||||||
|
/** @var User $user */
|
||||||
|
$user = User::query()
|
||||||
|
->whereRelation("profile", "slack_id", $slackId)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
}
|
30
app/Domain/Slack/KeyList.php
Normal file
30
app/Domain/Slack/KeyList.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Toby\Domain\Slack;
|
||||||
|
|
||||||
|
use Spatie\SlashCommand\Request;
|
||||||
|
use Spatie\SlashCommand\Response;
|
||||||
|
use Spatie\SlashCommand\Handlers\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
|
||||||
|
{
|
||||||
|
$temp = [];
|
||||||
|
|
||||||
|
foreach (Key::orderBy("id")->get() as $key) {
|
||||||
|
$temp[] = "Klucz nr {$key->id} - <@{$key->user->profile->slack_id}>";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $this->respondToSlack(implode("\n", $temp))
|
||||||
|
->displayResponseToEveryoneOnChannel();
|
||||||
|
}
|
||||||
|
}
|
49
app/Domain/Slack/TakeKeysFrom.php
Normal file
49
app/Domain/Slack/TakeKeysFrom.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Toby\Domain\Slack;
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Spatie\SlashCommand\Request;
|
||||||
|
use Spatie\SlashCommand\Response;
|
||||||
|
use Spatie\SlashCommand\Handlers\SignatureHandler;
|
||||||
|
use Toby\Eloquent\Models\Key;
|
||||||
|
use Toby\Eloquent\Models\User;
|
||||||
|
|
||||||
|
class TakeKeysFrom extends SignatureHandler
|
||||||
|
{
|
||||||
|
protected $signature = "toby klucze:od {from}";
|
||||||
|
|
||||||
|
protected $description = "Zabierz klucze użytkownikowi {from}";
|
||||||
|
|
||||||
|
public function handle(Request $request): Response
|
||||||
|
{
|
||||||
|
$from = $this->getArgument('from');
|
||||||
|
|
||||||
|
$id = Str::between($from, "@", "|");
|
||||||
|
|
||||||
|
$authUser = $this->findUserBySlackId($request->userId);
|
||||||
|
$user = $this->findUserBySlackId($id);
|
||||||
|
|
||||||
|
/** @var Key $key */
|
||||||
|
$key = $user->keys()->first();
|
||||||
|
|
||||||
|
$key->user()->associate($authUser);
|
||||||
|
|
||||||
|
$key->save();
|
||||||
|
|
||||||
|
return $this->respondToSlack("<@{$authUser->profile->slack_id}> zabiera klucz nr {$key->id} użytkownikowi <@{$user->profile->slack_id}>")
|
||||||
|
->displayResponseToEveryoneOnChannel();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function findUserBySlackId(string $slackId): User
|
||||||
|
{
|
||||||
|
/** @var User $user */
|
||||||
|
$user = User::query()
|
||||||
|
->whereRelation("profile", "slack_id", $slackId)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,8 @@
|
|||||||
"maatwebsite/excel": "^3.1",
|
"maatwebsite/excel": "^3.1",
|
||||||
"rackbeat/laravel-ui-avatars": "^1.0",
|
"rackbeat/laravel-ui-avatars": "^1.0",
|
||||||
"spatie/laravel-google-calendar": "^3.5",
|
"spatie/laravel-google-calendar": "^3.5",
|
||||||
"spatie/laravel-model-states": "^2.1"
|
"spatie/laravel-model-states": "^2.1",
|
||||||
|
"spatie/laravel-slack-slash-command": "^1.11"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"blumilksoftware/codestyle": "^1.0.0",
|
"blumilksoftware/codestyle": "^1.0.0",
|
||||||
|
125
composer.lock
generated
125
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "414a1fc13e0731e59605248bd4e39de6",
|
"content-hash": "17caa1f146a96a76822006d13f440645",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "asm89/stack-cors",
|
"name": "asm89/stack-cors",
|
||||||
@ -1910,6 +1910,62 @@
|
|||||||
},
|
},
|
||||||
"time": "2022-04-05T15:07:51+00:00"
|
"time": "2022-04-05T15:07:51+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "laravel/helpers",
|
||||||
|
"version": "v1.5.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/laravel/helpers.git",
|
||||||
|
"reference": "c28b0ccd799d58564c41a62395ac9511a1e72931"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/laravel/helpers/zipball/c28b0ccd799d58564c41a62395ac9511a1e72931",
|
||||||
|
"reference": "c28b0ccd799d58564c41a62395ac9511a1e72931",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"illuminate/support": "~5.8.0|^6.0|^7.0|^8.0|^9.0",
|
||||||
|
"php": "^7.1.3|^8.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^7.0|^8.0|^9.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"src/helpers.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Taylor Otwell",
|
||||||
|
"email": "taylor@laravel.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Dries Vints",
|
||||||
|
"email": "dries@laravel.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Provides backwards compatibility for helpers in the latest Laravel release.",
|
||||||
|
"keywords": [
|
||||||
|
"helpers",
|
||||||
|
"laravel"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/laravel/helpers/tree/v1.5.0"
|
||||||
|
},
|
||||||
|
"time": "2022-01-12T15:58:51+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "laravel/sanctum",
|
"name": "laravel/sanctum",
|
||||||
"version": "v2.15.0",
|
"version": "v2.15.0",
|
||||||
@ -5171,6 +5227,71 @@
|
|||||||
],
|
],
|
||||||
"time": "2022-03-15T20:01:36+00:00"
|
"time": "2022-03-15T20:01:36+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "spatie/laravel-slack-slash-command",
|
||||||
|
"version": "1.11.3",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/spatie/laravel-slack-slash-command.git",
|
||||||
|
"reference": "8e507653054ff08581b28d6ddf5bb4ce8c2e2335"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/spatie/laravel-slack-slash-command/zipball/8e507653054ff08581b28d6ddf5bb4ce8c2e2335",
|
||||||
|
"reference": "8e507653054ff08581b28d6ddf5bb4ce8c2e2335",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"guzzlehttp/guzzle": "^7.0",
|
||||||
|
"illuminate/config": "~5.8.0|^6.0|^7.0|^8.0|^9.0",
|
||||||
|
"illuminate/queue": "~5.8.0|^6.0|^7.0|^8.0|^9.0",
|
||||||
|
"illuminate/routing": "~5.8.0|^6.0|^7.0|^8.0|^9.0",
|
||||||
|
"illuminate/support": "~5.8.0|^6.0|^7.0|^8.0|^9.0",
|
||||||
|
"laravel/helpers": "^1.0",
|
||||||
|
"php": "^7.3|^8.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"mockery/mockery": "^1.0",
|
||||||
|
"orchestra/testbench": "~3.8.0|^4.0|^5.0|^6.0|^7.0",
|
||||||
|
"phpunit/phpunit": "^9.2"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"laravel": {
|
||||||
|
"providers": [
|
||||||
|
"Spatie\\SlashCommand\\SlashCommandServiceProvider"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Spatie\\SlashCommand\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Freek Van der Herten",
|
||||||
|
"email": "freek@spatie.be",
|
||||||
|
"homepage": "https://spatie.be",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Make a Laravel app respond to a slash command from Slack",
|
||||||
|
"homepage": "https://github.com/spatie/laravel-slack-slash-command",
|
||||||
|
"keywords": [
|
||||||
|
"laravel-slack",
|
||||||
|
"spatie"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/spatie/laravel-slack-slash-command/issues",
|
||||||
|
"source": "https://github.com/spatie/laravel-slack-slash-command/tree/1.11.3"
|
||||||
|
},
|
||||||
|
"time": "2022-02-09T07:58:01+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/console",
|
"name": "symfony/console",
|
||||||
"version": "v6.0.7",
|
"version": "v6.0.7",
|
||||||
@ -10931,5 +11052,5 @@
|
|||||||
"ext-redis": "*"
|
"ext-redis": "*"
|
||||||
},
|
},
|
||||||
"platform-dev": [],
|
"platform-dev": [],
|
||||||
"plugin-api-version": "2.1.0"
|
"plugin-api-version": "2.2.0"
|
||||||
}
|
}
|
||||||
|
@ -37,12 +37,13 @@ return [
|
|||||||
Illuminate\Translation\TranslationServiceProvider::class,
|
Illuminate\Translation\TranslationServiceProvider::class,
|
||||||
Illuminate\Validation\ValidationServiceProvider::class,
|
Illuminate\Validation\ValidationServiceProvider::class,
|
||||||
Illuminate\View\ViewServiceProvider::class,
|
Illuminate\View\ViewServiceProvider::class,
|
||||||
|
Barryvdh\DomPDF\ServiceProvider::class,
|
||||||
|
Spatie\SlashCommand\SlashCommandServiceProvider::class,
|
||||||
Toby\Architecture\Providers\AppServiceProvider::class,
|
Toby\Architecture\Providers\AppServiceProvider::class,
|
||||||
Toby\Architecture\Providers\AuthServiceProvider::class,
|
Toby\Architecture\Providers\AuthServiceProvider::class,
|
||||||
Toby\Architecture\Providers\EventServiceProvider::class,
|
Toby\Architecture\Providers\EventServiceProvider::class,
|
||||||
Toby\Architecture\Providers\RouteServiceProvider::class,
|
Toby\Architecture\Providers\RouteServiceProvider::class,
|
||||||
Toby\Architecture\Providers\TelescopeServiceProvider::class,
|
Toby\Architecture\Providers\TelescopeServiceProvider::class,
|
||||||
Toby\Architecture\Providers\ObserverServiceProvider::class,
|
Toby\Architecture\Providers\ObserverServiceProvider::class,
|
||||||
Barryvdh\DomPDF\ServiceProvider::class,
|
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
20
config/laravel-slack-slash-command.php
Normal file
20
config/laravel-slack-slash-command.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Toby\Domain\Slack\GiveKeysTo;
|
||||||
|
use Toby\Domain\Slack\HomeOffice;
|
||||||
|
use Toby\Domain\Slack\KeyList;
|
||||||
|
use Toby\Domain\Slack\TakeKeysFrom;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'url' => 'api/slack',
|
||||||
|
'signing_secret' => env('SLACK_SIGNING_SECRET'),
|
||||||
|
'verify_with_signing' => true,
|
||||||
|
'handlers' => [
|
||||||
|
TakeKeysFrom::class,
|
||||||
|
GiveKeysTo::class,
|
||||||
|
KeyList::class,
|
||||||
|
HomeOffice::class,
|
||||||
|
Spatie\SlashCommand\Handlers\Help::class,
|
||||||
|
Spatie\SlashCommand\Handlers\CatchAll::class,
|
||||||
|
],
|
||||||
|
];
|
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class() extends Migration {
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table("profiles", function (Blueprint $table): void {
|
||||||
|
$table->string("slack_id")->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table("profiles", function (Blueprint $table): void {
|
||||||
|
$table->string("slack_id");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user