From 208586869a58a38461e372c647ce97f31def2570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Redrejo?= Date: Fri, 26 Jan 2024 17:27:28 +0100 Subject: [PATCH 1/2] Capture more errors from the backend and show error messages for them --- kolibri/plugins/setup_wizard/api.py | 8 +++- .../src/views/ImportIndividualUserForm.vue | 38 ++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/kolibri/plugins/setup_wizard/api.py b/kolibri/plugins/setup_wizard/api.py index 196f766497b..35c88bf21cb 100644 --- a/kolibri/plugins/setup_wizard/api.py +++ b/kolibri/plugins/setup_wizard/api.py @@ -1,6 +1,7 @@ import requests from django.urls import reverse from rest_framework import decorators +from rest_framework.exceptions import AuthenticationFailed from rest_framework.exceptions import NotFound from rest_framework.exceptions import PermissionDenied from rest_framework.exceptions import ValidationError @@ -154,7 +155,12 @@ def listfacilitylearners(self, request): baseurl = request.data.get("baseurl") password = request.data.get("password") username = request.data.get("username") - facility_info = get_remote_users_info(baseurl, facility_id, username, password) + try: + facility_info = get_remote_users_info( + baseurl, facility_id, username, password + ) + except AuthenticationFailed: + raise PermissionDenied() user_info = facility_info["user"] roles = user_info["roles"] admin_roles = (user_kinds.ADMIN, user_kinds.SUPERUSER) diff --git a/kolibri/plugins/setup_wizard/assets/src/views/ImportIndividualUserForm.vue b/kolibri/plugins/setup_wizard/assets/src/views/ImportIndividualUserForm.vue index 36ffa3f2e68..8f23ae4261c 100644 --- a/kolibri/plugins/setup_wizard/assets/src/views/ImportIndividualUserForm.vue +++ b/kolibri/plugins/setup_wizard/assets/src/views/ImportIndividualUserForm.vue @@ -32,7 +32,9 @@ :disabled="formSubmitted" :label="coreString('usernameLabel')" :autofocus="$attrs.autofocus" - @blur="blurred = true" + :invalid="Boolean(invalidText)" + :invalidText="invalidText" + @blur="shouldValidate = true" /> { @@ -225,12 +242,21 @@ this.useAdmin = false; }, openAdminCredentialsForm() { + // clean error from non-admin form: + this.shouldValidate = false; + this.error = false; + this.useAdmin = true; this.$nextTick(function() { this.$refs.adminUsernameTextbox.focus(); }); }, handleSubmit() { + this.shouldValidate = true; + if (this.invalidText) { + this.$refs.usernameTextbox.focus(); + return; + } this.formSubmitted = true; const task_name = 'kolibri.core.auth.tasks.peeruserimport'; const password = this.password === '' ? DemographicConstants.NOT_SPECIFIED : this.password; @@ -314,6 +340,11 @@ this.handleSubmit(); }, moveAdmin() { + this.shouldValidate = true; + if (this.invalidText) { + this.$refs.adminUsernameTextbox.focus(); + return; + } const params = { baseurl: this.device.baseurl, username: this.adminUsername, @@ -337,6 +368,9 @@ ERROR_CONSTANTS.INVALID_CREDENTIALS, ERROR_CONSTANTS.AUTHENTICATION_FAILED, ERROR_CONSTANTS.PERMISSION_DENIED, + ERROR_CONSTANTS.MISSING_PASSWORD, + ERROR_CONSTANTS.PASSWORD_NOT_SPECIFIED, + ERROR_CONSTANTS.INVALID_USERNAME, ]); if (errorsCaught) { this.error = true; From 5b47241ad2c6fb0334239335411dbbb7f308c674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Redrejo?= Date: Mon, 29 Jan 2024 20:52:13 +0100 Subject: [PATCH 2/2] Force validation only if there are not imported users --- .../assets/src/views/ImportIndividualUserForm.vue | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kolibri/plugins/setup_wizard/assets/src/views/ImportIndividualUserForm.vue b/kolibri/plugins/setup_wizard/assets/src/views/ImportIndividualUserForm.vue index 8f23ae4261c..b2b2aa79695 100644 --- a/kolibri/plugins/setup_wizard/assets/src/views/ImportIndividualUserForm.vue +++ b/kolibri/plugins/setup_wizard/assets/src/views/ImportIndividualUserForm.vue @@ -252,10 +252,12 @@ }); }, handleSubmit() { - this.shouldValidate = true; - if (this.invalidText) { - this.$refs.usernameTextbox.focus(); - return; + if (this.wizardService.state.context.importedUsers.length === 0) { + this.shouldValidate = true; + if (this.invalidText) { + this.$refs.usernameTextbox.focus(); + return; + } } this.formSubmitted = true; const task_name = 'kolibri.core.auth.tasks.peeruserimport';