Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture more errors from the backend and show error messages for them #11807

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion kolibri/plugins/setup_wizard/api.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
:disabled="formSubmitted"
:label="coreString('usernameLabel')"
:autofocus="$attrs.autofocus"
@blur="blurred = true"
:invalid="Boolean(invalidText)"
:invalidText="invalidText"
@blur="shouldValidate = true"
/>
<PasswordTextbox
v-if="!facility.learner_can_login_with_no_password"
Expand Down Expand Up @@ -79,7 +81,9 @@
v-model.trim="adminUsername"
:label="coreString('usernameLabel')"
:autofocus="$attrs.autofocus"
@blur="blurred = true"
:invalid="Boolean(invalidText)"
:invalidText="invalidText"
@blur="shouldValidate = true"
/>
<PasswordTextbox
ref="adminPasswordTextbox"
Expand Down Expand Up @@ -135,6 +139,7 @@
facilities: [],
selectedFacilityId: 'selectedFacilityId',
formSubmitted: false,
shouldValidate: false,
};
},
inject: ['wizardService'],
Expand Down Expand Up @@ -191,6 +196,18 @@
adminModalMessage() {
return this.$tr('enterAdminCredentials', { facility: this.facility.name });
},
invalidText() {
if (!this.shouldValidate) {
return '';
}
if (
!this.useAdmin & (this.username.trim() === '') ||
this.useAdmin & (this.adminUsername === null || this.adminUsername.trim() === '')
) {
return this.coreString('requiredFieldError');
}
return '';
},
},
beforeMount() {
this.fetchNetworkLocation(this.deviceId).then(() => {
Expand Down Expand Up @@ -225,12 +242,23 @@
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() {
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';
const password = this.password === '' ? DemographicConstants.NOT_SPECIFIED : this.password;
Expand Down Expand Up @@ -314,6 +342,11 @@
this.handleSubmit();
},
moveAdmin() {
this.shouldValidate = true;
if (this.invalidText) {
this.$refs.adminUsernameTextbox.focus();
return;
}
const params = {
baseurl: this.device.baseurl,
username: this.adminUsername,
Expand All @@ -337,6 +370,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;
Expand Down
Loading