Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Requests/Admin/Api/StoreApplicationApiKeyRequest.php
10283 views
1
<?php
2
3
namespace Pterodactyl\Http\Requests\Admin\Api;
4
5
use Pterodactyl\Models\ApiKey;
6
use Pterodactyl\Services\Acl\Api\AdminAcl;
7
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
8
9
class StoreApplicationApiKeyRequest extends AdminFormRequest
10
{
11
/**
12
* @throws \ReflectionException
13
* @throws \ReflectionException
14
*/
15
public function rules(): array
16
{
17
$modelRules = ApiKey::getRules();
18
19
return collect(AdminAcl::getResourceList())->mapWithKeys(function ($resource) use ($modelRules) {
20
return [AdminAcl::COLUMN_IDENTIFIER . $resource => $modelRules['r_' . $resource]];
21
})->merge(['memo' => $modelRules['memo']])->toArray();
22
}
23
24
public function attributes(): array
25
{
26
return [
27
'memo' => 'Description',
28
];
29
}
30
31
public function getKeyPermissions(): array
32
{
33
return collect($this->validated())->filter(function ($value, $key) {
34
return substr($key, 0, strlen(AdminAcl::COLUMN_IDENTIFIER)) === AdminAcl::COLUMN_IDENTIFIER;
35
})->toArray();
36
}
37
}
38
39