Skip to content

Commit

Permalink
PR #350 Fix spaces for notify emails (issue #346)
Browse files Browse the repository at this point in the history
* Fix spaces for notify emails (issue #346)

The input for the email address for the notification allows for multiply
entries if they are separated by commas. When the form is displayed again,
spaces are added after the commas. The extra spaces generate an error when the
user tries to safe the edits.

This commit fixes:
- no spaces are added when the form is displayed again.
- removes spaces in the email address field before saving.

* Add strip() to remove space in emails
  • Loading branch information
borrob committed Apr 23, 2021
1 parent 2cd301a commit 38be31c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions GeoHealthCheck/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,13 @@ def update(resource_identifier):

update_counter += 1
elif key == 'notify_emails':
resource.set_recipients('email',
[v for v in value if v.strip()])
resource.set_recipients(
'email',
[v.strip() for v in value if v.strip()])
elif key == 'notify_webhooks':
resource.set_recipients('webhook',
[v for v in value if v.strip()])
resource.set_recipients(
'webhook',
[v.strip() for v in value if v.strip()])
elif key == 'auth':
resource.auth = value
elif getattr(resource, key) != resource_identifier_dict[key]:
Expand Down
4 changes: 2 additions & 2 deletions GeoHealthCheck/templates/edit_resource.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ <h1 class="page-header">[{{ _('Edit') }}] <span id="resource_title_h1">{{ resour
<th>{{ _("Notify emails") }}</th>
<td>
<label>{{ _('You can enter multiple emails separated with comma') }}</label>
<input type="text" class="form-control" id="input_resource_notify_emails" name="resource_notify_emails_value" value="{{ resource.get_recipients('email')|join(', ') }}"/>
<input type="text" class="form-control" id="input_resource_notify_emails" name="resource_notify_emails_value" value="{{ resource.get_recipients('email')|join(',') }}"/>
</td>
</tr>

Expand Down Expand Up @@ -349,7 +349,7 @@ <h1 class="page-header">[{{ _('Edit') }}] <span id="resource_title_h1">{{ resour
var new_active = $('#input_resource_active').prop('checked');

// Collect recipients
var new_notify_emails = $('#input_resource_notify_emails').val().split(',');
var new_notify_emails = $('#input_resource_notify_emails').val().replace(' ','').split(',');
var new_notify_webhooks = [];

$('textarea[name="resource_notify_webhooks_value"]').each(function(idx, elm){
Expand Down

0 comments on commit 38be31c

Please sign in to comment.