Commit f276b36d authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Structures : la création des rôles par défaut à partir des profils existants...

Structures : la création des rôles par défaut à partir des profils existants oubliait de créer le lien role-->profil.
parent 10fbc514
Loading
Loading
Loading
Loading
+1 −0
Changes for CHANGELOG.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ Journal des modifications
8.5.0
-----
- Module Soutenance : modif de la qualité par défaut des membres lors de la création automatique de la proposition (lors du 1er accès à la page Proposition).
- Structures : la création des rôles par défaut à partir des profils existants oubliait de créer le lien role-->profil.
- [FIX] Requête de recherche de thèses par acteur : les acteurs historisés n'étaient pas écartés.
- [FIX] Module Information : utilisation d'une langue par défaut (FR) pour permettre la création d'une page d'information.

+12 −15
Changes for module/Application/src/Application/Service/Role/RoleService.php: 12 added lines, 15 removed lines.
Original line number Diff line number Diff line
@@ -11,8 +11,8 @@ use Application\Service\Profil\ProfilServiceAwareTrait;
use Application\Service\Source\SourceServiceAwareTrait;
use Application\SourceCodeStringHelperAwareTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\Query\Expr\Join;
use Individu\Entity\Db\Individu;
use Individu\Entity\Db\IndividuRole;
@@ -23,10 +23,6 @@ use Structure\Entity\Db\TypeStructure;
use Structure\Entity\Db\UniteRecherche;
use UnicaenApp\Exception\RuntimeException;

/**
 * Class RoleService
 * @package Application\Service\Role
 */
class RoleService extends BaseService
{
    use SourceServiceAwareTrait;
@@ -227,7 +223,7 @@ class RoleService extends BaseService
    /**
     * @param UniteRecherche|EcoleDoctorale|Etablissement $structure
     */
    public function addRoleByStructure($structure)
    public function addRoleByStructure($structure): void
    {
        /** @var TypeStructure $type */
        $type = null;
@@ -243,24 +239,25 @@ class RoleService extends BaseService
                break;
        }

        /** @var Profil[] $roleModeles */
        /** @var Profil[] $profils */
        $qb = $this->entityManager->getRepository(Profil::class)->createQueryBuilder("rm")
            ->andWhere("rm.structureType = :stype")->setParameter("stype", $type);
        $roleModeles = $qb->getQuery()->execute();
        $profils = $qb->getQuery()->execute();

        foreach ($roleModeles as $roleModele) {
        foreach ($profils as $profil) {
            if ($structure instanceof Etablissement) {
                $sourceCode = $this->sourceCodeStringHelper->addEtablissementPrefixTo($roleModele->getRoleCode() . "_" . $structure->getSourceCode(), $structure);
                $roleId = $roleModele->getLibelle() . " " . $structure->getStructure()->getSourceCode();
                $sourceCode = $this->sourceCodeStringHelper->addEtablissementPrefixTo($profil->getRoleCode() . "_" . $structure->getSourceCode(), $structure);
                $roleId = trim($profil->getLibelle() . " " . $structure->getStructure()->getSourceCode());
            } else {
                $sourceCode = $this->sourceCodeStringHelper->addDefaultPrefixTo($roleModele->getRoleCode() . "_" . $structure->getSourceCode());
                $roleId = $roleModele->getLibelle() . " " . $structure->getStructure()->getSigle();
                $sourceCode = $this->sourceCodeStringHelper->addDefaultPrefixTo($profil->getRoleCode() . "_" . $structure->getSourceCode());
                $roleId = trim($profil->getLibelle() . " " . $structure->getStructure()->getCode());
            }

            $role = $this->createRole($roleModele->getRoleCode(), $roleModele->getLibelle(), $sourceCode);
            $role = $this->createRole($profil->getRoleCode(), $profil->getLibelle(), $sourceCode);
            $role->setRoleId($roleId);
            $role->setTypeStructureDependant($type);
            $role->setStructure($structure->getStructure());
            $role->addProfil($profil);
            try {
                $this->entityManager->flush($role);
            } catch (ORMException $e) {
@@ -268,7 +265,7 @@ class RoleService extends BaseService
            }

            /** @var Privilege $privilege */
            foreach ($roleModele->getPrivileges() as $privilege) {
            foreach ($profil->getPrivileges() as $privilege) {
                $privilege->addRole($role);
                try {
                    $this->entityManager->flush($privilege);
+1 −0
Changes for module/Structure/config/others/structure.config.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ return [
                        'options'       => [
                            'route'       => '/generer-roles-defauts/:id/:type',
                            'defaults'    => [
                                /** @see StructureController::genererRolesDefautsAction() */
                                'action' => 'generer-roles-defauts',
                            ],
                        ],