2018-02-28 03:28:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Server;
|
2020-03-22 23:56:00 +00:00
|
|
|
use Pterodactyl\Repositories\Eloquent\SubuserRepository;
|
2018-02-28 03:28:43 +00:00
|
|
|
use Pterodactyl\Transformers\Api\Client\ServerTransformer;
|
2020-03-22 23:56:00 +00:00
|
|
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
2018-02-28 03:28:43 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest;
|
|
|
|
|
|
|
|
class ServerController extends ClientApiController
|
|
|
|
{
|
2020-03-22 23:56:00 +00:00
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Repositories\Eloquent\SubuserRepository
|
|
|
|
*/
|
|
|
|
private $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ServerController constructor.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Repositories\Eloquent\SubuserRepository $repository
|
|
|
|
*/
|
|
|
|
public function __construct(SubuserRepository $repository)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
2018-02-28 03:28:43 +00:00
|
|
|
/**
|
|
|
|
* Transform an individual server into a response that can be consumed by a
|
|
|
|
* client using the API.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Client\Servers\GetServerRequest $request
|
2019-09-06 04:41:20 +00:00
|
|
|
* @param \Pterodactyl\Models\Server $server
|
2018-02-28 03:28:43 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2019-09-06 04:41:20 +00:00
|
|
|
public function index(GetServerRequest $request, Server $server): array
|
2018-02-28 03:28:43 +00:00
|
|
|
{
|
2020-03-22 23:56:00 +00:00
|
|
|
try {
|
|
|
|
$permissions = $this->repository->findFirstWhere([
|
|
|
|
'server_id' => $server->id,
|
|
|
|
'user_id' => $request->user()->id,
|
|
|
|
])->permissions;
|
|
|
|
} catch (RecordNotFoundException $exception) {
|
|
|
|
$permissions = [];
|
|
|
|
}
|
|
|
|
|
2019-09-06 04:41:20 +00:00
|
|
|
return $this->fractal->item($server)
|
2018-02-28 03:28:43 +00:00
|
|
|
->transformWith($this->getTransformer(ServerTransformer::class))
|
2020-03-22 23:56:00 +00:00
|
|
|
->addMeta([
|
|
|
|
'is_server_owner' => $request->user()->id === $server->owner_id,
|
|
|
|
'user_permissions' => $permissions,
|
|
|
|
])
|
2018-02-28 03:28:43 +00:00
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
}
|