diff --git a/.env b/.env index 4e35438..6e6fc2e 100644 --- a/.env +++ b/.env @@ -8,10 +8,7 @@ MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0 # Database DATABASE_URL="postgresql://symfony:ChangeMe@127.0.0.1:5432/app?serverVersion=13&charset=utf8" -# Redis Session -REDIS_HOST=127.0.0.1 -REDIS_PORT=6379 - +# Redis Sessionphp bin/console make:entity --regenerate # Mailer MAILER_METHOD=smtp MAILER_DSN=smtp://127.0.0.1:1025 @@ -20,18 +17,48 @@ MAILER_NOREPLY=noreply@noreply.fr # Basic APP_WEBURL=127.0.0.1:8000 APP_MASTERIDENTITY=SQL # SQL | SSO | LDAP -APP_AUTH=SQL # SQL | CAS| LDAP | OPENID | à faire SAML +APP_AUTH=SQL # SQL | CAS | LDAP | OPENID | à faire SAML APP_ALIAS=/ APP_NAME=Nineskeletor APP_MODEREGISTRATION= # null | BYADMIN | BYUSER APP_ADMINS='["admin"]' + +# Structure Organisationnelle APP_NIVEAU01LABEL="Niveau 01" +APP_NIVEAU01LABELS="Niveaux 01" + +APP_NIVEAU02USE=1 APP_NIVEAU02LABEL="Niveau 02" +APP_NIVEAU02LABELS="Niveaux 02" +APP_NIVEAU02MANDATORY='[""]' + +APP_NIVEAU03USE=1 +APP_NIVEAU03LABEL="Niveau 03" +APP_NIVEAU03LABELS="Niveaux 03" +APP_NIVEAU03MANDATORY='[""]' + +APP_NIVEAU04USE=0 +APP_NIVEAU04LABEL="Niveau 04" +APP_NIVEAU04LABELS="Niveaux 04" +APP_NIVEAU04MANDATORY='[""]' + +APP_NIVEAUUPDATABLE=0 # Quel degres de niveau est modifiable par les utilisateurs seule les admin et modo via console peuvent outre passer ce param + +APP_GROUPUSE=1 +APP_GROUPSUBMITER='["ALL"]' + +APP_ANNUSCOPEADMIN=ALL +APP_ANNUSCOPEMODO=ALL +APP_ANNUSCOPEMASTER=ALL +APP_ANNUSCOPEMANAGER=ALL +APP_ANNUSCOPEUSER=ALL # Synchronisation APP_SYNCHRO= # Synchronisation null | LDAP2NINE | NINE2LDAP | NINE2NINE APP_SYNDCHROPURGENIVEAU01=1 # Purger les niveau01s obsolète en cas de synchronisation APP_SYNDCHROPURGENIVEAU02=1 # Purger les niveau02s obsolète en cas de synchronisation +APP_SYNDCHROPURGENIVEAU03=1 # Purger les niveau03s obsolète en cas de synchronisation +APP_SYNDCHROPURGENIVEAU04=1 # Purger les niveau04s obsolète en cas de synchronisation APP_SYNDCHROPURGEGROUP=1 # Purger les groups obsolète en cas de synchronisation APP_SYNDCHROPURGEUSER=1 # Purger les users obsolète en cas de synchronisation @@ -42,12 +69,14 @@ LDAP_USETLS=0 # connection TLS 0/1 LDAP_USERWRITER=0 # LDAP_USER compte writer ? 0/1 LDAP_USER= # DN compte access ldap LDAP_PASSWORD= # Password comte access ldap -LDAP_BASEDN= # Base DN ex:o=gouv,c=fr -LDAP_BASEORGANISATION= # Base Organisation ex:ou=nine,o=gouv,c=fr -LDAP_BASENIVEAU01= # Base Niveau01 ex:ou=niveau01,ou=nine,o=gouv,c=fr -LDAP_BASENIVEAU02= # Base Niveau02 ex:ou=niveau02,ou=nine,o=gouv,c=fr -LDAP_BASEGROUP= # Base Group ex:ou=groups,ou=nine,o=gouv,c=fr -LDAP_BASEUSER= # Base User ex:ou=users,ou=nine,o=gouv,c=fr +LDAP_BASEDN= # Base DN ex:dc=nine,dc=fr +LDAP_BASEORGANISATION= # Base Organisation ex:ou=nineskeletor,dc=nine,dc=fr +LDAP_BASENIVEAU01= # Base Niveau01 ex:ou=niveau01,ou=nineskeletor,dc=nine,dc=fr +LDAP_BASENIVEAU02= # Base Niveau02 ex:ou=niveau02,ou=nineskeletor,dc=nine,dc=fr +LDAP_BASENIVEAU03= # Base Niveau03 ex:ou=niveau03,ou=nineskeletor,dc=nine,dc=fr +LDAP_BASENIVEAU04= # Base Niveau04 ex:ou=niveau04,ou=nineskeletor,dc=nine,dc=fr +LDAP_BASEGROUP= # Base Group ex:ou=groups,ou=nineskeletor,dc=nine,dc=fr +LDAP_BASEUSER= # Base User ex:ou=users,ou=nineskeletor,dc=nine,dc=fr LDAP_USERNAME=uid # Attribut id d'un user LDAP_FIRSTNAME=givenname # Attribut firstname d'un user LDAP_LASTNAME=sn # Attribut lastname d'un user diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index 31787fa..18594d5 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -12,7 +12,20 @@ twig: appSynchro: '%appSynchro%' appSynchroPurgeUser: '%appSynchroPurgeUser%' appNiveau01label: '%appNiveau01label%' + appNiveau01labels: '%appNiveau01labels%' + appNiveau02use: '%appNiveau02use%' appNiveau02label: '%appNiveau02label%' + appNiveau02labels: '%appNiveau02labels%' + appNiveau02mandatory: '%appNiveau02mandatory%' + appNiveau03use: '%appNiveau03use%' + appNiveau03label: '%appNiveau03label%' + appNiveau03labels: '%appNiveau03labels%' + appNiveau03mandatory: '%appNiveau03mandatory%' + appNiveau04use: '%appNiveau04use%' + appNiveau04label: '%appNiveau04label%' + appNiveau04labels: '%appNiveau04labels%' + appNiveau04mandatory: '%appNiveau04mandatory%' + appGroupuse: '%appGroupuse%' sondeUse: '%sondeUse%' sondeUrl: '%sondeUrl%' auditUse: '%auditUse%' diff --git a/config/routes.yaml b/config/routes.yaml index b537b5d..57a6c98 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -330,6 +330,122 @@ app_niveau02_selectlist: path: /niveau02/selectlist controller: App\Controller\Niveau02Controller::selectlist +#== Niveau03 ==================================================================================================== +#-- Access admin +app_admin_niveau03: + path: /admin/niveau03 + controller: App\Controller\Niveau03Controller::list + defaults: { access: admin } + +app_admin_niveau03_tablelist: + path: /admin/niveau03/tablelist + controller: App\Controller\Niveau03Controller::tablelist + defaults: { access: admin } + +app_admin_niveau03_submit: + path: /admin/niveau03/submit + controller: App\Controller\Niveau03Controller::submit + defaults: { access: admin } + +app_admin_niveau03_update: + path: /admin/niveau03/update/{id} + controller: App\Controller\Niveau03Controller::update + defaults: { access: admin } + +app_admin_niveau03_delete: + path: /admin/niveau03/delete/{id} + controller: App\Controller\Niveau03Controller::delete + defaults: { access: admin } + +#-- Access modo +app_modo_niveau03: + path: /modo/niveau03 + controller: App\Controller\Niveau03Controller::list + defaults: { access: modo } + +app_modo_niveau03_tablelist: + path: /modo/niveau03/tablelist + controller: App\Controller\Niveau03Controller::tablelist + defaults: { access: modo } + +app_modo_niveau03_submit: + path: /modo/niveau03/submit + controller: App\Controller\Niveau03Controller::submit + defaults: { access: modo } + +app_modo_niveau03_update: + path: /modo/niveau03/update/{id} + controller: App\Controller\Niveau03Controller::update + defaults: { access: modo } + +app_modo_niveau03_delete: + path: /modo/niveau03/delete/{id} + controller: App\Controller\Niveau03Controller::delete + defaults: { access: modo } + + +#-- Access visiteur +app_niveau03_selectlist: + path: /niveau03/selectlist + controller: App\Controller\Niveau03Controller::selectlist + +#== Niveau04 ==================================================================================================== +#-- Access admin +app_admin_niveau04: + path: /admin/niveau04 + controller: App\Controller\Niveau04Controller::list + defaults: { access: admin } + +app_admin_niveau04_tablelist: + path: /admin/niveau04/tablelist + controller: App\Controller\Niveau04Controller::tablelist + defaults: { access: admin } + +app_admin_niveau04_submit: + path: /admin/niveau04/submit + controller: App\Controller\Niveau04Controller::submit + defaults: { access: admin } + +app_admin_niveau04_update: + path: /admin/niveau04/update/{id} + controller: App\Controller\Niveau04Controller::update + defaults: { access: admin } + +app_admin_niveau04_delete: + path: /admin/niveau04/delete/{id} + controller: App\Controller\Niveau04Controller::delete + defaults: { access: admin } + +#-- Access modo +app_modo_niveau04: + path: /modo/niveau04 + controller: App\Controller\Niveau04Controller::list + defaults: { access: modo } + +app_modo_niveau04_tablelist: + path: /modo/niveau04/tablelist + controller: App\Controller\Niveau04Controller::tablelist + defaults: { access: modo } + +app_modo_niveau04_submit: + path: /modo/niveau04/submit + controller: App\Controller\Niveau04Controller::submit + defaults: { access: modo } + +app_modo_niveau04_update: + path: /modo/niveau04/update/{id} + controller: App\Controller\Niveau04Controller::update + defaults: { access: modo } + +app_modo_niveau04_delete: + path: /modo/niveau04/delete/{id} + controller: App\Controller\Niveau04Controller::delete + defaults: { access: modo } + +#-- Access visiteur +app_niveau04_selectlist: + path: /niveau04/selectlist + controller: App\Controller\Niveau04Controller::selectlist #== Group ======================================================================================================= #-- Access admin diff --git a/config/services.yaml b/config/services.yaml index ddc241c..fd5ed06 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -10,12 +10,41 @@ parameters: appMasteridentity: '%env(resolve:APP_MASTERIDENTITY)%' appModeregistration: '%env(resolve:APP_MODEREGISTRATION)%' appAdmins: '%env(json:APP_ADMINS)%' + appNiveau01label: '%env(resolve:APP_NIVEAU01LABEL)%' + appNiveau01labels: '%env(resolve:APP_NIVEAU01LABELS)%' + + appNiveau02use: '%env(resolve:APP_NIVEAU02USE)%' appNiveau02label: '%env(resolve:APP_NIVEAU02LABEL)%' + appNiveau02labels: '%env(resolve:APP_NIVEAU02LABELS)%' + appNiveau02mandatory: '%env(json:APP_NIVEAU02MANDATORY)%' + + appNiveau03use: '%env(resolve:APP_NIVEAU03USE)%' + appNiveau03label: '%env(resolve:APP_NIVEAU03LABEL)%' + appNiveau03labels: '%env(resolve:APP_NIVEAU03LABELS)%' + appNiveau03mandatory: '%env(json:APP_NIVEAU03MANDATORY)%' + + appNiveau04use: '%env(resolve:APP_NIVEAU04USE)%' + appNiveau04label: '%env(resolve:APP_NIVEAU04LABEL)%' + appNiveau04labels: '%env(resolve:APP_NIVEAU04LABELS)%' + appNiveau04mandatory: '%env(json:APP_NIVEAU04MANDATORY)%' + + appNiveauupdatable: '%env(resolve:APP_NIVEAUUPDATABLE)%' + + appGroupuse: '%env(resolve:APP_GROUPUSE)%' + appGroupsubmiter: '%env(json:APP_GROUPSUBMITER)%' + + appAnnuscopeadmin: '%env(resolve:APP_ANNUSCOPEADMIN)%' + appAnnuscopemodo: '%env(resolve:APP_ANNUSCOPEMODO)%' + appAnnuscopemaster: '%env(resolve:APP_ANNUSCOPEMASTER)%' + appAnnuscopemanager: '%env(resolve:APP_ANNUSCOPEMANAGER)%' + appAnnuscopeuser: '%env(resolve:APP_ANNUSCOPEUSER)%' appSynchro: '%env(resolve:APP_SYNCHRO)%' appSynchroPurgeNiveau01: '%env(resolve:APP_SYNDCHROPURGENIVEAU01)%' appSynchroPurgeNiveau02: '%env(resolve:APP_SYNDCHROPURGENIVEAU02)%' + appSynchroPurgeNiveau03: '%env(resolve:APP_SYNDCHROPURGENIVEAU03)%' + appSynchroPurgeNiveau04: '%env(resolve:APP_SYNDCHROPURGENIVEAU04)%' appSynchroPurgeGroup: '%env(resolve:APP_SYNDCHROPURGEGROUP)%' appSynchroPurgeUser: '%env(resolve:APP_SYNDCHROPURGEUSER)%' @@ -35,6 +64,8 @@ parameters: ldapBaseorganisation: '%env(resolve:LDAP_BASEORGANISATION)%' ldapBaseniveau01: '%env(resolve:LDAP_BASENIVEAU01)%' ldapBaseniveau02: '%env(resolve:LDAP_BASENIVEAU02)%' + ldapBaseniveau03: '%env(resolve:LDAP_BASENIVEAU03)%' + ldapBaseniveau04: '%env(resolve:LDAP_BASENIVEAU04)%' ldapBasegroup: '%env(resolve:LDAP_BASEGROUP)%' ldapBaseuser: '%env(resolve:LDAP_BASEUSER)%' ldapUsername: '%env(resolve:LDAP_USERNAME)%' diff --git a/migrations/Version20220926081328.php b/migrations/Version20220926081328.php new file mode 100644 index 0000000..e3625ad --- /dev/null +++ b/migrations/Version20220926081328.php @@ -0,0 +1,70 @@ +addSql('CREATE SEQUENCE niveau03_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE niveau04_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE niveau03 (id INT NOT NULL, niveau02_id INT NOT NULL, label VARCHAR(250) NOT NULL, apikey VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_83F21F0FEA750E8 ON niveau03 (label)'); + $this->addSql('CREATE INDEX IDX_83F21F0F4B487845 ON niveau03 (niveau02_id)'); + $this->addSql('CREATE TABLE niveau04 (id INT NOT NULL, niveau03_id INT NOT NULL, label VARCHAR(250) NOT NULL, apikey VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_1D968AACEA750E8 ON niveau04 (label)'); + $this->addSql('CREATE INDEX IDX_1D968AACF3F41F20 ON niveau04 (niveau03_id)'); + $this->addSql('ALTER TABLE niveau03 ADD CONSTRAINT FK_83F21F0F4B487845 FOREIGN KEY (niveau02_id) REFERENCES niveau02 (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE niveau04 ADD CONSTRAINT FK_1D968AACF3F41F20 FOREIGN KEY (niveau03_id) REFERENCES niveau03 (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE registration ADD niveau03_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE registration ADD niveau04_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE registration ADD CONSTRAINT FK_62A8A7A7F3F41F20 FOREIGN KEY (niveau03_id) REFERENCES niveau03 (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE registration ADD CONSTRAINT FK_62A8A7A76E232799 FOREIGN KEY (niveau04_id) REFERENCES niveau04 (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_62A8A7A7F3F41F20 ON registration (niveau03_id)'); + $this->addSql('CREATE INDEX IDX_62A8A7A76E232799 ON registration (niveau04_id)'); + $this->addSql('ALTER TABLE useraccount ADD niveau03_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE useraccount ADD niveau04_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE useraccount ADD CONSTRAINT FK_E157AA1AF3F41F20 FOREIGN KEY (niveau03_id) REFERENCES niveau03 (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE useraccount ADD CONSTRAINT FK_E157AA1A6E232799 FOREIGN KEY (niveau04_id) REFERENCES niveau04 (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_E157AA1AF3F41F20 ON useraccount (niveau03_id)'); + $this->addSql('CREATE INDEX IDX_E157AA1A6E232799 ON useraccount (niveau04_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE registration DROP CONSTRAINT FK_62A8A7A7F3F41F20'); + $this->addSql('ALTER TABLE useraccount DROP CONSTRAINT FK_E157AA1AF3F41F20'); + $this->addSql('ALTER TABLE registration DROP CONSTRAINT FK_62A8A7A76E232799'); + $this->addSql('ALTER TABLE useraccount DROP CONSTRAINT FK_E157AA1A6E232799'); + $this->addSql('DROP SEQUENCE niveau03_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE niveau04_id_seq CASCADE'); + $this->addSql('ALTER TABLE niveau03 DROP CONSTRAINT FK_83F21F0F4B487845'); + $this->addSql('ALTER TABLE niveau04 DROP CONSTRAINT FK_1D968AACF3F41F20'); + $this->addSql('DROP TABLE niveau03'); + $this->addSql('DROP TABLE niveau04'); + $this->addSql('DROP INDEX IDX_E157AA1AF3F41F20'); + $this->addSql('DROP INDEX IDX_E157AA1A6E232799'); + $this->addSql('ALTER TABLE useraccount DROP niveau03_id'); + $this->addSql('ALTER TABLE useraccount DROP niveau04_id'); + $this->addSql('DROP INDEX IDX_62A8A7A7F3F41F20'); + $this->addSql('DROP INDEX IDX_62A8A7A76E232799'); + $this->addSql('ALTER TABLE registration DROP niveau03_id'); + $this->addSql('ALTER TABLE registration DROP niveau04_id'); + } +} diff --git a/src/Command/CronCommand.php b/src/Command/CronCommand.php index 93e7a20..8900862 100644 --- a/src/Command/CronCommand.php +++ b/src/Command/CronCommand.php @@ -77,7 +77,10 @@ class CronCommand extends Command $command = $this->getApplication()->find($cron->getCommand()); // Réccuépration des parametres - $jsonparameter = json_decode($cron->getJsonargument(), true); + $jsonparameter = null; + if ($cron->getJsonargument()) { + $jsonparameter = json_decode($cron->getJsonargument(), true); + } // Formater la chaine de parametre if (!$jsonparameter) { diff --git a/src/Command/InitCommand.php b/src/Command/InitCommand.php index 340afee..4e965b2 100644 --- a/src/Command/InitCommand.php +++ b/src/Command/InitCommand.php @@ -174,51 +174,6 @@ class InitCommand extends Command 'Forcer la connexion afin de rendre votre site privé' ); - $this->insertConfig( - 200, // order - 'site', // category - 'permgroup', // id - 'Rôle créateur de groupe de travail', // title - '', // value - 'ROLE_MASTER', // default - 'role', // type, - true, // visible - true, // changeable - true, // required - '', // grouped - 'Détermine quel rôle aura la permission de créer des groupes de travail' - ); - - $this->insertConfig( - 201, // order - 'site', // category - 'permannu', // id - "Rôle accédant à l'annuaire", // title - '', // value - 'ROLE_USER', // default - 'role', // type, - true, // visible - true, // changeable - true, // required - '', // grouped - "Détermine quel rôle aura la permission de voir l'annuaire" - ); - - $this->insertConfig( - 202, // order - 'site', // category - 'scopeannu', // id - "Scope de l'annuaire", // title - '', // value - 'ALL', // default - 'scopeannu', // type, - true, // visible - true, // changeable - true, // required - '', // grouped - "Détermine le scope des utilisateurs visibles dans l'annuaire par d'autres utilisateurs" - ); - $this->insertConfig( 500, // order 'site', // category diff --git a/src/Command/SynchroCommand.php b/src/Command/SynchroCommand.php index e349628..1f11da9 100644 --- a/src/Command/SynchroCommand.php +++ b/src/Command/SynchroCommand.php @@ -29,6 +29,8 @@ class SynchroCommand extends Command private $synchro; private $synchropurgeniveau01; private $synchropurgeniveau02; + private $synchropurgeniveau03; + private $synchropurgeniveau04; private $synchropurgegroup; private $synchropurgeuser; private $host; @@ -41,6 +43,8 @@ class SynchroCommand extends Command private $baseorganisation; private $baseniveau01; private $baseniveau02; + private $baseniveau03; + private $baseniveau04; private $basegroup; private $baseuser; private $username; @@ -86,6 +90,8 @@ class SynchroCommand extends Command $this->synchro = $this->container->getParameter('appSynchro'); $this->synchropurgeniveau01 = $this->container->getParameter('appSynchroPurgeNiveau01'); $this->synchropurgeniveau02 = $this->container->getParameter('appSynchroPurgeNiveau02'); + $this->synchropurgeniveau03 = $this->container->getParameter('appSynchroPurgeNiveau03'); + $this->synchropurgeniveau04 = $this->container->getParameter('appSynchroPurgeNiveau04'); $this->synchropurgegroup = $this->container->getParameter('appSynchroPurgeGroup'); $this->synchropurgeuser = $this->container->getParameter('appSynchroPurgeUser'); @@ -99,6 +105,8 @@ class SynchroCommand extends Command $this->baseorganisation = $this->container->getParameter('ldapBaseorganisation'); $this->baseniveau01 = $this->container->getParameter('ldapBaseniveau01'); $this->baseniveau02 = $this->container->getParameter('ldapBaseniveau02'); + $this->baseniveau03 = $this->container->getParameter('ldapBaseniveau03'); + $this->baseniveau04 = $this->container->getParameter('ldapBaseniveau04'); $this->basegroup = $this->container->getParameter('ldapBasegroup'); $this->baseuser = $this->container->getParameter('ldapBaseuser'); $this->username = $this->container->getParameter('ldapUsername'); @@ -353,6 +361,8 @@ class SynchroCommand extends Command // Mise à jour du niveau01 if ($niveau01 != $user->getNiveau01()) { $user->setNiveau02(null); + $user->setNiveau03(null); + $user->setNiveau04(null); } $user->setNiveau01($niveau01); @@ -453,6 +463,8 @@ class SynchroCommand extends Command $resetniveau01 = $this->em->getRepository("App\Entity\User")->find(-1); $user->setNiveau01($resetniveau01); $user->setNiveau02(null); + $user->setNiveau03(null); + $user->setNiveau04(null); } $this->writeln(' > '.$niveau01->getLabel()); @@ -497,6 +509,8 @@ class SynchroCommand extends Command $this->writeln($this->baseorganisation); $this->writeln($this->baseniveau01); $this->writeln($this->baseniveau02); + $this->writeln($this->baseniveau03); + $this->writeln($this->baseniveau04); $this->writeln($this->basegroup); $this->writeln($this->baseuser); $this->ldap->addOrganisations(); @@ -563,6 +577,68 @@ class SynchroCommand extends Command } } + $this->writeln(''); + $this->writeln('== NIVEAU04 ========================================='); + $niveau04s = $this->em->getRepository("App\Entity\Niveau04")->findAll(); + $attributes = $this->ldap->listAttributesNiveau04(); + foreach ($niveau04s as $niveau04) { + $filter = 'gidnumber='.$niveau04->getId(); + $ldapentrys = $this->ldap->search($filter, $attributes, $this->baseniveau04); + if (empty($ldapentrys)) { + $filter = str_replace('*', $niveau04->getLabel(), $this->filtergroup); + $ldapentrys = $this->ldap->search($filter, $attributes, $this->baseniveau01); + } + + if (empty($ldapentrys)) { + $this->writeln($niveau04->getLabel().' = SUBMIT'); + $this->ldap->addNiveau04($niveau04); + } elseif ($this->ldap->ismodifyNiveau04($niveau04, $ldapentrys[0])) { + $this->writeln($niveau04->getLabel().' = UPDATE'); + $this->ldap->modifyNiveau04($niveau04, $ldapentrys[0]['cn']); + } + } + + $ldapentrys = $this->ldap->search($this->filtergroup, $attributes, $this->baseniveau04); + foreach ($ldapentrys as $ldapentry) { + $niveau04 = $this->em->getRepository("App\Entity\Niveau04")->find($ldapentry['gidnumber']); + if (!$niveau04) { + $this->writeln($ldapentry['cn'].' = DELETE'); + $dn = $this->ldap->getNiveau04DN($ldapentry['cn']); + $this->ldap->deleteByDN($dn); + } + } + + $this->writeln(''); + $this->writeln('== NIVEAU03 ========================================='); + $niveau03s = $this->em->getRepository("App\Entity\Niveau03")->findAll(); + $attributes = $this->ldap->listAttributesNiveau03(); + foreach ($niveau03s as $niveau03) { + $filter = 'gidnumber='.$niveau03->getId(); + $ldapentrys = $this->ldap->search($filter, $attributes, $this->baseniveau03); + if (empty($ldapentrys)) { + $filter = str_replace('*', $niveau03->getLabel(), $this->filtergroup); + $ldapentrys = $this->ldap->search($filter, $attributes, $this->baseniveau01); + } + + if (empty($ldapentrys)) { + $this->writeln($niveau03->getLabel().' = SUBMIT'); + $this->ldap->addNiveau03($niveau03); + } elseif ($this->ldap->ismodifyNiveau03($niveau03, $ldapentrys[0])) { + $this->writeln($niveau03->getLabel().' = UPDATE'); + $this->ldap->modifyNiveau03($niveau03, $ldapentrys[0]['cn']); + } + } + + $ldapentrys = $this->ldap->search($this->filtergroup, $attributes, $this->baseniveau03); + foreach ($ldapentrys as $ldapentry) { + $niveau03 = $this->em->getRepository("App\Entity\Niveau03")->find($ldapentry['gidnumber']); + if (!$niveau03) { + $this->writeln($ldapentry['cn'].' = DELETE'); + $dn = $this->ldap->getNiveau03DN($ldapentry['cn']); + $this->ldap->deleteByDN($dn); + } + } + $this->writeln(''); $this->writeln('== NIVEAU02 ========================================='); $niveau02s = $this->em->getRepository("App\Entity\Niveau02")->findAll(); @@ -824,6 +900,8 @@ class SynchroCommand extends Command // Mise à jour du niveau01 if ($niveau01 != $user->getNiveau01()) { $user->setNiveau02(null); + $user->setNiveau03(null); + $user->setNiveau04(null); } $user->setNiveau01($niveau01); @@ -919,6 +997,8 @@ class SynchroCommand extends Command $resetniveau01 = $this->em->getRepository("App\Entity\User")->find(-1); $user->setNiveau01($resetniveau01); $user->setNiveau02(null); + $user->setNiveau03(null); + $user->setNiveau04(null); } $this->writeln(' > '.$niveau01->getLabel()); diff --git a/src/Controller/GroupController.php b/src/Controller/GroupController.php index 34214c5..1d67023 100644 --- a/src/Controller/GroupController.php +++ b/src/Controller/GroupController.php @@ -200,7 +200,9 @@ class GroupController extends AbstractController } // Controler les permissions - $this->cansubmit($access, $em); + if (!$this->cansubmit($access, $request)) { + throw $this->createAccessDeniedException('Permission denied'); + } // Création du formulaire $form = $this->createForm(Form::class, $data, [ @@ -363,6 +365,8 @@ class GroupController extends AbstractController $usermodo = null; $niveau01 = null; $niveau02 = null; + $niveau03 = null; + $niveau04 = null; // Nombre total d'enregistrement $qb = $em->getManager()->createQueryBuilder(); @@ -389,6 +393,8 @@ class GroupController extends AbstractController case 'user': $niveau01 = $this->getUser()->getNiveau01(); $niveau02 = $this->getUser()->getNiveau02(); + $niveau03 = $this->getUser()->getNiveau03(); + $niveau04 = $this->getUser()->getNiveau04(); $qb->select('COUNT(user)') ->from('App:User', 'user') @@ -396,13 +402,21 @@ class GroupController extends AbstractController ->setParameter('groupid', $id); switch ($request->getSession()->get('scopeannu')) { - case 'SAME_NIVEAU01': + case 1: $qb->andWhere('user.niveau01 = :niveau01')->setParameter('niveau01', $niveau01); break; - case 'SAME_NIVEAU02': + case 2: $qb->andWhere('user.niveau02 = :niveau02')->setParameter('niveau02', $niveau02); break; + + case 3: + $qb->andWhere('user.niveau03 = :niveau03')->setParameter('niveau02', $niveau03); + break; + + case 4: + $qb->andWhere('user.niveau04 = :niveau04')->setParameter('niveau04', $niveau04); + break; } break; } @@ -452,13 +466,21 @@ class GroupController extends AbstractController ->setParameter('groupid', $id); switch ($request->getSession()->get('scopeannu')) { - case 'SAME_NIVEAU01': + case 1: $qb->andWhere('user.niveau01 = :niveau01')->setParameter('niveau01', $niveau01); break; - case 'SAME_NIVEAU02': + case 2: $qb->andWhere('user.niveau02 = :niveau02')->setParameter('niveau02', $niveau02); break; + + case 3: + $qb->andWhere('user.niveau03 = :niveau03')->setParameter('niveau02', $niveau03); + break; + + case 4: + $qb->andWhere('user.niveau04 = :niveau04')->setParameter('niveau04', $niveau04); + break; } $totalf = $qb->getQuery()->getSingleScalarResult(); @@ -494,13 +516,21 @@ class GroupController extends AbstractController case 'user': $qb->where($qb->expr()->not($qb->expr()->exists($sub->getDQL()))); switch ($request->getSession()->get('scopeannu')) { - case 'SAME_NIVEAU01': + case 1: $qb->andWhere('user.niveau01 = :niveau01')->setParameter('niveau01', $niveau01); break; - case 'SAME_NIVEAU02': + case 2: $qb->andWhere('user.niveau02 = :niveau02')->setParameter('niveau02', $niveau02); break; + + case 3: + $qb->andWhere('user.niveau03 = :niveau03')->setParameter('niveau02', $niveau03); + break; + + case 4: + $qb->andWhere('user.niveau04 = :niveau04')->setParameter('niveau04', $niveau04); + break; } break; } @@ -805,12 +835,14 @@ class GroupController extends AbstractController return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route)); } - private function cansubmit($access, $em) + private function cansubmit($access, $request) { switch ($access) { case 'admin': return true; break; - case 'user': return true; + case 'modo': return false; + break; + case 'user': return $request->getSession()->get('submitgroup'); break; } throw $this->createAccessDeniedException('Permission denied'); diff --git a/src/Controller/Niveau03Controller.php b/src/Controller/Niveau03Controller.php new file mode 100644 index 0000000..5d2450b --- /dev/null +++ b/src/Controller/Niveau03Controller.php @@ -0,0 +1,354 @@ +render($this->twig.'list.html.twig', [ + 'useheader' => true, + 'usemenu' => false, + 'usesidebar' => true, + 'access' => $access, + ]); + } + + public function tablelist($access, Request $request, ManagerRegistry $em): Response + { + $query = $request->query->all(); + $start = $query['start']; + $length = $query['length']; + $search = $query['search']; + $draw = $query['draw']; + $ordercolumn = $query['order'][0]['column']; + $orderdir = $query['order'][0]['dir']; + $total = null; + $totalf = null; + + // Nombre total d'enregistrement + switch ($access) { + case 'admin': + $total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult(); + break; + + case 'modo': + $total = $em->getManager()->createQueryBuilder() + ->select('COUNT(entity)') + ->from($this->entity, 'entity') + ->from("App\Entity\UserModo", 'usermodo') + ->from("App\Entity\Niveau02", 'niveau02') + ->where('entity.niveau02 = niveau02.id') + ->andwhere('usermodo.niveau01 = niveau02.niveau01') + ->andWhere('usermodo.user = :user') + ->setParameter('user', $this->getUser()) + ->getQuery()->getSingleScalarResult(); + break; + } + + // Nombre d'enregistrement filtré + if (!$search || '' == $search['value']) { + $totalf = $total; + } else { + switch ($access) { + case 'admin': + $totalf = $em->getManager()->createQueryBuilder() + ->select('COUNT(entity)') + ->from($this->entity, 'entity') + ->from("App\Entity\Niveau01", 'niveau01') + ->from("App\Entity\Niveau02", 'niveau02') + ->where('entity.niveau02 = niveau02.id') + ->andwhere('niveau02.niveau01=niveau01.id') + ->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value OR niveau02.label LIKE :value') + ->setParameter('value', '%'.$search['value'].'%') + ->getQuery() + ->getSingleScalarResult(); + break; + + case 'modo': + $totalf = $em->getManager()->createQueryBuilder() + ->select('COUNT(entity)') + ->from($this->entity, 'entity') + ->from("App\Entity\Niveau01", 'niveau01') + ->from("App\Entity\Niveau02", 'niveau02') + ->from("App\Entity\UserModo", 'usermodo') + ->where('entity.niveau02 = niveau02.id') + ->andwhere('niveau02.niveau01=niveau01.id') + ->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value OR niveau02.label LIKE :value') + ->andWhere('usermodo.niveau01 = niveau01.id') + ->andWhere('usermodo.user = :user') + ->setParameter('value', '%'.$search['value'].'%') + ->setParameter('user', $this->getUser()) + ->getQuery() + ->getSingleScalarResult(); + break; + } + } + + // Construction du tableau de retour + $output = [ + 'draw' => $draw, + 'recordsFiltered' => $totalf, + 'recordsTotal' => $total, + 'data' => [], + ]; + + // Parcours des Enregistrement + $qb = $em->getManager()->createQueryBuilder(); + switch ($access) { + case 'admin': + $qb->select('entity') + ->from($this->entity, 'entity') + ->from('App:Niveau01', 'niveau01') + ->from('App:Niveau02', 'niveau02') + ->where('entity.niveau02=niveau02.id') + ->andwhere('niveau02.niveau01=niveau01.id'); + break; + + case 'modo': + $qb->select('entity') + ->from($this->entity, 'entity') + ->from('App:Niveau01', 'niveau01') + ->from('App:Niveau02', 'niveau02') + ->from("App\Entity\UserModo", 'usermodo') + ->where('entity.niveau02=niveau02.id') + ->andwhere('niveau02.niveau01=niveau01.id') + ->andWhere('usermodo.niveau01 = niveau01.id') + ->andWhere('usermodo.user = :user') + ->setParameter('user', $this->getUser()); + break; + } + + if ($search && '' != $search['value']) { + $qb->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value OR niveau02.label LIKE :value') + ->setParameter('value', '%'.$search['value'].'%'); + } + + if ($ordercolumn) { + switch ($ordercolumn) { + case 1: + $qb->orderBy('niveau01.label', $orderdir); + break; + + case 2: + $qb->orderBy('niveau02.label', $orderdir); + break; + + case 3: + $qb->orderBy('entity.label', $orderdir); + break; + } + } + + $datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult(); + + foreach ($datas as $data) { + // Action + $action = ''; + switch ($access) { + case 'admin': + $action .= " $data->getId()])."'>"; + break; + case 'modo': + $action .= "route).'_update', ['id' => $data->getId()])."'>"; + break; + } + + $tmp = []; + array_push($tmp, $action); + array_push($tmp, $data->getNiveau02()->getNiveau01()->getLabel()); + array_push($tmp, $data->getNiveau02()->getLabel()); + array_push($tmp, $data->getLabel()); + + array_push($output['data'], $tmp); + } + + // Retour + return new JsonResponse($output); + } + + public function selectlist(Request $request, ManagerRegistry $em): Response + { + $output = []; + $page_limit = $request->query->get('page_limit'); + $q = $request->query->get('q'); + $niveau02id = $request->get('niveau02'); + + $qb = $em->getManager()->createQueryBuilder(); + $qb->select('entity') + ->from($this->entity, 'entity') + ->where('entity.label LIKE :value') + ->andwhere('entity.niveau02=:niveau02') + ->setParameter('value', '%'.$q.'%') + ->setParameter('niveau02', $niveau02id) + ->orderBy('entity.label'); + + $datas = $qb->setFirstResult(0)->setMaxResults($page_limit)->getQuery()->getResult(); + foreach ($datas as $data) { + array_push($output, ['id' => $data->getId(), 'text' => $data->getLabel()]); + } + + $ret_string['results'] = $output; + $response = new Response(json_encode($ret_string)); + $response->headers->set('Content-Type', 'application/json'); + + return $response; + } + + public function submit($access, Request $request, ManagerRegistry $em): Response + { + // Initialisation de l'enregistrement + $data = new Entity(); + $data->setApikey(Uuid::uuid4()); + + // Controler les permissions + $this->cansubmit($access, $em); + + // Création du formulaire + $form = $this->createForm(Form::class, $data, [ + 'mode' => 'submit', + 'access' => $access, + 'userid' => $this->getUser()->getId(), + 'appMasteridentity' => $this->GetParameter('appMasteridentity'), + 'appNiveau01label' => $this->GetParameter('appNiveau01label'), + 'appNiveau02label' => $this->GetParameter('appNiveau02label'), + 'appNiveau03label' => $this->GetParameter('appNiveau03label'), + ]); + + // Récupération des data du formulaire + $form->handleRequest($request); + + // Sur validation + if ($form->get('submit')->isClicked() && $form->isValid()) { + $data = $form->getData(); + + // Sauvegarde + $em->getManager()->persist($data); + $em->getManager()->flush(); + + // Retour à la liste + return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route)); + } + + // Affichage du formulaire + return $this->render($this->twig.'edit.html.twig', [ + 'useheader' => true, + 'usemenu' => false, + 'usesidebar' => true, + 'mode' => 'submit', + 'access' => $access, + 'form' => $form->createView(), + $this->data => $data, + ]); + } + + public function update($id, $access, Request $request, ManagerRegistry $em): Response + { + // Initialisation de l'enregistrement + $data = $em->getRepository($this->entity)->find($id); + if (!$data) { + throw $this->createNotFoundException('Unable to find entity.'); + } + + // Controler les permissions + $this->canupdate($access, $data, $em); + + // Création du formulaire + $form = $this->createForm(Form::class, $data, [ + 'mode' => 'update', + 'appMasteridentity' => $this->GetParameter('appMasteridentity'), + 'appNiveau01label' => $this->GetParameter('appNiveau01label'), + 'appNiveau02label' => $this->GetParameter('appNiveau02label'), + 'appNiveau03label' => $this->GetParameter('appNiveau03label'), + ]); + + // Récupération des data du formulaire + $form->handleRequest($request); + + // Sur validation + if ($form->get('submit')->isClicked() && $form->isValid()) { + $data = $form->getData(); + $em->getManager()->flush(); + + // Retour à la liste + return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route)); + } + + // Affichage du formulaire + return $this->render($this->twig.'edit.html.twig', [ + 'useheader' => true, + 'usemenu' => false, + 'usesidebar' => true, + $this->data => $data, + 'mode' => 'update', + 'access' => $access, + 'form' => $form->createView(), + ]); + } + + public function delete($id, $access, Request $request, ManagerRegistry $em): Response + { + // Récupération de l'enregistrement courant + $data = $em->getRepository($this->entity)->find($id); + if (!$data) { + throw $this->createNotFoundException('Unable to find entity.'); + } + + // Controler les permissions + $this->canupdate($access, $data, $em); + + // Tentative de suppression + try { + $em->getManager()->remove($data); + $em->getManager()->flush(); + } catch (\Exception $e) { + $request->getSession()->getFlashBag()->add('error', $e->getMessage()); + + return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $id]); + } + + return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route)); + } + + private function cansubmit($access, $em) + { + switch ($access) { + case 'admin': return true; + break; + case 'modo': return true; + break; + } + throw $this->createAccessDeniedException('Permission denied'); + } + + private function canupdate($access, $entity, $em) + { + switch ($access) { + case 'admin': return true; + break; + case 'modo': + $usermodo = $em->getRepository("App\Entity\UserModo")->findOneBy(['user' => $this->getUser(), 'niveau01' => $entity->getNiveau02()->getNiveau01()]); + if (!$usermodo) { + throw $this->createAccessDeniedException('Permission denied'); + } + + return true; + break; + } + throw $this->createAccessDeniedException('Permission denied'); + } +} diff --git a/src/Controller/Niveau04Controller.php b/src/Controller/Niveau04Controller.php new file mode 100644 index 0000000..8a12e02 --- /dev/null +++ b/src/Controller/Niveau04Controller.php @@ -0,0 +1,371 @@ +render($this->twig.'list.html.twig', [ + 'useheader' => true, + 'usemenu' => false, + 'usesidebar' => true, + 'access' => $access, + ]); + } + + public function tablelist($access, Request $request, ManagerRegistry $em): Response + { + $query = $request->query->all(); + $start = $query['start']; + $length = $query['length']; + $search = $query['search']; + $draw = $query['draw']; + $ordercolumn = $query['order'][0]['column']; + $orderdir = $query['order'][0]['dir']; + $total = null; + $totalf = null; + + // Nombre total d'enregistrement + switch ($access) { + case 'admin': + $total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult(); + break; + + case 'modo': + $total = $em->getManager()->createQueryBuilder() + ->select('COUNT(entity)') + ->from($this->entity, 'entity') + ->from("App\Entity\UserModo", 'usermodo') + ->from("App\Entity\Niveau02", 'niveau02') + ->from("App\Entity\Niveau03", 'niveau03') + ->where('entity.niveau03 = niveau03.id') + ->andWhere('niveau03.niveau02=niveau02.id') + ->andwhere('usermodo.niveau01 = niveau02.niveau01') + ->andWhere('usermodo.user = :user') + ->setParameter('user', $this->getUser()) + ->getQuery()->getSingleScalarResult(); + break; + } + + // Nombre d'enregistrement filtré + if (!$search || '' == $search['value']) { + $totalf = $total; + } else { + switch ($access) { + case 'admin': + $totalf = $em->getManager()->createQueryBuilder() + ->select('COUNT(entity)') + ->from($this->entity, 'entity') + ->from("App\Entity\Niveau01", 'niveau01') + ->from("App\Entity\Niveau02", 'niveau02') + ->from("App\Entity\Niveau03", 'niveau03') + ->where('entity.niveau03 = niveau03.id') + ->andWhere('niveau03.niveau02=niveau02.id') + ->andwhere('niveau02.niveau01=niveau01.id') + ->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value OR niveau02.label LIKE :value OR niveau03.label LIKE :value') + ->setParameter('value', '%'.$search['value'].'%') + ->getQuery() + ->getSingleScalarResult(); + break; + + case 'modo': + $totalf = $em->getManager()->createQueryBuilder() + ->select('COUNT(entity)') + ->from($this->entity, 'entity') + ->from("App\Entity\Niveau01", 'niveau01') + ->from("App\Entity\Niveau02", 'niveau02') + ->from("App\Entity\Niveau03", 'niveau03') + ->from("App\Entity\UserModo", 'usermodo') + ->where('entity.niveau03 = niveau03.id') + ->andWhere('niveau03.niveau02=niveau02.id') + ->andwhere('niveau02.niveau01=niveau01.id') + ->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value OR niveau02.label LIKE :value OR niveau03.label LIKE :value') + ->andWhere('usermodo.niveau01 = niveau01.id') + ->andWhere('usermodo.user = :user') + ->setParameter('value', '%'.$search['value'].'%') + ->setParameter('user', $this->getUser()) + ->getQuery() + ->getSingleScalarResult(); + break; + } + } + + // Construction du tableau de retour + $output = [ + 'draw' => $draw, + 'recordsFiltered' => $totalf, + 'recordsTotal' => $total, + 'data' => [], + ]; + + // Parcours des Enregistrement + $qb = $em->getManager()->createQueryBuilder(); + switch ($access) { + case 'admin': + $qb->select('entity') + ->from($this->entity, 'entity') + ->from('App:Niveau01', 'niveau01') + ->from('App:Niveau02', 'niveau02') + ->from("App\Entity\Niveau03", 'niveau03') + ->where('entity.niveau03 = niveau03.id') + ->andWhere('niveau03.niveau02=niveau02.id') + ->andwhere('niveau02.niveau01=niveau01.id'); + break; + + case 'modo': + $qb->select('entity') + ->from($this->entity, 'entity') + ->from('App:Niveau01', 'niveau01') + ->from('App:Niveau02', 'niveau02') + ->from("App\Entity\Niveau03", 'niveau03') + ->from("App\Entity\UserModo", 'usermodo') + ->where('entity.niveau03 = niveau03.id') + ->andWhere('niveau03.niveau02=niveau02.id') + ->andwhere('niveau02.niveau01=niveau01.id') + ->andWhere('usermodo.niveau01 = niveau01.id') + ->andWhere('usermodo.user = :user') + ->setParameter('user', $this->getUser()); + break; + } + + if ($search && '' != $search['value']) { + $qb->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value OR niveau02.label LIKE :value OR niveau03.label LIKE :value') + ->setParameter('value', '%'.$search['value'].'%'); + } + + if ($ordercolumn) { + switch ($ordercolumn) { + case 1: + $qb->orderBy('niveau01.label', $orderdir); + break; + + case 2: + $qb->orderBy('niveau02.label', $orderdir); + break; + + case 3: + $qb->orderBy('niveau03.label', $orderdir); + break; + + case 4: + $qb->orderBy('entity.label', $orderdir); + break; + } + } + + $datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult(); + + foreach ($datas as $data) { + // Action + $action = ''; + switch ($access) { + case 'admin': + $action .= " $data->getId()])."'>"; + break; + case 'modo': + $action .= "route).'_update', ['id' => $data->getId()])."'>"; + break; + } + + $tmp = []; + array_push($tmp, $action); + array_push($tmp, $data->getNiveau03()->getNiveau02()->getNiveau01()->getLabel()); + array_push($tmp, $data->getNiveau03()->getNiveau02()->getLabel()); + array_push($tmp, $data->getNiveau03()->getLabel()); + array_push($tmp, $data->getLabel()); + + array_push($output['data'], $tmp); + } + + // Retour + return new JsonResponse($output); + } + + public function selectlist(Request $request, ManagerRegistry $em): Response + { + $output = []; + $page_limit = $request->query->get('page_limit'); + $q = $request->query->get('q'); + $niveau03id = $request->get('niveau03'); + + $qb = $em->getManager()->createQueryBuilder(); + $qb->select('entity') + ->from($this->entity, 'entity') + ->where('entity.label LIKE :value') + ->andwhere('entity.niveau03=:niveau03') + ->setParameter('value', '%'.$q.'%') + ->setParameter('niveau03', $niveau03id) + ->orderBy('entity.label'); + + $datas = $qb->setFirstResult(0)->setMaxResults($page_limit)->getQuery()->getResult(); + foreach ($datas as $data) { + array_push($output, ['id' => $data->getId(), 'text' => $data->getLabel()]); + } + + $ret_string['results'] = $output; + $response = new Response(json_encode($ret_string)); + $response->headers->set('Content-Type', 'application/json'); + + return $response; + } + + public function submit($access, Request $request, ManagerRegistry $em): Response + { + // Initialisation de l'enregistrement + $data = new Entity(); + $data->setApikey(Uuid::uuid4()); + + // Controler les permissions + $this->cansubmit($access, $em); + + // Création du formulaire + $form = $this->createForm(Form::class, $data, [ + 'mode' => 'submit', + 'access' => $access, + 'userid' => $this->getUser()->getId(), + 'appMasteridentity' => $this->GetParameter('appMasteridentity'), + 'appNiveau01label' => $this->GetParameter('appNiveau01label'), + 'appNiveau02label' => $this->GetParameter('appNiveau02label'), + 'appNiveau03label' => $this->GetParameter('appNiveau03label'), + 'appNiveau04label' => $this->GetParameter('appNiveau04label'), + ]); + + // Récupération des data du formulaire + $form->handleRequest($request); + + // Sur validation + if ($form->get('submit')->isClicked() && $form->isValid()) { + $data = $form->getData(); + + // Sauvegarde + $em->getManager()->persist($data); + $em->getManager()->flush(); + + // Retour à la liste + return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route)); + } + + // Affichage du formulaire + return $this->render($this->twig.'edit.html.twig', [ + 'useheader' => true, + 'usemenu' => false, + 'usesidebar' => true, + 'mode' => 'submit', + 'access' => $access, + 'form' => $form->createView(), + $this->data => $data, + ]); + } + + public function update($id, $access, Request $request, ManagerRegistry $em): Response + { + // Initialisation de l'enregistrement + $data = $em->getRepository($this->entity)->find($id); + if (!$data) { + throw $this->createNotFoundException('Unable to find entity.'); + } + + // Controler les permissions + $this->canupdate($access, $data, $em); + + // Création du formulaire + $form = $this->createForm(Form::class, $data, [ + 'mode' => 'update', + 'appMasteridentity' => $this->GetParameter('appMasteridentity'), + 'appNiveau01label' => $this->GetParameter('appNiveau01label'), + 'appNiveau02label' => $this->GetParameter('appNiveau02label'), + 'appNiveau03label' => $this->GetParameter('appNiveau03label'), + 'appNiveau04label' => $this->GetParameter('appNiveau04label'), + ]); + + // Récupération des data du formulaire + $form->handleRequest($request); + + // Sur validation + if ($form->get('submit')->isClicked() && $form->isValid()) { + $data = $form->getData(); + $em->getManager()->flush(); + + // Retour à la liste + return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route)); + } + + // Affichage du formulaire + return $this->render($this->twig.'edit.html.twig', [ + 'useheader' => true, + 'usemenu' => false, + 'usesidebar' => true, + $this->data => $data, + 'mode' => 'update', + 'access' => $access, + 'form' => $form->createView(), + ]); + } + + public function delete($id, $access, Request $request, ManagerRegistry $em): Response + { + // Récupération de l'enregistrement courant + $data = $em->getRepository($this->entity)->find($id); + if (!$data) { + throw $this->createNotFoundException('Unable to find entity.'); + } + + // Controler les permissions + $this->canupdate($access, $data, $em); + + // Tentative de suppression + try { + $em->getManager()->remove($data); + $em->getManager()->flush(); + } catch (\Exception $e) { + $request->getSession()->getFlashBag()->add('error', $e->getMessage()); + + return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $id]); + } + + return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route)); + } + + private function cansubmit($access, $em) + { + switch ($access) { + case 'admin': return true; + break; + case 'modo': return true; + break; + } + throw $this->createAccessDeniedException('Permission denied'); + } + + private function canupdate($access, $entity, $em) + { + switch ($access) { + case 'admin': return true; + break; + case 'modo': + $usermodo = $em->getRepository("App\Entity\UserModo")->findOneBy(['user' => $this->getUser(), 'niveau01' => $entity->getNiveau03()->getNiveau02()->getNiveau01()]); + if (!$usermodo) { + throw $this->createAccessDeniedException('Permission denied'); + } + + return true; + break; + } + throw $this->createAccessDeniedException('Permission denied'); + } +} diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php index 815e4bf..7c71d7d 100755 --- a/src/Controller/RegistrationController.php +++ b/src/Controller/RegistrationController.php @@ -138,11 +138,11 @@ class RegistrationController extends AbstractController $qb->orderBy('entity.label', $orderdir); break; - case 4: + case 7: $qb->orderBy('entity.statut', $orderdir); break; - case 5: + case 8: $qb->orderBy('entity.keyexpire', $orderdir); break; } @@ -171,6 +171,9 @@ class RegistrationController extends AbstractController $data->getUsername(), $data->getEmail(), $data->getNiveau01()->getLabel(), + $data->getNiveau02() ? $data->getNiveau02()->getLabel() : '', + $data->getNiveau03() ? $data->getNiveau03()->getLabel() : '', + $data->getNiveau04() ? $data->getNiveau04()->getLabel() : '', $statut, is_null($data->getKeyexpire()) ? '' : $data->getKeyexpire()->format('d/m/Y H:i:s'), ]); @@ -199,7 +202,12 @@ class RegistrationController extends AbstractController 'userid' => null, 'appMasteridentity' => $this->GetParameter('appMasteridentity'), 'appNiveau01label' => $this->GetParameter('appNiveau01label'), + 'appNiveau02use' => $this->GetParameter('appNiveau02use'), 'appNiveau02label' => $this->GetParameter('appNiveau02label'), + 'appNiveau03use' => $this->GetParameter('appNiveau03use'), + 'appNiveau03label' => $this->GetParameter('appNiveau03label'), + 'appNiveau04use' => $this->GetParameter('appNiveau04use'), + 'appNiveau04label' => $this->GetParameter('appNiveau04label'), ]); // Récupération des data du formulaire @@ -383,7 +391,12 @@ class RegistrationController extends AbstractController 'userid' => $this->getUser()->getId(), 'appMasteridentity' => $this->GetParameter('appMasteridentity'), 'appNiveau01label' => $this->GetParameter('appNiveau01label'), + 'appNiveau02use' => $this->GetParameter('appNiveau02use'), 'appNiveau02label' => $this->GetParameter('appNiveau02label'), + 'appNiveau03use' => $this->GetParameter('appNiveau03use'), + 'appNiveau03label' => $this->GetParameter('appNiveau03label'), + 'appNiveau04use' => $this->GetParameter('appNiveau04use'), + 'appNiveau04label' => $this->GetParameter('appNiveau04label'), ]); // Récupération des data du formulaire @@ -499,6 +512,8 @@ class RegistrationController extends AbstractController $user->setNiveau01($data->getNiveau01()); $user->setNiveau02($data->getNiveau02()); + $user->setNiveau03($data->getNiveau03()); + $user->setNiveau04($data->getNiveau04()); $user->setTelephonenumber($data->getTelephonenumber()); $user->setPostaladress($data->getPostaladress()); diff --git a/src/Controller/RestController.php b/src/Controller/RestController.php index 95cf43f..09e645f 100644 --- a/src/Controller/RestController.php +++ b/src/Controller/RestController.php @@ -283,6 +283,186 @@ class RestController extends AbstractFOSRestController return $this->handleView($view); } + /** + * getAllNiveau03s. + * + * @FOSRest\Get("/rest/getAllNiveau03s") + * @OA\Response( + * response=200, + * description="get all niveau03" + * ) + * ) + * @OA\Parameter( + * name="key", + * in="header", + * required=true, + * description="APIKey", + * @OA\Schema(type="string") + * ) + */ + public function getAllNiveau03s(Request $request, ManagerRegistry $em) + { + set_time_limit(0); + ini_set('memory_limit', '1024M'); + + // Récupération des parametres + if (!$this->iskey($request->headers->get('key'))) { + $view = $this->view('API Key inconnue', 403); + + return $this->handleView($view); + } + + $output = []; + $niveau03s = $em->getRepository("App\Entity\Niveau03")->findAll(); + foreach ($niveau03s as $niveau03) { + array_push($output, $this->niveau03Format($niveau03, true)); + } + + $view = $this->view($output, 200); + + return $this->handleView($view); + } + + /** + * getOneNiveau03. + * + * @FOSRest\Get("/rest/getOneNiveau03") + * @OA\Response( + * response=200, + * description="get one niveau03 by label" + * ) + * ) + * @OA\Parameter( + * name="key", + * in="header", + * required=true, + * description="APIKey", + * @OA\Schema(type="string") + * ) + * @OA\Parameter( + * name="label", + * in="header", + * required=true, + * description="Label", + * @OA\Schema(type="string") + * ) + */ + public function getOneNiveau03(Request $request, ManagerRegistry $em) + { + set_time_limit(0); + ini_set('memory_limit', '1024M'); + + // Récupération des parametres + if (!$this->iskey($request->headers->get('key'))) { + $view = $this->view('API Key inconnue', 403); + + return $this->handleView($view); + } + + $output = []; + $niveau03 = $em->getRepository("App\Entity\Niveau03")->findOneBy(['label' => $request->headers->get('label')]); + if (!$niveau03) { + $view = $this->view('Niveau03 inconnu', 403); + + return $this->handleView($view); + } + + $output = $this->niveau03Format($niveau03, true); + $view = $this->view($output, 200); + + return $this->handleView($view); + } + + /** + * getAllNiveau04s. + * + * @FOSRest\Get("/rest/getAllNiveau04s") + * @OA\Response( + * response=200, + * description="get all niveau04" + * ) + * ) + * @OA\Parameter( + * name="key", + * in="header", + * required=true, + * description="APIKey", + * @OA\Schema(type="string") + * ) + */ + public function getAllNiveau04s(Request $request, ManagerRegistry $em) + { + set_time_limit(0); + ini_set('memory_limit', '1024M'); + + // Récupération des parametres + if (!$this->iskey($request->headers->get('key'))) { + $view = $this->view('API Key inconnue', 403); + + return $this->handleView($view); + } + + $output = []; + $niveau04s = $em->getRepository("App\Entity\Niveau04")->findAll(); + foreach ($niveau04s as $niveau04) { + array_push($output, $this->niveau04Format($niveau04, true)); + } + + $view = $this->view($output, 200); + + return $this->handleView($view); + } + + /** + * getOneNiveau04. + * + * @FOSRest\Get("/rest/getOneNiveau04") + * @OA\Response( + * response=200, + * description="get one niveau04 by label" + * ) + * ) + * @OA\Parameter( + * name="key", + * in="header", + * required=true, + * description="APIKey", + * @OA\Schema(type="string") + * ) + * @OA\Parameter( + * name="label", + * in="header", + * required=true, + * description="Label", + * @OA\Schema(type="string") + * ) + */ + public function getOneNiveau04(Request $request, ManagerRegistry $em) + { + set_time_limit(0); + ini_set('memory_limit', '1024M'); + + // Récupération des parametres + if (!$this->iskey($request->headers->get('key'))) { + $view = $this->view('API Key inconnue', 403); + + return $this->handleView($view); + } + + $output = []; + $niveau04 = $em->getRepository("App\Entity\Niveau04")->findOneBy(['label' => $request->headers->get('label')]); + if (!$niveau04) { + $view = $this->view('Niveau04 inconnu', 403); + + return $this->handleView($view); + } + + $output = $this->niveau04Format($niveau04, true); + $view = $this->view($output, 200); + + return $this->handleView($view); + } + /** * getAllGroups. * @@ -397,6 +577,8 @@ class RestController extends AbstractFOSRestController $output['useravatar'] = 'https://'.str_replace('//', '/', $this->getParameter('appWeburl').$this->getParameter('appAlias').$this->generateUrl('app_minio_image', ['file' => 'avatar/'.$user->getAvatar()], true)); $output['userniveau01'] = $this->niveau01Format($user->getNiveau01()); $output['userniveau02'] = $this->niveau02Format($user->getNiveau02()); + $output['userniveau03'] = $this->niveau03Format($user->getNiveau03()); + $output['userniveau04'] = $this->niveau03Format($user->getNiveau04()); $output['usergroups'] = []; foreach ($user->getGroups() as $usergroup) { $groupFormat = $this->groupFormat($usergroup->getGroup()); @@ -456,6 +638,55 @@ class RestController extends AbstractFOSRestController return $output; } + private function niveau03Format($niveau03, $withmembers = false) + { + if (!$niveau03) { + return null; + } + $output = []; + $output['niveau03id'] = $niveau03->getId(); + $output['niveau03label'] = $niveau03->getLabel(); + + if ($withmembers) { + $output['niveau03niveau01'] = $this->niveau01Format($niveau03->getNiveau02()->getNiveau01()); + $output['niveau03niveau02'] = $this->niveau02Format($niveau03->getNiveau02()); + $output['niveau03users'] = []; + foreach ($niveau03->getUsers() as $user) { + array_push($output['niveau03users'], ['userid' => $user->getId(), 'userlogin' => $user->getUsername()]); + } + if (empty($output['niveau03users'])) { + $output['niveau03users'] = null; + } + } + + return $output; + } + + private function niveau04Format($niveau04, $withmembers = false) + { + if (!$niveau04) { + return null; + } + $output = []; + $output['niveau04id'] = $niveau04->getId(); + $output['niveau04label'] = $niveau04->getLabel(); + + if ($withmembers) { + $output['niveau04niveau01'] = $this->niveau01Format($niveau04->getNiveau03()->getNiveau02()->getNiveau01()); + $output['niveau04niveau02'] = $this->niveau02Format($niveau04->getNiveau03()->getNiveau02()); + $output['niveau04niveau03'] = $this->niveau02Format($niveau04->getNiveau03()); + $output['niveau04users'] = []; + foreach ($niveau04->getUsers() as $user) { + array_push($output['niveau04users'], ['userid' => $user->getId(), 'userlogin' => $user->getUsername()]); + } + if (empty($output['niveau04users'])) { + $output['niveau04users'] = null; + } + } + + return $output; + } + private function groupFormat($group, $withmembers = false) { if (!$group || $group->getId() < 0) { diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 08b1e7b..62fc7c3 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -45,6 +45,8 @@ class UserController extends AbstractController $orderdir = $query['order'][0]['dir']; $niveau01 = null; $niveau02 = null; + $niveau03 = null; + $niveau04 = null; // Nombre total d'enregistrement switch ($access) { @@ -66,16 +68,26 @@ class UserController extends AbstractController default: $niveau01 = $this->getUser()->getNiveau01(); $niveau02 = $this->getUser()->getNiveau02(); + $niveau03 = $this->getUser()->getNiveau03(); + $niveau04 = $this->getUser()->getNiveau04(); $qb = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->where('entity.isvisible=true'); switch ($request->getSession()->get('scopeannu')) { - case 'SAME_NIVEAU01': + case 1: $qb->andWhere('entity.niveau01 = :niveau01')->setParameter('niveau01', $niveau01); break; - case 'SAME_NIVEAU02': + case 2: $qb->andWhere('entity.niveau02 = :niveau02')->setParameter('niveau02', $niveau02); break; + + case 3: + $qb->andWhere('entity.niveau03 = :niveau03')->setParameter('niveau03', $niveau03); + break; + + case 4: + $qb->andWhere('entity.niveau04 = :niveau04')->setParameter('niveau04', $niveau04); + break; } $total = $qb->getQuery()->getSingleScalarResult(); @@ -126,13 +138,21 @@ class UserController extends AbstractController ->setParameter('value', '%'.$search['value'].'%'); switch ($request->getSession()->get('scopeannu')) { - case 'SAME_NIVEAU01': + case 1: $qb->andWhere('entity.niveau01 = :niveau01')->setParameter('niveau01', $niveau01); break; - case 'SAME_NIVEAU02': + case 2: $qb->andWhere('entity.niveau02 = :niveau02')->setParameter('niveau02', $niveau02); break; + + case 3: + $qb->andWhere('entity.niveau03 = :niveau03')->setParameter('niveau03', $niveau03); + break; + + case 4: + $qb->andWhere('entity.niveau04 = :niveau04')->setParameter('niveau04', $niveau04); + break; } $totalf = $qb->getQuery()->getSingleScalarResult(); @@ -170,13 +190,21 @@ class UserController extends AbstractController $qb->andWhere('entity.isvisible=true'); switch ($request->getSession()->get('scopeannu')) { - case 'SAME_NIVEAU01': + case 1: $qb->andWhere('entity.niveau01 = :niveau01')->setParameter('niveau01', $niveau01); break; - case 'SAME_NIVEAU02': + case 2: $qb->andWhere('entity.niveau02 = :niveau02')->setParameter('niveau02', $niveau02); break; + + case 3: + $qb->andWhere('entity.niveau03 = :niveau03')->setParameter('niveau03', $niveau03); + break; + + case 4: + $qb->andWhere('entity.niveau04 = :niveau04')->setParameter('niveau04', $niveau04); + break; } break; } @@ -266,6 +294,8 @@ class UserController extends AbstractController array_push($tmp, $data->getTelephonenumber()); array_push($tmp, $data->getNiveau01()->getLabel()); array_push($tmp, $data->getNiveau02() ? $data->getNiveau02()->getLabel() : ''); + array_push($tmp, $data->getNiveau03() ? $data->getNiveau03()->getLabel() : ''); + array_push($tmp, $data->getNiveau04() ? $data->getNiveau04()->getLabel() : ''); array_push($tmp, $data->getVisitedate() ? $data->getVisitedate()->format('d/m/Y H:i').'
nb = '.$data->getVisitecpt() : ''); array_push($tmp, $roles); array_push($tmp, $groups); @@ -323,7 +353,13 @@ class UserController extends AbstractController 'userid' => $this->getUser()->getId(), 'appMasteridentity' => $this->GetParameter('appMasteridentity'), 'appNiveau01label' => $this->GetParameter('appNiveau01label'), + 'appNiveau02use' => $this->GetParameter('appNiveau02use'), 'appNiveau02label' => $this->GetParameter('appNiveau02label'), + 'appNiveau03use' => $this->GetParameter('appNiveau03use'), + 'appNiveau03label' => $this->GetParameter('appNiveau03label'), + 'appNiveau04use' => $this->GetParameter('appNiveau04use'), + 'appNiveau04label' => $this->GetParameter('appNiveau04label'), + 'appNiveauupdatable' => $this->GetParameter('appNiveauupdatable'), ]); // Récupération des data du formulaire @@ -436,7 +472,13 @@ class UserController extends AbstractController 'userid' => $this->getUser()->getId(), 'appMasteridentity' => $this->GetParameter('appMasteridentity'), 'appNiveau01label' => $this->GetParameter('appNiveau01label'), + 'appNiveau02use' => $this->GetParameter('appNiveau02use'), 'appNiveau02label' => $this->GetParameter('appNiveau02label'), + 'appNiveau03use' => $this->GetParameter('appNiveau03use'), + 'appNiveau03label' => $this->GetParameter('appNiveau03label'), + 'appNiveau04use' => $this->GetParameter('appNiveau04use'), + 'appNiveau04label' => $this->GetParameter('appNiveau04label'), + 'appNiveauupdatable' => $this->GetParameter('appNiveauupdatable'), ]); // Récupération des data du formulaire diff --git a/src/Entity/Niveau02.php b/src/Entity/Niveau02.php index 346085c..f25a857 100644 --- a/src/Entity/Niveau02.php +++ b/src/Entity/Niveau02.php @@ -43,6 +43,14 @@ class Niveau02 */ private $niveau01; + /** + * @var ArrayCollection + * @var Registration + * + * @ORM\OneToMany(targetEntity="Niveau03", mappedBy="niveau02", cascade={"persist"}, orphanRemoval=false) + */ + private $niveau03s; + /** * @var ArrayCollection * @var Registration @@ -61,6 +69,7 @@ class Niveau02 public function __construct() { + $this->niveau03s = new ArrayCollection(); $this->registrations = new ArrayCollection(); $this->users = new ArrayCollection(); } @@ -106,6 +115,36 @@ class Niveau02 return $this; } + /** + * @return Collection + */ + public function getNiveau03s(): Collection + { + return $this->niveau03s; + } + + public function addNiveau03(Niveau03 $niveau03): self + { + if (!$this->niveau03s->contains($niveau03)) { + $this->niveau03s->add($niveau03); + $niveau03->setNiveau02($this); + } + + return $this; + } + + public function removeNiveau03(Niveau03 $niveau03): self + { + if ($this->niveau03s->removeElement($niveau03)) { + // set the owning side to null (unless already changed) + if ($niveau03->getNiveau02() === $this) { + $niveau03->setNiveau02(null); + } + } + + return $this; + } + /** * @return Collection */ @@ -117,7 +156,7 @@ class Niveau02 public function addRegistration(Registration $registration): self { if (!$this->registrations->contains($registration)) { - $this->registrations[] = $registration; + $this->registrations->add($registration); $registration->setNiveau02($this); } @@ -147,7 +186,7 @@ class Niveau02 public function addUser(User $user): self { if (!$this->users->contains($user)) { - $this->users[] = $user; + $this->users->add($user); $user->setNiveau02($this); } diff --git a/src/Entity/Niveau03.php b/src/Entity/Niveau03.php new file mode 100644 index 0000000..36ab22e --- /dev/null +++ b/src/Entity/Niveau03.php @@ -0,0 +1,223 @@ +niveau02 ? $this->niveau02->getNiveau01() : null; + } + + public function setNiveau01(?Niveau01 $niveau01): self + { + $this->niveau01 = $niveau01; + + return $this; + } + // == + + public function __construct() + { + $this->niveau04s = new ArrayCollection(); + $this->registrations = new ArrayCollection(); + $this->users = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getLabel(): ?string + { + return $this->label; + } + + public function setLabel(string $label): self + { + $this->label = $label; + + return $this; + } + + public function getApikey(): ?string + { + return $this->apikey; + } + + public function setApikey(string $apikey): self + { + $this->apikey = $apikey; + + return $this; + } + + public function getNiveau02(): ?Niveau02 + { + return $this->niveau02; + } + + public function setNiveau02(?Niveau02 $niveau02): self + { + $this->niveau02 = $niveau02; + + return $this; + } + + /** + * @return Collection + */ + public function getNiveau04s(): Collection + { + return $this->niveau04s; + } + + public function addNiveau04(Niveau04 $niveau04): self + { + if (!$this->niveau04s->contains($niveau04)) { + $this->niveau04s->add($niveau04); + $niveau04->setNiveau03($this); + } + + return $this; + } + + public function removeNiveau04(Niveau04 $niveau04): self + { + if ($this->niveau04s->removeElement($niveau04)) { + // set the owning side to null (unless already changed) + if ($niveau04->getNiveau03() === $this) { + $niveau04->setNiveau03(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getRegistrations(): Collection + { + return $this->registrations; + } + + public function addRegistration(Registration $registration): self + { + if (!$this->registrations->contains($registration)) { + $this->registrations->add($registration); + $registration->setNiveau03($this); + } + + return $this; + } + + public function removeRegistration(Registration $registration): self + { + if ($this->registrations->removeElement($registration)) { + // set the owning side to null (unless already changed) + if ($registration->getNiveau03() === $this) { + $registration->setNiveau03(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getUsers(): Collection + { + return $this->users; + } + + public function addUser(User $user): self + { + if (!$this->users->contains($user)) { + $this->users->add($user); + $user->setNiveau03($this); + } + + return $this; + } + + public function removeUser(User $user): self + { + if ($this->users->removeElement($user)) { + // set the owning side to null (unless already changed) + if ($user->getNiveau03() === $this) { + $user->setNiveau03(null); + } + } + + return $this; + } +} diff --git a/src/Entity/Niveau04.php b/src/Entity/Niveau04.php new file mode 100644 index 0000000..11d5a19 --- /dev/null +++ b/src/Entity/Niveau04.php @@ -0,0 +1,199 @@ +niveau03 ? $this->niveau03->getNiveau02()->getNiveau01() : null; + } + + public function setNiveau01(?Niveau01 $niveau01): self + { + $this->niveau01 = $niveau01; + + return $this; + } + + private $niveau02; + + public function getNiveau02(): ?Niveau02 + { + return $this->niveau03 ? $this->niveau03->getNiveau02() : null; + } + + public function setNiveau02(?Niveau02 $niveau02): self + { + $this->niveau02 = $niveau02; + + return $this; + } + + // == + + public function __construct() + { + $this->registrations = new ArrayCollection(); + $this->users = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getLabel(): ?string + { + return $this->label; + } + + public function setLabel(string $label): self + { + $this->label = $label; + + return $this; + } + + public function getApikey(): ?string + { + return $this->apikey; + } + + public function setApikey(string $apikey): self + { + $this->apikey = $apikey; + + return $this; + } + + public function getNiveau03(): ?Niveau03 + { + return $this->niveau03; + } + + public function setNiveau03(?Niveau03 $niveau03): self + { + $this->niveau03 = $niveau03; + + return $this; + } + + /** + * @return Collection + */ + public function getRegistrations(): Collection + { + return $this->registrations; + } + + public function addRegistration(Registration $registration): self + { + if (!$this->registrations->contains($registration)) { + $this->registrations->add($registration); + $registration->setNiveau04($this); + } + + return $this; + } + + public function removeRegistration(Registration $registration): self + { + if ($this->registrations->removeElement($registration)) { + // set the owning side to null (unless already changed) + if ($registration->getNiveau04() === $this) { + $registration->setNiveau04(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getUsers(): Collection + { + return $this->users; + } + + public function addUser(User $user): self + { + if (!$this->users->contains($user)) { + $this->users->add($user); + $user->setNiveau04($this); + } + + return $this; + } + + public function removeUser(User $user): self + { + if ($this->users->removeElement($user)) { + // set the owning side to null (unless already changed) + if ($user->getNiveau04() === $this) { + $user->setNiveau04(null); + } + } + + return $this; + } +} diff --git a/src/Entity/Registration.php b/src/Entity/Registration.php index b0ca6b7..b8d2580 100644 --- a/src/Entity/Registration.php +++ b/src/Entity/Registration.php @@ -122,6 +122,16 @@ class Registration implements UserInterface, LegacyPasswordAuthenticatedUserInte */ private $niveau02; + /** + * @ORM\ManyToOne(targetEntity="Niveau03", inversedBy="registrations") + */ + private $niveau03; + + /** + * @ORM\ManyToOne(targetEntity="Niveau04", inversedBy="registrations") + */ + private $niveau04; + // == CODE A NE PAS REGENERER private $roles; @@ -410,4 +420,28 @@ class Registration implements UserInterface, LegacyPasswordAuthenticatedUserInte return $this; } + + public function getNiveau03(): ?Niveau03 + { + return $this->niveau03; + } + + public function setNiveau03(?Niveau03 $niveau03): self + { + $this->niveau03 = $niveau03; + + return $this; + } + + public function getNiveau04(): ?Niveau04 + { + return $this->niveau04; + } + + public function setNiveau04(?Niveau04 $niveau04): self + { + $this->niveau04 = $niveau04; + + return $this; + } } diff --git a/src/Entity/User.php b/src/Entity/User.php index 1a21be3..0c75688 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -152,6 +152,16 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface */ private $niveau02; + /** + * @ORM\ManyToOne(targetEntity="Niveau03", inversedBy="users") + */ + private $niveau03; + + /** + * @ORM\ManyToOne(targetEntity="Niveau04", inversedBy="users") + */ + private $niveau04; + /** * @var ArrayCollection * @var UserGroup @@ -621,4 +631,28 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface return $this; } + + public function getNiveau03(): ?Niveau03 + { + return $this->niveau03; + } + + public function setNiveau03(?Niveau03 $niveau03): self + { + $this->niveau03 = $niveau03; + + return $this; + } + + public function getNiveau04(): ?Niveau04 + { + return $this->niveau04; + } + + public function setNiveau04(?Niveau04 $niveau04): self + { + $this->niveau04 = $niveau04; + + return $this; + } } diff --git a/src/EventListener/Niveau02Subscriber.php b/src/EventListener/Niveau02Subscriber.php index 472750d..e48c914 100644 --- a/src/EventListener/Niveau02Subscriber.php +++ b/src/EventListener/Niveau02Subscriber.php @@ -69,6 +69,11 @@ class Niveau02Subscriber implements EventSubscriberInterface return; } + // Impossible de supprimer si présence de niveau03 rattaché + if (!$this->entity->getNiveau03s()->isEmpty()) { + throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des niveaux de rang 03'); + } + // Impossible de supprimer si présence de registration rattaché if (!$this->entity->getRegistrations()->isEmpty()) { throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des inscriptions'); diff --git a/src/EventListener/Niveau03Subscriber.php b/src/EventListener/Niveau03Subscriber.php new file mode 100644 index 0000000..159a065 --- /dev/null +++ b/src/EventListener/Niveau03Subscriber.php @@ -0,0 +1,128 @@ +em = $em; + $this->ldap = $ldap; + } + + public function getSubscribedEvents(): array + { + return [ + Events::postPersist, + Events::preUpdate, + Events::postUpdate, + Events::preRemove, + Events::postRemove, + ]; + } + + public function postPersist(LifecycleEventArgs $args): void + { + $this->entity = $args->getObject(); + if (!$this->entity instanceof Entity) { + return; + } + + // Synchronisation nine2ldap + $this->nine2ldap(); + } + + public function preUpdate(LifecycleEventArgs $args): void + { + $this->entity = $args->getObject(); + if (!$this->entity instanceof Entity) { + return; + } + } + + public function postUpdate(LifecycleEventArgs $args): void + { + $this->entity = $args->getObject(); + if (!$this->entity instanceof Entity) { + return; + } + + // Synchronisation nine2ldap + $this->nine2ldap(); + } + + public function preRemove(LifecycleEventArgs $args): void + { + $this->entity = $args->getObject(); + if (!$this->entity instanceof Entity) { + return; + } + + // Impossible de supprimer si présence de niveau04 rattaché + if (!$this->entity->getNiveau04s()->isEmpty()) { + throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des niveaux de rang 04'); + } + + // Impossible de supprimer si présence de registration rattaché + if (!$this->entity->getRegistrations()->isEmpty()) { + throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des inscriptions'); + } + + // Impossible de supprimer si présence de user rattaché + if (!$this->entity->getUsers()->isEmpty()) { + throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des utilisateurs'); + } + + // Synchronisation nine2ldap + $this->nine2ldapremove(); + } + + public function postRemove(LifecycleEventArgs $args): void + { + $this->entity = $args->getObject(); + if (!$this->entity instanceof Entity) { + return; + } + } + + private function nine2ldap() + { + if ($this->ldap->isNine2Ldap()) { + // On s'assure que la structure organisationnelle est présente + $this->ldap->addOrganisations(); + + // Ajout / Modification dans annuaire + $filter = 'gidnumber='.$this->entity->getId(); + $attributes = $this->ldap->listAttributesNiveau03(); + $ldapentrys = $this->ldap->search($filter, $attributes, $this->ldap->getParameter('baseniveau03')); + if (empty($ldapentrys)) { + $this->ldap->addNiveau03($this->entity); + } elseif ($this->ldap->ismodifyNiveau03($this->entity, $ldapentrys[0])) { + $this->ldap->modifyNiveau03($this->entity, $ldapentrys[0]['cn']); + } + } + } + + private function nine2ldapremove() + { + if ($this->ldap->isNine2Ldap()) { + $filter = 'gidnumber='.$this->entity->getId(); + $attributes = $this->ldap->listAttributesNiveau03(); + $ldapentrys = $this->ldap->search($filter, $attributes, $this->ldap->getParameter('baseniveau03')); + if (!empty($ldapentrys)) { + $this->ldap->deleteNiveau03($this->entity); + } + } + } +} diff --git a/src/EventListener/Niveau04Subscriber.php b/src/EventListener/Niveau04Subscriber.php new file mode 100644 index 0000000..524827f --- /dev/null +++ b/src/EventListener/Niveau04Subscriber.php @@ -0,0 +1,123 @@ +em = $em; + $this->ldap = $ldap; + } + + public function getSubscribedEvents(): array + { + return [ + Events::postPersist, + Events::preUpdate, + Events::postUpdate, + Events::preRemove, + Events::postRemove, + ]; + } + + public function postPersist(LifecycleEventArgs $args): void + { + $this->entity = $args->getObject(); + if (!$this->entity instanceof Entity) { + return; + } + + // Synchronisation nine2ldap + $this->nine2ldap(); + } + + public function preUpdate(LifecycleEventArgs $args): void + { + $this->entity = $args->getObject(); + if (!$this->entity instanceof Entity) { + return; + } + } + + public function postUpdate(LifecycleEventArgs $args): void + { + $this->entity = $args->getObject(); + if (!$this->entity instanceof Entity) { + return; + } + + // Synchronisation nine2ldap + $this->nine2ldap(); + } + + public function preRemove(LifecycleEventArgs $args): void + { + $this->entity = $args->getObject(); + if (!$this->entity instanceof Entity) { + return; + } + + // Impossible de supprimer si présence de registration rattaché + if (!$this->entity->getRegistrations()->isEmpty()) { + throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des inscriptions'); + } + + // Impossible de supprimer si présence de user rattaché + if (!$this->entity->getUsers()->isEmpty()) { + throw new \Exception('Impossible de supprimer cet enregistrement. Il est lié à des utilisateurs'); + } + + // Synchronisation nine2ldap + $this->nine2ldapremove(); + } + + public function postRemove(LifecycleEventArgs $args): void + { + $this->entity = $args->getObject(); + if (!$this->entity instanceof Entity) { + return; + } + } + + private function nine2ldap() + { + if ($this->ldap->isNine2Ldap()) { + // On s'assure que la structure organisationnelle est présente + $this->ldap->addOrganisations(); + + // Ajout / Modification dans annuaire + $filter = 'gidnumber='.$this->entity->getId(); + $attributes = $this->ldap->listAttributesNiveau04(); + $ldapentrys = $this->ldap->search($filter, $attributes, $this->ldap->getParameter('baseniveau04')); + if (empty($ldapentrys)) { + $this->ldap->addNiveau04($this->entity); + } elseif ($this->ldap->ismodifyNiveau04($this->entity, $ldapentrys[0])) { + $this->ldap->modifyNiveau04($this->entity, $ldapentrys[0]['cn']); + } + } + } + + private function nine2ldapremove() + { + if ($this->ldap->isNine2Ldap()) { + $filter = 'gidnumber='.$this->entity->getId(); + $attributes = $this->ldap->listAttributesNiveau04(); + $ldapentrys = $this->ldap->search($filter, $attributes, $this->ldap->getParameter('baseniveau04')); + if (!empty($ldapentrys)) { + $this->ldap->deleteNiveau04($this->entity); + } + } + } +} diff --git a/src/EventListener/UserSubscriber.php b/src/EventListener/UserSubscriber.php index c86d9c2..f69d063 100644 --- a/src/EventListener/UserSubscriber.php +++ b/src/EventListener/UserSubscriber.php @@ -106,7 +106,7 @@ class UserSubscriber implements EventSubscriberInterface // Ajout / Modification dans annuaire $filter = str_replace('*', $this->entity->getUsername(), $this->ldap->getParameter('filteruser')); - $attributes = $this->ldap->listAttributesNiveau02(); + $attributes = $this->ldap->listAttributesUser(); $ldapentrys = $this->ldap->search($filter, $attributes, $this->ldap->getParameter('baseuser')); if (empty($ldapentrys)) { $this->ldap->addUser($this->entity); @@ -123,7 +123,7 @@ class UserSubscriber implements EventSubscriberInterface { if ($this->ldap->isNine2Ldap()) { $filter = str_replace('*', $this->entity->getUsername(), $this->ldap->getParameter('filteruser')); - $attributes = $this->ldap->listAttributesNiveau02(); + $attributes = $this->ldap->listAttributesUser(); $ldapentrys = $this->ldap->search($filter, $attributes, $this->ldap->getParameter('baseuser')); if (!empty($ldapentrys)) { $this->ldap->deleteUser($this->entity); diff --git a/src/Form/ConfigType.php b/src/Form/ConfigType.php index 562e553..5efad82 100644 --- a/src/Form/ConfigType.php +++ b/src/Form/ConfigType.php @@ -120,6 +120,7 @@ class ConfigType extends AbstractType 'NO_BODY' => 'NO_BODY', 'ROLE_USER' => 'ROLE_USER', 'ROLE_MASTER' => 'ROLE_MASTER', + 'ROLE_MANAGER' => 'ROLE_MANAGER', 'ROLE_MODO' => 'ROLE_MODO', ]; @@ -131,21 +132,6 @@ class ConfigType extends AbstractType 'choices' => $choices, ]); break; - case 'scopeannu': - $choices = [ - 'ALL' => 'ALL', - 'SAME_NIVEAU01' => 'SAME_NIVEAU01', - 'SAME_NIVEAU02' => 'SAME_NIVEAU02', - ]; - - $builder->add('value', ChoiceType::class, - ['label' => 'Valeur', - 'label_attr' => ['style' => 'margin-top:15px;'], - 'attr' => ['class' => 'form-control'], - 'required' => (0 == $options['required'] ? false : true), - 'choices' => $choices, ]); - break; - case 'logo': $builder->add('value', HiddenType::class); break; diff --git a/src/Form/Niveau03Type.php b/src/Form/Niveau03Type.php new file mode 100644 index 0000000..0b3d2f0 --- /dev/null +++ b/src/Form/Niveau03Type.php @@ -0,0 +1,94 @@ +add('submit', + SubmitType::class, [ + 'label' => 'Valider', + 'attr' => ['class' => 'btn btn-success'], + ] + ); + + $access = $options['access']; + $userid = $options['userid']; + $builder->add('niveau01', + EntityType::class, [ + 'class' => "App\Entity\Niveau01", + 'label' => $options['appNiveau01label'], + 'placeholder' => '== Choisir '.$options['appNiveau01label'].' ==', + 'choice_label' => 'label', + 'disabled' => ('submit' != $options['mode']), + 'query_builder' => function (EntityRepository $er) use ($access, $userid) { + switch ($access) { + case 'admin': + return $er->createQueryBuilder('niveau01')->orderBy('niveau01.label', 'ASC'); + break; + + case 'modo': + $result = $er->createQueryBuilder('table')->innerJoin('App:UserModo', 'usermodo', Join::WITH, 'table.id = usermodo.niveau01')->orderBy('table.label', 'ASC'); + $result->andWhere('usermodo.user = :user'); + $result->setParameter('user', $userid); + + return $result; + break; + } + }, + ] + ); + + $builder->add('niveau02', + Select2EntityType::class, [ + 'label' => $options['appNiveau02label'], + 'required' => true, + 'disabled' => ('submit' != $options['mode']), + 'remote_route' => 'app_niveau02_selectlist', + 'class' => "App\Entity\Niveau02", + // "req_params" => ["niveau01" => "parent.children[niveau01]"], + 'primary_key' => 'id', + 'text_property' => 'label', + 'minimum_input_length' => 0, + 'page_limit' => 10, + 'allow_clear' => true, + 'delay' => 250, + 'cache' => false, + 'cache_timeout' => 60000, + 'language' => 'fr', + 'placeholder' => '== Choisir '.$options['appNiveau02label'].' ==', + ] + ); + + $builder->add('label', + TextType::class, [ + 'label' => 'Label', + ] + ); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => 'App\Entity\Niveau03', + 'mode' => 'string', + 'access' => 'string', + 'userid' => 'string', + 'appMasteridentity' => 'string', + 'appNiveau01label' => 'string', + 'appNiveau02label' => 'string', + 'appNiveau03label' => 'string', + ]); + } +} diff --git a/src/Form/Niveau04Type.php b/src/Form/Niveau04Type.php new file mode 100644 index 0000000..970b27f --- /dev/null +++ b/src/Form/Niveau04Type.php @@ -0,0 +1,116 @@ +add('submit', + SubmitType::class, [ + 'label' => 'Valider', + 'attr' => ['class' => 'btn btn-success'], + ] + ); + + $access = $options['access']; + $userid = $options['userid']; + $builder->add('niveau01', + EntityType::class, [ + 'class' => "App\Entity\Niveau01", + 'label' => $options['appNiveau01label'], + 'placeholder' => '== Choisir '.$options['appNiveau01label'].' ==', + 'choice_label' => 'label', + 'disabled' => ('submit' != $options['mode']), + 'query_builder' => function (EntityRepository $er) use ($access, $userid) { + switch ($access) { + case 'admin': + return $er->createQueryBuilder('niveau01')->orderBy('niveau01.label', 'ASC'); + break; + + case 'modo': + $result = $er->createQueryBuilder('table')->innerJoin('App:UserModo', 'usermodo', Join::WITH, 'table.id = usermodo.niveau01')->orderBy('table.label', 'ASC'); + $result->andWhere('usermodo.user = :user'); + $result->setParameter('user', $userid); + + return $result; + break; + } + }, + ] + ); + + $builder->add('niveau02', + Select2EntityType::class, [ + 'label' => $options['appNiveau02label'], + 'required' => true, + 'disabled' => ('submit' != $options['mode']), + 'remote_route' => 'app_niveau02_selectlist', + 'class' => "App\Entity\Niveau02", + // "req_params" => ["niveau01" => "parent.children[niveau01]"], + 'primary_key' => 'id', + 'text_property' => 'label', + 'minimum_input_length' => 0, + 'page_limit' => 10, + 'allow_clear' => true, + 'delay' => 250, + 'cache' => false, + 'cache_timeout' => 60000, + 'language' => 'fr', + 'placeholder' => '== Choisir '.$options['appNiveau02label'].' ==', + ] + ); + + $builder->add('niveau03', + Select2EntityType::class, [ + 'label' => $options['appNiveau03label'], + 'required' => true, + 'disabled' => ('submit' != $options['mode']), + 'remote_route' => 'app_niveau03_selectlist', + 'class' => "App\Entity\Niveau03", + // "req_params" => ["niveau01" => "parent.children[niveau01]"], + 'primary_key' => 'id', + 'text_property' => 'label', + 'minimum_input_length' => 0, + 'page_limit' => 10, + 'allow_clear' => true, + 'delay' => 250, + 'cache' => false, + 'cache_timeout' => 60000, + 'language' => 'fr', + 'placeholder' => '== Choisir '.$options['appNiveau03label'].' ==', + ] + ); + + $builder->add('label', + TextType::class, [ + 'label' => 'Label', + ] + ); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => 'App\Entity\Niveau04', + 'mode' => 'string', + 'access' => 'string', + 'userid' => 'string', + 'appMasteridentity' => 'string', + 'appNiveau01label' => 'string', + 'appNiveau02label' => 'string', + 'appNiveau03label' => 'string', + 'appNiveau04label' => 'string', + ]); + } +} diff --git a/src/Form/RegistrationType.php b/src/Form/RegistrationType.php index adda64b..788bbe4 100644 --- a/src/Form/RegistrationType.php +++ b/src/Form/RegistrationType.php @@ -106,26 +106,68 @@ class RegistrationType extends AbstractType }, ] ); + if ($options['appNiveau02use']) { + $builder->add('niveau02', + Select2EntityType::class, [ + 'label' => $options['appNiveau02label'], + 'required' => false, + 'remote_route' => 'app_niveau02_selectlist', + 'class' => "App\Entity\Niveau02", + 'primary_key' => 'id', + 'text_property' => 'label', + 'minimum_input_length' => 0, + 'page_limit' => 10, + 'allow_clear' => true, + 'delay' => 250, + 'cache' => false, + 'cache_timeout' => 60000, + 'language' => 'fr', + 'placeholder' => '== Choisir '.$options['appNiveau02label'].' ==', + ] + ); + } - $builder->add('niveau02', - Select2EntityType::class, [ - 'label' => $options['appNiveau02label'], - 'required' => false, - 'remote_route' => 'app_niveau02_selectlist', - 'class' => "App\Entity\Niveau02", - // "req_params" => ["niveau01" => "parent.children[niveau01]"], - 'primary_key' => 'id', - 'text_property' => 'label', - 'minimum_input_length' => 0, - 'page_limit' => 10, - 'allow_clear' => true, - 'delay' => 250, - 'cache' => false, - 'cache_timeout' => 60000, - 'language' => 'fr', - 'placeholder' => '== Choisir '.$options['appNiveau02label'].' ==', - ] - ); + if ($options['appNiveau03use']) { + $builder->add('niveau03', + Select2EntityType::class, [ + 'label' => $options['appNiveau03label'], + 'required' => false, + 'remote_route' => 'app_niveau03_selectlist', + 'class' => "App\Entity\Niveau03", + 'primary_key' => 'id', + 'text_property' => 'label', + 'minimum_input_length' => 0, + 'page_limit' => 10, + 'allow_clear' => true, + 'delay' => 250, + 'cache' => false, + 'cache_timeout' => 60000, + 'language' => 'fr', + 'placeholder' => '== Choisir '.$options['appNiveau03label'].' ==', + ] + ); + } + + if ($options['appNiveau04use']) { + $builder->add('niveau04', + Select2EntityType::class, [ + 'label' => $options['appNiveau04label'], + 'required' => false, + 'remote_route' => 'app_niveau04_selectlist', + 'class' => "App\Entity\Niveau04", + 'primary_key' => 'id', + 'text_property' => 'label', + 'minimum_input_length' => 0, + 'page_limit' => 10, + 'allow_clear' => true, + 'delay' => 250, + 'cache' => false, + 'cache_timeout' => 60000, + 'language' => 'fr', + 'placeholder' => '== Choisir '.$options['appNiveau04label'].' ==', + ] + ); + } // Password if ('submit' == $options['mode']) { @@ -204,7 +246,12 @@ class RegistrationType extends AbstractType 'userid' => 'string', 'appMasteridentity' => 'string', 'appNiveau01label' => 'string', + 'appNiveau02use' => 'string', 'appNiveau02label' => 'string', + 'appNiveau03use' => 'string', + 'appNiveau03label' => 'string', + 'appNiveau04use' => 'string', + 'appNiveau04label' => 'string', ]); } } diff --git a/src/Form/UserType.php b/src/Form/UserType.php index 3b32ffa..2a79290 100644 --- a/src/Form/UserType.php +++ b/src/Form/UserType.php @@ -82,7 +82,7 @@ class UserType extends AbstractType 'label' => $options['appNiveau01label'], 'placeholder' => '== Choisir '.$options['appNiveau01label'].' ==', 'choice_label' => 'label', - 'disabled' => ('SQL' != $options['appMasteridentity'] && 'submit' != $options['mode']), + 'disabled' => (('SQL' != $options['appMasteridentity'] && 'submit' != $options['mode']) || ('admin' != $access && 'modo' != $access && $options['appNiveauupdatable'] > 1)), 'query_builder' => function (EntityRepository $er) use ($access, $userid) { switch ($access) { case 'admin': @@ -105,25 +105,71 @@ class UserType extends AbstractType ] ); - $builder->add('niveau02', - Select2EntityType::class, [ - 'label' => $options['appNiveau02label'], - 'required' => false, - 'remote_route' => 'app_niveau02_selectlist', - 'class' => "App\Entity\Niveau02", - // "req_params" => ["niveau01" => "parent.children[niveau01]"], - 'primary_key' => 'id', - 'text_property' => 'label', - 'minimum_input_length' => 0, - 'page_limit' => 10, - 'allow_clear' => true, - 'delay' => 250, - 'cache' => false, - 'cache_timeout' => 60000, - 'language' => 'fr', - 'placeholder' => '== Choisir '.$options['appNiveau02label'].' ==', - ] - ); + if ($options['appNiveau02use']) { + $builder->add('niveau02', + Select2EntityType::class, [ + 'label' => $options['appNiveau02label'], + 'required' => false, + 'disabled' => ('admin' != $access && 'modo' != $access && $options['appNiveauupdatable'] > 2), + 'remote_route' => 'app_niveau02_selectlist', + 'class' => "App\Entity\Niveau02", + 'primary_key' => 'id', + 'text_property' => 'label', + 'minimum_input_length' => 0, + 'page_limit' => 10, + 'allow_clear' => true, + 'delay' => 250, + 'cache' => false, + 'cache_timeout' => 60000, + 'language' => 'fr', + 'placeholder' => '== Choisir '.$options['appNiveau02label'].' ==', + ] + ); + } + + if ($options['appNiveau03use']) { + $builder->add('niveau03', + Select2EntityType::class, [ + 'label' => $options['appNiveau03label'], + 'required' => false, + 'disabled' => ('admin' != $access && 'modo' != $access && $options['appNiveauupdatable'] > 3), + 'remote_route' => 'app_niveau03_selectlist', + 'class' => "App\Entity\Niveau03", + 'primary_key' => 'id', + 'text_property' => 'label', + 'minimum_input_length' => 0, + 'page_limit' => 10, + 'allow_clear' => true, + 'delay' => 250, + 'cache' => false, + 'cache_timeout' => 60000, + 'language' => 'fr', + 'placeholder' => '== Choisir '.$options['appNiveau03label'].' ==', + ] + ); + } + + if ($options['appNiveau04use']) { + $builder->add('niveau04', + Select2EntityType::class, [ + 'label' => $options['appNiveau04label'], + 'required' => false, + 'disabled' => ('admin' != $access && 'modo' != $access && $options['appNiveauupdatable'] > 4), + 'remote_route' => 'app_niveau04_selectlist', + 'class' => "App\Entity\Niveau04", + 'primary_key' => 'id', + 'text_property' => 'label', + 'minimum_input_length' => 0, + 'page_limit' => 10, + 'allow_clear' => true, + 'delay' => 250, + 'cache' => false, + 'cache_timeout' => 60000, + 'language' => 'fr', + 'placeholder' => '== Choisir '.$options['appNiveau04label'].' ==', + ] + ); + } $choices = ['oui' => '1', 'non' => '0']; $builder->add('isvisible', @@ -192,7 +238,7 @@ class UserType extends AbstractType $builder->add('linkmodos', HiddenType::class, ['mapped' => false]); if ('admin' == $options['access'] || 'modo' == $options['access']) { - $choices = ['ROLE_ADMIN' => 'ROLE_ADMIN', 'ROLE_MODO' => 'ROLE_MODO', 'ROLE_MASTER' => 'ROLE_MASTER', 'ROLE_USER' => 'ROLE_USER']; + $choices = ['ROLE_ADMIN' => 'ROLE_ADMIN', 'ROLE_MODO' => 'ROLE_MODO', 'ROLE_MASTER' => 'ROLE_MASTER', 'ROLE_MANAGER' => 'ROLE_MANAGER', 'ROLE_USER' => 'ROLE_USER']; $builder->add('roles', ChoiceType::class, [ 'label' => 'Rôle', @@ -222,7 +268,13 @@ class UserType extends AbstractType 'userid' => 'string', 'appMasteridentity' => 'string', 'appNiveau01label' => 'string', + 'appNiveau02use' => 'string', 'appNiveau02label' => 'string', + 'appNiveau03use' => 'string', + 'appNiveau03label' => 'string', + 'appNiveau04use' => 'string', + 'appNiveau04label' => 'string', + 'appNiveauupdatable' => 'string', ]); } } diff --git a/src/Repository/Niveau03Repository.php b/src/Repository/Niveau03Repository.php new file mode 100644 index 0000000..277b5db --- /dev/null +++ b/src/Repository/Niveau03Repository.php @@ -0,0 +1,33 @@ +getEntityManager()->persist($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } + } + + public function remove(Niveau03 $entity, bool $flush = false): void + { + $this->getEntityManager()->remove($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } + } +} diff --git a/src/Repository/Niveau04Repository.php b/src/Repository/Niveau04Repository.php new file mode 100644 index 0000000..dfdb762 --- /dev/null +++ b/src/Repository/Niveau04Repository.php @@ -0,0 +1,33 @@ +getEntityManager()->persist($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } + } + + public function remove(Niveau04 $entity, bool $flush = false): void + { + $this->getEntityManager()->remove($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } + } +} diff --git a/src/Service/AppSession.php b/src/Service/AppSession.php index 900c2bc..aeea678 100644 --- a/src/Service/AppSession.php +++ b/src/Service/AppSession.php @@ -2,165 +2,168 @@ namespace App\Service; - use Doctrine\ORM\EntityManagerInterface; - use Symfony\Component\DependencyInjection\ContainerInterface; - use Symfony\Component\HttpFoundation\RequestStack; - use Symfony\Component\HttpKernel\Event\RequestEvent; - use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; +use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; - class AppSession +class AppSession +{ + private $container; + protected $em; + protected $requeststack; + protected $token; + + public function __construct(ContainerInterface $container, EntityManagerInterface $em, RequestStack $requeststack, TokenStorageInterface $token) { - private $container; - protected $em; - protected $requeststack; - protected $token; + $this->container = $container; + $this->requeststack = $requeststack; + $this->em = $em; + $this->token = $token; + } - public function __construct(ContainerInterface $container, EntityManagerInterface $em, RequestStack $requeststack, TokenStorageInterface $token) - { - $this->container = $container; - $this->requeststack = $requeststack; - $this->em = $em; - $this->token = $token; + public function onDomainParse(RequestEvent $event) + { + $session = $this->requeststack->getSession(); + + $configs = $this->em->getRepository("App\Entity\Config")->findAll(); + foreach ($configs as $config) { + $session->set($config->getId(), strval($config->getValue())); + } + $session->set('headerimage', 'header/'.$session->get('headerimage')); + + // Calcul couleur + $session->set('colorbgbodylight-darker', $this->adjustBrightness($session->get('colorbgbodylight'), -10)); + $session->set('colorfttitlelight-darker', $this->adjustBrightness($session->get('colorfttitlelight'), -50)); + + $session->set('colorbgbodydark-darker', $this->adjustBrightness($session->get('colorbgbodydark'), -50)); + $session->set('colorbgbodydark-lighter', $this->adjustBrightness($session->get('colorbgbodydark'), +50)); + + $session->set('colorbgbodydark-rgb', $this->hexToRgb($session->get('colorbgbodydark'))); + $session->set('colorbgbodydark-darkrgb', $this->hexToRgb($session->get('colorbgbodydark-darker'))); + $session->set('colorbgbodydark-lightrgb', $this->hexToRgb($session->get('colorbgbodydark-lighter'))); + + // Current user + $token = $this->token->getToken(); + if (!$token) { + return; + } + $curentuser = $token->getUser(); + + // Préférence par défaut + $session->set('fgheader', true); + $session->set('fgaudit', false); + + // Préférence + if ('anon.' != $curentuser) { + $preference = $curentuser->getPreference(); + if (is_array($preference)) { + // Préférence header + if (array_key_exists('fgheader', $preference)) { + $fgheader = ('true' == $preference['fgheader'][0]); + $session->set('fgheader', $fgheader); + } + + // Préférence audit + if (array_key_exists('fgaudit', $preference)) { + $fgaudit = ('true' == $preference['fgaudit'][0]); + $session->set('fgaudit', $fgaudit); + } + } } - public function onDomainParse(RequestEvent $event) - { - $session = $this->requeststack->getSession(); - - $configs = $this->em->getRepository("App\Entity\Config")->findAll(); - foreach ($configs as $config) { - $session->set($config->getId(), strval($config->getValue())); - } - $session->set('headerimage', 'header/'.$session->get('headerimage')); - - // Calcul couleur - $session->set('colorbgbodylight-darker', $this->adjustBrightness($session->get('colorbgbodylight'), -10)); - $session->set('colorfttitlelight-darker', $this->adjustBrightness($session->get('colorfttitlelight'), -50)); - - $session->set('colorbgbodydark-darker', $this->adjustBrightness($session->get('colorbgbodydark'), -50)); - $session->set('colorbgbodydark-lighter', $this->adjustBrightness($session->get('colorbgbodydark'), +50)); - - $session->set('colorbgbodydark-rgb', $this->hexToRgb($session->get('colorbgbodydark'))); - $session->set('colorbgbodydark-darkrgb', $this->hexToRgb($session->get('colorbgbodydark-darker'))); - $session->set('colorbgbodydark-lightrgb', $this->hexToRgb($session->get('colorbgbodydark-lighter'))); - - // Current user - $token = $this->token->getToken(); - if (!$token) { - return; - } - $curentuser = $token->getUser(); - - // Préférence par défaut - $session->set('fgheader', true); - $session->set('fgaudit', false); - - // Préférence - if ('anon.' != $curentuser) { - $preference = $curentuser->getPreference(); - if (is_array($preference)) { - // Préférence header - if (array_key_exists('fgheader', $preference)) { - $fgheader = ('true' == $preference['fgheader'][0]); - $session->set('fgheader', $fgheader); - } - - // Préférence audit - if (array_key_exists('fgaudit', $preference)) { - $fgaudit = ('true' == $preference['fgaudit'][0]); - $session->set('fgaudit', $fgaudit); - } - } + // Permissions + $showannuaire = false; + $submitgroup = false; + if ('anon.' != $curentuser) { + if ($curentuser->hasRole('ROLE_ADMIN') && null != $this->container->getParameter('appAnnuscopeadmin')) { + $showannuaire = true; + $session->set('scopeannu', $this->container->getParameter('appAnnuscopeadmin')); + } elseif ($curentuser->hasRole('ROLE_MODO') && null != $this->container->getParameter('appAnnuscopemodo')) { + $showannuaire = true; + $session->set('scopeannu', $this->container->getParameter('appAnnuscopemodo')); + } elseif ($curentuser->hasRole('ROLE_MASTER') && null != $this->container->getParameter('appAnnuscopemaster')) { + $showannuaire = true; + $session->set('scopeannu', $this->container->getParameter('appAnnuscopemaster')); + } elseif ($curentuser->hasRole('ROLE_MANAGER') && null != $this->container->getParameter('appAnnuscopemanager')) { + $showannuaire = true; + $session->set('scopeannu', $this->container->getParameter('appAnnuscopemanager')); + } elseif ($curentuser->hasRole('ROLE_USER') && null != $this->container->getParameter('appAnnuscopeuser')) { + $showannuaire = true; + $session->set('scopeannu', $this->container->getParameter('appAnnuscopeuser')); } - // Permissions - $showannuaire = false; - $submitgroup = false; - if ('anon.' != $curentuser) { - switch ($session->get('permannu')) { - case 'ROLE_USER': - $showannuaire = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO') || $curentuser->hasRole('ROLE_MASTER') || $curentuser->hasRole('ROLE_USER')); - break; - - case 'ROLE_MASTER': - $showannuaire = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO') || $curentuser->hasRole('ROLE_MASTER')); - break; - - case 'ROLE_MODO': - $showannuaire = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO')); - break; - } - - switch ($session->get('permgroup')) { - case 'ROLE_USER': - $submitgroup = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO') || $curentuser->hasRole('ROLE_MASTER') || $curentuser->hasRole('ROLE_USER')); - break; - - case 'ROLE_MASTER': - $submitgroup = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO') || $curentuser->hasRole('ROLE_MASTER')); - break; - - case 'ROLE_MODO': - $submitgroup = ($curentuser->hasRole('ROLE_ADMIN') || $curentuser->hasRole('ROLE_MODO')); - break; - } + if (in_array('ALL', $this->container->getParameter('appGroupsubmiter'))) { + $submitgroup = true; + } elseif ($curentuser->hasRole('ROLE_ADMIN') && in_array('ROLE_ADMIN', $this->container->getParameter('appGroupsubmiter'))) { + $submitgroup = true; + } elseif ($curentuser->hasRole('ROLE_MODO') && in_array('ROLE_MODO', $this->container->getParameter('appGroupsubmiter'))) { + $submitgroup = true; + } elseif ($curentuser->hasRole('ROLE_MASTER') && in_array('ROLE_MASTER', $this->container->getParameter('appGroupsubmiter'))) { + $submitgroup = true; + } elseif ($curentuser->hasRole('ROLE_MANAGER') && in_array('ROLE_MANAGER', $this->container->getParameter('appGroupsubmiter'))) { + $submitgroup = true; + } elseif ($curentuser->hasRole('ROLE_USER') && in_array('ROLE_USER', $this->container->getParameter('appGroupsubmiter'))) { + $submitgroup = true; } - $session->set('showannuaire', $showannuaire); - $session->set('submitgroup', $submitgroup); + } + $session->set('showannuaire', $showannuaire); + $session->set('submitgroup', $submitgroup); - // Visite - if ('anon.' != $curentuser) { - $now = new \DateTime(); - if (!$curentuser->getVisitedate()) { + // Visite + if ('anon.' != $curentuser) { + $now = new \DateTime(); + if (!$curentuser->getVisitedate()) { + $curentuser->setVisitedate($now); + $curentuser->setVisitecpt($curentuser->getVisitecpt() + 1); + $this->em->persist($curentuser); + $this->em->flush(); + } else { + $visitedate = clone $curentuser->getVisitedate(); + $visitedate->add(new \DateInterval('PT1H')); + if ($visitedate < $now) { $curentuser->setVisitedate($now); $curentuser->setVisitecpt($curentuser->getVisitecpt() + 1); $this->em->persist($curentuser); $this->em->flush(); - } else { - $visitedate = clone $curentuser->getVisitedate(); - $visitedate->add(new \DateInterval('PT1H')); - if ($visitedate < $now) { - $curentuser->setVisitedate($now); - $curentuser->setVisitecpt($curentuser->getVisitecpt() + 1); - $this->em->persist($curentuser); - $this->em->flush(); - } } } } - - private function adjustBrightness($hex, $steps) - { - // Steps should be between -255 and 255. Negative = darker, positive = lighter - $steps = max(-255, min(255, $steps)); - - // Normalize into a six character long hex string - $hex = str_replace('#', '', $hex); - if (3 == strlen($hex)) { - $hex = str_repeat(substr($hex, 0, 1), 2).str_repeat(substr($hex, 1, 1), 2).str_repeat(substr($hex, 2, 1), 2); - } - - // Split into three parts: R, G and B - $color_parts = str_split($hex, 2); - $return = ''; - - foreach ($color_parts as $color) { - $color = hexdec($color); // Convert to decimal - $color = max(0, min(255, $color + $steps)); // Adjust color - $return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT); // Make two char hex code - } - - return '#'.$return; - } - - public function hexToRgb($hex) - { - $hex = str_replace('#', '', $hex); - $length = strlen($hex); - $rgb['r'] = hexdec(6 == $length ? substr($hex, 0, 2) : (3 == $length ? str_repeat(substr($hex, 0, 1), 2) : 0)); - $rgb['g'] = hexdec(6 == $length ? substr($hex, 2, 2) : (3 == $length ? str_repeat(substr($hex, 1, 1), 2) : 0)); - $rgb['b'] = hexdec(6 == $length ? substr($hex, 4, 2) : (3 == $length ? str_repeat(substr($hex, 2, 1), 2) : 0)); - - return $rgb['r'].','.$rgb['g'].','.$rgb['b']; - } } + + private function adjustBrightness($hex, $steps) + { + // Steps should be between -255 and 255. Negative = darker, positive = lighter + $steps = max(-255, min(255, $steps)); + + // Normalize into a six character long hex string + $hex = str_replace('#', '', $hex); + if (3 == strlen($hex)) { + $hex = str_repeat(substr($hex, 0, 1), 2).str_repeat(substr($hex, 1, 1), 2).str_repeat(substr($hex, 2, 1), 2); + } + + // Split into three parts: R, G and B + $color_parts = str_split($hex, 2); + $return = ''; + + foreach ($color_parts as $color) { + $color = hexdec($color); // Convert to decimal + $color = max(0, min(255, $color + $steps)); // Adjust color + $return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT); // Make two char hex code + } + + return '#'.$return; + } + + public function hexToRgb($hex) + { + $hex = str_replace('#', '', $hex); + $length = strlen($hex); + $rgb['r'] = hexdec(6 == $length ? substr($hex, 0, 2) : (3 == $length ? str_repeat(substr($hex, 0, 1), 2) : 0)); + $rgb['g'] = hexdec(6 == $length ? substr($hex, 2, 2) : (3 == $length ? str_repeat(substr($hex, 1, 1), 2) : 0)); + $rgb['b'] = hexdec(6 == $length ? substr($hex, 4, 2) : (3 == $length ? str_repeat(substr($hex, 2, 1), 2) : 0)); + + return $rgb['r'].','.$rgb['g'].','.$rgb['b']; + } +} diff --git a/src/Service/LdapService.php b/src/Service/LdapService.php index 580f719..f39be35 100644 --- a/src/Service/LdapService.php +++ b/src/Service/LdapService.php @@ -5,6 +5,8 @@ namespace App\Service; use App\Entity\Group; use App\Entity\Niveau01; use App\Entity\Niveau02; +use App\Entity\Niveau03; +use App\Entity\Niveau04; use App\Entity\User; use App\Entity\UserGroup; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -23,6 +25,8 @@ class LdapService private $baseorganisation; private $baseniveau01; private $baseniveau02; + private $baseniveau03; + private $baseniveau04; private $basegroup; private $baseuser; private $username; @@ -55,6 +59,8 @@ class LdapService $this->baseorganisation = $container->getParameter('ldapBaseorganisation'); $this->baseniveau01 = $container->getParameter('ldapBaseniveau01'); $this->baseniveau02 = $container->getParameter('ldapBaseniveau02'); + $this->baseniveau03 = $container->getParameter('ldapBaseniveau03'); + $this->baseniveau04 = $container->getParameter('ldapBaseniveau04'); $this->basegroup = $container->getParameter('ldapBasegroup'); $this->baseuser = $container->getParameter('ldapBaseuser'); $this->username = $container->getParameter('ldapUsername'); @@ -75,7 +81,7 @@ class LdapService public function isNine2Ldap() { - return 'SQL' == $this->appMasteridentity && 'NINE2LDAP' == $this->synchro && $this->userwriter && $this->baseorganisation && $this->baseniveau01 && $this->baseniveau02 && $this->basegroup && $this->baseuser && $this->connect(); + return ('SQL' == $this->appMasteridentity) && 'NINE2LDAP' == $this->synchro && $this->userwriter && $this->baseorganisation && $this->baseniveau01 && $this->baseniveau02 && $this->baseniveau03 && $this->baseniveau04 && $this->basegroup && $this->baseuser && $this->connect(); } public function connect() @@ -91,7 +97,6 @@ class LdapService return $this->connection; } else { $ldapConn = ldap_connect($this->host, $this->port); - if ($ldapConn) { ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ldapConn, LDAP_OPT_REFERRALS, 0); @@ -146,6 +151,10 @@ class LdapService break; case 'baseniveau02': return $this->baseniveau02; break; + case 'baseniveau03': return $this->baseniveau03; + break; + case 'baseniveau04': return $this->baseniveau04; + break; case 'basedn': return $this->basedn; break; case 'filteruser': return $this->filteruser; @@ -279,6 +288,16 @@ class LdapService $this->addOrganisation($this->baseniveau02); } + $ldapentrys = $this->searchdn($this->baseniveau03, $this->baseorganisation); + if (empty($ldapentrys)) { + $this->addOrganisation($this->baseniveau03); + } + + $ldapentrys = $this->searchdn($this->baseniveau04, $this->baseorganisation); + if (empty($ldapentrys)) { + $this->addOrganisation($this->baseniveau04); + } + $ldapentrys = $this->searchdn($this->basegroup, $this->baseorganisation); if (empty($ldapentrys)) { $this->addOrganisation($this->basegroup); @@ -482,6 +501,78 @@ class LdapService } } + // NIVEAU03 + // On recherche le Niveau03 actuellement asscocié à l'utilisateur + $criteria = '(&(cn=*)(memberUid='.$user->getUsername().'))'; + $subbranch = $this->baseniveau03; + $results = $this->search($criteria, ['cn'], $subbranch); + foreach ($results as $result) { + // Si Niveau03 différent de celui en cours on le détache de ce Niveau03 + if (null === $user->getNiveau03() || $result['cn'] != $user->getNiveau03()->getLabel() || $todel) { + $dn = $this->getNiveau03DN($result['cn']); + $entry['memberuid'] = $user->getUsername(); + $result = ldap_mod_del($connection, $dn, $entry); + if (!$result) { + $this->ldapError(); + } + } + } + + // On recherche le Niveau03 en cours + if (!$todel) { + if (null !== $user->getNiveau03()) { + $criteria = '(cn='.$user->getNiveau03()->getLabel().')'; + $subbranch = $this->baseniveau03; + $result = $this->search($criteria, ['memberuid'], $subbranch); + + // S'il n'est pas membre du Niveau03 on le rattache + if (empty($result) || !$this->in_array_r($user->getUsername(), $result[0])) { + $dn = $this->getNiveau03DN($user->getNiveau03()->getLabel()); + $entry['memberuid'] = $user->getUsername(); + $result = ldap_mod_add($connection, $dn, $entry); + if (!$result) { + $this->ldapError(); + } + } + } + } + + // NIVEAU04 + // On recherche le Niveau04 actuellement asscocié à l'utilisateur + $criteria = '(&(cn=*)(memberUid='.$user->getUsername().'))'; + $subbranch = $this->baseniveau04; + $results = $this->search($criteria, ['cn'], $subbranch); + foreach ($results as $result) { + // Si Niveau04 différent de celui en cours on le détache de ce Niveau04 + if (null === $user->getNiveau04() || $result['cn'] != $user->getNiveau04()->getLabel() || $todel) { + $dn = $this->getNiveau04DN($result['cn']); + $entry['memberuid'] = $user->getUsername(); + $result = ldap_mod_del($connection, $dn, $entry); + if (!$result) { + $this->ldapError(); + } + } + } + + // On recherche le Niveau04 en cours + if (!$todel) { + if (null !== $user->getNiveau04()) { + $criteria = '(cn='.$user->getNiveau04()->getLabel().')'; + $subbranch = $this->baseniveau04; + $result = $this->search($criteria, ['memberuid'], $subbranch); + + // S'il n'est pas membre du Niveau04 on le rattache + if (empty($result) || !$this->in_array_r($user->getUsername(), $result[0])) { + $dn = $this->getNiveau04DN($user->getNiveau04()->getLabel()); + $entry['memberuid'] = $user->getUsername(); + $result = ldap_mod_add($connection, $dn, $entry); + if (!$result) { + $this->ldapError(); + } + } + } + } + return $result; } @@ -816,6 +907,262 @@ class LdapService return 'cn='.$id.','.$this->baseniveau02; } + // ================================================================================================================================================================== + // == Function Niveau03============================================================================================================================================== + // ================================================================================================================================================================== + + public function addNiveau03(Niveau03 $niveau03) + { + $connection = $this->connect(); + $dn = $this->getNiveau03DN($niveau03->getLabel()); + + $attrs = []; + $attrs['objectclass'] = $this->getObjectClassesNiveau03(); + $this->fillAttributesNiveau03($niveau03, $attrs); + + foreach ($attrs as $key => $value) { + if (empty($value)) { + unset($attrs[$key]); + } + } + + $result = ldap_add($connection, $dn, $attrs); + if (!$result) { + $this->ldapError(); + } + + return $result; + } + + public function ismodifyNiveau03(Niveau03 $niveau03, $entry) + { + $attrs = []; + $this->fillAttributesNiveau03($niveau03, $attrs); + + foreach ($attrs as $key => $value) { + if (!array_key_exists($key, $entry) && !empty($value)) { + return true; + } elseif (array_key_exists($key, $entry) && $value != $entry[$key]) { + return true; + } + } + + foreach ($entry as $key => $value) { + if (!array_key_exists($key, $attrs) && !empty($value)) { + return true; + } elseif (array_key_exists($key, $attrs) && $value != $attrs[$key]) { + return true; + } + } + + return false; + } + + public function modifyNiveau03(Niveau03 $niveau03, $oldid) + { + $dn = $this->basedn; + $connection = $this->connect(); + + $attrs = []; + $this->fillAttributesNiveau03($niveau03, $attrs); + unset($attrs['cn']); + + $dn = $this->getNiveau03DN($niveau03->getLabel()); + + foreach ($attrs as $key => $value) { + if (empty($value)) { + // Bien mettre un @ car si l'attribut est déjà vide cela crache une erreur car l'attribut n'existe déjà plus + @ldap_mod_del($connection, $dn, [$key => []]); + unset($attrs[$key]); + } + } + + if (isset($oldid) && $oldid != $niveau03->getLabel()) { + $olddn = $this->getNiveau03DN($oldid); + $this->rename($olddn, 'cn='.$niveau03->getLabel(), $this->baseniveau03); + } + + $result = ldap_modify($connection, $dn, $attrs); + if (!$result) { + $this->ldapError(); + } + } + + public function deleteNiveau03(Niveau03 $niveau03) + { + $dn = $this->getNiveau03DN($niveau03->getLabel()); + + return $this->deleteByDN($dn); + } + + private function getObjectClassesNiveau03() + { + $oc = [ + 'top', + 'posixGroup', + ]; + + return $oc; + } + + public function listAttributesNiveau03() + { + return [ + 'cn', + 'gidnumber', + 'memberuid', + ]; + } + + public function fillAttributesNiveau03(Niveau03 $niveau03, array &$attrs) + { + $attrs['cn'] = $niveau03->getLabel(); + $attrs['gidnumber'] = $niveau03->getId(); + + $attrs['memberuid'] = []; + foreach ($niveau03->getUsers() as $user) { + array_push($attrs['memberuid'], $user->getUsername()); + } + + sort($attrs['memberuid']); + if (1 == count($attrs['memberuid'])) { + $attrs['memberuid'] = $attrs['memberuid'][0]; + } + } + + public function getNiveau03DN($id) + { + return 'cn='.$id.','.$this->baseniveau03; + } + + // ================================================================================================================================================================== + // == Function Niveau04============================================================================================================================================== + // ================================================================================================================================================================== + + public function addNiveau04(Niveau04 $niveau04) + { + $connection = $this->connect(); + $dn = $this->getNiveau04DN($niveau04->getLabel()); + + $attrs = []; + $attrs['objectclass'] = $this->getObjectClassesNiveau04(); + $this->fillAttributesNiveau04($niveau04, $attrs); + + foreach ($attrs as $key => $value) { + if (empty($value)) { + unset($attrs[$key]); + } + } + + $result = ldap_add($connection, $dn, $attrs); + if (!$result) { + $this->ldapError(); + } + + return $result; + } + + public function ismodifyNiveau04(Niveau04 $niveau04, $entry) + { + $attrs = []; + $this->fillAttributesNiveau04($niveau04, $attrs); + + foreach ($attrs as $key => $value) { + if (!array_key_exists($key, $entry) && !empty($value)) { + return true; + } elseif (array_key_exists($key, $entry) && $value != $entry[$key]) { + return true; + } + } + + foreach ($entry as $key => $value) { + if (!array_key_exists($key, $attrs) && !empty($value)) { + return true; + } elseif (array_key_exists($key, $attrs) && $value != $attrs[$key]) { + return true; + } + } + + return false; + } + + public function modifyNiveau04(Niveau04 $niveau04, $oldid) + { + $dn = $this->basedn; + $connection = $this->connect(); + + $attrs = []; + $this->fillAttributesNiveau04($niveau04, $attrs); + unset($attrs['cn']); + + $dn = $this->getNiveau04DN($niveau04->getLabel()); + + foreach ($attrs as $key => $value) { + if (empty($value)) { + // Bien mettre un @ car si l'attribut est déjà vide cela crache une erreur car l'attribut n'existe déjà plus + @ldap_mod_del($connection, $dn, [$key => []]); + unset($attrs[$key]); + } + } + + if (isset($oldid) && $oldid != $niveau04->getLabel()) { + $olddn = $this->getNiveau04DN($oldid); + $this->rename($olddn, 'cn='.$niveau04->getLabel(), $this->baseniveau04); + } + + $result = ldap_modify($connection, $dn, $attrs); + if (!$result) { + $this->ldapError(); + } + } + + public function deleteNiveau04(Niveau04 $niveau04) + { + $dn = $this->getNiveau04DN($niveau04->getLabel()); + + return $this->deleteByDN($dn); + } + + private function getObjectClassesNiveau04() + { + $oc = [ + 'top', + 'posixGroup', + ]; + + return $oc; + } + + public function listAttributesNiveau04() + { + return [ + 'cn', + 'gidnumber', + 'memberuid', + ]; + } + + public function fillAttributesNiveau04(Niveau04 $niveau04, array &$attrs) + { + $attrs['cn'] = $niveau04->getLabel(); + $attrs['gidnumber'] = $niveau04->getId(); + + $attrs['memberuid'] = []; + foreach ($niveau04->getUsers() as $user) { + array_push($attrs['memberuid'], $user->getUsername()); + } + + sort($attrs['memberuid']); + if (1 == count($attrs['memberuid'])) { + $attrs['memberuid'] = $attrs['memberuid'][0]; + } + } + + public function getNiveau04DN($id) + { + return 'cn='.$id.','.$this->baseniveau04; + } + // ================================================================================================================================================================== // == Function Group================================================================================================================================================= // ================================================================================================================================================================== diff --git a/templates/Include/sidebaradmin.html.twig b/templates/Include/sidebaradmin.html.twig index bd3ab0e..bbddea2 100644 --- a/templates/Include/sidebaradmin.html.twig +++ b/templates/Include/sidebaradmin.html.twig @@ -25,12 +25,22 @@ { icon: 'fa fa-building', route: 'app_admin_niveau01', - name: appNiveau01label~'s', + name: appNiveau01labels, }, { icon: 'fa fa-sitemap', route: 'app_admin_niveau02', - name: appNiveau02label~'s', + name: appNiveau02labels, + }, + { + icon: 'fas fa-store-alt', + route: 'app_admin_niveau03', + name: appNiveau03labels, + }, + { + icon: 'fas fa-monument', + route: 'app_admin_niveau04', + name: appNiveau04labels, }, { icon: 'fa fa-users', @@ -75,7 +85,6 @@ ] %} -