Uploaded image for project: 'Blesta Core'
  1. Blesta Core
  2. CORE-3964

Queued email change fails when additional client fields are required

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.12.3
    • Component/s: None
    • Labels:
      None

      Description

      • Under Settings > Company > Client Options > General Client Settings, Enable email verification
      • Under Settings > Company > Client Options > Required Client Field select Address 1
      • Login as a client
      • Change their email under the account settings
      • Go back to the client profile in the admin interface and switch them to verified
      • See that the contact email is not updated

      To fix:

      In app/models/contacts.php starting at line 1400 change:
      $rules = array_merge($rules, $this->getRequiredFieldRules($vars['client_id']));
      To
      $rules = array_merge($rules, $this->getRequiredFieldRules($vars['client_id'], $edit));

      Replace the getRequiredFieldRules() with

          /**
           * Gets the rules for all contact fields that are require by the client group
           *
           * @param int $client_id The ID of the client this contact is associated with
           * @param bool $edit Whether this data is being validated for an edit (optional, default false)
           * @return array A list of rules with the addition of the client groups required fields
           */
          private function getRequiredFieldRules($client_id, $edit = false)
          {
              Loader::loadModels($this, ['ClientGroups']);
      
              $required_fields = [];
              $client = $this->Record->select('client_group_id')
                  ->from('clients')
                  ->where('id', '=', $client_id)
                  ->fetch();
      
              if ($client) {
                  $required_contact_fields = $this->ClientGroups->getSetting(
                      $client->client_group_id,
                      'required_contact_fields'
                  );
      
                  if ($required_contact_fields) {
                      $required_fields = unserialize(base64_decode($required_contact_fields->value));
                  }
              }
      
              $rules = [];
              foreach ($required_fields as $field) {
                  $rules[$field]['empty'] = [
                      'if_set' => $edit,
                      'rule' => 'isEmpty',
                      'negate' => true,
                      'message' => $this->_('Contacts.!error.' . $field . '.empty')
                  ];
              }
      
              return $rules;
          }
      

        Activity

        jonathan Jonathan Reissmueller made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        jonathan Jonathan Reissmueller made changes -
        Description * Under Settings > Company > Client Options > General Client Settings, Enable email verification
        * Under Settings > Company > Client Options > Required Client Field select Address 1
        * Login as a client
        * Change their email under the account settings
        * Go back to the client profile in the admin interface and switch them to verified
        * See that the contact email is not updated

        To fix:


        In app/models/contacts.php starting at line 1400 change:
                    $rules = array_merge($rules, $this->getRequiredFieldRules($vars['client_id']));
        To
                    $rules = array_merge($rules, $this->getRequiredFieldRules($vars['client_id'], $edit));

        Replace the getRequiredFieldRules() with
        {code:java}
            /**
             * Gets the rules for all contact fields that are require by the client group
             *
             * @param int $client_id The ID of the client this contact is associated with
             * @param bool $edit Whether this data is being validated for an edit (optional, default false)
             * @return array A list of rules with the addition of the client groups required fields
             */
            private function getRequiredFieldRules($client_id, $edit = false)
            {
                Loader::loadModels($this, ['ClientGroups']);

                $required_fields = [];
                $client = $this->Record->select('client_group_id')
                    ->from('clients')
                    ->where('id', '=', $client_id)
                    ->fetch();

                if ($client) {
                    $required_contact_fields = $this->ClientGroups->getSetting(
                        $client->client_group_id,
                        'required_contact_fields'
                    );

                    if ($required_contact_fields) {
                        $required_fields = unserialize(base64_decode($required_contact_fields->value));
                    }
                }

                $rules = [];
                foreach ($required_fields as $field) {
                    $rules[$field]['empty'] = [
                        'if_set' => $edit,
                        'rule' => 'isEmpty',
                        'negate' => true,
                        'message' => $this->_('Contacts.!error.' . $field . '.empty')
                    ];
                }
        {code}
        * Under Settings > Company > Client Options > General Client Settings, Enable email verification
        * Under Settings > Company > Client Options > Required Client Field select Address 1
        * Login as a client
        * Change their email under the account settings
        * Go back to the client profile in the admin interface and switch them to verified
        * See that the contact email is not updated

        To fix:


        In app/models/contacts.php starting at line 1400 change:
                    $rules = array_merge($rules, $this->getRequiredFieldRules($vars['client_id']));
        To
                    $rules = array_merge($rules, $this->getRequiredFieldRules($vars['client_id'], $edit));

        Replace the getRequiredFieldRules() with
        {code:java}
            /**
             * Gets the rules for all contact fields that are require by the client group
             *
             * @param int $client_id The ID of the client this contact is associated with
             * @param bool $edit Whether this data is being validated for an edit (optional, default false)
             * @return array A list of rules with the addition of the client groups required fields
             */
            private function getRequiredFieldRules($client_id, $edit = false)
            {
                Loader::loadModels($this, ['ClientGroups']);

                $required_fields = [];
                $client = $this->Record->select('client_group_id')
                    ->from('clients')
                    ->where('id', '=', $client_id)
                    ->fetch();

                if ($client) {
                    $required_contact_fields = $this->ClientGroups->getSetting(
                        $client->client_group_id,
                        'required_contact_fields'
                    );

                    if ($required_contact_fields) {
                        $required_fields = unserialize(base64_decode($required_contact_fields->value));
                    }
                }

                $rules = [];
                foreach ($required_fields as $field) {
                    $rules[$field]['empty'] = [
                        'if_set' => $edit,
                        'rule' => 'isEmpty',
                        'negate' => true,
                        'message' => $this->_('Contacts.!error.' . $field . '.empty')
                    ];
                }

                return $rules;
            }
        {code}
        jonathan Jonathan Reissmueller made changes -
        Description * Under Settings > Company > Client Options > General Client Settings, Enable email verification
        * Under Settings > Company > Client Options > Required Client Field select Address 1
        * Login as a client
        * Change their email under the account settings
        * Go back to the client profile in the admin interface and switch them to verified
        * See that the contact email is not updated

        To fix:


        In app/models/contacts.php starting at line 1402 change:
                    $rules = array_merge($rules, $this->getRequiredFieldRules($vars['client_id']));
        To
                    $rules = array_merge($rules, $this->getRequiredFieldRules($vars['client_id'], $edit));

        Replace the getRequiredFieldRules() with
        {code:java}
            /**
             * Gets the rules for all contact fields that are require by the client group
             *
             * @param int $client_id The ID of the client this contact is associated with
             * @param bool $edit Whether this data is being validated for an edit (optional, default false)
             * @return array A list of rules with the addition of the client groups required fields
             */
            private function getRequiredFieldRules($client_id, $edit = false)
            {
                Loader::loadModels($this, ['ClientGroups']);

                $required_fields = [];
                $client = $this->Record->select('client_group_id')
                    ->from('clients')
                    ->where('id', '=', $client_id)
                    ->fetch();

                if ($client) {
                    $required_contact_fields = $this->ClientGroups->getSetting(
                        $client->client_group_id,
                        'required_contact_fields'
                    );

                    if ($required_contact_fields) {
                        $required_fields = unserialize(base64_decode($required_contact_fields->value));
                    }
                }

                $rules = [];
                foreach ($required_fields as $field) {
                    $rules[$field]['empty'] = [
                        'if_set' => $edit,
                        'rule' => 'isEmpty',
                        'negate' => true,
                        'message' => $this->_('Contacts.!error.' . $field . '.empty')
                    ];
                }
        {code}
        * Under Settings > Company > Client Options > General Client Settings, Enable email verification
        * Under Settings > Company > Client Options > Required Client Field select Address 1
        * Login as a client
        * Change their email under the account settings
        * Go back to the client profile in the admin interface and switch them to verified
        * See that the contact email is not updated

        To fix:


        In app/models/contacts.php starting at line 1400 change:
                    $rules = array_merge($rules, $this->getRequiredFieldRules($vars['client_id']));
        To
                    $rules = array_merge($rules, $this->getRequiredFieldRules($vars['client_id'], $edit));

        Replace the getRequiredFieldRules() with
        {code:java}
            /**
             * Gets the rules for all contact fields that are require by the client group
             *
             * @param int $client_id The ID of the client this contact is associated with
             * @param bool $edit Whether this data is being validated for an edit (optional, default false)
             * @return array A list of rules with the addition of the client groups required fields
             */
            private function getRequiredFieldRules($client_id, $edit = false)
            {
                Loader::loadModels($this, ['ClientGroups']);

                $required_fields = [];
                $client = $this->Record->select('client_group_id')
                    ->from('clients')
                    ->where('id', '=', $client_id)
                    ->fetch();

                if ($client) {
                    $required_contact_fields = $this->ClientGroups->getSetting(
                        $client->client_group_id,
                        'required_contact_fields'
                    );

                    if ($required_contact_fields) {
                        $required_fields = unserialize(base64_decode($required_contact_fields->value));
                    }
                }

                $rules = [];
                foreach ($required_fields as $field) {
                    $rules[$field]['empty'] = [
                        'if_set' => $edit,
                        'rule' => 'isEmpty',
                        'negate' => true,
                        'message' => $this->_('Contacts.!error.' . $field . '.empty')
                    ];
                }
        {code}
        jonathan Jonathan Reissmueller made changes -
        Assignee Jonathan Reissmueller [ jonathan ]
        jonathan Jonathan Reissmueller made changes -
        Rank Ranked lower
        jonathan Jonathan Reissmueller made changes -
        Sprint 5.0.0 Sprint 4 [ 121 ]
        jonathan Jonathan Reissmueller made changes -
        Fix Version/s 4.12.3 [ 11700 ]
        jonathan Jonathan Reissmueller made changes -
        Rank Ranked higher
        jonathan Jonathan Reissmueller made changes -
        Field Original Value New Value
        Rank Ranked higher
        jonathan Jonathan Reissmueller created issue -

          People

          • Assignee:
            jonathan Jonathan Reissmueller
            Reporter:
            jonathan Jonathan Reissmueller
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Fix Release Date:
              19/Nov/20

              Agile