fix(fixtureavatar): resolution csfixer
Cadoles/nineskeletor/pipeline/pr-master This commit looks good Details

This commit is contained in:
Arnaud Fornerot 2022-10-04 15:58:21 +02:00
parent 3af16b4c8b
commit 7d8ec5d8c5
4 changed files with 40 additions and 25 deletions

View File

@ -771,7 +771,7 @@ class UserController extends AbstractController
throw $this->createAccessDeniedException('Permission denied');
break;
case 'all':
if ($this->getUser()->getId() != $entity->getId()) {
throw $this->createAccessDeniedException('Permission denied');

View File

@ -8,18 +8,18 @@ use App\Entity\Niveau03;
use App\Entity\Niveau04;
use App\Entity\User;
use App\Entity\UserModo;
use App\Service\MinioService;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\ORM\Id\AssignedGenerator;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use LasseRafn\InitialAvatarGenerator\InitialAvatar;
use Symfony\Bundle\FrameworkBundle\Console\Application;
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;
use Symfony\Component\HttpKernel\KernelInterface;
class AppFixtures extends Fixture
{
@ -53,8 +53,8 @@ class AppFixtures extends Fixture
$manager->flush();
// Color
$this->colorbg=$manager->getRepository("App\Entity\Config")->find("colorbgbodydark")->getValue();
$this->colorft=$manager->getRepository("App\Entity\Config")->find("colorfttitledark")->getValue();
$this->colorbg = $manager->getRepository("App\Entity\Config")->find('colorbgbodydark')->getValue();
$this->colorft = $manager->getRepository("App\Entity\Config")->find('colorfttitledark')->getValue();
// app:Synchro
$manager->clear();
@ -250,7 +250,6 @@ class AppFixtures extends Fixture
$user->setNiveau01($niveau02->getNiveau01());
$user->setNiveau02($niveau02);
$this->generateavatar($username);
$user->setAvatar($username.'.png');
@ -290,7 +289,6 @@ class AppFixtures extends Fixture
$this->generateavatar($username);
$user->setAvatar($username.'.png');
$manager->flush();
}
@ -364,10 +362,11 @@ class AppFixtures extends Fixture
return $r;
}
private function generateavatar($username) {
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);
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

@ -1,22 +1,23 @@
<?php
namespace App\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
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;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
class ExceptionListener implements EventSubscriberInterface
{
private $router;
public function __construct(UrlGeneratorInterface $router) {
$this->router=$router;
public function __construct(UrlGeneratorInterface $router)
{
$this->router = $router;
}
public static function getSubscribedEvents(): array
@ -32,7 +33,7 @@ class ExceptionListener implements EventSubscriberInterface
public function onKernelException(ExceptionEvent $event): void
{
$exception = $event->getThrowable();
if (!$exception instanceof AccessDeniedException&&!$exception instanceof NotFoundHttpException) {
if (!$exception instanceof AccessDeniedException && !$exception instanceof NotFoundHttpException) {
return;
}
@ -40,6 +41,5 @@ class ExceptionListener implements EventSubscriberInterface
// optionally set the custom response
$event->setResponse($response);
}
}
}

View File

@ -157,6 +157,8 @@ class LdapService
break;
case 'basedn': return $this->basedn;
break;
case 'baseorganisation': return $this->baseorganisation;
break;
case 'filteruser': return $this->filteruser;
break;
}
@ -187,12 +189,26 @@ class LdapService
return $this->resultToArray($result);
}
public function deleteByDN($dn)
public function deleteByDN($dn, $recursive = false)
{
$connection = $this->connect();
$removed = ldap_delete($connection, $dn);
if (!$removed) {
$this->ldapError();
if (false == $recursive) {
$removed = ldap_delete($connection, $dn);
if (!$removed) {
$this->ldapError();
}
} else {
// searching for sub entries
$sr = ldap_list($connection, $dn, 'ObjectClass=*', ['']);
$info = ldap_get_entries($connection, $sr);
for ($i = 0; $i < $info['count']; ++$i) {
$result = $this->deleteByDN($info[$i]['dn'], $recursive);
if (!$result) {
return $result;
}
}
return ldap_delete($connection, $dn);
}
}