Don’t error if organisation name is unchanged

If you submit the rename organisation form without making any changes
you will get an error saying that the name is currently in use. This is
true because it’s being used by the current organisation.

However your intention is probably not to actually change anything, so
we can just redirect back to the settings page.

This is the same thing we do when renaming services:
60f5b74904/app/main/views/service_settings.py (L99-L100)
This commit is contained in:
Chris Hill-Scott
2022-01-11 14:17:39 +00:00
parent ef3b092831
commit d4ec4bf9f4
2 changed files with 23 additions and 0 deletions

View File

@@ -329,6 +329,10 @@ def edit_organisation_name(org_id):
form.name.data = current_organisation.name
if form.validate_on_submit():
if form.name.data == current_organisation.name:
return redirect(url_for('.organisation_settings', org_id=current_organisation.id))
unique_name = organisations_client.is_organisation_name_unique(org_id, form.name.data)
if not unique_name:
form.name.errors.append("This organisation name is already in use")

View File

@@ -1315,6 +1315,25 @@ def test_confirm_update_organisation_with_incorrect_password(
) == 'Error: Invalid password'
def test_confirm_update_organisation_with_existing_name(
client_request,
platform_admin_user,
fake_uuid,
mock_get_organisation,
):
client_request.login(platform_admin_user)
client_request.post(
'.edit_organisation_name',
org_id=fake_uuid,
_data={'name': 'Test organisation'},
_expected_redirect=url_for(
'.organisation_settings',
org_id=fake_uuid,
_external=True,
)
)
def test_confirm_update_organisation_with_name_already_in_use(
client_request,
platform_admin_user,