From 4b9a0d8cf84e85e8b93092818b52c7fb859b310b Mon Sep 17 00:00:00 2001 From: Walter Doekes Date: Fri, 25 Sep 2020 10:59:27 +0200 Subject: [PATCH] user/create/update: Fix password error reporting Fixed these: - When changing a user password, if the password requirements had LFs in them, they would not be shown. - When changing a password and the requirements were not met, the window was closed. - When creating a user and the password does not meet requirements, it would simply say "Unable to create user." and close the window. - When checking the logs, these errors would be not be shown. Change-Id: I6a97b7af581c9bcb301fd7f023c203df33e44e62 --- .../dashboards/identity/users/forms.py | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/openstack_dashboard/dashboards/identity/users/forms.py b/openstack_dashboard/dashboards/identity/users/forms.py index 8e794a4e3d..86f8035629 100644 --- a/openstack_dashboard/dashboards/identity/users/forms.py +++ b/openstack_dashboard/dashboards/identity/users/forms.py @@ -218,8 +218,26 @@ def handle(self, request, data): except exceptions.Conflict: msg = _('User name "%s" is already used.') % data['name'] messages.error(request, msg) - except Exception: - exceptions.handle(request, _('Unable to create user.')) + return False + except Exception as exc: + LOG.warn('Creating user failed: %s', exc) + response = exceptions.handle(request, ignore=True) + match = re.match((r'The password does not match the ' + r'requirements:(.*?) [(]HTTP 400[)]'), str(exc), + re.UNICODE | re.DOTALL) + if match: + info = match.group(1) + messages.error(request, _('The password does not match the ' + 'requirements: %s') % info) + return False + else: + messages.error(request, + _('Unable to create user.')) + + if isinstance(response, http.HttpResponse): + return response + else: + return True class UpdateUserForm(BaseUserForm, AddExtraColumnMixIn): @@ -287,7 +305,8 @@ def handle(self, request, data): msg = _('User name "%s" is already used.') % data['name'] messages.error(request, msg) return False - except Exception: + except Exception as exc: + LOG.warn('Updating user failed: %s', exc) response = exceptions.handle(request, ignore=True) messages.error(request, _('Unable to update the user.')) @@ -343,14 +362,16 @@ def handle(self, request, data): messages.success(request, _('User password has been updated successfully.')) except Exception as exc: + LOG.warn('Updating password failed: %s', exc) response = exceptions.handle(request, ignore=True) match = re.match((r'The password does not match the ' r'requirements:(.*?) [(]HTTP 400[)]'), str(exc), - re.UNICODE | re.MULTILINE) + re.UNICODE | re.DOTALL) if match: info = match.group(1) messages.error(request, _('The password does not match the ' 'requirements: %s') % info) + return False else: messages.error(request, _('Unable to update the user password.'))