Skip to content

Update voters.rst #13404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions security/voters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ would look like this::
return false;
}

// only vote on Post objects inside this voter
// only vote on `Post` objects
if (!$subject instanceof Post) {
return false;
}
Expand All @@ -142,7 +142,7 @@ would look like this::
return false;
}

// you know $subject is a Post object, thanks to supports
// you know $subject is a Post object, thanks to `supports()`
/** @var Post $post */
$post = $subject;

Expand All @@ -163,15 +163,13 @@ would look like this::
return true;
}

// the Post object could have, for example, a method isPrivate()
// that checks a boolean $private property
// the Post object could have, for example, a method `isPrivate()`
return !$post->isPrivate();
}

private function canEdit(Post $post, User $user)
{
// this assumes that the data object has a getOwner() method
// to get the entity of the user who owns this data object
// this assumes that the Post object has a `getOwner()` method
return $user === $post->getOwner();
}
}
Expand Down Expand Up @@ -271,9 +269,8 @@ voters vote for one action and object. For instance, suppose you have one voter
checks if the user is a member of the site and a second one that checks if the user
is older than 18.

To handle these cases, the access decision manager uses an access decision
strategy. You can configure this to suit your needs. There are three
strategies available:
To handle these cases, the access decision manager uses a "strategy" which you can configure.
There are three strategies available:

``affirmative`` (default)
This grants access as soon as there is *one* voter granting access;
Expand Down