Move services onto new services system, includes tests
This commit is contained in:
parent
e91079d128
commit
90bbe57148
26 changed files with 899 additions and 272 deletions
|
@ -38,7 +38,7 @@ use Pterodactyl\Http\Requests\Admin\Service\ServiceOptionFormRequest;
|
|||
use Pterodactyl\Services\Services\Options\InstallScriptUpdateService;
|
||||
use Pterodactyl\Contracts\Repository\ServiceOptionRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Services\ServiceOption\InvalidCopyFromException;
|
||||
use Pterodactyl\Exceptions\Services\ServiceOption\HasActiveServersException;
|
||||
use Pterodactyl\Exceptions\Services\HasActiveServersException;
|
||||
use Pterodactyl\Exceptions\Services\ServiceOption\NoParentConfigurationFoundException;
|
||||
|
||||
class OptionController extends Controller
|
||||
|
@ -145,14 +145,14 @@ class OptionController extends Controller
|
|||
/**
|
||||
* Delete a given option from the database.
|
||||
*
|
||||
* @param \Pterodactyl\Models\ServiceOption $option
|
||||
* @param \Pterodactyl\Models\ServiceOption $option
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete(ServiceOption $option)
|
||||
public function destroy(ServiceOption $option)
|
||||
{
|
||||
try {
|
||||
$this->optionDeletionService->handle($option->id);
|
||||
$this->alert->success()->flash();
|
||||
$this->alert->success(trans('admin/services.options.notices.option_deleted'))->flash();
|
||||
} catch (HasActiveServersException $exception) {
|
||||
$this->alert->danger($exception->getMessage())->flash();
|
||||
|
||||
|
@ -229,6 +229,7 @@ class OptionController extends Controller
|
|||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function updateScripts(EditOptionScript $request, ServiceOption $option)
|
||||
{
|
||||
|
|
|
@ -24,37 +24,76 @@
|
|||
|
||||
namespace Pterodactyl\Http\Controllers\Admin;
|
||||
|
||||
use Log;
|
||||
use Alert;
|
||||
use Pterodactyl\Models;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Models\Service;
|
||||
use Prologue\Alerts\AlertsMessageBag;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Repositories\ServiceRepository;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
use Pterodactyl\Services\Services\ServiceUpdateService;
|
||||
use Pterodactyl\Services\Services\ServiceCreationService;
|
||||
use Pterodactyl\Services\Services\ServiceDeletionService;
|
||||
use Pterodactyl\Exceptions\Services\HasActiveServersException;
|
||||
use Pterodactyl\Http\Requests\Admin\Service\ServiceFormRequest;
|
||||
use Pterodactyl\Contracts\Repository\ServiceRepositoryInterface;
|
||||
use Pterodactyl\Http\Requests\Admin\Service\ServiceFunctionsFormRequest;
|
||||
|
||||
class ServiceController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var \Prologue\Alerts\AlertsMessageBag
|
||||
*/
|
||||
protected $alert;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Services\ServiceCreationService
|
||||
*/
|
||||
protected $creationService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Services\ServiceDeletionService
|
||||
*/
|
||||
protected $deletionService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServiceRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Services\ServiceUpdateService
|
||||
*/
|
||||
protected $updateService;
|
||||
|
||||
public function __construct(
|
||||
AlertsMessageBag $alert,
|
||||
ServiceCreationService $creationService,
|
||||
ServiceDeletionService $deletionService,
|
||||
ServiceRepositoryInterface $repository,
|
||||
ServiceUpdateService $updateService
|
||||
) {
|
||||
$this->alert = $alert;
|
||||
$this->creationService = $creationService;
|
||||
$this->deletionService = $deletionService;
|
||||
$this->repository = $repository;
|
||||
$this->updateService = $updateService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display service overview page.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
public function index()
|
||||
{
|
||||
return view('admin.services.index', [
|
||||
'services' => Models\Service::withCount('servers', 'options', 'packs')->get(),
|
||||
'services' => $this->repository->getWithOptions(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display create service page.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create(Request $request)
|
||||
public function create()
|
||||
{
|
||||
return view('admin.services.new');
|
||||
}
|
||||
|
@ -62,91 +101,96 @@ class ServiceController extends Controller
|
|||
/**
|
||||
* Return base view for a service.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @param int $service
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function view(Request $request, $id)
|
||||
public function view($service)
|
||||
{
|
||||
return view('admin.services.view', [
|
||||
'service' => Models\Service::with('options', 'options.servers')->findOrFail($id),
|
||||
'service' => $this->repository->getWithOptionServers($service),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return function editing view for a service.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @param \Pterodactyl\Models\Service $service
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function viewFunctions(Request $request, $id)
|
||||
public function viewFunctions(Service $service)
|
||||
{
|
||||
return view('admin.services.functions', ['service' => Models\Service::findOrFail($id)]);
|
||||
return view('admin.services.functions', ['service' => $service]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle post action for new service.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Pterodactyl\Http\Requests\Admin\Service\ServiceFormRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store(ServiceFormRequest $request)
|
||||
{
|
||||
$repo = new ServiceRepository;
|
||||
$service = $this->creationService->handle($request->normalize());
|
||||
$this->alert->success(trans('admin/services.notices.service_created', ['name' => $service->name]))->flash();
|
||||
|
||||
try {
|
||||
$service = $repo->create($request->intersect([
|
||||
'name', 'description', 'folder', 'startup',
|
||||
]));
|
||||
Alert::success('Successfully created new service!')->flash();
|
||||
|
||||
return redirect()->route('admin.services.view', $service->id);
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.services.new')->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error occured while attempting to add a new service. This error has been logged.')->flash();
|
||||
}
|
||||
|
||||
return redirect()->route('admin.services.new')->withInput();
|
||||
return redirect()->route('admin.services.view', $service->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits configuration for a specific service.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @param \Pterodactyl\Http\Requests\Admin\Service\ServiceFormRequest $request
|
||||
* @param \Pterodactyl\Models\Service $service
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function update(ServiceFormRequest $request, Service $service)
|
||||
{
|
||||
$this->updateService->handle($service->id, $request->normalize());
|
||||
$this->alert->success(trans('admin/services.notices.service_updated'))->flash();
|
||||
|
||||
return redirect()->route('admin.services.view', $service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the functions file for a service.
|
||||
*
|
||||
* @param \Pterodactyl\Http\Requests\Admin\Service\ServiceFunctionsFormRequest $request
|
||||
* @param \Pterodactyl\Models\Service $service
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function updateFunctions(ServiceFunctionsFormRequest $request, Service $service)
|
||||
{
|
||||
$this->updateService->handle($service->id, $request->normalize());
|
||||
$this->alert->success(trans('admin/services.notices.functions_updated'))->flash();
|
||||
|
||||
return redirect()->route('admin.services.view.functions', $service->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a service from the panel.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Service $service
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function edit(Request $request, $id)
|
||||
public function destroy(Service $service)
|
||||
{
|
||||
$repo = new ServiceRepository;
|
||||
$redirectTo = ($request->input('redirect_to')) ? 'admin.services.view.functions' : 'admin.services.view';
|
||||
|
||||
try {
|
||||
if ($request->input('action') !== 'delete') {
|
||||
$repo->update($id, $request->intersect([
|
||||
'name', 'description', 'folder', 'startup', 'index_file',
|
||||
]));
|
||||
Alert::success('Service has been updated successfully.')->flash();
|
||||
} else {
|
||||
$repo->delete($id);
|
||||
Alert::success('Successfully deleted service from the system.')->flash();
|
||||
$this->deletionService->handle($service->id);
|
||||
$this->alert->success(trans('admin/services.notices.service_deleted'))->flash();
|
||||
} catch (HasActiveServersException $exception) {
|
||||
$this->alert->danger($exception->getMessage())->flash();
|
||||
|
||||
return redirect()->route('admin.services');
|
||||
}
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route($redirectTo, $id)->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error occurred while attempting to update this service. This error has been logged.')->flash();
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
return redirect()->route($redirectTo, $id);
|
||||
return redirect()->route('admin.services');
|
||||
}
|
||||
}
|
||||
|
|
52
app/Http/Requests/Admin/Service/ServiceFormRequest.php
Normal file
52
app/Http/Requests/Admin/Service/ServiceFormRequest.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/*
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Http\Requests\Admin\Service;
|
||||
|
||||
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
|
||||
|
||||
class ServiceFormRequest extends AdminFormRequest
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$rules = [
|
||||
'name' => 'required|string|min:1|max:255',
|
||||
'description' => 'required|nullable|string',
|
||||
'folder' => 'required|regex:/^[\w.-]{1,50}$/|unique:services,folder',
|
||||
'startup' => 'required|nullable|string',
|
||||
];
|
||||
|
||||
if ($this->method() === 'PATCH') {
|
||||
$service = $this->route()->parameter('service');
|
||||
$rules['folder'] = $rules['folder'] . ',' . $service->id;
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/*
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Http\Requests\Admin\Service;
|
||||
|
||||
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
|
||||
|
||||
class ServiceFunctionsFormRequest extends AdminFormRequest
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'index_file' => 'required|nullable|string',
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue