mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-14 23:08:07 -04:00
Update email_from when the service name is changed.
Update unit tests Service name is uniqueness is not based on case.
This commit is contained in:
@@ -180,7 +180,7 @@ class ServiceNameForm(Form):
|
||||
])
|
||||
|
||||
def validate_name(self, a):
|
||||
if a.data in self._names_func():
|
||||
if a.data.lower() in self._names_func():
|
||||
raise ValidationError('This service name is already in use')
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ from notifications_python_client import HTTPError
|
||||
|
||||
from app import service_api_client
|
||||
from app.main import main
|
||||
from app.utils import user_has_permissions
|
||||
from app.utils import user_has_permissions, email_safe
|
||||
from app.main.forms import ConfirmPasswordForm, ServiceNameForm
|
||||
from app import user_api_client
|
||||
|
||||
@@ -65,6 +65,7 @@ def service_name_change_confirm(service_id):
|
||||
|
||||
if form.validate_on_submit():
|
||||
service['name'] = session['service_name_change']
|
||||
service['email_from'] = email_safe(session['service_name_change'])
|
||||
try:
|
||||
service_api_client.update_service(
|
||||
service['id'],
|
||||
@@ -72,7 +73,8 @@ def service_name_change_confirm(service_id):
|
||||
service['active'],
|
||||
service['limit'],
|
||||
service['restricted'],
|
||||
service['users'])
|
||||
service['users'],
|
||||
service['email_from'])
|
||||
except HTTPError as e:
|
||||
error_msg = "Duplicate service name '{}'".format(session['service_name_change'])
|
||||
if e.status_code == 400 and error_msg in e.message['name']:
|
||||
@@ -144,7 +146,8 @@ def service_status_change_confirm(service_id):
|
||||
service['active'],
|
||||
service['limit'],
|
||||
service['restricted'],
|
||||
service['users'])
|
||||
service['users'],
|
||||
service['email_from'])
|
||||
return redirect(url_for('.service_settings', service_id=service_id))
|
||||
return render_template(
|
||||
'views/service-settings/confirm.html',
|
||||
|
||||
@@ -57,7 +57,8 @@ class ServiceAPIClient(NotificationsAPIClient):
|
||||
active,
|
||||
limit,
|
||||
restricted,
|
||||
users):
|
||||
users,
|
||||
email_from):
|
||||
"""
|
||||
Update a service.
|
||||
"""
|
||||
@@ -67,7 +68,8 @@ class ServiceAPIClient(NotificationsAPIClient):
|
||||
"active": active,
|
||||
"limit": limit,
|
||||
"restricted": restricted,
|
||||
"users": users
|
||||
"users": users,
|
||||
"email_from": email_from
|
||||
}
|
||||
endpoint = "/service/{0}".format(service_id)
|
||||
return self.post(endpoint, data)
|
||||
@@ -142,7 +144,7 @@ class ServiceAPIClient(NotificationsAPIClient):
|
||||
|
||||
def find_all_service_names(self, user_id=None):
|
||||
resp = self.get_services(user_id)
|
||||
return [x['name'] for x in resp['data']]
|
||||
return [x['name'].lower() for x in resp['data']]
|
||||
|
||||
|
||||
class ServicesBrowsableItem(BrowsableItem):
|
||||
|
||||
@@ -101,3 +101,9 @@ def generate_previous_next_dict(view, view_dict, page, title, label):
|
||||
'title': title,
|
||||
'label': label
|
||||
}
|
||||
|
||||
|
||||
def email_safe(string):
|
||||
return "".join([
|
||||
character.lower() if character.isalnum() or character == "." else "" for character in re.sub("\s+", ".", string.strip()) # noqa
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user