Exemplo n.º 1
0
 public function testGetRoleNames()
 {
     $roleUtil = new RoleUtil();
     $resource = new EntityMock();
     $this->assertEquals('ROLE_ENHAVO_APP_ENTITYMOCK_CREATE', $roleUtil->getRoleName($resource, RoleUtil::ACTION_CREATE));
     $this->assertEquals('ROLE_ENHAVO_APP_ENTITYMOCK_UPDATE', $roleUtil->getRoleName($resource, RoleUtil::ACTION_UPDATE));
     $this->assertEquals('ROLE_ENHAVO_APP_ENTITYMOCK_INDEX', $roleUtil->getRoleName($resource, RoleUtil::ACTION_INDEX));
     $this->assertEquals('ROLE_ENHAVO_APP_ENTITYMOCK_DELETE', $roleUtil->getRoleName($resource, RoleUtil::ACTION_DELETE));
 }
Exemplo n.º 2
0
 public function getUpdateRoute($resource)
 {
     $roleUtil = new RoleUtil();
     $roleName = $roleUtil->getRoleName($resource, 'update');
     $updateRoute = str_replace('ROLE_', '', $roleName);
     return strtolower($updateRoute);
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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));
 }