浏览代码

Merged in FD3-451 (pull request #30)

Se cambio la validación de la mac para que solo acepte caracteres válidos

Approved-by: Guillermo Espinoza <guillermo@interlink.com.ar>
Approved-by: Maximiliano Schvindt <maximiliano@interlink.com.ar>
Gabriel Gosparo 6 年之前
父节点
当前提交
a30ab46e87

+ 16 - 3
src/CablemodemBundle/Admin/CablemodemAdmin.php

@@ -70,9 +70,10 @@ class CablemodemAdmin extends WorkflowBaseAdmin
                         ->add('model')
                         ->add('mac', 'text', array(
                             'attr' => array(
-                                'pattern' => '[a-zA-Z0-9]+',
-                                'title' => $this->trans('Only accept [0-9a-zA-Z]', [], 'CablemodemBundle'),
-                                'maxlength' => '12',
+                                'pattern' => '([a-fA-F0-9]{2}[:]*){6}',
+//                                'pattern' => '[a-zA-Z0-9]+',
+                                'title' => $this->trans('Only accept', [], 'CablemodemBundle') . " ([a-fA-F0-9]{2}[:]*){6}",
+                                'maxlength' => '17',
                                 'minlength' => '12'
                             )))
                         ->add('activationCode')
@@ -174,4 +175,16 @@ class CablemodemAdmin extends WorkflowBaseAdmin
         $showMapper->end();
     }
 
+    public function prePersist($object)
+    {
+        parent::prePersist($object);
+        $object->setMac(str_replace(":", "", $object->getMac()));
+    }
+
+    public function preUpdate($object)
+    {
+        parent::preUpdate($object);
+        $object->setMac(str_replace(":", "", $object->getMac()));
+    }
+
 }

+ 38 - 27
src/CablemodemBundle/Entity/Cablemodem.php

@@ -18,6 +18,7 @@ use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
 use WorkflowBundle\Entity\Traits\WorkflowTrait;
 use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity as SoftDeleteable;
 use Base\AdminBundle\Interfaces\SoftDeleteInterface;
+use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
 
 /**
  * @ORM\Entity
@@ -29,6 +30,7 @@ use Base\AdminBundle\Interfaces\SoftDeleteInterface;
  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=true)
  *
  * @ValidatorAssert\Device
+ * @HasLifecycleCallbacks
  */
 class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface, SoftDeleteInterface
 {
@@ -64,8 +66,8 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
      *
      * @Gedmo\Versioned
      *
-     * @Assert\Regex(pattern="/^[a-z0-9]+$/")
-     * @Assert\Length(min=12, max=12)
+     * @Assert\Regex(pattern="/([a-fA-F0-9]{2}[:]*){6}/")
+     * @Assert\Length(min=12, max=17)
      * @Assert\NotBlank()
      * @Assert\NotNull
      */
@@ -97,7 +99,7 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
     /**
      * @ORM\ManyToOne(targetEntity="CablemodemModel", fetch="EXTRA_LAZY")
      * @ORM\JoinColumn(onDelete="SET NULL")
-     * 
+     *
      * @JMS\MaxDepth(1)
      */
     protected $model;
@@ -154,26 +156,26 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
      * )
      */
     protected $voip = null;
-    
+
     /**
      * @ORM\Column(type="string", nullable=true)
      */
     protected $fixedIP;
-    
+
     /**
      * @ORM\Column(type="string", nullable=true)
      *
      * @Assert\Ip()
      */
     protected $cpeFixedIP;
-    
+
     /**
      * @ORM\Column(type="string", nullable=true)
      *
      * @Assert\Ip()
      */
     protected $mtaFixedIP;
-    
+
     /**
      * @ORM\Column(type="text", nullable=true)
      *
@@ -187,7 +189,7 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
      */
     public function __toString()
     {
-        return (string) ($this->mac ?: $this->activationCode);
+        return (string)($this->mac ?: $this->activationCode);
     }
 
     /**
@@ -415,7 +417,7 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
     {
         global $kernel;
         $options = [
-           'filename' => $this->mac . '.bin',
+            'filename' => $this->mac . '.bin',
         ];
         $container = $kernel->getContainer();
         if ($this->mtaEnabled && $container->hasParameter('dhcp_server_ip')) {
@@ -441,17 +443,17 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
      */
     public function setVoip($voip)
     {
-        if(is_null($voip)) {
+        if (is_null($voip)) {
             $this->voip = $voip;
-            
+
             return $this;
         }
 
         $this->voip = array_values($voip);
-        
+
         return $this;
     }
-    
+
     /**
      * @param string $index
      *
@@ -459,11 +461,11 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
      */
     public function getVoipData($index)
     {
-        if(is_null($this->voip)) return null;
+        if (is_null($this->voip)) return null;
 
-        if(isset($this->voip[$index])) return $this->voip[$index];
+        if (isset($this->voip[$index])) return $this->voip[$index];
     }
-    
+
     /**
      * @return string
      */
@@ -471,7 +473,7 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
     {
         return $this->fixedIP;
     }
-    
+
     /**
      * @param string $fixedIP
      *
@@ -480,10 +482,10 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
     public function setFixedIP($fixedIP)
     {
         $this->fixedIP = $fixedIP;
-        
+
         return $this;
     }
-    
+
     /**
      * @return string
      */
@@ -491,7 +493,7 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
     {
         return $this->cpeFixedIP;
     }
-    
+
     /**
      * @param string $cpeFixedIP
      *
@@ -500,10 +502,10 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
     public function setCpeFixedIP($cpeFixedIP)
     {
         $this->cpeFixedIP = $cpeFixedIP;
-        
+
         return $this;
     }
-    
+
     /**
      * @return string
      */
@@ -511,7 +513,7 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
     {
         return $this->mtaFixedIP;
     }
-    
+
     /**
      * @param string $mtaFixedIP
      *
@@ -520,10 +522,10 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
     public function setMtaFixedIP($mtaFixedIP)
     {
         $this->mtaFixedIP = $mtaFixedIP;
-        
+
         return $this;
     }
-    
+
     /**
      * @return string
      */
@@ -531,7 +533,7 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
     {
         return $this->comments;
     }
-    
+
     /**
      * @param string $comments
      *
@@ -540,8 +542,17 @@ class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationIn
     public function setComments($comments)
     {
         $this->comments = $comments;
-        
+
         return $this;
     }
 
+    /**
+     * @ORM\PreUpdate()
+     * @ORM\PreUpdate()
+     */
+    public function prePersist()
+    {
+        $this->setMac(str_replace(":", "", $this->getMac()));
+    }
+
 }

+ 1 - 1
src/CablemodemBundle/Resources/translations/CablemodemBundle.es.yml

@@ -171,7 +171,7 @@ help:
     profile_value_default: Al deja en blanco el valor, se asignará un valor por defecto!
     profile_template: Template a utilizar para generar archivo docsis
 
-'Only accept [0-9a-zA-Z]': Utilice solo [0-9a-zA-Z]
+Only accept: Utilice solo
 'Fixed i p':  IP fija
 'Cpe fixed i p':  IP fija CPE
 'Mta fixed i p':  IP fija MTA