소스 검색

user role

master
Charly 3 년 전
부모
커밋
a4d5a648f1
12개의 변경된 파일225개의 추가작업 그리고 67개의 파일을 삭제
  1. +31
    -0
      migrations/Version20210602130250.php
  2. +4
    -5
      src/Controller/Admin/ConfigurationCrudController.php
  3. +8
    -6
      src/Controller/Admin/DashboardController.php
  4. +23
    -5
      src/Controller/Admin/IndividualDataCrudController.php
  5. +3
    -5
      src/Controller/Admin/TerritoryCrudController.php
  6. +0
    -1
      src/Controller/Admin/ThematicCrudController.php
  7. +89
    -3
      src/Controller/Admin/UserCrudController.php
  8. +5
    -0
      src/Entity/Configuration.php
  9. +5
    -0
      src/Entity/IndividualData.php
  10. +10
    -1
      src/Entity/Territory.php
  11. +46
    -41
      src/Entity/User/User.php
  12. +1
    -0
      translations/admin.fr.yaml

+ 31
- 0
migrations/Version20210602130250.php 파일 보기

@@ -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 파일 보기

@@ -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'),
];
}
*/
}

+ 8
- 6
src/Controller/Admin/DashboardController.php 파일 보기

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


use App\Entity\Common\TaxRate;
use App\Entity\Configuration;
use App\Entity\IndividualData;
use App\Entity\Site\Page;
use App\Entity\Territory;
@@ -22,17 +23,17 @@ class DashboardController extends SovDashboardController
{
yield MenuItem::linkToDashboard('dashboard', 'circle');
yield MenuItem::linkToCrud('page', 'copy', Page::class);
yield MenuItem::subMenu('account', 'user')->setSubItems(
[
MenuItem::linkToRoute('account_profile', '', 'sov_admin_account_profile'),
MenuItem::linkToRoute('account_password', '', 'sov_admin_account_password'),
]
);
yield MenuItem::subMenu('user', 'user')->setSubItems(
[
MenuItem::linkToCrud('user_index', '', User::class),
]
);
yield MenuItem::subMenu('account', 'user')->setSubItems(
[
MenuItem::linkToRoute('account_profile', '', 'sov_admin_account_profile'),
MenuItem::linkToRoute('account_password', '', 'sov_admin_account_password'),
]
);
yield MenuItem::subMenu('data_individual', 'user')->setSubItems(
[
MenuItem::linkToCrud('data_individual_validate', '', IndividualData::class),
@@ -47,5 +48,6 @@ class DashboardController extends SovDashboardController
);
yield MenuItem::linkToCrud('thematic', 'copy', Thematic::class);
yield MenuItem::linkToCrud('territory', 'copy', Territory::class);
yield MenuItem::linkToCrud('configuration', 'copy', Configuration::class);
}
}

+ 23
- 5
src/Controller/Admin/IndividualDataCrudController.php 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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,
Environment $twig,
TranslatorAdmin $translatorAdmin,
UserPasswordEncoderInterface $passwordEncoder,
EntityManager $entityManager,
MailerInterface $mailerInterface
)
{

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

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

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;
}

}

+ 5
- 0
src/Entity/Configuration.php 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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 파일 보기

@@ -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;
}

}

+ 1
- 0
translations/admin.fr.yaml 파일 보기

@@ -7,3 +7,4 @@ menu:
data_collectif_waiting: Données en attente de validation
territory: Territoires
thematic: Thématiques
configuration: Configuration question Intro

Loading…
취소
저장