From d4ec4bf9f480506adcccd32f0e709c2b40f6cb04 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 11 Jan 2022 14:17:39 +0000 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20error=20if=20organisation=20nam?= =?UTF-8?q?e=20is=20unchanged?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/alphagov/notifications-admin/blob/60f5b7490412406695d535060e13bc6184d901df/app/main/views/service_settings.py#L99-L100 --- app/main/views/organisations.py | 4 ++++ .../views/organisations/test_organisations.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/app/main/views/organisations.py b/app/main/views/organisations.py index 5e6aef6bb..ac88afe37 100644 --- a/app/main/views/organisations.py +++ b/app/main/views/organisations.py @@ -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") diff --git a/tests/app/main/views/organisations/test_organisations.py b/tests/app/main/views/organisations/test_organisations.py index 63c80c84f..fd3ee85c8 100644 --- a/tests/app/main/views/organisations/test_organisations.py +++ b/tests/app/main/views/organisations/test_organisations.py @@ -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,