|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Tahoe\Bundle\MultiTenancyBundle\Controller; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
|
|
10
|
|
|
class InvitationController extends Controller |
|
11
|
|
|
{ |
|
12
|
|
|
public function pendingAction() |
|
13
|
|
|
{ |
|
14
|
|
|
$filters = $this->getDoctrine()->getManager()->getFilters(); |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
// for a moment we need to disable tenant aware filter to fetch invitations from all tenants |
|
17
|
|
|
$filters->disable("tenantAware"); |
|
18
|
|
|
$invitations = $this->container->get('invitation_repository')->findBy(array( |
|
19
|
|
|
'email' => $this->getUser()->getEmailCanonical() |
|
20
|
|
|
)); |
|
21
|
|
|
$filters->enable("tenantAware"); |
|
22
|
|
|
|
|
23
|
|
|
return $this->render('@TahoeMultiTenancy/Invitation/index.html.twig', array('invitations' => $invitations)); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function actionAction(Request $request) |
|
27
|
|
|
{ |
|
28
|
|
|
|
|
29
|
|
|
$action = $request->get('invitation'); |
|
30
|
|
|
|
|
31
|
|
|
$invitationHandler = $this->container->get('tahoe.multi_tenancy.invitation_handler'); |
|
32
|
|
|
|
|
33
|
|
|
$filters = $this->getDoctrine()->getManager()->getFilters(); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
// for a moment we need to disable tenant aware filter to fetch invitations from all tenants |
|
36
|
|
|
$filters->disable("tenantAware"); |
|
37
|
|
|
|
|
38
|
|
|
if (isset($action['accept'])) { |
|
39
|
|
|
$invitationId = $action['accept']; |
|
40
|
|
|
$invitationHandler->acceptInvitationById($invitationId); |
|
41
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if (isset($action['reject'])) { |
|
45
|
|
|
$invitationId = $action['reject']; |
|
46
|
|
|
$invitationHandler->rejectInvitationById($invitationId); |
|
47
|
|
|
} |
|
48
|
|
|
$filters->enable("tenantAware"); |
|
49
|
|
|
|
|
50
|
|
|
return $this->redirect($this->generateUrl('pending_invitation')); |
|
51
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
} |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: