Improve devtools interface
This commit revamps the interface and adds more commands.
This commit is contained in:
parent
59cfbd7ed1
commit
93172d1e81
@ -23,30 +23,33 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Application;
|
||||
use App\Events\ApplicationApprovedEvent;
|
||||
use App\Services\AccountSuspensionService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class DevToolsController extends Controller
|
||||
{
|
||||
// The use case for Laravel's gate and/or validation Requests is so tiny here that a full-blown policy would be overkill.
|
||||
protected function isolatedAuthorise()
|
||||
{
|
||||
public function __construct() {
|
||||
//
|
||||
}
|
||||
|
||||
private function singleAuthorise() {
|
||||
if (! Auth::user()->can('admin.developertools.use')) {
|
||||
abort(403, __('You\'re not authorized to access this page.'));
|
||||
}
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->isolatedAuthorise();
|
||||
public function index() {
|
||||
$this->singleAuthorise();
|
||||
|
||||
return view('dashboard.administration.devtools')
|
||||
->with('applications', Application::where('applicationStatus', 'STAGE_PEERAPPROVAL')->get());
|
||||
}
|
||||
|
||||
public function forceVoteCount(Request $request)
|
||||
{
|
||||
$this->isolatedAuthorise();
|
||||
public function forceApprovalEvent(Request $request) {
|
||||
$this->singleAuthorise();
|
||||
|
||||
$application = Application::find($request->application);
|
||||
|
||||
if (! is_null($application)) {
|
||||
@ -59,4 +62,32 @@ class DevToolsController extends Controller
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function evaluateVotes() {
|
||||
|
||||
$this->singleAuthorise();
|
||||
|
||||
$code = Artisan::call("votes:evaluate");
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', 'Ran vote evaluation logic, with exit code ' . $code);
|
||||
|
||||
}
|
||||
|
||||
public function purgeSuspensions(AccountSuspensionService $service) {
|
||||
|
||||
$this->singleAuthorise();
|
||||
|
||||
if ($service->purgeExpired()) {
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', 'Force purged all expired suspensions.');
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', 'There were no expired suspensions (or no suspensions at all) to purge.');
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
<x-modal id="confirmForceEventDispatch" modal-label="confirmForceEventDispatch" modal-title="{{__('messages.choose_app')}}" include-close-button="true">
|
||||
|
||||
<p>{{__('messages.forceeval')}}</p>
|
||||
<form method="POST" id="forceEval" action="{{route('devToolsForceVoteCount')}}">
|
||||
<form method="POST" id="forceEval" action="{{route('devForceApprovalEvent')}}">
|
||||
@csrf
|
||||
<select name="application" class="custom-select">
|
||||
@if(!$applications->isEmpty())
|
||||
@ -53,15 +53,25 @@
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="col">
|
||||
<div class="col text-center">
|
||||
|
||||
<x-card id="tools" card-title="{{__('messages.devtools_evn')}}" footer-style="text-center">
|
||||
<x-card id="tools" card-title="Commands & Actions" footer-style="text-center">
|
||||
|
||||
<x-slot name="cardHeader">
|
||||
|
||||
</x-slot>
|
||||
<button type="button" class="btn btn-danger" onclick="$('#confirmForceEventDispatch').modal('show')">{{__('messages.override_votes')}}</button>
|
||||
<button type="button" class="btn btn-warning ml-3">{{__('messages.artisan_evaluate')}}</button>
|
||||
<button data-toggle="tooltip" data-placement="top" title="Forces a selected application to be approved, regardless of how many votes it has." type="button" class="btn btn-primary" onclick="$('#confirmForceEventDispatch').modal('show')"><i class="fas fa-bullhorn"></i> Force application approval</button>
|
||||
|
||||
<form name="evalvotes" method="post" action="{{ route('devForceEvaluateVotes') }}" class="d-inline">
|
||||
@csrf
|
||||
<button data-toggle="tooltip" data-placement="top" title="Counts and processes all backlogged votes, for all applications." type="submit" class="btn btn-primary ml-3"><i class="fas fa-redo"></i> Count all votes now</button>
|
||||
</form>
|
||||
|
||||
<form name="purgebans" method="post" action="{{ route('devPurgeExpired') }}" class="d-inline">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button data-toggle="tooltip" data-placement="top" title="Cleans the database of old, expired suspensions, therefore unbanning certain users." type="submit" class="btn btn-primary ml-3"><i class="far fa-trash-alt"></i> Purge expired bans</button>
|
||||
</form>
|
||||
|
||||
<x-slot name="cardFooter">
|
||||
<p class="text-muted"> .</p>
|
||||
|
@ -303,12 +303,24 @@ Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => ['lo
|
||||
Route::patch('forms/update/{form}', [FormController::class, 'update'])
|
||||
->name('updateForm');
|
||||
|
||||
Route::get('devtools', [DevToolsController::class, 'index'])
|
||||
->name('devTools');
|
||||
|
||||
// we could use route model binding
|
||||
Route::post('devtools/vote-evaluation/force', [DevToolsController::class, 'forceVoteCount'])
|
||||
->name('devToolsForceVoteCount');
|
||||
Route::group(['prefix' => 'devtools'], function () {
|
||||
|
||||
Route::get('/', [DevToolsController::class, 'index'])
|
||||
->name('devTools');
|
||||
|
||||
|
||||
Route::post('/applications/force-approval', [DevToolsController::class, 'forceApprovalEvent'])
|
||||
->name('devForceApprovalEvent');
|
||||
|
||||
Route::post('/applications/count-votes', [DevToolsController::class, 'evaluateVotes'])
|
||||
->name('devForceEvaluateVotes');
|
||||
|
||||
Route::delete('/suspensions/purge-expired', [DevToolsController::class, 'purgeSuspensions'])
|
||||
->name('devPurgeExpired');
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user