Skip to content

Commit 236f654

Browse files
committed
Handle user import errors in setup wizard plugin
1 parent 6798dd5 commit 236f654

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

kolibri/plugins/setup_wizard/assets/src/views/ImportMultipleUsers.vue

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
:step="step"
66
:steps="steps"
77
:showBackArrow="true"
8+
:backArrowDisabled="learnersBeingImported.length > 0"
89
:eventOnGoBack="backArrowEvent"
910
:title="selectAUser$()"
1011
:description="facilityDescription"
@@ -52,6 +53,7 @@
5253
<template #buttons>
5354
<div></div>
5455
</template>
56+
<GlobalSnackbar />
5557
</OnboardingStepBase>
5658

5759
</template>
@@ -65,8 +67,10 @@
6567
import PaginatedListContainer from 'kolibri-common/components/PaginatedListContainer';
6668
import { lodUsersManagementStrings } from 'kolibri-common/strings/lodUsersManagementStrings';
6769
import { DemographicConstants } from 'kolibri/constants';
68-
import { TaskStatuses } from 'kolibri-common/utils/syncTaskUtils';
70+
import { TaskStatuses, TaskTypes } from 'kolibri-common/utils/syncTaskUtils';
6971
import UserTable from 'kolibri-common/components/UserTable';
72+
import useSnackbar from 'kolibri/composables/useSnackbar';
73+
import GlobalSnackbar from 'kolibri/components/GlobalSnackbar';
7074
import { FooterMessageTypes, SoudQueue } from '../constants';
7175
import OnboardingStepBase from './OnboardingStepBase';
7276
@@ -85,14 +89,19 @@
8589
OnboardingStepBase,
8690
PaginatedListContainer,
8791
UserTable,
92+
GlobalSnackbar,
8893
},
8994
mixins: [commonCoreStrings, commonSyncElements],
9095
setup() {
91-
const { selectAUser$, importedLabel$ } = lodUsersManagementStrings;
96+
const { selectAUser$, importedLabel$, importUserError$ } = lodUsersManagementStrings;
97+
const { createSnackbar } = useSnackbar();
9298
9399
return {
100+
createSnackbar,
101+
94102
selectAUser$,
95103
importedLabel$,
104+
importUserError$,
96105
};
97106
},
98107
data() {
@@ -151,6 +160,9 @@
151160
beforeMount() {
152161
this.isPolling = true;
153162
this.pollImportTask();
163+
this.learnersBeingImported = this.wizardService.state.context.usersBeingImported.map(
164+
u => u.id,
165+
);
154166
},
155167
methods: {
156168
importedLearners() {
@@ -159,14 +171,20 @@
159171
pollImportTask() {
160172
TaskResource.list({ queue: SoudQueue }).then(tasks => {
161173
if (tasks.length) {
174+
let isFailingTasks = false;
162175
tasks.forEach(task => {
163-
if (task.status === TaskStatuses.COMPLETED) {
164-
// Remove completed user id from 'being imported'
176+
if ([TaskStatuses.COMPLETED, TaskStatuses.FAILED].includes(task.status)) {
177+
// Remove completed/failed user id from 'being imported'
165178
const taskUserId = task.extra_metadata.user_id;
166179
this.learnersBeingImported = this.learnersBeingImported.filter(
167180
id => id != taskUserId,
168181
);
169-
182+
this.wizardService.send({
183+
type: 'REMOVE_USER_BEING_IMPORTED',
184+
value: taskUserId,
185+
});
186+
}
187+
if (task.status === TaskStatuses.COMPLETED) {
170188
// Update the wizard context to know this user has been imported - only if they
171189
// haven't already been added to the list (ie, imported by other means)
172190
const taskUsername = task.extra_metadata.username;
@@ -186,8 +204,14 @@
186204
value: taskUsername,
187205
});
188206
}
207+
} else if (task.status === TaskStatuses.FAILED) {
208+
isFailingTasks = true;
189209
}
190210
});
211+
if (isFailingTasks) {
212+
this.createSnackbar(this.importUserError$());
213+
TaskResource.clearAll(SoudQueue);
214+
}
191215
}
192216
});
193217
if (this.isPolling) {
@@ -196,11 +220,11 @@
196220
}, 2000);
197221
}
198222
},
199-
startImport(learner) {
223+
async startImport(learner) {
200224
// Push the learner into being imported, we'll remove it if we get an error later on
201225
this.learnersBeingImported.push(learner.id);
202226
203-
const task_name = 'kolibri.core.auth.tasks.peeruserimport';
227+
const task_name = TaskTypes.IMPORTLODUSER;
204228
const params = {
205229
type: task_name,
206230
...this.wizardService.state.context.remoteAdmin,
@@ -216,9 +240,21 @@
216240
value: { username: learner.username, password: DemographicConstants.NOT_SPECIFIED },
217241
});
218242
}
219-
TaskResource.startTask(params).catch(() => {
243+
try {
244+
const newTask = await TaskResource.startTask(params);
245+
this.wizardService.send({
246+
type: 'ADD_USER_BEING_IMPORTED',
247+
value: {
248+
id: learner.id,
249+
full_name: learner.full_name,
250+
username: learner.username,
251+
taskId: newTask.id,
252+
},
253+
});
254+
} catch (error) {
255+
this.createSnackbar(this.importUserError$());
220256
this.learnersBeingImported = this.learnersBeingImported.filter(id => id != learner.id);
221-
});
257+
}
222258
},
223259
isImported(learner) {
224260
return this.importedLearners().find(u => u === learner.username);

kolibri/plugins/setup_wizard/assets/src/views/OnboardingStepBase.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
v-if="showBackArrow"
6868
icon="back"
6969
style="margin-left: -12px"
70+
:disabled="backArrowDisabled"
7071
@click="wizardService.send(eventOnGoBack)"
7172
/>
7273

@@ -188,6 +189,10 @@
188189
type: Boolean,
189190
default: false,
190191
},
192+
backArrowDisabled: {
193+
type: Boolean,
194+
default: false,
195+
},
191196
noBackAction: {
192197
type: Boolean,
193198
default: false,

0 commit comments

Comments
 (0)