#5364 fix(user_settings): unable to change default email
Merged a year ago by ngompa. Opened a year ago by wombelix.

@@ -7,6 +7,7 @@ 

  {% set tag = "users"%}

  

  {% macro render_email(email, form, validated=True) %}

+ {% set random_number = range(0, 256) | random() %}
ngompa commented a year ago

Is it only possible to have 255 email addresses? I mean, it's a high number and unlikely to be hit, but I have to ask. :laughing:

  <div class="list-group-item {% if not validated %}disabled{% endif %}">

    <span class="fa fa-envelope text-muted"></span> &nbsp;{{ email.email }}

    {% if validated %}
@@ -25,11 +26,11 @@ 

      </div>

      {% else %}

      <form class="inline" method="POST"

-       action="{{ url_for('ui_ns.set_default_email') }}" id="default_mail">

+       action="{{ url_for('ui_ns.set_default_email') }}" id="default_mail_{{ random_number }}">

        <input type="hidden" value="{{ email.email }}" name="email" />

        {{ form.csrf_token }}

        <a class="float-right p-r-1 btn btn-outline-warning border-0 text-secondary mr-1 pointer submit-btn"

-          data-form-id="default_mail" title="Set as default email address">

+          data-form-id="default_mail_{{ random_number }}" title="Set as default email address">

           <span class="fa fa-star" data-toggle="tooltip"></span>

        </a>

      </form>

If more then two email addresses are defined in the user settings, it was not possible to change the default address to one of those additional addresses.
This was caused by the frontend, all addresses got the same html 'form-id', that way always the first one was submitted when clicking the submit button, independent of the actual selected email address.
Resolved by adding a random number as suffix to the 'form-id' of each email address, that way there are unique and the default mail address can be changed even with more then two assigned addresses.

Fixes: https://pagure.io/pagure/issue/5327
Fixes: https://pagure.io/pagure/issue/5338

Is it only possible to have 255 email addresses? I mean, it's a high number and unlikely to be hit, but I have to ask. :laughing:

Is it only possible to have 255 email addresses? I mean, it's a high number and unlikely to be hit, but I have to ask. :laughing:

In theory it would be probably less, it's not really a unique random number I generate, so it could overlap at some point. I'm open to suggestions of a better way to generate the number to allow nearly unlimited emails ;)

17:51:16  RuntimeError: can't start new thread
17:51:16  ERROR: InvocationError for command /pagure/.tox/py38/bin/pytest -n auto tests (exited with code 1)
17:51:17  ___________________________________ summary ____________________________________
17:51:17  ERROR:   py38: commands failed

No errors besides that generic one which I also run into locally when using tox.
I'm actually not sure about test coverage of the user settings, but I tested it manually on my dev instance as well.

I think we'll let this limit slide and if it comes up, we can fix it later...

rebased onto 7b766af

a year ago

Pull-Request has been merged by ngompa

a year ago
Metadata