misc_pterodactyl-panel/app/Http/Requests/Admin/Api/StoreApplicationApiKeyRequest.php

42 lines
1.1 KiB
PHP
Raw Normal View History

2018-01-19 03:36:15 +00:00
<?php
namespace Pterodactyl\Http\Requests\Admin\Api;
use Pterodactyl\Models\ApiKey;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
class StoreApplicationApiKeyRequest extends AdminFormRequest
{
/**
* @return array
2018-05-13 16:30:53 +00:00
* @throws \ReflectionException
* @throws \ReflectionException
2018-01-19 03:36:15 +00:00
*/
public function rules()
{
$modelRules = ApiKey::getCreateRules();
return collect(AdminAcl::getResourceList())->mapWithKeys(function ($resource) use ($modelRules) {
2018-05-13 14:50:56 +00:00
return [AdminAcl::COLUMN_IDENTIFIER . $resource => $modelRules['r_' . $resource]];
2018-01-19 03:36:15 +00:00
})->merge(['memo' => $modelRules['memo']])->toArray();
}
/**
* @return array
*/
public function attributes()
{
return [
'memo' => 'Description',
];
}
public function getKeyPermissions(): array
{
return collect($this->validated())->filter(function ($value, $key) {
2018-05-13 14:50:56 +00:00
return substr($key, 0, strlen(AdminAcl::COLUMN_IDENTIFIER)) === AdminAcl::COLUMN_IDENTIFIER;
2018-01-19 03:36:15 +00:00
})->toArray();
}
}