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:
Arnaud Fornerot 2022-10-04 13:46:14 +02:00
parent 3d1c5a2159
commit ffe8f2f722
12 changed files with 491 additions and 11 deletions

1
.env
View File

@ -1,6 +1,7 @@
# Symfony
APP_ENV=prod
APP_SECRET=changeme
APP_SESSIONTIME=1440
# Messenger
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0

Binary file not shown.

View File

@ -178,4 +178,12 @@ font-family: 'Theboldfont';
src: url('../fonts/theboldfont.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
}
@font-face {
font-family: 'Futura-Condensed-Extra-Bold';
src: url('../fonts/Futura-Condensed-Extra-Bold.otf') format('opentype');
font-weight: normal;
font-style: normal;
}

View File

@ -122,6 +122,7 @@
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4",
"lasserafn/php-initial-avatar-generator": "^4.2",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "6.1.*",
"symfony/css-selector": "6.1.*",

372
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "d3be737db4f7ce5089c83be63c8dbf09",
"content-hash": "479a2464d612243533a7aa3eae4281d9",
"packages": [
{
"name": "aws/aws-crt-php",
@ -11096,6 +11096,253 @@
],
"time": "2022-04-28T17:58:29+00:00"
},
{
"name": "intervention/image",
"version": "2.7.2",
"source": {
"type": "git",
"url": "https://github.com/Intervention/image.git",
"reference": "04be355f8d6734c826045d02a1079ad658322dad"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Intervention/image/zipball/04be355f8d6734c826045d02a1079ad658322dad",
"reference": "04be355f8d6734c826045d02a1079ad658322dad",
"shasum": ""
},
"require": {
"ext-fileinfo": "*",
"guzzlehttp/psr7": "~1.1 || ^2.0",
"php": ">=5.4.0"
},
"require-dev": {
"mockery/mockery": "~0.9.2",
"phpunit/phpunit": "^4.8 || ^5.7 || ^7.5.15"
},
"suggest": {
"ext-gd": "to use GD library based image processing.",
"ext-imagick": "to use Imagick based image processing.",
"intervention/imagecache": "Caching extension for the Intervention Image library"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
},
"laravel": {
"providers": [
"Intervention\\Image\\ImageServiceProvider"
],
"aliases": {
"Image": "Intervention\\Image\\Facades\\Image"
}
}
},
"autoload": {
"psr-4": {
"Intervention\\Image\\": "src/Intervention/Image"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Oliver Vogel",
"email": "oliver@intervention.io",
"homepage": "https://intervention.io/"
}
],
"description": "Image handling and manipulation library with support for Laravel integration",
"homepage": "http://image.intervention.io/",
"keywords": [
"gd",
"image",
"imagick",
"laravel",
"thumbnail",
"watermark"
],
"support": {
"issues": "https://github.com/Intervention/image/issues",
"source": "https://github.com/Intervention/image/tree/2.7.2"
},
"funding": [
{
"url": "https://paypal.me/interventionio",
"type": "custom"
},
{
"url": "https://github.com/Intervention",
"type": "github"
}
],
"time": "2022-05-21T17:30:32+00:00"
},
{
"name": "lasserafn/php-initial-avatar-generator",
"version": "4.2.1",
"source": {
"type": "git",
"url": "https://github.com/LasseRafn/php-initial-avatar-generator.git",
"reference": "49d0b10cc8819af831e0f6fb1056a7d5ed9512d0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/LasseRafn/php-initial-avatar-generator/zipball/49d0b10cc8819af831e0f6fb1056a7d5ed9512d0",
"reference": "49d0b10cc8819af831e0f6fb1056a7d5ed9512d0",
"shasum": ""
},
"require": {
"ext-json": "*",
"intervention/image": "^2.3",
"lasserafn/php-initials": "^3.0",
"lasserafn/php-string-script-language": "^0.3.0",
"meyfa/php-svg": "^0.9.0",
"overtrue/pinyin": "^4.0",
"php": "^7.0|^7.1|^7.2|^7.3|^7.4|^8.0"
},
"require-dev": {
"doctrine/instantiator": "1.0.*",
"phpunit/phpunit": "^6.5",
"satooshi/php-coveralls": "^1.0"
},
"type": "library",
"autoload": {
"psr-4": {
"LasseRafn\\InitialAvatarGenerator\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Lasse Rafn",
"email": "lasserafn@gmail.com"
}
],
"description": "A package to generate avatars with initials for PHP",
"keywords": [
"Initials",
"avatar",
"image",
"svg"
],
"support": {
"issues": "https://github.com/LasseRafn/php-initial-avatar-generator/issues",
"source": "https://github.com/LasseRafn/php-initial-avatar-generator/tree/4.2.1"
},
"funding": [
{
"url": "https://opencollective.com/ui-avatars",
"type": "open_collective"
}
],
"time": "2020-12-24T13:12:12+00:00"
},
{
"name": "lasserafn/php-initials",
"version": "3.1",
"source": {
"type": "git",
"url": "https://github.com/LasseRafn/php-initials.git",
"reference": "d287e1542687390eb68de779949bc0adc49e2d52"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/LasseRafn/php-initials/zipball/d287e1542687390eb68de779949bc0adc49e2d52",
"reference": "d287e1542687390eb68de779949bc0adc49e2d52",
"shasum": ""
},
"require": {
"php": "^5.6|^7.0|^7.1|^8.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"satooshi/php-coveralls": "^1.0"
},
"type": "library",
"autoload": {
"psr-4": {
"LasseRafn\\Initials\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Lasse Rafn",
"email": "lasserafn@gmail.com"
}
],
"description": "A package to generate initials in PHP",
"keywords": [
"Initials",
"php"
],
"support": {
"issues": "https://github.com/LasseRafn/php-initials/issues",
"source": "https://github.com/LasseRafn/php-initials/tree/3.1"
},
"time": "2020-12-24T12:25:51+00:00"
},
{
"name": "lasserafn/php-string-script-language",
"version": "0.3",
"source": {
"type": "git",
"url": "https://github.com/LasseRafn/php-string-script-language.git",
"reference": "49a09d4a5e38c1e59a2656ac05b601d615c7cddb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/LasseRafn/php-string-script-language/zipball/49a09d4a5e38c1e59a2656ac05b601d615c7cddb",
"reference": "49a09d4a5e38c1e59a2656ac05b601d615c7cddb",
"shasum": ""
},
"require": {
"php": "^5.6|^7.0|^7.1|^8.0"
},
"require-dev": {
"doctrine/instantiator": "1.0.5",
"phpunit/phpunit": "^5.6",
"phpunit/phpunit-mock-objects": "3.2.4",
"satooshi/php-coveralls": "^1.0",
"sebastian/exporter": "^1.2"
},
"type": "library",
"autoload": {
"psr-4": {
"LasseRafn\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Lasse Rafn",
"email": "lasserafn@gmail.com"
}
],
"description": "Detect language/encoding of a string in PHP",
"keywords": [
"language",
"php",
"string"
],
"support": {
"issues": "https://github.com/LasseRafn/php-string-script-language/issues",
"source": "https://github.com/LasseRafn/php-string-script-language/tree/0.3"
},
"time": "2020-12-24T12:43:59+00:00"
},
{
"name": "masterminds/html5",
"version": "2.7.6",
@ -11165,6 +11412,56 @@
},
"time": "2022-08-18T16:18:26+00:00"
},
{
"name": "meyfa/php-svg",
"version": "v0.9.1",
"source": {
"type": "git",
"url": "https://github.com/meyfa/php-svg.git",
"reference": "34401edef1f724898f468f71b85505fbcc8351bb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/meyfa/php-svg/zipball/34401edef1f724898f468f71b85505fbcc8351bb",
"reference": "34401edef1f724898f468f71b85505fbcc8351bb",
"shasum": ""
},
"require": {
"ext-gd": "*",
"ext-simplexml": "*",
"php": ">=5.3.3"
},
"require-dev": {
"meyfa/phpunit-assert-gd": "^1.1",
"phpunit/phpunit": "^4.8"
},
"type": "library",
"autoload": {
"psr-4": {
"SVG\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabian Meyer",
"homepage": "http://meyfa.net"
}
],
"description": "Read, edit, write, and render SVG files with PHP",
"homepage": "https://github.com/meyfa/php-svg",
"keywords": [
"svg"
],
"support": {
"issues": "https://github.com/meyfa/php-svg/issues",
"source": "https://github.com/meyfa/php-svg/tree/v0.9.1"
},
"time": "2019-07-30T18:41:25+00:00"
},
{
"name": "myclabs/deep-copy",
"version": "1.11.0",
@ -11224,6 +11521,79 @@
],
"time": "2022-03-03T13:19:32+00:00"
},
{
"name": "overtrue/pinyin",
"version": "4.0.8",
"source": {
"type": "git",
"url": "https://github.com/overtrue/pinyin.git",
"reference": "04bdb4d33d50e8fb1aa5a824064c5151c4b15dc2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/overtrue/pinyin/zipball/04bdb4d33d50e8fb1aa5a824064c5151c4b15dc2",
"reference": "04bdb4d33d50e8fb1aa5a824064c5151c4b15dc2",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"require-dev": {
"brainmaestro/composer-git-hooks": "^2.7",
"friendsofphp/php-cs-fixer": "^2.16",
"phpunit/phpunit": "~8.0"
},
"type": "library",
"extra": {
"hooks": {
"pre-commit": [
"composer test",
"composer fix-style"
],
"pre-push": [
"composer test",
"composer check-style"
]
}
},
"autoload": {
"files": [
"src/const.php"
],
"psr-4": {
"Overtrue\\Pinyin\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "overtrue",
"email": "anzhengchao@gmail.com",
"homepage": "http://github.com/overtrue"
}
],
"description": "Chinese to pinyin translator.",
"homepage": "https://github.com/overtrue/pinyin",
"keywords": [
"Chinese",
"Pinyin",
"cn2pinyin"
],
"support": {
"issues": "https://github.com/overtrue/pinyin/issues",
"source": "https://github.com/overtrue/pinyin/tree/4.0.8"
},
"funding": [
{
"url": "https://www.patreon.com/overtrue",
"type": "patreon"
}
],
"time": "2021-07-19T03:43:32+00:00"
},
{
"name": "phar-io/manifest",
"version": "2.0.3",

View File

@ -10,6 +10,7 @@ framework:
handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler
name: '%env(APP_ALIAS)%'
gc_probability: null
gc_maxlifetime: '%env(resolve:APP_SESSIONTIME)%'
cookie_secure: auto
cookie_samesite: lax
storage_factory_id: session.storage.factory.native

View File

@ -2,7 +2,8 @@ parameters:
appEnv: '%env(resolve:APP_ENV)%'
appSecret: '%env(resolve:APP_SECRET)%'
appSessiontime: '%env(resolve:APP_SESSIONTIME)%'
appWeburl: '%env(resolve:APP_WEBURL)%'
appAuth: '%env(resolve:APP_AUTH)%'
appAlias: '%env(resolve:APP_ALIAS)%'

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',

View File

@ -87,7 +87,13 @@
<img src="{{ path('app_minio_image',{file:"logo/"~app.session.get("logodark")}) }}">
</a>
<a class="nav-link " href="{{ path('app_home')}}">Accueil</a>
<a class="nav-link ps-0" href="{{ path('app_home')}}">
{% if not app.session.get("fgheader") %}
{{app.session.get("appname")}}
{% else %}
Accueil
{% endif %}
</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">