Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
UserPluginEditFilterMiddleware | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
handleBefore | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
42 | |||
handleAfter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Middleware; |
6 | |
7 | use PeServer\App\Models\AppDatabase; |
8 | use PeServer\App\Models\Dao\Entities\PluginsEntityDao; |
9 | use PeServer\App\Models\SessionKey; |
10 | use PeServer\Core\Database\IDatabaseConnection; |
11 | use PeServer\Core\Http\HttpRequest; |
12 | use PeServer\Core\Http\HttpRequestExists; |
13 | use PeServer\Core\Http\HttpResponse; |
14 | use PeServer\Core\Http\HttpStatus; |
15 | use PeServer\Core\Mvc\Middleware\IMiddleware; |
16 | use PeServer\Core\Mvc\Middleware\MiddlewareArgument; |
17 | use PeServer\Core\Mvc\Middleware\MiddlewareResult; |
18 | use PeServer\Core\Uuid; |
19 | |
20 | final class UserPluginEditFilterMiddleware implements IMiddleware |
21 | { |
22 | public function __construct( |
23 | private IDatabaseConnection $connection |
24 | ) { |
25 | } |
26 | |
27 | //[IMiddleware] |
28 | |
29 | final public function handleBefore(MiddlewareArgument $argument): MiddlewareResult |
30 | { |
31 | $pluginIdState = $argument->request->exists('plugin_id'); |
32 | if ($pluginIdState->exists && $pluginIdState->kind === HttpRequestExists::KIND_URL) { |
33 | $pluginId = $argument->request->getValue($pluginIdState->name); |
34 | // ここにきてるってことはユーザーフィルタを通過しているのでセッションを見る必要はないけど一応ね |
35 | if (Uuid::isGuid($pluginId) && $argument->stores->session->tryGet(SessionKey::ACCOUNT, $account)) { |
36 | $pluginId = Uuid::adjustGuid($pluginId); |
37 | $database = $this->connection->open(); |
38 | $pluginsEntityDao = new PluginsEntityDao($database); |
39 | /** @var \PeServer\App\Models\Data\SessionAccount $account */ |
40 | if ($pluginsEntityDao->selectIsUserPlugin($pluginId, $account->userId)) { |
41 | return MiddlewareResult::none(); |
42 | } |
43 | } |
44 | } |
45 | |
46 | return MiddlewareResult::error(HttpStatus::NotFound); |
47 | } |
48 | |
49 | public function handleAfter(MiddlewareArgument $argument, HttpResponse $response): MiddlewareResult |
50 | { |
51 | return MiddlewareResult::none(); |
52 | } |
53 | } |