Sfoglia il codice sorgente

Merge branch 'feature/admincrud' into develop

master
Charly 3 anni fa
parent
commit
8025f2e970
16 ha cambiato i file con 330 aggiunte e 80 eliminazioni
  1. +7
    -1
      config/packages/lc_sov.yaml
  2. +4
    -0
      config/routes.yaml
  3. +31
    -0
      migrations/Version20210602130250.php
  4. +4
    -5
      src/Controller/Admin/ConfigurationCrudController.php
  5. +49
    -0
      src/Controller/Admin/DashboardAnimatorController.php
  6. +48
    -18
      src/Controller/Admin/DashboardController.php
  7. +23
    -5
      src/Controller/Admin/IndividualDataCrudController.php
  8. +3
    -5
      src/Controller/Admin/TerritoryCrudController.php
  9. +0
    -1
      src/Controller/Admin/ThematicCrudController.php
  10. +89
    -3
      src/Controller/Admin/UserCrudController.php
  11. +4
    -0
      src/Entity/CollectifData.php
  12. +5
    -0
      src/Entity/Configuration.php
  13. +5
    -0
      src/Entity/IndividualData.php
  14. +10
    -1
      src/Entity/Territory.php
  15. +46
    -41
      src/Entity/User/User.php
  16. +2
    -0
      translations/admin.fr.yaml

+ 7
- 1
config/packages/lc_sov.yaml Vedi File

@@ -1,3 +1,9 @@
# see https://symfony.com/doc/current/reference/configuration/framework.html
lc_sov:
homepage_route: 'app_homepage'
homepage_route: 'app_homepage'
login_redirection:
redirect_referer: false
roles_redirection:
- { role: "ROLE_ADMIN", redirect: "admin_dashboard" }
- { role: "ROLE_ANIMATOR", redirect: "admin_dashboard_animator" }
- { role: "ROLE_SUPER_ADMIN", redirect: "admin_dashboard" }

+ 4
- 0
config/routes.yaml Vedi File

@@ -6,6 +6,10 @@ admin_dashboard:
path: /admin
controller: App\Controller\Admin\DashboardController::index

admin_dashboard_animator:
path: /admin-animator
controller: App\Controller\Admin\DashboardAnimatorController::index

app_homepage:
path: /
controller: App\Controller\Frontend\DefaultController:home

+ 31
- 0
migrations/Version20210602130250.php Vedi File

@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210602130250 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE territory ADD dev_alias VARCHAR(255) DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE territory DROP dev_alias');
}
}

+ 4
- 5
src/Controller/Admin/ConfigurationCrudController.php Vedi File

@@ -3,6 +3,7 @@
namespace App\Controller\Admin;

use App\Entity\Configuration;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Controller\Admin\AbstractCrudController;

class ConfigurationCrudController extends AbstractCrudController
@@ -12,14 +13,12 @@ class ConfigurationCrudController extends AbstractCrudController
return Configuration::class;
}

/*
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id'),
TextField::new('title'),
TextEditorField::new('description'),
TextField::new('devAlias'),
TextField::new('value'),
];
}
*/
}

+ 49
- 0
src/Controller/Admin/DashboardAnimatorController.php Vedi File

@@ -0,0 +1,49 @@
<?php

namespace App\Controller\Admin;


use App\Entity\CollectifData;
use App\Entity\Common\TaxRate;
use App\Entity\Configuration;
use App\Entity\IndividualData;
use App\Entity\Site\Page;
use App\Entity\Territory;
use App\Entity\Thematic;
use App\Entity\User\GroupUser;
use App\Entity\User\User;
use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Lc\SovBundle\Controller\Admin\DashboardController as SovDashboardController;
use Symfony\Component\HttpFoundation\Response;

class DashboardAnimatorController extends SovDashboardController
{
private $adminUrlGenerator;

public function __construct(AdminUrlGenerator $adminUrlGenerator)
{
$this->adminUrlGenerator = $adminUrlGenerator;
}

public function configureMenuItems(): iterable
{
$urlCreate = $this->adminUrlGenerator
->setController(CollectifDataCrudController::class)
->setAction('new')
->generateUrl();

yield MenuItem::linkToDashboard('dashboard', 'circle');
yield MenuItem::subMenu('account', 'user')
->setSubItems(
[
MenuItem::linkToRoute('account_profile', '', 'sov_admin_account_profile'),
MenuItem::linkToRoute('account_password', '', 'sov_admin_account_password'),
]
);
yield MenuItem::linkToUrl('data_collectif_create', '', $urlCreate);

}
}

+ 48
- 18
src/Controller/Admin/DashboardController.php Vedi File

@@ -3,7 +3,9 @@
namespace App\Controller\Admin;


use App\Entity\CollectifData;
use App\Entity\Common\TaxRate;
use App\Entity\Configuration;
use App\Entity\IndividualData;
use App\Entity\Site\Page;
use App\Entity\Territory;
@@ -13,39 +15,67 @@ use App\Entity\User\User;
use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Lc\SovBundle\Controller\Admin\DashboardController as SovDashboardController;

class DashboardController extends SovDashboardController
{
const ROLE_ADMIN = "ROLE_ADMIN";
const ROLE_SUPER_ADMIN = "ROLE_SUPER_ADMIN";

private $adminUrlGenerator;

public function __construct(AdminUrlGenerator $adminUrlGenerator)
{
$this->adminUrlGenerator = $adminUrlGenerator;
}

public function configureMenuItems(): iterable
{

$urlCreate = $this->adminUrlGenerator
->setController(CollectifDataCrudController::class)
->setAction('new')
->generateUrl();

yield MenuItem::linkToDashboard('dashboard', 'circle');
yield MenuItem::linkToCrud('page', 'copy', Page::class);
yield MenuItem::subMenu('user', 'user')->setSubItems(
yield MenuItem::subMenu('account', 'user')
->setSubItems(
[
MenuItem::linkToCrud('user_index', '', User::class),
MenuItem::linkToRoute('account_profile', '', 'sov_admin_account_profile'),
MenuItem::linkToRoute('account_password', '', 'sov_admin_account_password'),
]
);
yield MenuItem::subMenu('account', 'user')->setSubItems(
);
yield MenuItem::subMenu('user', 'user')
->setPermission(self::ROLE_ADMIN)
->setSubItems(
[
MenuItem::linkToRoute('account_profile', '', 'sov_admin_account_profile'),
MenuItem::linkToRoute('account_password', '', 'sov_admin_account_password'),
MenuItem::linkToCrud('user_index', '', User::class),
]
);
yield MenuItem::subMenu('data_individual', 'user')->setSubItems(
);
yield MenuItem::subMenu('data_individual', 'user')
->setPermission(self::ROLE_ADMIN)
->setSubItems(
[
MenuItem::linkToCrud('data_individual_validate', '', IndividualData::class),
MenuItem::linkToCrud('data_individual_waiting', '', IndividualData::class),
MenuItem::linkToCrud('data_individual_validate', '', IndividualData::class),
MenuItem::linkToCrud('data_individual_waiting', '', IndividualData::class),
]
);
yield MenuItem::subMenu('data_collectif', 'user')->setSubItems(
);
yield MenuItem::subMenu('data_collectif', 'user')
->setPermission(self::ROLE_ADMIN)
->setSubItems(
[
MenuItem::linkToCrud('data_collectif_validate', '', IndividualData::class),
MenuItem::linkToCrud('data_collectif_waiting', '', IndividualData::class),
MenuItem::linkToCrud('data_collectif_validate', '', CollectifData::class),
MenuItem::linkToCrud('data_collectif_waiting', '', CollectifData::class),
]
);
yield MenuItem::linkToCrud('thematic', 'copy', Thematic::class);
yield MenuItem::linkToCrud('territory', 'copy', Territory::class);
);
yield MenuItem::linkToCrud('thematic', 'copy', Thematic::class)
->setPermission(self::ROLE_ADMIN);
yield MenuItem::linkToCrud('territory', 'copy', Territory::class)
->setPermission(self::ROLE_SUPER_ADMIN);
yield MenuItem::linkToCrud('configuration', 'copy', Configuration::class)
->setPermission(self::ROLE_SUPER_ADMIN);
yield MenuItem::linkToCrud('page', 'copy', Page::class)
->setPermission(self::ROLE_ADMIN);
}
}

+ 23
- 5
src/Controller/Admin/IndividualDataCrudController.php Vedi File

@@ -2,8 +2,14 @@

namespace App\Controller\Admin;

use App\Entity\Configuration;
use App\Entity\IndividualData;
use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Field\BooleanField;

class IndividualDataCrudController extends AbstractCrudController
{
@@ -12,14 +18,26 @@ class IndividualDataCrudController extends AbstractCrudController
return IndividualData::class;
}

/*
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id'),
TextField::new('title'),
TextEditorField::new('description'),
TextField::new('firstname'),
TextField::new('lastname'),
EmailField::new('email'),
TextField::new('introAnswer'),
BooleanField::new('status')->setRequired(false)
];
}
*/

public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void
{
$configurationRepository = $this->getDoctrine()->getRepository(Configuration::class);

$configuration = $configurationRepository->findOneByDevAlias('intro_question');
$entityInstance->setIntroQuestion($configuration->getValue());
$entityManager->persist($entityInstance);
$entityManager->flush();

parent::persistEntity($entityManager, $entityInstance); // TODO: Change the autogenerated stub
}
}

+ 3
- 5
src/Controller/Admin/TerritoryCrudController.php Vedi File

@@ -3,6 +3,7 @@
namespace App\Controller\Admin;

use App\Entity\Territory;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Controller\Admin\AbstractCrudController;

class TerritoryCrudController extends AbstractCrudController
@@ -12,14 +13,11 @@ class TerritoryCrudController extends AbstractCrudController
return Territory::class;
}

/*
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id'),
TextField::new('title'),
TextEditorField::new('description'),
TextField::new('devAlias'),
TextField::new('name'),
];
}
*/
}

+ 0
- 1
src/Controller/Admin/ThematicCrudController.php Vedi File

@@ -14,7 +14,6 @@ class ThematicCrudController extends AbstractCrudController
return Thematic::class;
}


public function configureFields(string $pageName): iterable
{
return [

+ 89
- 3
src/Controller/Admin/UserCrudController.php Vedi File

@@ -3,13 +3,99 @@
namespace App\Controller\Admin;

use App\Entity\User\User;
use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Controller\Admin\UserCrudController as AbstractUserCrudController;
use Lc\SovBundle\Doctrine\EntityManager;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Message;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Twig\Environment;

class UserCrudController extends AbstractUserCrudController
{
public static function getEntityFqcn(): string
{
return User::class;
protected $passwordEncoder;
protected $entityManager;
protected $mailerInterface;

public function __construct(
SessionInterface $session,
RequestStack $request,
EntityManager $em,
TranslatorAdmin $translatorAdmin,
Environment $twig,
UserPasswordEncoderInterface $passwordEncoder,
EntityManager $entityManager,
MailerInterface $mailerInterface
)
{

$this->passwordEncoder = $passwordEncoder;
$this->entityManager = $entityManager;
$this->mailerInterface = $mailerInterface;

parent::__construct($session, $request, $em, $translatorAdmin ,$twig);
}

public static function getEntityFqcn(): string
{
return User::class;
}

public function configureFields(string $pageName): iterable
{
return [
TextField::new('firstname'),
TextField::new('lastname'),
EmailField::new('email'),
ArrayField::new('roles'),
ChoiceField::new('roles')
->allowMultipleChoices()
->autocomplete()
->setChoices(["Utilisateur" => "ROLE_USER", "Animateur" => "ROLE_ANIMATOR", "Admin" => "ROLE_ADMIN"]),

];
}

public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void
{

// @TODO : gérer avec UserManager
$plainPassword = $this->generatePassword(12, 'azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN123456789#!?+=-/%');
$newPasswordEncoded = $this->passwordEncoder->encodePassword($entityInstance, $plainPassword);
$entityInstance->setPassword($newPasswordEncoded);

$this->entityManager->create($entityInstance);
$this->entityManager->flush();

$email = (new Email())
->from('contact@laclic.fr')
->to('charly@laclic.fr')
->subject('Password')
->html($plainPassword);

$this->mailerInterface->send($email);

parent::persistEntity($entityManager, $entityInstance); // TODO: Change the autogenerated stub
}

function generatePassword($caracteres = 12, $chaine = 'azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN123456789#!?+=-/%')
{
$nb_lettres = strlen($chaine) - 1;
$generation = '';
for ($i = 0; $i < $caracteres; $i++) {
$pos = mt_rand(0, $nb_lettres);
$car = $chaine[$pos];
$generation .= $car;
}
return $generation;
}

}

+ 4
- 0
src/Entity/CollectifData.php Vedi File

@@ -68,6 +68,10 @@ class CollectifData implements StatusInterface, EntityInterface
$this->projectsInspiring = new ArrayCollection();
}

public function __toString()
{
return $this->nbParticipant;
}
public function getId(): ?int
{
return $this->id;

+ 5
- 0
src/Entity/Configuration.php Vedi File

@@ -27,6 +27,11 @@ class Configuration implements DevAliasInterface, EntityInterface
*/
private $value;

public function __toString()
{
return $this->value;
}

public function getId(): ?int
{
return $this->id;

+ 5
- 0
src/Entity/IndividualData.php Vedi File

@@ -83,6 +83,11 @@ class IndividualData implements StatusInterface, EntityInterface
$this->territory = new ArrayCollection();
}

public function __toString()
{
return $this->firstname . " " . $this->lastname;
}

public function getId(): ?int
{
return $this->id;

+ 10
- 1
src/Entity/Territory.php Vedi File

@@ -7,12 +7,16 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface;
use Lc\SovBundle\Doctrine\Extension\DevAliasTrait;

/**
* @ORM\Entity(repositoryClass=TerritoryRepository::class)
*/
class Territory implements EntityInterface
class Territory implements EntityInterface, DevAliasInterface
{
use DevAliasTrait;

/**
* @ORM\Id
* @ORM\GeneratedValue
@@ -40,6 +44,11 @@ class Territory implements EntityInterface
$this->collectifData = new ArrayCollection();
}

public function __toString()
{
return $this->name;
}

public function getId(): ?int
{
return $this->id;

+ 46
- 41
src/Entity/User/User.php Vedi File

@@ -16,56 +16,61 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
*/
class User extends SovUserModel implements UserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;

/**
* @ORM\OneToMany(targetEntity=CollectifData::class, mappedBy="user")
*/
private $collectifData;
/**
* @ORM\OneToMany(targetEntity=CollectifData::class, mappedBy="user")
*/
private $collectifData;

public function __construct()
{
$this->collectifData = new ArrayCollection();
}
public function __construct()
{
$this->collectifData = new ArrayCollection();
}

public function getId(): ?int
{
return $this->id;
}
public function __toString()
{
return $this->firstname . " " . $this->lastname;
}

/**
* @return Collection|CollectifData[]
*/
public function getCollectifData(): Collection
{
return $this->collectifData;
}
public function getId(): ?int
{
return $this->id;
}

public function addCollectifData(CollectifData $collectifData): self
{
if (!$this->collectifData->contains($collectifData)) {
$this->collectifData[] = $collectifData;
$collectifData->setUser($this);
}
/**
* @return Collection|CollectifData[]
*/
public function getCollectifData(): Collection
{
return $this->collectifData;
}

return $this;
public function addCollectifData(CollectifData $collectifData): self
{
if (!$this->collectifData->contains($collectifData)) {
$this->collectifData[] = $collectifData;
$collectifData->setUser($this);
}

public function removeCollectifData(CollectifData $collectifData): self
{
if ($this->collectifData->removeElement($collectifData)) {
// set the owning side to null (unless already changed)
if ($collectifData->getUser() === $this) {
$collectifData->setUser(null);
}
}
return $this;
}

return $this;
public function removeCollectifData(CollectifData $collectifData): self
{
if ($this->collectifData->removeElement($collectifData)) {
// set the owning side to null (unless already changed)
if ($collectifData->getUser() === $this) {
$collectifData->setUser(null);
}
}

return $this;
}

}

+ 2
- 0
translations/admin.fr.yaml Vedi File

@@ -5,5 +5,7 @@ menu:
data_collectif: Formulaire collectif
data_collectif_validate: Données validées
data_collectif_waiting: Données en attente de validation
data_collectif_create: Formulaire collectif
territory: Territoires
thematic: Thématiques
configuration: Configuration question Intro

Loading…
Annulla
Salva