Resolve "Allow super admin to do rider assignment regardless of locking" #899

Merged
jankstudio merged 1 commit from 106-allow-super-admin-to-do-rider-assignment-regardless-of-locking into master 2018-04-26 20:21:40 +00:00

View file

@ -1024,27 +1024,35 @@ class JobOrderController extends BaseController
throw $this->createNotFoundException('The job order does not have an assigning status');
}
// check if hub is assigned to current user
$user_hubs = $this->getUser()->getHubs();
if (!in_array($obj->getHub()->getID(), $user_hubs))
{
$em->getConnection()->rollback();
throw $this->createNotFoundException('The job order is not on a hub assigned to this user');
}
// check if we are the assignor
$assignor = $obj->getAssignedBy();
// check if super user
$user = $this->getUser();
if ($assignor != null && $assignor->getID() != $user->getID())
if ($user->isSuperAdmin())
{
$em->getConnection()->rollback();
throw $this->createAccessDeniedException('Not the assignor');
// do nothing, just allow page to be accessed
}
else
{
// check if hub is assigned to current user
$user_hubs = $this->getUser()->getHubs();
if (!in_array($obj->getHub()->getID(), $user_hubs))
{
$em->getConnection()->rollback();
throw $this->createNotFoundException('The job order is not on a hub assigned to this user');
}
// make this user be the assignor
$obj->setAssignedBy($user);
$em->flush();
// check if we are the assignor
$assignor = $obj->getAssignedBy();
if ($assignor != null && $assignor->getID() != $user->getID())
{
$em->getConnection()->rollback();
throw $this->createAccessDeniedException('Not the assignor');
}
// make this user be the assignor
$obj->setAssignedBy($user);
$em->flush();
}
$em->getConnection()->commit();
}