improve CRUD and switch to symfony3

This commit is contained in:
2018-06-05 14:53:30 +02:00
parent a1ee85b0c0
commit eda8f2c033
11 changed files with 167 additions and 78 deletions

View File

@@ -21,12 +21,14 @@ namespace Chill\DocStoreBundle\Security\Authorization;
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\ProvideRoleInterface;
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
use Chill\DocStoreBundle\Entity\PersonDocument;
use Chill\PersonBundle\Entity\Person;
/**
*
*/
class PersonDocumentVoter extends AbstractChillVoter implements ProvideRoleInterface
class PersonDocumentVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
{
const CREATE = 'CHILL_PERSON_DOCUMENT_CREATE';
const SEE = 'CHILL_PERSON_DOCUMENT_SEE';
@@ -44,16 +46,29 @@ class PersonDocumentVoter extends AbstractChillVoter implements ProvideRoleInter
{
$this->helper = $helper;
}
protected function getSupportedAttributes()
public function getRoles()
{
return array(self::CREATE, self::SEE, self::UPDATE, self::DELETE,
self::SEE_DETAILS);
return [
self::CREATE,
self::SEE,
self::SEE_DETAILS,
self::UPDATE,
self::DELETE
];
}
protected function getSupportedClasses()
protected function supports($attribute, $subject)
{
return array('Chill\DocStoreBundle\Entity\PersonDocument');
if (\in_array($attribute, $this->getRoles()) && $subject instanceof PersonDocument) {
return true;
}
if ($subject instanceof Person && $attribute === self::CREATE) {
return true;
}
return false;
}
protected function isGranted($attribute, $report, $user = null)
@@ -65,11 +80,6 @@ class PersonDocumentVoter extends AbstractChillVoter implements ProvideRoleInter
return $this->helper->userHasAccess($user, $report, $attribute);
}
public function getRoles()
{
return $this->getSupportedAttributes();
}
public function getRolesWithoutScope()
{
return array();