mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-06-28 19:31:00 -04:00
Change name of the form and form field for consistency
Following PR review. Also update function name for update name of security key in user api client to be more specific.
This commit is contained in:
@@ -2506,8 +2506,8 @@ class BroadcastAreaFormWithSelectAll(BroadcastAreaForm):
|
||||
return self.areas.data
|
||||
|
||||
|
||||
class ChangeNameOfSecurityKey(StripWhitespaceForm):
|
||||
name_of_key = GovukTextInputField(
|
||||
class ChangeSecurityKeyNameForm(StripWhitespaceForm):
|
||||
security_key_name = GovukTextInputField(
|
||||
'Name of key',
|
||||
validators=[
|
||||
DataRequired(message='Cannot be empty'),
|
||||
|
||||
@@ -20,8 +20,8 @@ from app.main.forms import (
|
||||
ChangeEmailForm,
|
||||
ChangeMobileNumberForm,
|
||||
ChangeNameForm,
|
||||
ChangeNameOfSecurityKey,
|
||||
ChangePasswordForm,
|
||||
ChangeSecurityKeyNameForm,
|
||||
ConfirmPasswordForm,
|
||||
ServiceOnOffSettingForm,
|
||||
TwoFactorForm,
|
||||
@@ -261,14 +261,14 @@ def user_profile_manage_security_key(key_id):
|
||||
if not security_key:
|
||||
abort(404)
|
||||
|
||||
form = ChangeNameOfSecurityKey(name_of_key=security_key["name"])
|
||||
form = ChangeSecurityKeyNameForm(security_key_name=security_key["name"])
|
||||
|
||||
if form.validate_on_submit():
|
||||
if form.name_of_key.data != security_key["name"]:
|
||||
user_api_client.update_webauthn_credential_for_user(
|
||||
if form.security_key_name.data != security_key["name"]:
|
||||
user_api_client.update_webauthn_credential_name_for_user(
|
||||
user_id=current_user.id,
|
||||
credential_id=key_id,
|
||||
new_name_for_credential=form.name_of_key.data
|
||||
new_name_for_credential=form.security_key_name.data
|
||||
)
|
||||
return redirect(url_for('.user_profile_security_keys'))
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ class UserApiClient(NotifyAdminAPIClient):
|
||||
|
||||
return self.post(endpoint, data=credential.serialize())
|
||||
|
||||
def update_webauthn_credential_for_user(self, *, user_id, credential_id, new_name_for_credential):
|
||||
def update_webauthn_credential_name_for_user(self, *, user_id, credential_id, new_name_for_credential):
|
||||
endpoint = f'/user/{user_id}/webauthn/{credential_id}'
|
||||
|
||||
return self.post(endpoint, data={"name": new_name_for_credential})
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<div class="govuk-grid-row">
|
||||
<div class="govuk-grid-column-three-quarters">
|
||||
{% call form_wrapper(autocomplete=True) %}
|
||||
{{ form.name_of_key }}
|
||||
{{ form.security_key_name }}
|
||||
{{ page_footer(
|
||||
'Save',
|
||||
delete_link=url_for(
|
||||
|
||||
@@ -401,7 +401,7 @@ def test_should_show_manage_security_key_page(
|
||||
assert page.select_one('.govuk-back-link').text.strip() == 'Back'
|
||||
assert page.select_one('.govuk-back-link')['href'] == url_for('.user_profile_security_keys')
|
||||
|
||||
assert page.select_one('#name_of_key')["value"] == webauthn_credential["name"]
|
||||
assert page.select_one('#security_key_name')["value"] == webauthn_credential["name"]
|
||||
|
||||
|
||||
def test_manage_security_key_page_404s_when_key_not_found(
|
||||
@@ -464,14 +464,14 @@ def test_should_redirect_after_change_of_security_key_name(
|
||||
)
|
||||
|
||||
mock_update = mocker.patch(
|
||||
'app.user_api_client.update_webauthn_credential_for_user',
|
||||
'app.user_api_client.update_webauthn_credential_name_for_user',
|
||||
return_value=[webauthn_credential],
|
||||
)
|
||||
|
||||
client_request.post(
|
||||
'main.user_profile_manage_security_key',
|
||||
key_id=webauthn_credential['id'],
|
||||
_data={'name_of_key': "new name"},
|
||||
_data={'security_key_name': "new name"},
|
||||
_expected_status=302,
|
||||
_expected_redirect=url_for(
|
||||
'main.user_profile_security_keys',
|
||||
@@ -501,14 +501,14 @@ def test_user_profile_manage_security_key_should_not_call_api_if_key_name_stays_
|
||||
)
|
||||
|
||||
mock_update = mocker.patch(
|
||||
'app.user_api_client.update_webauthn_credential_for_user',
|
||||
'app.user_api_client.update_webauthn_credential_name_for_user',
|
||||
return_value=[webauthn_credential],
|
||||
)
|
||||
|
||||
client_request.post(
|
||||
'main.user_profile_manage_security_key',
|
||||
key_id=webauthn_credential['id'],
|
||||
_data={'name_of_key': webauthn_credential['name']},
|
||||
_data={'security_key_name': webauthn_credential['name']},
|
||||
_expected_status=302,
|
||||
_expected_redirect=url_for(
|
||||
'main.user_profile_security_keys',
|
||||
|
||||
Reference in New Issue
Block a user