From 4ccbd90bade4a8f830b94cc2ab82a48842aaa746 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Mon, 2 Dec 2024 23:57:25 -0500 Subject: [PATCH] Removed job parameter from the User class and replaced it with additional "roles" Replaed nav links with class constant NavLinks for easier updating Moved listCases method to CaseController --- src/Controller/AdminController.php | 78 ++++++++++++++---------------- 1 file changed, 36 insertions(+), 42 deletions(-) diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 3f41740..4b9691b 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -7,6 +7,7 @@ use App\Entity\User; use App\Form\EditUserFormType; use App\Form\SupervisorFormType; use App\Form\UserFormType; +use App\Libs\NavList; use App\Repository\UserRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -25,13 +26,7 @@ class AdminController extends AbstractController private readonly UserPasswordHasherInterface $userPasswordHasher, private array $navLinks = [] ) { - $this->navLinks = [ - 'admin_dashboard' => 'nav-link text-dark', - 'user_dashboard' => 'nav-link text-dark', - 'profile' => 'nav-link text-dark', - 'user_list' => 'nav-link text-dark', - 'staff_dashboard' => 'nav-link text-dark', - ]; + $this->navLinks = NavList::LIST; } #[Route('/admin-dashboard', name: 'app_admin_dashboard')] @@ -99,23 +94,38 @@ class AdminController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { $plainPassword = $form->get('password')->getData(); + $roles = ['ROLE_USER']; - $user->setUsername($form->get('username')->getData()); - $user->setPassword( - $this->userPasswordHasher->hashPassword( - $user, - $plainPassword - ) - ); - $user->setRoles(['ROLE_USER']); - $user->setName($form->get('name')->getData()); - $user->setEmail($form->get('email')->getData()); - $user->setJob($form->get('job')->getData()); - $user->setRateType($form->get('rateType')->getData()); - $user->setRate($form->get('rate')->getData()); - $user->setLevel($form->get('level')->getData()); + if ($form->get('caseWorker')->getData()) { + $roles[] = 'ROLE_CASE_WORKER'; + } - $user->setCompany($admin->getCompany()); + if ($form->get('caseManager')->getData()) { + $roles[] = 'ROLE_CASE_MANAGER'; + } + + if ($form->get('therapist')->getData()) { + $roles[] = 'ROLE_THERAPIST'; + } + + if ($form->get('su')->getData()) { + $roles[] = 'ROLE_ADMIN'; + } + + $user->setUsername($form->get('username')->getData()) + ->setPassword( + $this->userPasswordHasher->hashPassword( + $user, + $plainPassword + ) + ) + ->setName($form->get('name')->getData()) + ->setEmail($form->get('email')->getData()) + ->setRoles($roles) + ->setRateType($form->get('rateType')->getData()) + ->setRate($form->get('rate')->getData()) + ->setLevel($form->get('level')->getData()) + ->setCompany($admin->getCompany()); $this->entityManager->persist($user); $this->entityManager->flush(); @@ -157,7 +167,10 @@ class AdminController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { $user->setName($form->get('name')->getData()) ->setEmail($form->get('email')->getData()) - ->setJob($form->get('job')->getData()) + ->setCaseWorker($form->get('caseWorker')->getData()) + ->setCaseManager($form->get('caseManager')->getData()) + ->setTherapist($form->get('therapist')->getData()) + ->setSu($form->get('su')->getData()) ->setRateType($form->get('rateType')->getData()) ->setRate($form->get('rate')->getData()) ->setLevel($form->get('level')->getData()); @@ -225,23 +238,4 @@ class AdminController extends AbstractController ) ); } - - #[Route('/list-cases', name: 'app_list_cases')] - public function listCases(#[CurrentUser()] User $user): Response - { - $this->denyAccessUnlessGranted('ROLE_ADMIN'); - - return $this->render( - 'internal/cases/case-list.html.twig', - array_merge( - $this->navLinks, - [ - 'breadcrumbs' => [ - 'List Cases' - ], - 'notifications' => $user->retrieveUnreadNotifications(), - ] - ) - ); - } }