<?php
namespace CompanyGroupBundle\Modules\ProvisioningOps\Controller;
use ApplicationBundle\Controller\GenericController;
use ApplicationBundle\Modules\Authentication\Constants\UserConstants;
use CompanyGroupBundle\Entity\ProvisioningJourney;
use Symfony\Component\HttpFoundation\Request;
class ProvisioningAdminController extends GenericController
{
public function indexAction(Request $request)
{
if (!$this->isAdmin($request)) { return $this->redirectToRoute('dashboard'); }
$queue = $this->get('app.provisioning_queue_service')->blocked((int)$request->query->get('limit', 50));
return $this->render('@CompanyGroup/Modules/ProvisioningOps/admin_queue.html.twig', array(
'page_title' => 'Provisioning Queue', 'queue' => $queue,
));
}
public function assignAction(Request $request, $id)
{
if (!$this->isAdmin($request)) { throw $this->createAccessDeniedException(); }
if (!$this->isCsrfTokenValid('provisioning_assign_' . (int)$id, (string)$request->request->get('_token'))) { throw $this->createAccessDeniedException('Invalid request token.'); }
$em = $this->getDoctrine()->getManager('company_group');
$journey = $em->getRepository(ProvisioningJourney::class)->find((int)$id);
if ($journey instanceof ProvisioningJourney) {
$journey->setAssignedOwnerId((int)$request->getSession()->get(UserConstants::USER_ID));
$em->flush(); $this->addFlash('success', 'Provisioning case assigned to you.');
}
return $this->redirectToRoute('admin_provisioning_queue');
}
public function retryAction(Request $request, $id)
{
if (!$this->isAdmin($request)) { throw $this->createAccessDeniedException(); }
if (!$this->isCsrfTokenValid('provisioning_retry_' . (int)$id, (string)$request->request->get('_token'))) { throw $this->createAccessDeniedException('Invalid request token.'); }
$journey = $this->getDoctrine()->getManager('company_group')->getRepository(ProvisioningJourney::class)->find((int)$id);
if ($journey instanceof ProvisioningJourney) {
$result = $this->get('app.provisioning_reconciliation_service')->retry($journey);
$this->addFlash(!empty($result['success']) ? 'success' : 'warning', !empty($result['success']) ? 'Provisioning checks are now clear.' : 'Provisioning still needs attention. No payment action was taken.');
}
return $this->redirectToRoute('admin_provisioning_queue');
}
private function isAdmin(Request $request)
{
$session = $request->getSession();
return (int)$session->get(UserConstants::USER_ID, 0) > 0 && ((int)$session->get(UserConstants::IS_BUDDYBEE_ADMIN, 0) === 1 || (int)$session->get(UserConstants::ALL_MODULE_ACCESS_FLAG, 0) === 1);
}
}