update logic to fit new role rework
This commit is contained in:
parent
e536a5ebc5
commit
f1d219544b
|
|
@ -51,7 +51,7 @@ class ApplicationController extends AbstractController
|
|||
#[Route(path: '/edit/{id}', name: 'edit', methods: ['GET', 'POST'])]
|
||||
public function edit(int $id, Request $request): Response{
|
||||
$this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
|
||||
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
|
||||
$actingUser = $this->getUser();
|
||||
$application = $this->entityManager->getRepository(Apps::class)->find($id);
|
||||
if (!$application) {
|
||||
$this->loggerService->logEntityNotFound('Application', [
|
||||
|
|
@ -101,114 +101,4 @@ class ApplicationController extends AbstractController
|
|||
]);
|
||||
|
||||
}
|
||||
|
||||
#[Route(path: '/authorize/{id}', name: 'authorize', methods: ['POST'])]
|
||||
public function authorize(int $id, Request $request): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
|
||||
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
|
||||
try{
|
||||
$application = $this->entityManager->getRepository(Apps::class)->find($id);
|
||||
if (!$application) {
|
||||
$this->loggerService->logEntityNotFound('Application', [
|
||||
'applicationId' => $id,
|
||||
'message' => "Application not found for authorization."
|
||||
], $actingUser->getId());
|
||||
throw $this->createNotFoundException("L'application n'existe pas.");
|
||||
}
|
||||
$orgId = $request->get('organizationId');
|
||||
|
||||
$organization = $this->entityManager->getRepository(Organizations::Class)->find($orgId);
|
||||
if (!$organization) {
|
||||
$this->loggerService->logEntityNotFound('Organization', [
|
||||
'Organization_id' => $orgId,
|
||||
'message' => "Organization not found for authorization."
|
||||
], $actingUser->getId());
|
||||
throw $this->createNotFoundException("L'Organization n'existe pas.");
|
||||
}
|
||||
$application->addOrganization($organization);
|
||||
$this->loggerService->logApplicationInformation('Application Authorized', [
|
||||
'applicationId' => $application->getId(),
|
||||
'applicationName' => $application->getName(),
|
||||
'organizationId' => $organization->getId(),
|
||||
'message' => "Application authorized for organization."
|
||||
], $actingUser->getId());
|
||||
$this->entityManager->persist($application);
|
||||
$this->entityManager->flush();
|
||||
$this->actionService->createAction("Authorization d'accès", $actingUser, $organization, $application->getName());
|
||||
return new Response('', Response::HTTP_OK);
|
||||
}catch (HttpExceptionInterface $e){
|
||||
throw $e;
|
||||
} catch (\Exception $e){
|
||||
$this->loggerService->logError('Application Authorization Failed', [
|
||||
'applicationId' => $id,
|
||||
'error' => $e->getMessage(),
|
||||
'message' => "Failed to authorize application.",
|
||||
'acting_user_id' => $actingUser->getId()
|
||||
]);
|
||||
return new Response('Erreur lors de l\'autorisation de l\'application.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#[Route(path: '/revoke/{id}', name: 'revoke', methods: ['POST'])]
|
||||
public function revoke(int $id, Request $request)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
|
||||
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
|
||||
$application = $this->entityManager->getRepository(Apps::class)->find($id);
|
||||
if (!$application) {
|
||||
$this->loggerService->logEntityNotFound('Application', [
|
||||
'applicationId' => $id,
|
||||
'message' => "Application not found for authorization removal."
|
||||
], $actingUser->getId());
|
||||
throw $this->createNotFoundException("L'application n'existe pas.");
|
||||
}
|
||||
$orgId = $request->get('organizationId');
|
||||
$organization = $this->entityManager->getRepository(Organizations::Class)->find($orgId);
|
||||
if (!$organization) {
|
||||
$this->loggerService->logEntityNotFound('Organization', [
|
||||
'Organization_id' => $orgId,
|
||||
'message' => "Organization not found for authorization removal."
|
||||
], $actingUser->getId());
|
||||
throw $this->createNotFoundException("L'Organization n'existe pas.");
|
||||
}
|
||||
$application->removeOrganization($organization);
|
||||
$this->loggerService->logApplicationInformation('Application Authorized removed', [
|
||||
'applicationId' => $application->getId(),
|
||||
'applicationName' => $application->getName(),
|
||||
'organizationId' => $organization->getId(),
|
||||
'message' => "Application authorized removed for organization."
|
||||
], $actingUser->getId());
|
||||
$this->actionService->createAction("Authorization retirer", $actingUser, $organization, $application->getName());
|
||||
|
||||
return new Response('', Response::HTTP_OK);
|
||||
}
|
||||
|
||||
#[Route(path:'/user/{id}', name: 'user', methods: ['GET'])]
|
||||
public function getApplicationUsers(int $id): JSONResponse
|
||||
{
|
||||
$user = $this->userRepository->find($id);
|
||||
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
|
||||
if (!$user) {
|
||||
$this->loggerService->logEntityNotFound('User', ['message'=> 'User not found for application list'], $actingUser->getId());
|
||||
return new JsonResponse(['error' => 'User not found'], Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
if ($this->isGranted('ROLE_SUPER_ADMIN')) {
|
||||
$applications = $this->entityManager->getRepository(Apps::class)->findAll();
|
||||
}else{
|
||||
$applications = $this->userOrganizationAppService->getUserApplications($user);
|
||||
|
||||
}
|
||||
$data = array_map(function($app) {
|
||||
return [
|
||||
'name' => $app->getName(),
|
||||
'subDomain' => $app->getSubDomain(),
|
||||
'logoMiniUrl' => $this->assetsManager->getUrl($app->getLogoMiniUrl()),
|
||||
];
|
||||
}, $applications);
|
||||
|
||||
return new JsonResponse($data, Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue