|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SumoCoders\FrameworkUserBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
6
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
7
|
|
|
use SumoCoders\FrameworkMultiUserBundle\Command\Handler; |
|
8
|
|
|
use SumoCoders\FrameworkMultiUserBundle\Controller\UserController; |
|
9
|
|
|
use SumoCoders\FrameworkMultiUserBundle\User\Interfaces\UserRepository; |
|
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Routing\Router; |
|
11
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; |
|
14
|
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
|
15
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
16
|
|
|
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
|
17
|
|
|
use Symfony\Component\Translation\TranslatorInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @Route(service="sumo_coders.user.controller.edit_user") |
|
21
|
|
|
*/ |
|
22
|
|
|
final class EditController extends UserController |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var AuthorizationCheckerInterface */ |
|
25
|
|
|
private $authorizationChecker; |
|
26
|
|
|
|
|
27
|
|
|
/** @var TokenStorageInterface */ |
|
28
|
|
|
private $tokenStorage; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct( |
|
31
|
|
|
AuthorizationCheckerInterface $authorizationChecker, |
|
32
|
|
|
TokenStorageInterface $tokenStorage, |
|
33
|
|
|
FormFactoryInterface $formFactory, |
|
34
|
|
|
Router $router, |
|
35
|
|
|
FlashBagInterface $flashBag, |
|
36
|
|
|
TranslatorInterface $translator, |
|
37
|
|
|
string $form, |
|
38
|
|
|
Handler $handler, |
|
39
|
|
|
UserRepository $userRepository, |
|
40
|
|
|
$redirectRoute = null |
|
41
|
|
|
) { |
|
42
|
|
|
$this->authorizationChecker = $authorizationChecker; |
|
43
|
|
|
$this->tokenStorage = $tokenStorage; |
|
44
|
|
|
|
|
45
|
|
|
parent::__construct( |
|
46
|
|
|
$formFactory, |
|
47
|
|
|
$router, |
|
48
|
|
|
$flashBag, |
|
49
|
|
|
$translator, |
|
50
|
|
|
$form, |
|
51
|
|
|
$handler, |
|
52
|
|
|
$userRepository, |
|
53
|
|
|
$redirectRoute |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @Template("SumoCodersFrameworkMultiUserBundle:User:base.html.twig") |
|
59
|
|
|
* |
|
60
|
|
|
* @param Request $request |
|
61
|
|
|
* @param int|null $id |
|
62
|
|
|
* |
|
63
|
|
|
* @return array |
|
64
|
|
|
* |
|
65
|
|
|
* @throws AccessDeniedHttpException if not allowed to edit user |
|
66
|
|
|
*/ |
|
67
|
|
|
public function editAction(Request $request, ?int $id): array |
|
68
|
|
|
{ |
|
69
|
|
|
if (!$this->authorizationChecker->isGranted('ROLE_ADMIN') |
|
70
|
|
|
&& $this->tokenStorage->getToken()->getUser()->getId() !== $id |
|
71
|
|
|
) { |
|
72
|
|
|
throw new AccessDeniedHttpException('Access denied.'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return parent::baseAction($request, $id); |
|
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.