fix(activeuser): user isactive & adress niveau & route all
Some checks reported warnings
Cadoles/nineskeletor/pipeline/head This commit is unstable
Cadoles/nineskeletor/pipeline/pr-master This commit is unstable

This commit is contained in:
2022-10-02 14:50:48 +02:00
parent 2cad98ca86
commit 84230eb347
35 changed files with 749 additions and 214 deletions

View File

@ -20,17 +20,20 @@ class UserController extends AbstractController
private $twig = 'User/';
private $route = 'app_admin_user';
public function list($access, Request $request): Response
public function list($access, Request $request, ManagerRegistry $em): Response
{
if ('user' == $access && !$request->getSession()->get('showannuaire')) {
if ('all' == $access && !$request->getSession()->get('showannuaire')) {
throw $this->createAccessDeniedException('Permission denied');
}
dump($em->getRepository($this->entity)->getPreference($this->getUser(), 'userisactive', true));
return $this->render($this->twig.'list.html.twig', [
'useheader' => true,
'usemenu' => false,
'usesidebar' => ('user' != $access),
'usesidebar' => ('all' != $access),
'access' => $access,
'isactive' => ('true' == $em->getRepository($this->entity)->getPreference($this->getUser(), 'userisactive', true)),
]);
}
@ -47,31 +50,48 @@ class UserController extends AbstractController
$niveau02 = null;
$niveau03 = null;
$niveau04 = null;
$isactive = true;
// Nombre total d'enregistrement
switch ($access) {
case 'admin':
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult();
$isactive = $em->getRepository($this->entity)->getPreference($this->getUser(), 'userisactive', true);
$total = $em->getManager()->createQueryBuilder()
->select('COUNT(entity)')
->from($this->entity, 'entity')
->where('entity.isactive = :isactive')
->setParameter('isactive', $isactive)
->getQuery()->getSingleScalarResult();
break;
case 'modo':
$isactive = $em->getRepository($this->entity)->getPreference($this->getUser(), 'userisactive', true);
$total = $em->getManager()->createQueryBuilder()
->select('COUNT(entity)')
->from($this->entity, 'entity')
->from("App\Entity\UserModo", 'usermodo')
->where('usermodo.niveau01 = entity.niveau01')
->andWhere('usermodo.user = :user')
->where('entity.isactive = :isactive')
->setParameter('isactive', $isactive)
->setParameter('user', $this->getUser())
->getQuery()->getSingleScalarResult();
break;
default:
$isactive = true;
$niveau01 = $this->getUser()->getNiveau01();
$niveau02 = $this->getUser()->getNiveau02();
$niveau03 = $this->getUser()->getNiveau03();
$niveau04 = $this->getUser()->getNiveau04();
$qb = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->where('entity.isvisible=true');
$qb = $em->getManager()->createQueryBuilder()
->select('COUNT(entity)')
->from($this->entity, 'entity')
->where('entity.isvisible=true')
->where('entity.isactive = :isactive')
->setParameter('isactive', $isactive);
switch ($request->getSession()->get('scopeannu')) {
case 1:
$qb->andWhere('entity.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
@ -105,7 +125,9 @@ class UserController extends AbstractController
->from($this->entity, 'entity')
->from('App:Niveau01', 'niveau01')
->where('entity.niveau01=niveau01.id')
->andwhere('entity.isactive = :isactive')
->andWhere('entity.username LIKE :value OR entity.firstname LIKE :value OR entity.lastname LIKE :value OR entity.email LIKE :value OR entity.roles LIKE :value OR niveau01.label LIKE :value')
->setParameter('isactive', $isactive)
->setParameter('value', '%'.$search['value'].'%')
->getQuery()
->getSingleScalarResult();
@ -118,10 +140,12 @@ class UserController extends AbstractController
->from('App:Niveau01', 'niveau01')
->from('App:UserModo', 'usermodo')
->where('entity.niveau01=niveau01.id')
->andwhere('entity.isactive = :isactive')
->andWhere('entity.username LIKE :value OR entity.firstname LIKE :value OR entity.lastname LIKE :value OR entity.email LIKE :value OR entity.roles LIKE :value OR niveau01.label LIKE :value')
->andWhere('usermodo.niveau01 = entity.niveau01')
->andWhere('usermodo.user = :userid')
->setParameter('value', '%'.$search['value'].'%')
->setParameter('isactive', $isactive)
->setParameter('userid', $this->getUser()->getId())
->getQuery()
->getSingleScalarResult();
@ -133,9 +157,11 @@ class UserController extends AbstractController
->from($this->entity, 'entity')
->from('App:Niveau01', 'niveau01')
->where('entity.niveau01=niveau01.id')
->andwhere('entity.isactive = :isactive')
->andWhere('entity.isvisible=true')
->andWhere('entity.username LIKE :value OR entity.firstname LIKE :value OR entity.lastname LIKE :value OR entity.email LIKE :value OR entity.roles LIKE :value OR niveau01.label LIKE :value')
->setParameter('value', '%'.$search['value'].'%');
->setParameter('value', '%'.$search['value'].'%')
->setParameter('isactive', $isactive);
switch ($request->getSession()->get('scopeannu')) {
case 1:
@ -174,6 +200,8 @@ class UserController extends AbstractController
case 'admin':
$qb->select('entity')->from($this->entity, 'entity')->from('App:Niveau01', 'niveau01');
$qb->where('entity.niveau01=niveau01.id');
$qb->andwhere('entity.isactive = :isactive');
$qb->setParameter('isactive', $isactive);
break;
case 'modo':
@ -181,6 +209,8 @@ class UserController extends AbstractController
$qb->where('entity.niveau01=niveau01.id');
$qb->andWhere('usermodo.niveau01 = entity.niveau01');
$qb->andWhere('usermodo.user = :userid');
$qb->andwhere('entity.isactive = :isactive');
$qb->setParameter('isactive', $isactive);
$qb->setParameter('userid', $this->getUser()->getId());
break;
@ -188,6 +218,8 @@ class UserController extends AbstractController
$qb->select('entity')->from($this->entity, 'entity')->from('App:Niveau01', 'niveau01');
$qb->where('entity.niveau01=niveau01.id');
$qb->andWhere('entity.isvisible=true');
$qb->andwhere('entity.isactive = :isactive');
$qb->setParameter('isactive', $isactive);
switch ($request->getSession()->get('scopeannu')) {
case 1:
@ -316,12 +348,14 @@ class UserController extends AbstractController
$qb = $em->getManager()->createQueryBuilder();
$qb->select('entity')->from($this->entity, 'entity')
->where('entity.username LIKE :value')
->orWhere('entity.lastname LIKE :value')
->orWhere('entity.firstname LIKE :value')
->setParameter('value', '%'.$q.'%')
->orderBy('entity.username');
$datas = $qb->setFirstResult(0)->setMaxResults($page_limit)->getQuery()->getResult();
foreach ($datas as $data) {
array_push($output, ['id' => $data->getId(), 'text' => $data->getUsername()]);
array_push($output, ['id' => $data->getId(), 'text' => $data->getFullname()]);
}
$ret_string['results'] = $output;
@ -344,6 +378,7 @@ class UserController extends AbstractController
$data = new Entity();
$data->setAvatar('noavatar.png');
$data->setIsvisible(true);
$data->setIsactive(true);
$data->setApikey(Uuid::uuid4());
// Création du formulaire
@ -566,7 +601,7 @@ class UserController extends AbstractController
}
// Retour à la liste
if ('user' == $access) {
if ('all' == $access) {
return $this->redirectToRoute('app_home');
} else {
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
@ -584,7 +619,7 @@ class UserController extends AbstractController
$this->data => $data,
'listgroups' => $this->getListGroups($access, $em),
'listmodos' => $this->getListModos($em),
'maxsize' => ('user' == $access ? 1200 : null),
'maxsize' => ('all' == $access ? 1200 : null),
]);
}
@ -660,7 +695,7 @@ class UserController extends AbstractController
return true;
break;
case 'user':
case 'all':
if ($this->getUser()->getId() != $entity->getId()) {
throw $this->createAccessDeniedException('Permission denied');
}
@ -688,7 +723,7 @@ class UserController extends AbstractController
return true;
break;
case 'user':
case 'all':
if ($this->getUser()->getId() != $entity->getId()) {
throw $this->createAccessDeniedException('Permission denied');
}