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
This commit is contained in:
Ryan Prather 2024-12-02 23:57:25 -05:00
parent 3eecb04257
commit 4ccbd90bad

View File

@ -7,6 +7,7 @@ use App\Entity\User;
use App\Form\EditUserFormType; use App\Form\EditUserFormType;
use App\Form\SupervisorFormType; use App\Form\SupervisorFormType;
use App\Form\UserFormType; use App\Form\UserFormType;
use App\Libs\NavList;
use App\Repository\UserRepository; use App\Repository\UserRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -25,13 +26,7 @@ class AdminController extends AbstractController
private readonly UserPasswordHasherInterface $userPasswordHasher, private readonly UserPasswordHasherInterface $userPasswordHasher,
private array $navLinks = [] private array $navLinks = []
) { ) {
$this->navLinks = [ $this->navLinks = NavList::LIST;
'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',
];
} }
#[Route('/admin-dashboard', name: 'app_admin_dashboard')] #[Route('/admin-dashboard', name: 'app_admin_dashboard')]
@ -99,23 +94,38 @@ class AdminController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$plainPassword = $form->get('password')->getData(); $plainPassword = $form->get('password')->getData();
$roles = ['ROLE_USER'];
$user->setUsername($form->get('username')->getData()); if ($form->get('caseWorker')->getData()) {
$user->setPassword( $roles[] = 'ROLE_CASE_WORKER';
$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());
$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->persist($user);
$this->entityManager->flush(); $this->entityManager->flush();
@ -157,7 +167,10 @@ class AdminController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$user->setName($form->get('name')->getData()) $user->setName($form->get('name')->getData())
->setEmail($form->get('email')->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()) ->setRateType($form->get('rateType')->getData())
->setRate($form->get('rate')->getData()) ->setRate($form->get('rate')->getData())
->setLevel($form->get('level')->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(),
]
)
);
}
} }