Fused activate and deactived user for organization route
This commit is contained in:
parent
f0ae5a8c8a
commit
c673fcd83b
|
|
@ -704,9 +704,10 @@ export default class extends Controller {
|
||||||
const userId = target.getAttribute('data-id');
|
const userId = target.getAttribute('data-id');
|
||||||
if (confirm('Voulez-vous vraiment désactiver cet utilisateur ?')) {
|
if (confirm('Voulez-vous vraiment désactiver cet utilisateur ?')) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
formData.append('status', 'deactivate');
|
||||||
formData.append('organizationId', target.getAttribute('data-org-id'));
|
formData.append('organizationId', target.getAttribute('data-org-id'));
|
||||||
|
|
||||||
fetch(`/user/organization/deactivate/${userId}`, {
|
fetch(`/user/organization/activateStatus/${userId}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
headers: {'X-Requested-With': 'XMLHttpRequest'}
|
headers: {'X-Requested-With': 'XMLHttpRequest'}
|
||||||
|
|
@ -731,9 +732,10 @@ export default class extends Controller {
|
||||||
const userId = target.getAttribute('data-id');
|
const userId = target.getAttribute('data-id');
|
||||||
if (confirm('Voulez-vous réactiver cet utilisateur ?')) {
|
if (confirm('Voulez-vous réactiver cet utilisateur ?')) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
formData.append('status', 'activate');
|
||||||
formData.append('organizationId', target.getAttribute('data-org-id'));
|
formData.append('organizationId', target.getAttribute('data-org-id'));
|
||||||
|
|
||||||
fetch(`/user/organization/activate/${userId}`, {
|
fetch(`/user/organization/activateStatus/${userId}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
headers: {'X-Requested-With': 'XMLHttpRequest'}
|
headers: {'X-Requested-With': 'XMLHttpRequest'}
|
||||||
|
|
@ -757,7 +759,7 @@ export default class extends Controller {
|
||||||
// columns.push(
|
// columns.push(
|
||||||
// {
|
// {
|
||||||
// title: "Statut", field: "role", // or any field you want
|
// title: "Statut", field: "role", // or any field you want
|
||||||
// headerSort: false,
|
// headerSort: false,x
|
||||||
// hozAlign: "center",
|
// hozAlign: "center",
|
||||||
// vertAlign: "middle",
|
// vertAlign: "middle",
|
||||||
// formatter: (cell) => {
|
// formatter: (cell) => {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ use App\Service\UserOrganizationAppService;
|
||||||
use App\Service\UserOrganizationService;
|
use App\Service\UserOrganizationService;
|
||||||
use App\Service\UserService;
|
use App\Service\UserService;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use mysql_xdevapi\Exception;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
|
@ -322,77 +323,54 @@ class UserController extends AbstractController
|
||||||
throw $this->createNotFoundException(self::NOT_FOUND);
|
throw $this->createNotFoundException(self::NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO : MONOLOG
|
#[Route('/organization/activateStatus/{id}', name: 'activate_organization', methods: ['GET', 'POST'])]
|
||||||
#[Route('/organization/deactivate/{id}', name: 'deactivate_organization', methods: ['GET', 'POST'])]
|
public function activateStatusOrganization(int $id, Request $request): JsonResponse{
|
||||||
public function deactivateUserInOrganization(int $id, Request $request): Response
|
|
||||||
{
|
|
||||||
$this->denyAccessUnlessGranted('ROLE_ADMIN');
|
$this->denyAccessUnlessGranted('ROLE_ADMIN');
|
||||||
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
|
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
|
||||||
if ($this->userService->hasAccessTo($actingUser, true)) {
|
try {
|
||||||
$orgId = $request->get('organizationId');
|
if ($this->userService->hasAccessTo($actingUser, true)) {
|
||||||
$org = $this->organizationRepository->find($orgId);
|
$orgId = $request->get('organizationId');
|
||||||
if (!$org) {
|
$org = $this->organizationRepository->find($orgId);
|
||||||
throw $this->createNotFoundException(self::NOT_FOUND);
|
if (!$org) {
|
||||||
|
throw $this->createNotFoundException(self::NOT_FOUND);
|
||||||
|
}
|
||||||
|
$user = $this->userRepository->find($id);
|
||||||
|
if (!$user) {
|
||||||
|
throw $this->createNotFoundException(self::NOT_FOUND);
|
||||||
|
}
|
||||||
|
$uo = $this->uoRepository->findOneBy(['users' => $user,
|
||||||
|
'organization' => $org]);
|
||||||
|
if (!$uo) {
|
||||||
|
throw $this->createNotFoundException(self::NOT_FOUND);
|
||||||
|
}
|
||||||
|
$status = $request->get('status');
|
||||||
|
if ($status === 'deactivate') {
|
||||||
|
$uo->setIsActive(false);
|
||||||
|
$this->userOrganizationAppService->deactivateAllUserOrganizationsAppLinks($uo);
|
||||||
|
$this->entityManager->persist($uo);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
$data = ['user' => $user,
|
||||||
|
'organization' => $org];
|
||||||
|
$this->organizationsService->notifyOrganizationAdmins($data, "USER_DEACTIVATED");
|
||||||
|
$this->logger->notice("User Organizaton deactivated " . $user->getUserIdentifier());
|
||||||
|
$this->actionService->createAction("Deactivate user in organization", $actingUser, $org, $org->getName() . " for user " . $user->getUserIdentifier());
|
||||||
|
return new JsonResponse(['status' => 'deactivated'], Response::HTTP_OK);
|
||||||
|
}
|
||||||
|
if($status === "activate"){
|
||||||
|
$uo->setIsActive(true);
|
||||||
|
$this->entityManager->persist($uo);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
$this->actionService->createAction("Activate user in organization", $actingUser, $org, $org->getName() . " for user " . $user->getUserIdentifier());
|
||||||
|
$data = ['user' => $user,
|
||||||
|
'organization' => $org];
|
||||||
|
$this->organizationsService->notifyOrganizationAdmins($data, "USER_ACTIVATED");
|
||||||
|
return new JsonResponse(['status' => 'activated'], Response::HTTP_OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$user = $this->userRepository->find($id);
|
}catch (\Exception $exception){
|
||||||
if (!$user) {
|
$this->logger->error($exception->getMessage());
|
||||||
throw $this->createNotFoundException(self::NOT_FOUND);
|
|
||||||
}
|
|
||||||
$uo = $this->uoRepository->findOneBy(['users' => $user,
|
|
||||||
'organization' => $org,
|
|
||||||
'isActive' => true]);
|
|
||||||
if (!$uo) {
|
|
||||||
throw $this->createNotFoundException(self::NOT_FOUND);
|
|
||||||
}
|
|
||||||
$uo->setIsActive(false);
|
|
||||||
$this->userOrganizationAppService->deactivateAllUserOrganizationsAppLinks($uo);
|
|
||||||
$data = ['user' => $user,
|
|
||||||
'organization' => $org];
|
|
||||||
$this->organizationsService->notifyOrganizationAdmins($data, "USER_DEACTIVATED");
|
|
||||||
$this->entityManager->persist($uo);
|
|
||||||
$this->entityManager->flush();
|
|
||||||
$this->actionService->createAction("Deactivate user in organization", $actingUser, $org, $org->getName() . " for user " . $user->getUserIdentifier());
|
|
||||||
|
|
||||||
return new Response('', Response::HTTP_NO_CONTENT); //204
|
|
||||||
}
|
}
|
||||||
|
throw $this->createNotFoundException(self::NOT_FOUND);
|
||||||
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO : MONOLOG
|
|
||||||
#[Route('/organization/activate/{id}', name: 'activate_organization', methods: ['GET', 'POST'])]
|
|
||||||
public function activateUserInOrganization(int $id, Request $request): Response
|
|
||||||
{
|
|
||||||
$this->denyAccessUnlessGranted('ROLE_ADMIN');
|
|
||||||
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
|
|
||||||
if ($this->userService->hasAccessTo($actingUser, true)) {
|
|
||||||
$orgId = $request->get('organizationId');
|
|
||||||
$org = $this->organizationRepository->find($orgId);
|
|
||||||
if (!$org) {
|
|
||||||
throw $this->createNotFoundException(self::NOT_FOUND);
|
|
||||||
}
|
|
||||||
$user = $this->userRepository->find($id);
|
|
||||||
if (!$user) {
|
|
||||||
throw $this->createNotFoundException(self::NOT_FOUND);
|
|
||||||
}
|
|
||||||
$uo = $this->uoRepository->findOneBy(['users' => $user,
|
|
||||||
'organization' => $org,
|
|
||||||
'isActive' => false]);
|
|
||||||
if (!$uo) {
|
|
||||||
throw $this->createNotFoundException(self::NOT_FOUND);
|
|
||||||
}
|
|
||||||
$uo->setIsActive(true);
|
|
||||||
$this->entityManager->persist($uo);
|
|
||||||
$this->entityManager->flush();
|
|
||||||
$this->actionService->createAction("Activate user in organization", $actingUser, $org, $org->getName() . " for user " . $user->getUserIdentifier());
|
|
||||||
$data = ['user' => $user,
|
|
||||||
'organization' => $org];
|
|
||||||
$this->organizationsService->notifyOrganizationAdmins($data, "USER_ACTIVATED");
|
|
||||||
|
|
||||||
return $this->redirectToRoute('user_index');
|
|
||||||
}
|
|
||||||
|
|
||||||
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO : MONOLOG + remove picture from bucket
|
//TODO : MONOLOG + remove picture from bucket
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue