Ver Fonte

v8-4454 after tests fixes 2

Olivier Massot há 2 anos atrás
pai
commit
3d3aaf2e8e

+ 78 - 0
config/opentalent/modulesbyconditions.yaml

@@ -1,5 +1,20 @@
 opentalent:
     modulesbyconditions:
+        ConsultOwnPedagogicResult:
+            conditions:
+                service:
+                    name: App\Service\Education\Utils
+                    function: isConsultOwnPedagogicResult
+        TeacherContactList:
+            conditions:
+                service:
+                    name: App\Service\Education\Utils
+                    function: isConsultTeacherListing
+        PeriodValidation:
+            conditions:
+                service:
+                    name: App\Service\Education\Utils
+                    function: isPeriodValidation
         CotisationCall:
             roles:
                 - ROLE_COTISATION
@@ -59,6 +74,13 @@ opentalent:
                 service:
                     name: App\Service\Cotisation\Utils
                     function: isManagerAndCMF
+        Statistic:
+            roles:
+                - ROLE_STATISTIC
+            conditions:
+                service:
+                    name: App\Service\Cotisation\Utils
+                    function: isStructure
         Network:
             conditions:
                 service:
@@ -74,3 +96,59 @@ opentalent:
                 service:
                     name: App\Service\Network\Utils
                     function: isCMF
+        Pes:
+            conditions:
+                service:
+                    name: App\Service\Organization\Utils
+                    function: hasModule
+                    args:
+                        - 'Pes'
+        BergerLevrault:
+            conditions:
+                service:
+                    name: App\Service\Organization\Utils
+                    function: hasModule
+                    args:
+                        - 'BergerLevrault'
+        Jvs:
+            conditions:
+                service:
+                    name: App\Service\Organization\Utils
+                    function: hasModule
+                    args:
+                        - 'Jvs'
+        SddBank:
+            conditions:
+                service:
+                    name: App\Service\Organization\Utils
+                    function: hasModule
+                    args:
+                        - 'SddBank'
+        SddRegie:
+            conditions:
+                service:
+                    name: App\Service\Organization\Utils
+                    function: hasModule
+                    args:
+                        - 'SddRegie'
+        UnpaidPes:
+            conditions:
+                service:
+                    name: App\Service\Organization\Utils
+                    function: hasModule
+                    args:
+                        - 'UnpaidPes'
+        UnpaidBergerLevrault:
+            conditions:
+                service:
+                    name: App\Service\Organization\Utils
+                    function: hasModule
+                    args:
+                        - 'UnpaidBergerLevrault'
+        UnpaidJvs:
+            conditions:
+                service:
+                    name: App\Service\Organization\Utils
+                    function: hasModule
+                    args:
+                        - 'UnpaidJvs'

+ 3 - 0
config/services.yaml

@@ -37,6 +37,9 @@ services:
     App\Service\Cotisation\Utils:
         public: true
 
+    App\Service\Education\Utils:
+        public: true
+
     App\Service\Network\Utils:
         public: true
 

+ 112 - 0
src/Entity/Organization/Parameters.php

@@ -161,6 +161,20 @@ class Parameters
     #[ORM\Column(options: ['default' => false])]
     private bool $sendAttendanceSms = false;
 
+    #[ORM\Column(options: ['default' => true])]
+    private bool $generateAttendanceReport = true;
+
+    #[ORM\Column(options: ['default' => true])]
+    private bool $consultPedagogicResult = true;
+
+    #[ORM\Column(options: ['default' => true])]
+    private bool $consultTeacherListing = true;
+
+    #[ORM\Column(options: ['default' => true])]
+    private bool $periodValidation = true;
+
+
+
     #[Pure]
     public function __construct()
     {
@@ -575,4 +589,102 @@ class Parameters
         $this->sendAttendanceEmail = $sendAttendanceEmail;
         return $this;
     }
+
+    /**
+     * @return string|null
+     */
+    public function getSubDomain(): ?string
+    {
+        return $this->subDomain;
+    }
+
+    /**
+     * @param string|null $subDomain
+     */
+    public function setSubDomain(?string $subDomain): void
+    {
+        $this->subDomain = $subDomain;
+    }
+
+    /**
+     * @return string|null
+     */
+    public function getWebsite(): ?string
+    {
+        return $this->website;
+    }
+
+    /**
+     * @param string|null $website
+     */
+    public function setWebsite(?string $website): void
+    {
+        $this->website = $website;
+    }
+
+    /**
+     * @return bool
+     */
+    public function isGenerateAttendanceReport(): bool
+    {
+        return $this->generateAttendanceReport;
+    }
+
+    /**
+     * @param bool $generateAttendanceReport
+     */
+    public function setGenerateAttendanceReport(bool $generateAttendanceReport): void
+    {
+        $this->generateAttendanceReport = $generateAttendanceReport;
+    }
+
+    /**
+     * @return bool
+     */
+    public function isConsultPedagogicResult(): bool
+    {
+        return $this->consultPedagogicResult;
+    }
+
+    /**
+     * @param bool $consultPedagogicResult
+     */
+    public function setConsultPedagogicResult(bool $consultPedagogicResult): void
+    {
+        $this->consultPedagogicResult = $consultPedagogicResult;
+    }
+
+    /**
+     * @return bool
+     */
+    public function isConsultTeacherListing(): bool
+    {
+        return $this->consultTeacherListing;
+    }
+
+    /**
+     * @param bool $consultTeacherListing
+     */
+    public function setConsultTeacherListing(bool $consultTeacherListing): void
+    {
+        $this->consultTeacherListing = $consultTeacherListing;
+    }
+
+    /**
+     * Period validation is enabled
+     *
+     * @return bool
+     */
+    public function isPeriodValidation(): bool
+    {
+        return $this->periodValidation;
+    }
+
+    /**
+     * @param bool $periodValidation
+     */
+    public function setPeriodValidation(bool $periodValidation): void
+    {
+        $this->periodValidation = $periodValidation;
+    }
 }

+ 26 - 0
src/Service/Cotisation/Utils.php

@@ -32,6 +32,8 @@ class Utils
 
     /**
      * Test si l'organisation est un dernier parent ET appartient à la CMF.
+     * @see config/opentalent/modulesbyconditions.yaml
+     *
      * @param Organization $organization
      * @return bool
      * @see UtilsTest::testIsLastParentAndCMF()
@@ -41,8 +43,24 @@ class Utils
         return $this->networkOrganizationRepository->isLastParent($organization) && $this->networkUtils->isCMF($organization);
     }
 
+    /**
+     * Test si l'organisation est une structure (non manager)
+     * @see config/opentalent/modulesbyconditions.yaml
+     *
+     * @param Organization $organization
+     * @return bool
+     * @see UtilsTest::testIsStructure()
+     */
+    public function isStructure(Organization $organization): bool
+    {
+        return true;  // TODO: revoir la définition dans la V1 :  https://gitlab.2iopenservice.com/opentalent/opentalent-platform/-/blob/master/src/AppBundle/Services/Cotisation/Utils.php#L144
+//        return $this->organizationUtils->isStructure($organization);
+    }
+
     /**
      * Test si l'organisation est une structure (non manager) ET appartient à la CMF
+     * @see config/opentalent/modulesbyconditions.yaml
+     *
      * @param Organization $organization
      * @return bool
      * @see UtilsTest::testIsStructureAndCMF()
@@ -54,6 +72,8 @@ class Utils
 
     /**
      * Test si la structure est un manager ET qu'elle appartient à la CMF
+     * @see config/opentalent/modulesbyconditions.yaml
+     *
      * @param Organization $organization
      * @return bool
      * @see UtilsTest::testIsManagerAndCMF()
@@ -65,6 +85,8 @@ class Utils
 
     /**
      * Test si l'organisation est un manager ET un dernier parent ET appartient à la CMF
+     * @see config/opentalent/modulesbyconditions.yaml
+     *
      * @param Organization $organization
      * @return bool
      * @see UtilsTest::testIsManagerAndLastParentAndCMF()
@@ -76,6 +98,8 @@ class Utils
 
     /**
      * Test si l'organisation est un manager ET n'est pas un dernier parent ET appartient à la CMF
+     * @see config/opentalent/modulesbyconditions.yaml
+     *
      * @param Organization $organization
      * @return bool
      * @see UtilsTest::testIsManagerAndNotLastParentAndCMF()
@@ -88,6 +112,7 @@ class Utils
 
     /**
      * Retourne le niveau d'alerte de l'appel de cotisation pour une année.
+     *
      * @param Organization $organization
      * @param int $year
      * @return string|null
@@ -114,6 +139,7 @@ class Utils
 
     /**
      * Retourne dans quelle année de cotisation on est aujourd'hui
+     *
      * @return int
      * @throws \Exception
      * @see UtilsTest::testGetCurrentCotisationYear()

+ 55 - 0
src/Service/Education/Utils.php

@@ -0,0 +1,55 @@
+<?php
+
+namespace App\Service\Education;
+
+use App\Entity\Organization\Organization;
+
+/**
+ * Education utils methods
+ */
+class Utils
+{
+    /**
+     * TODO: complete
+     * @see config/opentalent/modulesbyconditions.yaml
+     *
+     * @param Organization $organization
+     * @return bool
+     */
+    public function isCreateOwnPresence(Organization $organization): bool {
+        return $organization->getParameters()->isGenerateAttendanceReport();
+    }
+
+    /**
+     * TODO: complete
+     * @see config/opentalent/modulesbyconditions.yaml
+     *
+     * @param Organization $organization
+     * @return bool
+     */
+    public function isConsultOwnPedagogicResult(Organization $organization): bool {
+        return $organization->getParameters()->isConsultPedagogicResult();
+    }
+
+    /**
+     * TODO: complete
+     * @see config/opentalent/modulesbyconditions.yaml
+     *
+     * @param Organization $organization
+     * @return bool
+     */
+    public function isConsultTeacherListing(Organization $organization): bool {
+        return $organization->getParameters()->isConsultTeacherListing();
+    }
+
+    /**
+     * Did the organization enable the validation period limit in its settings?
+     * @see config/opentalent/modulesbyconditions.yaml
+     *
+     * @param Organization $organization
+     * @return bool
+     */
+    public function isPeriodValidation(Organization $organization): bool {
+        return $organization->getParameters()->isPeriodValidation();
+    }
+}

+ 11 - 0
src/Service/Organization/Utils.php

@@ -202,4 +202,15 @@ class Utils
 
         return 'https://' . $subdomain . '.opentalent.fr';
     }
+
+    /**
+     * Does the organization own the given module
+     *
+     * @param Organization $organization
+     * @param string $module
+     * @return bool
+     */
+    public function hasModule(Organization $organization, string $module): bool {
+        return (($organization->getSettings()->getModules() ?? [])[$module]) ?? false === true;
+    }
 }

+ 15 - 7
src/Service/Security/Module.php

@@ -90,18 +90,26 @@ class Module
     {
         $modulesByConditions = [];
         $modules = $this->getModuleByConditionsConfig()['opentalent']['modulesbyconditions'];
+
         foreach ($modules as $moduleName => $module) {
-            try{
+            try {
+                $service = $module["conditions"]["service"];
+                $args = $service['args'] ?? [];
+
                 $response = $this->reflection->dynamicInvokeServiceWithArgsAndMethod(
-                    $module["conditions"]["service"]["name"],
-                    $module["conditions"]["service"]["function"],
-                    array($organization)
+                    $service["name"],
+                    $service["function"],
+                    array_merge([$organization], $args)
                 );
-                if($response) {
+                if ($response) {
                     $modulesByConditions[] = $moduleName;
                 }
-            }catch (\Exception $exception){
-                throw new \LogicException($exception->getMessage(), 400, $exception);
+            } catch (\Exception $exception){
+                throw new \LogicException(
+                    $exception->getMessage(),
+                    400,
+                    $exception
+                );
             }
         }
         return $modulesByConditions;