Conditions | 5 |
Paths | 7 |
Total Lines | 22 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
35 | protected function voteOnAttribute($attribute, $subject, TokenInterface $token) |
||
36 | { |
||
37 | // our previous business logic indicates that admins can do it regardless |
||
38 | foreach ($token->getRoles() as $role) { |
||
39 | if (\in_array($role->getRole(), ['ROLE_ADMIN'])) { |
||
40 | return true; |
||
41 | } |
||
42 | } |
||
43 | |||
44 | // allow controller handle not found subject |
||
45 | if (null === $subject) { |
||
46 | return true; |
||
47 | } |
||
48 | |||
49 | $user = $token->getUser(); |
||
50 | |||
51 | // allow user to delete account |
||
52 | if ($user instanceof User) { |
||
53 | return $subject->getAuthor()->getId() === $user->getId(); |
||
54 | } |
||
55 | |||
56 | return false; |
||
57 | } |
||
59 |