diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 1a0e784..2f23ef7 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -14,15 +14,20 @@ security: entity: class: App\Entity\Employee property: nickname + + app_combined_provider: + chain: + providers: [app_intern_provider, app_employee_provider] # used to reload user from session & other features (e.g. switch_user) # used to reload user from session & other features (e.g. switch_user) + firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false - intern: + main: lazy: true - provider: app_intern_provider + provider: app_combined_provider form_login: login_path: app_login check_path: app_login @@ -30,20 +35,6 @@ security: enable_csrf: true logout: path: app_logout - # where to redirect after logout - # target: app_any_route - employee: - lazy: true - provider: app_employee_provider - form_login: - login_path: app_login - check_path: app_login - default_target_path: app_index - enable_csrf: true - logout: - path: app_logout - # where to redirect after logout - # target: app_any_route # activate different ways to authenticate # https://symfony.com/doc/current/security.html#the-firewall diff --git a/src/Controller/AnnouncementController.php b/src/Controller/AnnouncementController.php index 0c7a22e..dcfe11b 100644 --- a/src/Controller/AnnouncementController.php +++ b/src/Controller/AnnouncementController.php @@ -14,19 +14,42 @@ use Symfony\Component\Routing\Attribute\Route; #[Route('/announcement')] final class AnnouncementController extends AbstractController { - #[Route('/', name: 'app_announcement_index', methods: ['GET'])] - public function index(Request $request, AnnouncementRepository $announcementRepository): Response + #[Route('/', name: 'app_announcement_index')] + public function list(Request $request, AnnouncementRepository $announcementRepository): Response { - $showNonValidated = $request->query->get('show_non_validated') === '1'; + $user = $this->getUser(); + $announcements = []; - $announcements = $showNonValidated - ? $announcementRepository->findBy(['status' => 'notVerified']) - : $announcementRepository->findAll(); + if (in_array('ROLE_ADMIN', $user->getRoles())) { + $showNonValidated = $request->query->get('show_non_validated'); + if ($showNonValidated) { + $announcements = $announcementRepository->findBy(['status' => 'notVerified']); + } + if (!$showNonValidated){ + $announcements = $announcementRepository->findAll(); + } - return $this->render('announcement/index.html.twig', [ + } + + if (in_array('ROLE_EMPLOYEE', $user->getRoles())) { + $company = $user->getCompany(); + + if ($company) + { + $announcements = $announcementRepository->findBy(['company' => $company]); + } + } + + if (in_array('ROLE_INTERN', $user->getRoles())) + { + $announcements = $announcementRepository->findBy(['status' => 'verified']); + } + + // Rendre la vue avec les annonces + return $this->render('announcement/list.html.twig', [ 'announcements' => $announcements, - 'showNonValidated' => $showNonValidated, + 'showNonValidated' => $request->query->get('show_non_validated', false), ]); } diff --git a/templates/announcement/index.html.twig b/templates/announcement/index.html.twig index 028356d..39ecc15 100644 --- a/templates/announcement/index.html.twig +++ b/templates/announcement/index.html.twig @@ -6,6 +6,7 @@

Liste des Annonces

+ {% if 'ROLE_ADMIN' in app.user.roles %}