Fix and Enhancements

This commit is contained in:
Xbird
2022-04-26 19:17:57 +00:00
parent 200c6ac256
commit 72123b8782
22 changed files with 173 additions and 143 deletions

View File

@@ -70,23 +70,34 @@ class AdminController extends AbstractController
//-- users
#[Route('/user', name: 'user_list')]
#[Route('/user/admin', name: 'user_list_admin')]
#[Route('/user/desactivated', name: 'user_list_desactivated')]
public function user(PaginatorInterface $paginator, Request $request, UserRepository $UserRepository): Response
{
$searchForm = $this->createForm(SearchBarType::class);
$searchForm->handleRequest($request);
$req = $UserRepository->getAll()
->search(
(
$searchForm->isSubmitted()
&& $searchForm->isValid()
&& $searchForm->getData()['subject'] !== null
) ? $searchForm->getData()['subject'] : null,
true
);
if ($request->attributes->get('_route') == 'admin_user_list_admin') {
$req->onlyRole('ADMIN');
}
if ($request->attributes->get('_route') == 'admin_user_list_desactivated') {
$req->onlyDesactivated();
}
$pagination = $paginator->paginate(
$UserRepository->getAll()
->search(
(
$searchForm->isSubmitted()
&& $searchForm->isValid()
&& $searchForm->getData()['subject'] !== null
) ? $searchForm->getData()['subject'] : null,
true
)
->getResult(),
$req->getResult(),
$request->query->getInt('page', 1)
);
@@ -94,6 +105,8 @@ class AdminController extends AbstractController
'controller_name' => 'AdminController',
'searchForm' => $searchForm->createView(),
'pagination' => $pagination,
'admin' => ($request->attributes->get('_route') == 'admin_user_list_admin'),
'desactivated' => ($request->attributes->get('_route') == 'admin_user_list_desactivated')
]);
}

View File

@@ -3,7 +3,6 @@
namespace App\Controller;
use App\Entity\User;
use App\Form\TestType;
use App\Entity\Comment;
use App\Entity\Document;
use App\Entity\Directory;

View File

@@ -18,7 +18,12 @@ class GroupController extends AbstractController
#[Route('/', name: 'index')]
public function index(Request $request, TemplateRepository $TemplateRepository): Response
{
$group = $this->getUser()->getMainGroup();
/**
* @var User $currentUser
*/
$currentUser = $this->getUser();
$group = $currentUser->getMainGroup();
if (!$this->IsGranted('administrate', $group)) {
throw new AccessDeniedHttpException('granted_not_allowed_administrate_group');
}
@@ -49,7 +54,7 @@ class GroupController extends AbstractController
'controller_name' => 'GroupController',
'formMOTD' => $form->createView(),
'group' => $group,
'templates' => $TemplateRepository->listForUser($this->getUser())->getResult()
'templates' => $TemplateRepository->listForUser($currentUser)->getResult()
]);
}
@@ -57,16 +62,16 @@ class GroupController extends AbstractController
public function fire(User $User, Request $Request): Response
{
$group = $this->getUser()->getMainGroup();
if (!$this->IsGranted('fire', $group)) {
throw new AccessDeniedHttpException('granted_not_allowed_fire_employee');
}
/**
* @var User $currentUser
*/
$currentUser = $this->getUser();
$group = $currentUser->getMainGroup();
if (!$this->IsGranted('fire', $group)) {
throw new AccessDeniedHttpException('granted_not_allowed_fire_employee');
}
if (
$User->getMainRank()->getPower() >= $currentUser->getMainRank()->getPower()
&& !$currentUser->getAdminMode()
@@ -101,14 +106,19 @@ class GroupController extends AbstractController
#[Route('/employee/{id}', name: 'employee')]
public function employee(User $Employee, Request $Request): Response
{
$group = $this->getUser()->getMainGroup();
/**
* @var User $currentUser
*/
$currentUser = $this->getUser();
$group = $currentUser->getMainGroup();
if (!$this->IsGranted('administrate', $group)) {
throw new AccessDeniedHttpException('granted_not_allowed_administrate_group');
}
//check if employee belong to user group
if ($Employee->getMainGroup() != $this->getUser()->getMainGroup()) {
if ($Employee->getMainGroup() != $currentUser->getMainGroup()) {
throw new AccessDeniedHttpException('granted_not_allowed_administrate_other_group_employee');
}