2020-12-28 19:47:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Api\Application\Roles;
|
|
|
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
use Pterodactyl\Models\AdminRole;
|
|
|
|
use Pterodactyl\Transformers\Api\Application\AdminRoleTransformer;
|
2021-01-04 18:50:43 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Roles\GetRoleRequest;
|
2020-12-28 19:47:08 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Roles\GetRolesRequest;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Roles\StoreRoleRequest;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Roles\DeleteRoleRequest;
|
|
|
|
use Pterodactyl\Http\Requests\Api\Application\Roles\UpdateRoleRequest;
|
|
|
|
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
|
|
|
|
|
|
|
class RoleController extends ApplicationApiController
|
|
|
|
{
|
|
|
|
/**
|
2021-01-05 21:52:49 +00:00
|
|
|
* RoleController constructor.
|
2020-12-28 19:47:08 +00:00
|
|
|
*/
|
2021-01-05 21:52:49 +00:00
|
|
|
public function __construct()
|
2020-12-28 19:47:08 +00:00
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of all roles.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Application\Roles\GetRolesRequest $request
|
|
|
|
*
|
|
|
|
* @return array
|
2021-01-01 22:55:30 +00:00
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
2020-12-28 19:47:08 +00:00
|
|
|
*/
|
2021-01-01 22:55:30 +00:00
|
|
|
public function index(GetRolesRequest $request): array
|
2020-12-28 19:47:08 +00:00
|
|
|
{
|
|
|
|
return $this->fractal->collection(AdminRole::all())
|
|
|
|
->transformWith($this->getTransformer(AdminRoleTransformer::class))
|
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a single role.
|
|
|
|
*
|
2021-01-04 18:50:43 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Application\Roles\GetRoleRequest $request
|
2020-12-28 19:47:08 +00:00
|
|
|
* @param \Pterodactyl\Models\AdminRole $role
|
|
|
|
*
|
|
|
|
* @return array
|
2021-01-01 22:55:30 +00:00
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
2020-12-28 19:47:08 +00:00
|
|
|
*/
|
2021-01-04 18:50:43 +00:00
|
|
|
public function view(GetRoleRequest $request, AdminRole $role): array
|
2020-12-28 19:47:08 +00:00
|
|
|
{
|
|
|
|
return $this->fractal->item($role)
|
|
|
|
->transformWith($this->getTransformer(AdminRoleTransformer::class))
|
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new role.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Application\Roles\StoreRoleRequest $request
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2021-01-01 22:55:30 +00:00
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
2020-12-28 19:47:08 +00:00
|
|
|
*/
|
2021-01-01 22:55:30 +00:00
|
|
|
public function store(StoreRoleRequest $request): JsonResponse
|
2020-12-28 19:47:08 +00:00
|
|
|
{
|
|
|
|
$role = AdminRole::query()->create($request->validated());
|
|
|
|
|
|
|
|
return $this->fractal->item($role)
|
|
|
|
->transformWith($this->getTransformer(AdminRoleTransformer::class))
|
|
|
|
->respond(JsonResponse::HTTP_CREATED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates a role.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Application\Roles\UpdateRoleRequest $request
|
|
|
|
* @param \Pterodactyl\Models\AdminRole $role
|
|
|
|
*
|
|
|
|
* @return array
|
2021-01-01 22:55:30 +00:00
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
2020-12-28 19:47:08 +00:00
|
|
|
*/
|
2021-01-01 22:55:30 +00:00
|
|
|
public function update(UpdateRoleRequest $request, AdminRole $role): array
|
2020-12-28 19:47:08 +00:00
|
|
|
{
|
|
|
|
$role->update($request->validated());
|
|
|
|
|
|
|
|
return $this->fractal->item($role)
|
|
|
|
->transformWith($this->getTransformer(AdminRoleTransformer::class))
|
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a role.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Api\Application\Roles\DeleteRoleRequest $request
|
|
|
|
* @param \Pterodactyl\Models\AdminRole $role
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2021-01-05 21:52:49 +00:00
|
|
|
* @throws \Exception
|
2020-12-28 19:47:08 +00:00
|
|
|
*/
|
2021-01-01 22:55:30 +00:00
|
|
|
public function delete(DeleteRoleRequest $request, AdminRole $role): JsonResponse
|
2020-12-28 19:47:08 +00:00
|
|
|
{
|
2021-01-05 21:52:49 +00:00
|
|
|
$role->delete();
|
2020-12-28 19:47:08 +00:00
|
|
|
|
|
|
|
return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT);
|
|
|
|
}
|
|
|
|
}
|