|
| 1 | +<template> |
| 2 | + |
| 3 | + <div> |
| 4 | + <template v-if="reason === DeviceUnusableReason.NO_SUPERUSERS"> |
| 5 | + <p>{{ strings.noSuperusersNotice$() }}</p> |
| 6 | + <p>{{ strings.noSuperuserCallToAction$() }}</p> |
| 7 | + </template> |
| 8 | + <template v-else-if="reason === DeviceUnusableReason.SUPERUSERS_SOFT_DELETED"> |
| 9 | + <p> |
| 10 | + {{ strings.superusersSoftDeletedNotice$() }} |
| 11 | + </p> |
| 12 | + <p> |
| 13 | + {{ strings.superusersSoftDeletedCallToAction$() }} |
| 14 | + </p> |
| 15 | + </template> |
| 16 | + <p v-else>{{ strings.unknownIssueNotice$() }}</p> |
| 17 | + <KButton |
| 18 | + :disabled="taskLoading" |
| 19 | + style="margin-top: 16px" |
| 20 | + primary |
| 21 | + :text="strings.reinstallKolibriAction$()" |
| 22 | + @click="deprovision" |
| 23 | + /> |
| 24 | + </div> |
| 25 | + |
| 26 | +</template> |
| 27 | + |
| 28 | + |
| 29 | +<script> |
| 30 | +
|
| 31 | + import TaskResource from 'kolibri/apiResources/TaskResource'; |
| 32 | + import useTaskPolling from 'kolibri-common/composables/useTaskPolling'; |
| 33 | + import useSnackbar from 'kolibri/composables/useSnackbar'; |
| 34 | + import { TaskStatuses, TaskTypes } from 'kolibri-common/utils/syncTaskUtils'; |
| 35 | + import redirectBrowser from 'kolibri/utils/redirectBrowser'; |
| 36 | + import { createTranslator } from 'kolibri/utils/i18n'; |
| 37 | +
|
| 38 | + import { computed, ref, watch } from 'vue'; |
| 39 | + import { DeviceUnusableReason } from '../constants'; |
| 40 | +
|
| 41 | + const DEPROVISION_TASK_QUEUE = 'device_deprovision'; |
| 42 | +
|
| 43 | + const strings = createTranslator('DeviceUnusableStrings', { |
| 44 | + noSuperusersNotice: { |
| 45 | + message: 'This device is unusable because there are no superuser accounts on this device.', |
| 46 | + context: 'Notice that there are no superuser accounts on the device', |
| 47 | + }, |
| 48 | + noSuperuserCallToAction: { |
| 49 | + message: 'Please reinstall Kolibri to create a superuser account.', |
| 50 | + context: 'Call to action to reinstall Kolibri to create a superuser account', |
| 51 | + }, |
| 52 | + superusersSoftDeletedNotice: { |
| 53 | + message: |
| 54 | + 'This device is unusable because all superuser accounts on this device have been deleted on the server.', |
| 55 | + context: 'Notice that all superuser accounts have been deleted on the server', |
| 56 | + }, |
| 57 | + superusersSoftDeletedCallToAction: { |
| 58 | + message: |
| 59 | + 'Please contact your system administrator to restore your account or reinstall Kolibri to create a new superuser account.', |
| 60 | + context: |
| 61 | + 'Call to action to contact system administrator or reinstall Kolibri to create a new superuser account', |
| 62 | + }, |
| 63 | + unknownIssueNotice: { |
| 64 | + message: 'This device is unusable due to an unknown reason. Please contact support.', |
| 65 | + context: 'Notice that the device is unusable due to an unknown reason', |
| 66 | + }, |
| 67 | + reinstallKolibriAction: { |
| 68 | + message: 'Reinstall Kolibri', |
| 69 | + context: 'Button text to reinstall Kolibri', |
| 70 | + }, |
| 71 | + deprovisioningError: { |
| 72 | + message: 'An error occurred while trying to reinstall Kolibri. Please try again.', |
| 73 | + context: 'Error message when there is an error deprovisioning the device', |
| 74 | + }, |
| 75 | + }); |
| 76 | +
|
| 77 | + export default { |
| 78 | + name: 'DeviceUnusableMessage', |
| 79 | + setup() { |
| 80 | + const taskLoading = ref(false); |
| 81 | + const { tasks } = useTaskPolling(DEPROVISION_TASK_QUEUE); |
| 82 | + const { createSnackbar } = useSnackbar(); |
| 83 | + const deprovisionTask = computed(() => tasks.value[tasks.value.length - 1]); |
| 84 | +
|
| 85 | + const deprovision = async () => { |
| 86 | + try { |
| 87 | + taskLoading.value = true; |
| 88 | + await TaskResource.startTask({ |
| 89 | + type: TaskTypes.DEPROVISIONDEVICE, |
| 90 | + }); |
| 91 | + } catch (e) { |
| 92 | + createSnackbar(strings.deprovisioningError$()); |
| 93 | + } |
| 94 | + }; |
| 95 | +
|
| 96 | + const clearTasks = async () => { |
| 97 | + try { |
| 98 | + await TaskResource.clearAll(DEPROVISION_TASK_QUEUE); |
| 99 | + } catch (e) { |
| 100 | + return; |
| 101 | + } |
| 102 | + }; |
| 103 | +
|
| 104 | + watch(deprovisionTask, task => { |
| 105 | + if (!task) return; |
| 106 | + taskLoading.value = true; |
| 107 | + if (task.status === TaskStatuses.FAILED) { |
| 108 | + taskLoading.value = false; |
| 109 | + createSnackbar(strings.deprovisioningError$()); |
| 110 | + clearTasks(); |
| 111 | + return; |
| 112 | + } |
| 113 | + if (task.status === TaskStatuses.COMPLETED) { |
| 114 | + clearTasks(); |
| 115 | + redirectBrowser(); |
| 116 | + } |
| 117 | + }); |
| 118 | +
|
| 119 | + return { |
| 120 | + strings, |
| 121 | + taskLoading, |
| 122 | + DeviceUnusableReason, |
| 123 | + deprovision, |
| 124 | + }; |
| 125 | + }, |
| 126 | + props: { |
| 127 | + reason: { |
| 128 | + type: String, |
| 129 | + required: true, |
| 130 | + validator: value => Object.values(DeviceUnusableReason).includes(value), |
| 131 | + }, |
| 132 | + }, |
| 133 | + }; |
| 134 | +
|
| 135 | +</script> |
0 commit comments