fix invocation of old method and upgrade ActivitySTatVoter to sf3

This commit is contained in:
Julien Fastré 2018-04-06 02:42:11 +02:00
parent ea5d3f7940
commit b84a77d9de
2 changed files with 22 additions and 8 deletions

View File

@ -45,7 +45,7 @@ class ActivityStatsVoter extends AbstractChillVoter implements ProvideRoleHierar
$this->helper = $helper; $this->helper = $helper;
} }
protected function getSupportedAttributes() private function getAttributes()
{ {
return array(self::STATS, self::LISTS); return array(self::STATS, self::LISTS);
} }
@ -54,6 +54,17 @@ class ActivityStatsVoter extends AbstractChillVoter implements ProvideRoleHierar
{ {
return array(Center::class); return array(Center::class);
} }
protected function supports($attribute, $subject)
{
if ($subject instanceof Center
&& \in_array($attribute, $this->getAttributes())) {
return true;
}
return false;
}
protected function isGranted($attribute, $object, $user = null) protected function isGranted($attribute, $object, $user = null)
{ {
@ -66,12 +77,12 @@ class ActivityStatsVoter extends AbstractChillVoter implements ProvideRoleHierar
public function getRoles() public function getRoles()
{ {
return $this->getSupportedAttributes(); return $this->getAttributes();
} }
public function getRolesWithoutScope() public function getRolesWithoutScope()
{ {
return $this->getSupportedAttributes(); return $this->getAttributes();
} }
public function getRolesWithHierarchy() public function getRolesWithHierarchy()

View File

@ -55,10 +55,7 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
protected function supports($attribute, $subject) protected function supports($attribute, $subject)
{ {
if ($subject instanceof Activity) { if ($subject instanceof Activity) {
return \in_array($attribute, [ return \in_array($attribute, $this->getAttributes());
self::CREATE, self::SEE, self::UPDATE, self::DELETE,
self::SEE_DETAILS
]);
} else { } else {
return false; return false;
} }
@ -71,11 +68,17 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
} }
return $this->helper->userHasAccess($token->getUser(), $subject, $attribute); return $this->helper->userHasAccess($token->getUser(), $subject, $attribute);
} }
private function getAttributes()
{
return [ self::CREATE, self::SEE, self::UPDATE, self::DELETE,
self::SEE_DETAILS ];
}
public function getRoles() public function getRoles()
{ {
return $this->getSupportedAttributes(); return $this->getAttributes();
} }
public function getRolesWithoutScope() public function getRolesWithoutScope()