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;
|
|
|
|
use Pterodactyl\Contracts\Http\ClientPermissionsRequest;
|
2018-02-28 03:28:43 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
|
|
|
|
2019-07-27 22:17:50 +00:00
|
|
|
/**
|
2020-03-19 04:08:32 +00:00
|
|
|
* @method \Pterodactyl\Models\User user($guard = null)
|
2019-07-27 22:17:50 +00:00
|
|
|
*/
|
2020-03-19 04:08:32 +00:00
|
|
|
class ClientApiRequest extends ApplicationApiRequest
|
2018-02-28 03:28:43 +00:00
|
|
|
{
|
|
|
|
/**
|
2018-08-23 05:29:20 +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
|
|
|
|
{
|
2018-08-23 05:29:20 +00:00
|
|
|
if ($this instanceof ClientPermissionsRequest || method_exists($this, 'permission')) {
|
2020-03-22 20:56:15 +00:00
|
|
|
$server = $this->route()->parameter('server');
|
|
|
|
|
|
|
|
if ($server instanceof Server) {
|
|
|
|
return $this->user()->can($this->permission(), $server);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-08-23 05:29:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 03:28:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|