1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the vseth-semesterly-reports project. |
5
|
|
|
* |
6
|
|
|
* (c) Florian Moser <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace App\Security\Voter; |
13
|
|
|
|
14
|
|
|
use App\Entity\Event; |
15
|
|
|
use App\Entity\Organisation; |
16
|
|
|
use App\Model\User; |
17
|
|
|
use App\Security\Voter\Base\BaseVoter; |
18
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
19
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
20
|
|
|
|
21
|
|
|
class EventVoter extends BaseVoter |
22
|
|
|
{ |
23
|
|
|
/** @var ManagerRegistry */ |
24
|
|
|
private $doctrine; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* EntryVoter constructor. |
28
|
|
|
*/ |
29
|
|
|
public function __construct(ManagerRegistry $doctrine) |
30
|
|
|
{ |
31
|
|
|
$this->doctrine = $doctrine; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $attribute An attribute |
36
|
|
|
* @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type |
37
|
|
|
* |
38
|
|
|
* @return bool True if the attribute and subject are supported, false otherwise |
39
|
|
|
*/ |
40
|
|
|
protected function supports($attribute, $subject) |
41
|
|
|
{ |
42
|
|
|
return $subject instanceof Event; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Perform a single access check operation on a given attribute, subject and token. |
47
|
|
|
* It is safe to assume that $attribute and $subject already passed the "supports()" method check. |
48
|
|
|
* |
49
|
|
|
* @param string $attribute |
50
|
|
|
* @param Event $subject |
51
|
|
|
* |
52
|
|
|
* @return bool |
53
|
|
|
*/ |
54
|
|
|
protected function voteOnAttribute($attribute, $subject, TokenInterface $token) |
55
|
|
|
{ |
56
|
|
|
if (\in_array(User::ROLE_ADMIN, $token->getRoleNames(), true)) { |
|
|
|
|
57
|
|
|
return true; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$organisation = $this->doctrine->getRepository(Organisation::class)->findOneBy(['email' => $token->getUser()->getUsername()]); |
61
|
|
|
|
62
|
|
|
return $subject->getOrganisation() === $organisation; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.