Added pages to view the list of potential jobs
TODO: add ability to run a job & view queued jobs
This commit is contained in:
102
src/Controller/JobController.php
Normal file
102
src/Controller/JobController.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* AVSDev UF Worker (https://avsdev.uk)
|
||||
*
|
||||
* @link https://git.avsdev.uk/avsdev/sprinkle-worker
|
||||
* @license https://git.avsdev.uk/avsdev/sprinkle-worker/blob/master/LICENSE.md (LGPL-3.0 License)
|
||||
*/
|
||||
|
||||
namespace UserFrosting\Sprinkle\Worker\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use UserFrosting\Sprinkle\Core\Controller\SimpleController;
|
||||
use UserFrosting\Support\Exception\ForbiddenException;
|
||||
use UserFrosting\Support\Exception\NotFoundException;
|
||||
|
||||
/**
|
||||
* Controller class for job-related requests, (listing jobs).
|
||||
*
|
||||
* @author Craig Williams (https://avsdev.uk)
|
||||
*/
|
||||
class JobController extends SimpleController
|
||||
{
|
||||
/**
|
||||
* Returns a list of Jobs.
|
||||
*
|
||||
* Generates a list of jobs from the JobInspector. No sorting or pagination functionality.
|
||||
* This page requires authentication.
|
||||
*
|
||||
* Request type: GET
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param array $args
|
||||
*
|
||||
* @throws ForbiddenException If user is not authorized to access page
|
||||
*/
|
||||
public function getList(Request $request, Response $response, $args)
|
||||
{
|
||||
// GET parameters
|
||||
$params = $request->getQueryParams();
|
||||
|
||||
/** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
|
||||
$authorizer = $this->ci->authorizer;
|
||||
|
||||
/** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */
|
||||
$currentUser = $this->ci->currentUser;
|
||||
|
||||
// Access-controlled page
|
||||
if (!$authorizer->checkAccess($currentUser, 'uri_jobs')) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
/** @var \UserFrosting\Sprinkle\Jobs\JobInspector $jobInspector */
|
||||
$jobInspector = $this->ci->jobInspector;
|
||||
|
||||
$jobs = $jobInspector->getAvailableJobDefinitions();
|
||||
|
||||
// Be careful how you consume this data - it has not been escaped and contains untrusted user-supplied content.
|
||||
// For example, if you plan to insert it into an HTML DOM, you must escape it on the client side (or use client-side templating).
|
||||
return $response->withJson($jobs, 200, JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the job listing page.
|
||||
*
|
||||
* This page renders a table of jobs, with dropdown menus for admin actions for each job.
|
||||
* Actions typically include: run job
|
||||
* This page requires authentication.
|
||||
*
|
||||
* Request type: GET
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param array $args
|
||||
*
|
||||
* @throws ForbiddenException If user is not authorized to access page
|
||||
*/
|
||||
public function pageList(Request $request, Response $response, $args)
|
||||
{
|
||||
/** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
|
||||
$authorizer = $this->ci->authorizer;
|
||||
|
||||
/** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */
|
||||
$currentUser = $this->ci->currentUser;
|
||||
|
||||
// Access-controlled page
|
||||
if (!$authorizer->checkAccess($currentUser, 'uri_jobs')) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
/** @var \UserFrosting\Sprinkle\Jobs\JobInspector $jobInspector */
|
||||
$jobInspector = $this->ci->jobInspector;
|
||||
|
||||
$jobs = $jobInspector->getAvailableJobDefinitions();
|
||||
|
||||
return $this->ci->view->render($response, 'pages/jobs.html.twig', [
|
||||
'jobs' => $jobs
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user