checkUser($token->getUser())) { return false; } //then set prefix $this->setPermissionsPrefix('comment'); switch ($attribute) { case 'edit': return $this->canEdit($subject); break; case 'delete': return $this->canDelete($subject); break; } return false; } private function canEdit($subject) { //user appartient au groupe du commentaire if ($subject->getMainGroup() === $this->user->getMainGroup()) { if ($subject->getCreator() === $this->user) { //c'est son propre commentaire return $this->hasPermission('EDIT'); } return $this->hasPermission('EDIT_GROUP'); } //user n'appartient pas au groupe du commentaire if ($subject->getMainGroup() !== $this->user->getMainGroup()) { return $this->hasPermission('EDIT_OTHERGROUP'); } return false; //false by default } private function canDelete($subject) { //user appartient au groupe du commentaire if ($subject->getMainGroup() === $this->user->getMainGroup()) { if ($subject->getCreator() === $this->user) { //c'est son propre commentaire return $this->hasPermission('DELETE'); } return $this->hasPermission('DELETE_GROUP'); } //user n'appartient pas au groupe du commentaire if ($subject->getMainGroup() !== $this->user->getMainGroup()) { return $this->hasPermission('DELETE_OTHERGROUP'); } return false; //false by default } }