| @@ 106-131 (lines=26) @@ | ||
| 103 | throw new \Exception(sprintf('User is not a member of given tenant')); |
|
| 104 | } |
|
| 105 | ||
| 106 | public function addRoleToUserInTenant( |
|
| 107 | $role, |
|
| 108 | MultiTenantUserInterface $user, |
|
| 109 | MultiTenantTenantInterface $tenant) |
|
| 110 | { |
|
| 111 | $tenantUser = $this->tenantUserRepository->findOneBy( |
|
| 112 | array( |
|
| 113 | 'tenant' => $tenant, |
|
| 114 | 'user' => $user |
|
| 115 | ) |
|
| 116 | ); |
|
| 117 | ||
| 118 | if ($tenantUser) { |
|
| 119 | ||
| 120 | if (false === $tenantUser->hasRole($role)) { |
|
| 121 | $tenantUser->addRole($role); |
|
| 122 | } |
|
| 123 | ||
| 124 | $this->entityManager->persist($tenantUser); |
|
| 125 | $this->entityManager->flush(); |
|
| 126 | ||
| 127 | return true; |
|
| 128 | } |
|
| 129 | ||
| 130 | throw new \Exception(sprintf('User with id %d is not a member of tenant with id %d' , $user->getId(), $tenant->getId())); |
|
| 131 | } |
|
| 132 | ||
| 133 | public function removeRoleFromUserInTenant( |
|
| 134 | $role, |
|
| @@ 133-158 (lines=26) @@ | ||
| 130 | throw new \Exception(sprintf('User with id %d is not a member of tenant with id %d' , $user->getId(), $tenant->getId())); |
|
| 131 | } |
|
| 132 | ||
| 133 | public function removeRoleFromUserInTenant( |
|
| 134 | $role, |
|
| 135 | MultiTenantUserInterface $user, |
|
| 136 | MultiTenantTenantInterface $tenant) |
|
| 137 | { |
|
| 138 | $tenantUser = $this->tenantUserRepository->findOneBy( |
|
| 139 | array( |
|
| 140 | 'tenant' => $tenant, |
|
| 141 | 'user' => $user |
|
| 142 | ) |
|
| 143 | ); |
|
| 144 | ||
| 145 | if ($tenantUser) { |
|
| 146 | ||
| 147 | if ($tenantUser->hasRole($role)) { |
|
| 148 | $tenantUser->removeRole($role); |
|
| 149 | } |
|
| 150 | ||
| 151 | $this->entityManager->persist($tenantUser); |
|
| 152 | $this->entityManager->flush(); |
|
| 153 | ||
| 154 | return true; |
|
| 155 | } |
|
| 156 | ||
| 157 | throw new \Exception(sprintf('User with id %d is not a member of tenant with id %d' , $user->getId(), $tenant->getId())); |
|
| 158 | } |
|
| 159 | } |
|
| 160 | ||