Ver Fonte

Merge branch 'master' of ssh://gitlab.com/interlink-sa/flowdat3/modules/ftth into 36

Guillermo Espinoza há 6 anos atrás
pai
commit
95f720aa5a

+ 2 - 2
.gitlab-ci.yml

@@ -63,8 +63,8 @@ docker_version_tag:
     - docker info
     - docker login -u $DOCKER_USER -p $DOCKER_PWD docker.infra.flowdat.com
     - docker pull $CONTAINER_IMAGE:latest || true
-    - docker build --no-cache --tag $CONTAINER_IMAGE:"${CI_COMMIT_TAG##v}" .
-    - docker push $CONTAINER_IMAGE:"${CI_COMMIT_TAG##v}"
+    - docker build --no-cache --tag $CONTAINER_IMAGE:${CI_COMMIT_TAG} .
+    - docker push $CONTAINER_IMAGE:${CI_COMMIT_TAG}
   only:
     refs:
       - tags

+ 40 - 7
src/FTTHBundle/Admin/NAPAdmin.php

@@ -54,16 +54,45 @@ class NAPAdmin extends BaseAdmin
      * @param FormMapper $formMapper
      */
     protected function configureFormFields(FormMapper $formMapper)
-    {
+    {   
+        $id = $this->getSubject()->getId();
+        $readonly = is_null($id) ? false : 'readonly';
+        if ($id) {
+            $this->get('session')->getFlashBag()->add('warning', $this->trans('warning.disabled.fields'));
+        }
+
         $formMapper
             ->tab('default')
             ->with('')
             ->add('name')
-            ->add('parent')
-            ->add('olt')
-            ->add('slot', null, array('attr' => array('min' => 0)))
-            ->add('capacity', null, array('attr' => array('min' => 0)))
-            ->add('link', null, array('attr' => array('min' => 0)))
+            ->add('parent', null, [
+                'attr' => [
+                    'readonly' => $readonly,
+                ],
+            ])
+            ->add('olt', null, [
+                'attr' => [
+                    'readonly' => $readonly,
+                ],
+            ])
+            ->add('slot', null, [
+                'attr' => [
+                    'min' => 0,
+                    'readonly' => $readonly,
+                ],
+            ])
+            ->add('capacity', null, [
+                'attr' => [
+                    'min' => 0,
+                    'readonly' => $readonly,
+                ],
+            ])
+            ->add('link', null, [
+                'attr' => [
+                    'min' => 0,
+                    'readonly' => $readonly,
+                ],
+            ])
             ->add('address', 'text', [
                 'required' => false,
             ])
@@ -71,7 +100,11 @@ class NAPAdmin extends BaseAdmin
             ->end()
             ->tab('Avanzado')
             ->with('Config')
-            ->add('extraData')
+            ->add('extraData', null, [
+                'attr' => [
+                    'readonly' => $readonly,
+                ],
+            ])
             ->end()
             ->end();
     }

+ 64 - 13
src/FTTHBundle/Admin/ONUAdmin.php

@@ -116,6 +116,13 @@ class ONUAdmin extends WorkflowBaseAdmin
     protected function configureFormFields(FormMapper $formMapper)
     {
         $subject = $this->getSubject();
+        $id = $subject->getId();
+        $readonly = is_null($id) ? false : 'readonly';
+        $flashbag = $this->get('session')->getFlashBag();
+        if ($id) {
+            $flashbag->add('warning', $this->trans('warning.disabled.fields'));
+        }
+
         $em = $this->get("doctrine.orm.entity_manager");
 
         // busco el ONU template si se pasa como parámetro
@@ -139,11 +146,12 @@ class ONUAdmin extends WorkflowBaseAdmin
             ],
             'attr' => [
                 'class' => 'zte_v4 hidden',
+                'readonly' => $readonly,
             ],
         ];
 
         // Editando la ONU o hay template base o pasado como parámetro
-        if ($subject->getId() || $template) {
+        if ($id || $template) {
             $olt = $subject->getOlt();
 
             // Según el modelo de OLT se muestran algunos campos específicos
@@ -162,7 +170,6 @@ class ONUAdmin extends WorkflowBaseAdmin
         }
 
         if ($template && $this->isCurrentRoute('create')) {
-            $flashbag = $this->get('session')->getFlashBag();
             $flashbag->add("warning", $this->trans("msg_use_template_onu_in_create_onu_ftth"));
         }
 
@@ -185,7 +192,8 @@ class ONUAdmin extends WorkflowBaseAdmin
                     ->add('clientId')
                     ->add('ponSerialNumber', null, array(
                         'attr' => array(
-                            'style' => 'text-transform: uppercase;'
+                            'style' => 'text-transform: uppercase;',
+                            'readonly' => $readonly,
                         )));
         if ($this->hasParameter('show.onu.activationCode') && $this->getParameter('show.onu.activationCode') == true) {
             $formMapper->add('activationCode');
@@ -210,8 +218,15 @@ class ONUAdmin extends WorkflowBaseAdmin
                                         return $value->getOlt()->getName();
                                     }
                                 },
-                            ))
-                    ->add('model')
+                                'attr' => [
+                                    'readonly' => $readonly,
+                                ],
+                                ))
+                    ->add('model', null, [
+                        'attr' => [
+                            'readonly' => $readonly,
+                        ],
+                    ])
                     ->add('comments')
                 ->end()
             ->end()
@@ -227,15 +242,29 @@ class ONUAdmin extends WorkflowBaseAdmin
                             'style' => 'text-transform: uppercase;',
                             'readonly' => 'readonly'
                         )))
-                    ->add('olt','hidden', array('attr' => array("hidden" => true)))
-                    ->add('position')
+                    ->add('olt','hidden', array(
+                        'attr' => array(
+                            "hidden" => true
+                    )))
+                    ->add('position', null, [
+                        'attr' => [
+                            'readonly' => $readonly,
+                        ],
+                    ])
                     ->add('ip')
-                    ->add('mac')
+                    ->add('mac', null, [
+                        'attr' => [
+                            'readonly' => $readonly,
+                        ],
+                    ])
                     ->add('radiusAuth', 'choice', [
                         'choices' => [
                             'Pon Serial Number' => 'psn',
                             'MAC Address' => 'mac'
-                        ]
+                        ],
+                        'attr' => [
+                            'readonly' => $readonly,
+                        ],
                     ])
                 ->end()
                 ->with('Huawei', ['class' => "col-md-12 {$hidden['Huawei']} olt_mark Huawei"])
@@ -245,21 +274,43 @@ class ONUAdmin extends WorkflowBaseAdmin
                         'allow_delete' => true,
                         'required' => false,
                         'by_reference' => false,
+                        'attr' => [
+                            'readonly' => $readonly,
+                        ],
                     ))
                 ->end()
                 ->with('ZTE', ['class' => "col-md-12 {$hidden['ZTE']} olt_mark ZTE"])
-                    ->add('vlan')
+                    ->add('vlan', null, [
+                        'attr' => [
+                            'readonly' => $readonly,
+                        ],
+                    ])
                     ->add('vlanProfile', null, $optionsZTEV4)
                     ->add('onuProfile', null, $optionsZTEV4)
-                    ->add('trafficProfileIn')
-                    ->add('trafficProfileOut')
-                    ->add('tcontprofile')
+                    ->add('trafficProfileIn', null, [
+                        'attr' => [
+                            'readonly' => $readonly,
+                        ],
+                    ])
+                    ->add('trafficProfileOut', null, [
+                        'attr' => [
+                            'readonly' => $readonly,
+                        ],
+                    ])
+                    ->add('tcontprofile', null, [
+                        'attr' => [
+                            'readonly' => $readonly,
+                        ],
+                    ])
                     ->add('catv')
                 ->end()
                 ->with("FiberLink | FiberHome", ['class' => "col-md-12 olt_mark FiberLink FiberHome"])
                     ->add('vlans', null, array(
                         'required' => false,
                         'multiple' => true,
+                        'attr' => [
+                            'readonly' => $readonly,
+                        ],
                     ))
                 ->end()
                 ->with('Extra')

+ 45 - 34
src/FTTHBundle/EventListener/ONUSubscriber.php

@@ -4,6 +4,7 @@ namespace FTTHBundle\EventListener;
 
 use Doctrine\Common\EventSubscriber;
 use Doctrine\ORM\Event\LifecycleEventArgs;
+use Base\AdminBundle\Controller\TenancyService;
 use FTTHBundle\Entity\ONU;
 use FTTHBundle\Entity\ONUProfile;
 use FTTHBundle\Entity\VLanID;
@@ -34,15 +35,22 @@ class ONUSubscriber implements EventSubscriber
      */
     private $translator;
 
+    /**
+     * @var TenancyService
+     */
+    private $tenancyService;
+
 
     /**
      * @param SessionInterface $session
      * @param TranslatorInterface $translator
+     * @param TenancyService $tenancyService
      */
-    public function __construct(SessionInterface $session, TranslatorInterface $translator)
+    public function __construct(SessionInterface $session, TranslatorInterface $translator, TenancyService $tenancyService)
     {
         $this->session = $session;
         $this->translator = $translator;
+        $this->tenancyService = $tenancyService;
     }
 
     /**
@@ -219,11 +227,7 @@ class ONUSubscriber implements EventSubscriber
      */
     public function assignTrafficProfile(LifecycleEventArgs $args)
     {
-        $obj = $args->getEntityManager()
-                ->getRepository(TrafficProfile::class)
-                ->findOneBy(array(
-                    "usedByDefault" => true,
-                ));
+        $obj = $this->getDefaultObject(TrafficProfile::class);
         if ($obj) {
             $args->getEntity()->setTrafficProfileOut($obj);
             $args->getEntity()->setTrafficProfileIn($obj);
@@ -236,11 +240,7 @@ class ONUSubscriber implements EventSubscriber
      */
     public function assignVlanProfile(LifecycleEventArgs $args)
     {
-        $obj = $args->getEntityManager()
-                ->getRepository(VLanProfile::class)
-                ->findOneBy(array(
-                    "usedByDefault" => true,
-                ));
+        $obj = $this->getDefaultObject(VLanProfile::class);        
         if ($obj) {
             $args->getEntity()->setVlanProfile($obj);
         }
@@ -252,11 +252,7 @@ class ONUSubscriber implements EventSubscriber
      */
     public function assignONUProfile(LifecycleEventArgs $args)
     {
-        $obj = $args->getEntityManager()
-                ->getRepository(ONUProfile::class)
-                ->findOneBy(array(
-                    "usedByDefault" => true,
-                ));
+        $obj = $this->getDefaultObject(ONUProfile::class);
         if ($obj) {
             $args->getEntity()->setONUProfile($obj);
         }
@@ -268,11 +264,7 @@ class ONUSubscriber implements EventSubscriber
      */
     public function assignTConProfile(LifecycleEventArgs $args)
     {
-        $obj = $args->getEntityManager()
-                ->getRepository(TContProfile::class)
-                ->findOneBy(array(
-                    "usedByDefault" => true,
-                ));
+        $obj = $this->getDefaultObject(TContProfile::class);
         if ($obj) {
             $args->getEntity()->setTcontprofile($obj);
         }
@@ -284,11 +276,7 @@ class ONUSubscriber implements EventSubscriber
      */
     public function assignVLanId(LifecycleEventArgs $args)
     {
-        $obj = $args->getEntityManager()
-                ->getRepository(VLanID::class)
-                ->findOneBy(array(
-                    "usedByDefault" => true,
-                ));
+        $obj = $this->getDefaultObject(VLanID::class);
         if ($obj) {
             $args->getEntity()->setVlan($obj);
         }
@@ -311,10 +299,7 @@ class ONUSubscriber implements EventSubscriber
             
             // Si la ONU no tiene asignadas vlans, busco alguna que este por default
             $vlans = $onu->getVlans() ?: [];
-            $vlanDefault = $this->em->getRepository(VLanID::class)
-                ->findOneBy(array(
-                    "usedByDefault" => true,
-                ));
+            $vlanDefault = $this->getDefaultObject(VLanID::class);
             if ((is_null($vlans) || count($vlans) == 0) && $vlanDefault) {
                 $vlans = [
                     $vlanDefault,
@@ -385,13 +370,15 @@ class ONUSubscriber implements EventSubscriber
         $olt = $args->getEntity()->getOlt();
         $vlanName = "vlanid_data";
 
-        if(!$olt || $olt->getMark() != "FiberHome") 
+        if (!$olt || $olt->getMark() != "FiberHome") {
             return true;
+        }
         
-        if($args->getEntity()->getVlanByName($vlanName)) 
+        if ($args->getEntity()->getVlanByName($vlanName))  {
             return true;
+        }
 
-        $obj = $this->em->getRepository(VLanID::class)->findOneBy(array("usedByDefault" => true, "name" => $vlanName));
+        $obj = $this->getDefaultObject(VLanID::class, ['name' => $vlanName,]);
         if ($obj) {
             $args->getEntity()->addVlan($obj);
             $this->em->flush();
@@ -401,11 +388,35 @@ class ONUSubscriber implements EventSubscriber
                 $args->getEntity()->addVlan($obj);
                 $this->em->flush();
             }
-
         }
 
         return true;
         
     }
+
+    /**
+     * Return the default object for the class parameter filter by current tenancy
+     * Optional filter by fields
+     * If there is no result, return the default object for base tenancy
+     * 
+     * @param string $class
+     * @param array $fields
+     * 
+     * @return mixed
+     */
+    private function getDefaultObject($class, $fields = [])
+    {
+        $filter = $fields + [
+            'usedByDefault' => true,
+            'tenancyId' => $this->tenancyService->getTenancyIdCurrent(),
+        ];
+        $obj = $this->em->getRepository($class)->findOneBy($filter);
+        if (is_null($obj)) {
+            $filter['tenancyId'] = 1;
+            $obj = $this->em->getRepository($class)->findOneBy($filter);
+        }
+
+        return $obj;
+    }
     
 }

+ 13 - 0
src/FTTHBundle/Form/NAPType.php

@@ -4,6 +4,8 @@ namespace FTTHBundle\Form;
 
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\FormBuilderInterface;
+use Symfony\Component\Form\FormEvent;
+use Symfony\Component\Form\FormEvents;
 use Symfony\Component\OptionsResolver\OptionsResolver;
 
 class NAPType extends AbstractType
@@ -21,6 +23,17 @@ class NAPType extends AbstractType
             ->add('tenancyId')
             ->add('capacity')
         ;
+
+        $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
+            $nap = $event->getData();
+            $form = $event->getForm();
+    
+            if ($nap && null !== $nap->getId()) {
+                $form->remove('olt');
+                $form->remove('capacity');
+                $form->remove('extraData');
+            }
+        });
     }
 
     /**

+ 23 - 0
src/FTTHBundle/Form/ONUType.php

@@ -105,6 +105,29 @@ class ONUType extends AbstractType
 
             }
         );
+
+        $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
+            $onu = $event->getData();
+            $form = $event->getForm();
+    
+            if ($onu && null !== $onu->getId()) {
+                $form->remove('mac');
+                $form->remove('serialNumber');
+                $form->remove('ponSerialNumber');
+                $form->remove('ponSerialNumberAux');
+                $form->remove('nap');
+                $form->remove('olt');
+                $form->remove('model');
+                $form->remove('position');
+                $form->remove('vlan');
+                $form->remove('vlans');
+                $form->remove('tcontprofile');
+                $form->remove('trafficProfileOut');
+                $form->remove('trafficProfileIn');
+                $form->remove('vlanProfile');
+                $form->remove('onuProfile');
+            }
+        });
     }
 
     /**

+ 1 - 1
src/FTTHBundle/Resources/config/services.yml

@@ -59,7 +59,7 @@ services:
         class: FTTHBundle\EventListener\ONUSubscriber
         tags:
             - { name: doctrine.event_subscriber, connection: default }
-        arguments: ["@session", "@translator"]
+        arguments: ["@session", "@translator", "@base_tenancy.tenancy_service"]
 
     ftth.onu.form:
         class: FTTHBundle\Form\ONUType

+ 2 - 1
src/FTTHBundle/Resources/translations/FTTHBundle.es.yml

@@ -413,4 +413,5 @@ Stats: Estadísticas
 Show stats: Mostrar detalle
 Set 0 to disable autodiscovery or set a x number to scan each x minutes the ONUs connected but without configuration: Seleccione 0 para deshabilitar la función 'Autodiscovery' o seleccione un valor x para escanear cada x minutos las ONUs conectadas pero sin configurar. 
 Profile to set the ONUs by autodiscovery: Perfíl con el cual se configurarán las ONUs mediante Autodiscovery.
-errors.duplicate_mac_key: La MAC se encuentra asignada a otra ONU
+errors.duplicate_mac_key: La MAC se encuentra asignada a otra ONU
+warning.disabled.fields: Para evitar problemas en la configuración, algunos campos fueron deshabilitados

+ 1 - 2
src/FTTHBundle/tests/ONURESTControllerTest.php

@@ -245,7 +245,7 @@ class ONURESTControllerTest extends WebTestCaseBase
         // seteo los datos del listener
         $this->setListener();
         // creo el nuevo set de datos a enviar.
-        $data = $this->obtainDataChange($this->obtainData(), array('ponSerialNumber' => 'pon_modifi', 'id' => $id));
+        $data = $this->obtainDataChange($this->obtainData(), array('clientId' => 2, 'id' => $id));
         // hago la modificacion llamando al servicio por put
         $this->getClient()->request('PUT', $this->getUriPutDelete() . $id, $data);
         // obtengo la respuesta
@@ -265,7 +265,6 @@ class ONURESTControllerTest extends WebTestCaseBase
         // verifco el resultado
         $this->assertEquals(200, $response->getStatusCode(), "Error en la respuesta http.");
         $this->assertJson($response->getContent(), "No se obtuvo un objeto json.");
-        $this->assertContains('pon_modifi', strtolower($response->getContent()), "Error al buscar al onu modificado.");
     }
 
     /**