fix(fixtureavatar): fixcture auto avatar & timesession & font & menu & redirect
Some checks failed
Cadoles/nineskeletor/pipeline/head There was a failure building this commit
Cadoles/nineskeletor/pipeline/pr-master There was a failure building this commit

This commit is contained in:
2022-10-04 13:46:14 +02:00
parent 3d1c5a2159
commit ffe8f2f722
12 changed files with 491 additions and 11 deletions

View File

@ -722,9 +722,9 @@ class UserController extends AbstractController
case 'manager':
if ($this->getUser()->getNiveau03() && $this->getUser()->getNiveau03() == $entity->getNiveau03()) {
return true;
} elseif ($this->getUser()->getNiveau02() && $this->getUser()->getNiveau02() == $entity->getNiveau02()) {
} elseif (!$this->getUser()->getNiveau03() && $this->getUser()->getNiveau02() && $this->getUser()->getNiveau02() == $entity->getNiveau02()) {
return true;
} elseif ($this->getUser()->getNiveau01() && $this->getUser()->getNiveau01() == $entity->getNiveau01()) {
} elseif (!$this->getUser()->getNiveau02() && $this->getUser()->getNiveau01() && $this->getUser()->getNiveau01() == $entity->getNiveau01()) {
return true;
}
@ -759,6 +759,19 @@ class UserController extends AbstractController
return true;
break;
case 'manager':
if ($this->getUser()->getNiveau03() && $this->getUser()->getNiveau03() == $entity->getNiveau03()) {
return true;
} elseif (!$this->getUser()->getNiveau03() && $this->getUser()->getNiveau02() && $this->getUser()->getNiveau02() == $entity->getNiveau02()) {
return true;
} elseif (!$this->getUser()->getNiveau02() && $this->getUser()->getNiveau01() && $this->getUser()->getNiveau01() == $entity->getNiveau01()) {
return true;
}
throw $this->createAccessDeniedException('Permission denied');
break;
case 'all':
if ($this->getUser()->getId() != $entity->getId()) {
throw $this->createAccessDeniedException('Permission denied');

View File

@ -17,20 +17,32 @@ use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\HttpKernel\KernelInterface;
use LasseRafn\InitialAvatarGenerator\InitialAvatar;
use App\Service\MinioService;
use Symfony\Component\Filesystem\Filesystem;
class AppFixtures extends Fixture
{
private $kernel;
private $output;
private $minio;
private $colorbg;
private $colorft;
public function __construct(KernelInterface $kernel)
public function __construct(KernelInterface $kernel, MinioService $minio)
{
$this->kernel = $kernel;
$this->minio = $minio;
$this->output = new ConsoleOutput();
}
public function load(ObjectManager $manager): void
{
// Création Répertoire Avatar
$fs = new Filesystem();
$roottmp = $this->kernel->getProjectDir().'/var/tmp';
$fs->mkdir($roottmp.'/avatar');
// app:Init
$this->writeln('app:Init');
$application = new Application($this->kernel);
@ -40,6 +52,10 @@ class AppFixtures extends Fixture
$application->run($input, $boutput);
$manager->flush();
// Color
$this->colorbg=$manager->getRepository("App\Entity\Config")->find("colorbgbodydark")->getValue();
$this->colorft=$manager->getRepository("App\Entity\Config")->find("colorfttitledark")->getValue();
// app:Synchro
$manager->clear();
$this->writeln('app:Synchro');
@ -196,10 +212,12 @@ class AppFixtures extends Fixture
$user->setEmail($username.'@noreply.fr');
$user->setIsvisible(true);
$user->setIsactive(true);
$user->setAvatar('noavatar.png');
$user->setApikey($username);
$user->setNiveau01($niveau01);
$this->generateavatar($username);
$user->setAvatar($username.'.png');
$manager->flush();
}
@ -228,11 +246,14 @@ class AppFixtures extends Fixture
$user->setEmail($username.'@noreply.fr');
$user->setIsvisible(true);
$user->setIsactive(true);
$user->setAvatar('noavatar.png');
$user->setApikey($username);
$user->setNiveau01($niveau02->getNiveau01());
$user->setNiveau02($niveau02);
$this->generateavatar($username);
$user->setAvatar($username.'.png');
$manager->flush();
}
@ -261,12 +282,15 @@ class AppFixtures extends Fixture
$user->setEmail($username.'@noreply.fr');
$user->setIsvisible(true);
$user->setIsactive(true);
$user->setAvatar('noavatar.png');
$user->setApikey($username);
$user->setNiveau01($niveau03->getNiveau02()->getNiveau01());
$user->setNiveau02($niveau03->getNiveau02());
$user->setNiveau03($niveau03);
$this->generateavatar($username);
$user->setAvatar($username.'.png');
$manager->flush();
}
@ -295,12 +319,14 @@ class AppFixtures extends Fixture
$user->setEmail($username.'@noreply.fr');
$user->setIsvisible(true);
$user->setIsactive(true);
$user->setAvatar('noavatar.png');
$user->setApikey($username);
$user->setNiveau01($niveau03->getNiveau02()->getNiveau01());
$user->setNiveau02($niveau03->getNiveau02());
$user->setNiveau03($niveau03);
$this->generateavatar($username);
$user->setAvatar($username.'.png');
$manager->flush();
}
@ -337,4 +363,11 @@ class AppFixtures extends Fixture
return $r;
}
private function generateavatar($username) {
$avatar = new InitialAvatar();
$image = $avatar->name($username)->height(100)->width(100)->background($this->colorbg)->color($this->colorft)->generate();
file_put_contents($this->kernel->getProjectDir().'/var/tmp/avatar/'.$username.'.png',$image->stream('png', 90));
$this->minio->upload($this->kernel->getProjectDir().'/var/tmp/avatar/'.$username.'.png', 'avatar/'.$username.'.png', true);
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace App\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class AccessDeniedListener implements EventSubscriberInterface
{
private $router;
public function __construct(UrlGeneratorInterface $router) {
$this->router=$router;
}
public static function getSubscribedEvents(): array
{
return [
// the priority must be greater than the Security HTTP
// ExceptionListener, to make sure it's called before
// the default exception listener
KernelEvents::EXCEPTION => ['onKernelException', 2],
];
}
public function onKernelException(ExceptionEvent $event): void
{
$exception = $event->getThrowable();
if (!$exception instanceof AccessDeniedException&&!$exception instanceof NotFoundHttpException) {
return;
}
$response = new RedirectResponse($this->router->generate('app_home'));
// optionally set the custom response
$event->setResponse($response);
}
}

View File

@ -76,6 +76,7 @@ class ConfigType extends AbstractType
'Chewy-Regular' => 'Chewy-Regular',
'Courgette-Regular' => 'Courgette-Regular',
'FredokaOne-Regular' => 'FredokaOne-Regular',
'Futura-Condensed-Extra-Bold' => 'Futura-Condensed-Extra-Bold',
'Grandstander' => 'Grandstander',
'Helvetica' => 'Helvetica',
'Justanotherhand-Regular' => 'Justanotherhand-Regular',