added remember me feature #53 (#98)

cleanup event subscriber
This commit is contained in:
Kevin Papst
2018-01-17 19:55:26 +01:00
committed by GitHub
parent 7df21f3f5a
commit 9a161b8fd9
26 changed files with 193 additions and 116 deletions

View File

@@ -36,6 +36,19 @@ abstract class AbstractVoter extends Voter
$this->decisionManager = $decisionManager;
}
/**
* @param TokenInterface $token
* @return bool
*/
protected function isFullyAuthenticated(TokenInterface $token)
{
if ($this->decisionManager->decide($token, ['IS_AUTHENTICATED_FULLY'])) {
return true;
}
return false;
}
/**
* @param string $role
* @param TokenInterface $token
@@ -43,7 +56,7 @@ abstract class AbstractVoter extends Voter
*/
protected function hasRole($role, TokenInterface $token)
{
if ($this->decisionManager->decide($token, array($role))) {
if ($this->decisionManager->decide($token, [$role])) {
return true;
}

View File

@@ -27,6 +27,12 @@ class ActivityVoter extends AbstractVoter
const EDIT = 'edit';
const DELETE = 'delete';
const ALLOWED_ATTRIBUTES = [
self::VIEW,
self::EDIT,
self::DELETE
];
/**
* @param string $attribute
* @param mixed $subject
@@ -34,7 +40,7 @@ class ActivityVoter extends AbstractVoter
*/
protected function supports($attribute, $subject)
{
if (!in_array($attribute, array(self::VIEW, self::EDIT, self::DELETE))) {
if (!in_array($attribute, self::ALLOWED_ATTRIBUTES)) {
return false;
}
@@ -107,6 +113,6 @@ class ActivityVoter extends AbstractVoter
*/
protected function canDelete(TokenInterface $token)
{
return $this->hasRole('ROLE_ADMIN', $token);
return $this->isFullyAuthenticated($token) && $this->hasRole('ROLE_ADMIN', $token);
}
}

View File

@@ -27,6 +27,12 @@ class CustomerVoter extends AbstractVoter
const EDIT = 'edit';
const DELETE = 'delete';
const ALLOWED_ATTRIBUTES = [
self::VIEW,
self::EDIT,
self::DELETE
];
/**
* @param string $attribute
* @param mixed $subject
@@ -34,7 +40,7 @@ class CustomerVoter extends AbstractVoter
*/
protected function supports($attribute, $subject)
{
if (!in_array($attribute, array(self::VIEW, self::EDIT, self::DELETE))) {
if (!in_array($attribute, self::ALLOWED_ATTRIBUTES)) {
return false;
}
@@ -107,6 +113,6 @@ class CustomerVoter extends AbstractVoter
*/
protected function canDelete(TokenInterface $token)
{
return $this->hasRole('ROLE_ADMIN', $token);
return $this->isFullyAuthenticated($token) && $this->hasRole('ROLE_ADMIN', $token);
}
}

View File

@@ -27,6 +27,12 @@ class ProjectVoter extends AbstractVoter
const EDIT = 'edit';
const DELETE = 'delete';
const ALLOWED_ATTRIBUTES = [
self::VIEW,
self::EDIT,
self::DELETE
];
/**
* @param string $attribute
* @param mixed $subject
@@ -34,7 +40,7 @@ class ProjectVoter extends AbstractVoter
*/
protected function supports($attribute, $subject)
{
if (!in_array($attribute, array(self::VIEW, self::EDIT, self::DELETE))) {
if (!in_array($attribute, self::ALLOWED_ATTRIBUTES)) {
return false;
}
@@ -107,6 +113,6 @@ class ProjectVoter extends AbstractVoter
*/
protected function canDelete(TokenInterface $token)
{
return $this->hasRole('ROLE_ADMIN', $token);
return $this->isFullyAuthenticated($token) && $this->hasRole('ROLE_ADMIN', $token);
}
}

View File

@@ -30,6 +30,14 @@ class TimesheetVoter extends AbstractVoter
const EDIT = 'edit';
const DELETE = 'delete';
const ALLOWED_ATTRIBUTES = [
self::START,
self::STOP,
self::VIEW,
self::EDIT,
self::DELETE
];
/**
* @param string $attribute
* @param mixed $subject
@@ -37,7 +45,7 @@ class TimesheetVoter extends AbstractVoter
*/
protected function supports($attribute, $subject)
{
if (!in_array($attribute, array(self::START, self::STOP, self::VIEW, self::EDIT, self::DELETE))) {
if (!in_array($attribute, self::ALLOWED_ATTRIBUTES)) {
return false;
}
@@ -146,6 +154,10 @@ class TimesheetVoter extends AbstractVoter
*/
protected function canDelete(Timesheet $timesheet, User $user, TokenInterface $token)
{
if (!$this->isFullyAuthenticated($token)) {
return false;
}
return $this->isOwnOrAdmin($timesheet, $user, $token);
}

View File

@@ -28,11 +28,9 @@ class UserVoter extends AbstractVoter
const PASSWORD = 'password';
const ROLES = 'roles';
const PREFERENCES = 'preferences';
const VIEW_ALL = 'view_all';
const ALLOWED_ATTRIBUTES = [
self::VIEW,
self::VIEW_ALL,
self::EDIT,
self::CREATE,
self::ROLES,
@@ -82,7 +80,6 @@ class UserVoter extends AbstractVoter
return $this->canEdit($subject, $user, $token);
case self::DELETE:
return $this->canDelete($subject, $user, $token);
case self::VIEW_ALL:
case self::CREATE: // create actually passes in the current user as $subject, not the new one
case self::ROLES:
return $this->canAdminUsers($token);
@@ -135,6 +132,6 @@ class UserVoter extends AbstractVoter
*/
protected function canAdminUsers(TokenInterface $token)
{
return $this->hasRole('ROLE_SUPER_ADMIN', $token);
return $this->isFullyAuthenticated($token) && $this->hasRole('ROLE_SUPER_ADMIN', $token);
}
}