Edit organization
This commit is contained in:
parent
6964bc0214
commit
1516e8c890
|
|
@ -73,12 +73,12 @@ class OrganizationController extends AbstractController
|
|||
if ($logoFile) {
|
||||
$this->organizationService->handleLogo($organization, $logoFile);
|
||||
}
|
||||
try{
|
||||
try {
|
||||
$this->entityManager->persist($organization);
|
||||
$this->entityManager->flush();
|
||||
$this->actionService->createAction("Create Organization", $actingUser, $organization, $organization->getName());
|
||||
return $this->redirectToRoute('organization_index');
|
||||
}catch (Exception $e){
|
||||
} catch (Exception $e) {
|
||||
$this->addFlash('error', 'Error creating organization: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -93,5 +93,51 @@ class OrganizationController extends AbstractController
|
|||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/edit/{id}', name: 'edit', methods: ['GET', 'POST'])]
|
||||
public function edit(Request $request, $id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ROLE_ADMIN');
|
||||
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
|
||||
$organization = $this->entityManager->getRepository(Organizations::class)->find($id);
|
||||
if (!$organization) {
|
||||
$this->addFlash('error', self::NOT_FOUND);
|
||||
return $this->redirectToRoute('organization_index');
|
||||
}
|
||||
if (!$this->isGranted("ROLE_SUPER_ADMIN")) {
|
||||
//check if the user is admin of the organization
|
||||
$user = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
|
||||
$uo = $this->entityManager->getRepository(UsersOrganizations::class)->findOneBy(['users' => $user, 'organization' => $organization]);
|
||||
if (!$uo) {
|
||||
$this->addFlash('error', self::ACCESS_DENIED);
|
||||
return $this->redirectToRoute('organization_index');
|
||||
}
|
||||
$roleAdmin = $this->entityManager->getRepository(Roles::class)->findOneBy(['name' => 'ADMIN']);
|
||||
$uoaAdmin = $this->entityManager->getRepository(UserOrganizatonApp::class)->findOneBy(['userOrganization' => $uo, 'role' => $roleAdmin]);
|
||||
if (!$uoaAdmin) {
|
||||
$this->addFlash('error', self::ACCESS_DENIED);
|
||||
return $this->redirectToRoute('organization_index');
|
||||
}
|
||||
}
|
||||
$form = $this->createForm(OrganizationForm::class, $organization);
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$logoFile = $form->get('logoUrl')->getData();
|
||||
if ($logoFile) {
|
||||
$this->organizationsService->handleLogo($organization, $logoFile);
|
||||
}
|
||||
try {
|
||||
$this->entityManager->flush();
|
||||
$this->actionService->createAction("Edit Organization", $actingUser, $organization, $organization->getName());
|
||||
return $this->redirectToRoute('organization_index');
|
||||
} catch (Exception $e) {
|
||||
$this->addFlash('error', 'Error editing organization: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
return $this->render('organization/edit.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'organization' => $organization,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue