Example #1
0
 public function vote(TokenInterface $token, $object, array $attributes)
 {
     if (in_array('WORKFLOW_UPDATE', $attributes)) {
         if (is_object($object)) {
             $repository = $this->manager->getRepository('EnhavoWorkflowBundle:Workflow');
             if ($repository->hasActiveWorkflow($object)) {
                 if ($this->isAllowed($object, $token)) {
                     return self::ACCESS_GRANTED;
                 } else {
                     return self::ACCESS_DENIED;
                 }
             } else {
                 $roleUtil = new RoleUtil();
                 $roleName = $roleUtil->getRoleName($object, RoleUtil::ACTION_UPDATE);
                 $securityContext = $this->container->get('security.context');
                 if ($securityContext->isGranted($roleName)) {
                     return self::ACCESS_GRANTED;
                 } else {
                     return self::ACCESS_DENIED;
                 }
             }
         }
     }
     return self::ACCESS_ABSTAIN;
 }
Example #2
0
 public function getUpdateRoute($resource)
 {
     $roleUtil = new RoleUtil();
     $roleName = $roleUtil->getRoleName($resource, 'update');
     $updateRoute = str_replace('ROLE_', '', $roleName);
     return strtolower($updateRoute);
 }
Example #3
0
 public function testGetAction()
 {
     $roleUtil = new RoleUtil();
     $this->assertEquals(RoleUtil::ACTION_UPDATE, $roleUtil->getAction('ROLE_ENHAVO_APP_ENTITYMOCK_UPDATE'));
     $this->assertEquals(RoleUtil::ACTION_DELETE, $roleUtil->getAction('ROLE_ENHAVO_APP_ENTITYMOCK_DELETE'));
     $this->assertEquals(RoleUtil::ACTION_INDEX, $roleUtil->getAction('ROLE_ENHAVO_APP_ENTITYMOCK_INDEX'));
     $this->assertEquals(RoleUtil::ACTION_CREATE, $roleUtil->getAction('ROLE_ENHAVO_APP_ENTITYMOCK_CREATE'));
 }
Example #4
0
 public function isGranted($resource)
 {
     $securityContext = $this->container->get('security.context');
     //check if user has the permission to see the resource
     $roleUtil = new RoleUtil();
     $role = $roleUtil->getRoleName($resource, 'index');
     if ($securityContext->isGranted($role)) {
         return true;
     }
     return false;
 }
Example #5
0
 public function render($options, $item)
 {
     $templateEngine = $this->container->get('templating');
     $securityContext = $this->container->get('security.context');
     $roleUtil = new RoleUtil();
     $roleName = $roleUtil->getRoleName($item, RoleUtil::ACTION_UPDATE);
     $isGranted = false;
     if ($securityContext->isGranted('WORKFLOW_UPDATE', $item)) {
         $isGranted = true;
     }
     return $templateEngine->render('EnhavoWorkflowBundle:Widget:workflowAssigned.html.twig', array('isGranted' => $isGranted));
 }
Example #6
0
 public function getActions()
 {
     $actions = [];
     $securityContext = $this->container->get('security.context');
     $configActions = $this->getConfig()->get('actions');
     if (!is_array($configActions)) {
         return [];
     }
     foreach ($configActions as $action => $value) {
         $roleUtil = new RoleUtil();
         $roleName = $roleUtil->getRoleNameByResourceName($this->getBundlePrefix(), $this->getResourceName(), $action);
         if ($securityContext->isGranted($roleName)) {
             $actions[] = $value;
         }
     }
     return $actions;
 }