tmp
This commit is contained in:
parent
df6f5c3a09
commit
e7aeeace26
18 changed files with 614 additions and 65 deletions
75
app/Http/Controllers/Admin/RolesController.php
Normal file
75
app/Http/Controllers/Admin/RolesController.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Admin;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Http\Requests\Admin\RoleFormRequest;
|
||||
use Pterodactyl\Repositories\Eloquent\AdminRolesRepository;
|
||||
|
||||
class RolesController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\AdminRolesRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* RolesController constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Repositories\Eloquent\AdminRolesRepository $repository
|
||||
*/
|
||||
public function __construct(AdminRolesRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all roles.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return new JsonResponse($this->repository->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new role.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Admin\RoleFormRequest $request
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function create(RoleFormRequest $request)
|
||||
{
|
||||
$role = $this->repository->create($request->normalize());
|
||||
|
||||
return new JsonResponse($role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a role.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
return response('', 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a role.
|
||||
*
|
||||
* @param int $role_id
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
|
||||
*/
|
||||
public function delete(int $role_id)
|
||||
{
|
||||
$this->repository->delete($role_id);
|
||||
|
||||
return response('', 204);
|
||||
}
|
||||
}
|
29
app/Http/Requests/Admin/RoleFormRequest.php
Normal file
29
app/Http/Requests/Admin/RoleFormRequest.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Http\Requests\Admin;
|
||||
|
||||
use Pterodactyl\Models\AdminRole;
|
||||
|
||||
class RoleFormRequest extends AdminFormRequest
|
||||
{
|
||||
/**
|
||||
* Setup the validation rules to use for these requests.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
if ($this->method() === 'PATCH') {
|
||||
return AdminRole::getRulesForUpdate($this->route()->parameter('mount')->id);
|
||||
}
|
||||
|
||||
return AdminRole::getRules();
|
||||
}
|
||||
}
|
43
app/Models/AdminRole.php
Normal file
43
app/Models/AdminRole.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string|null $description
|
||||
* @property int $sort_id
|
||||
*/
|
||||
class AdminRole extends Model
|
||||
{
|
||||
/**
|
||||
* The resource name for this model when it is transformed into an
|
||||
* API representation using fractal.
|
||||
*/
|
||||
const RESOURCE_NAME = 'admin_role';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'admin_roles';
|
||||
|
||||
/**
|
||||
* Fields that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
'name' => 'required|string|max:64',
|
||||
'description' => 'nullable|string|max:255',
|
||||
];
|
||||
}
|
18
app/Repositories/Eloquent/AdminRolesRepository.php
Normal file
18
app/Repositories/Eloquent/AdminRolesRepository.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Repositories\Eloquent;
|
||||
|
||||
use Pterodactyl\Models\AdminRole;
|
||||
|
||||
class AdminRolesRepository extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
{
|
||||
return AdminRole::class;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue