2018-02-28 03:28:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Requests\Api\Client;
|
|
|
|
|
2018-08-23 05:29:20 +00:00
|
|
|
use Pterodactyl\Models\Server;
|
2021-08-05 04:14:14 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\ApiRequest;
|
2018-02-28 03:28:43 +00:00
|
|
|
|
2021-08-05 04:14:14 +00:00
|
|
|
abstract class ClientApiRequest extends ApiRequest
|
2018-02-28 03:28:43 +00:00
|
|
|
{
|
2021-08-05 04:14:14 +00:00
|
|
|
/**
|
|
|
|
* Returns the permissions string indicating which permission should be used to
|
|
|
|
* validate that the authenticated user has permission to perform this action aganist
|
|
|
|
* the given resource (server).
|
|
|
|
*/
|
|
|
|
abstract public function permission(): string;
|
|
|
|
|
2018-02-28 03:28:43 +00:00
|
|
|
/**
|
2021-08-05 03:55:15 +00:00
|
|
|
* Determine if the current user is authorized to perform the requested action
|
|
|
|
* against the API.
|
2018-02-28 03:28:43 +00:00
|
|
|
*/
|
|
|
|
public function authorize(): bool
|
|
|
|
{
|
2021-08-05 03:55:15 +00:00
|
|
|
$server = $this->route()->parameter('server');
|
2020-03-22 20:56:15 +00:00
|
|
|
|
2021-08-05 03:55:15 +00:00
|
|
|
if ($server instanceof Server) {
|
|
|
|
return $this->user()->can($this->permission(), $server);
|
2018-08-23 05:29:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-05 03:55:15 +00:00
|
|
|
// If there is no server available on the reqest, trigger a failure since
|
|
|
|
// we expect there to be one at this point.
|
|
|
|
return false;
|
2018-02-28 03:28:43 +00:00
|
|
|
}
|
|
|
|
}
|