From 62865856e4055c7d4b1bc40c02d00c4e17969a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Redrejo?= Date: Thu, 18 Apr 2024 21:20:29 +0200 Subject: [PATCH] Avoid facilities that have been setup 'on my own' to be importable in the setup wizard --- .../SelectDeviceModalGroup/SelectDeviceForm.vue | 13 ++++++++++++- .../src/views/sync/SelectDeviceModalGroup/index.vue | 6 ++++++ .../views/sync/SelectDeviceModalGroup/useDevices.js | 11 ++++++++++- kolibri/core/auth/serializers.py | 7 +++++++ .../onboarding-forms/SetUpLearningFacilityForm.vue | 2 ++ 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/SelectDeviceForm.vue b/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/SelectDeviceForm.vue index 4c94ab43d4f..1fe5d7cdfec 100644 --- a/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/SelectDeviceForm.vue +++ b/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/SelectDeviceForm.vue @@ -163,12 +163,17 @@ deviceFilters.push(useDeviceChannelFilter({ id: props.filterByChannelId })); } - if (props.filterByFacilityId !== null || props.filterByFacilityCanSignUp !== null) { + if ( + props.filterByFacilityId !== null || + props.filterByFacilityCanSignUp !== null || + props.filterByOnMyOwnFacility !== null + ) { apiParams.subset_of_users_device = false; deviceFilters.push( useDeviceFacilityFilter({ id: props.filterByFacilityId, learner_can_sign_up: props.filterByFacilityCanSignUp, + on_my_own_setup: props.filterByOnMyOwnFacility, }) ); } @@ -243,6 +248,12 @@ type: Boolean, default: null, }, + // In the setup wizard, to exclude importiing facilities that are "On My Own" + // eslint-disable-next-line kolibri/vue-no-unused-properties + filterByOnMyOwnFacility: { + type: Boolean, + default: null, + }, // If an ID is provided, that device's radio button will be automatically selected selectedId: { type: String, diff --git a/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/index.vue b/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/index.vue index 1e95101db3a..8ac5d1f0731 100644 --- a/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/index.vue +++ b/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/index.vue @@ -12,6 +12,7 @@ :filterByFacilityId="filterByFacilityId" :filterLODAvailable="filterLODAvailable" :filterByFacilityCanSignUp="filterByFacilityCanSignUp" + :filterByOnMyOwnFacility="filterByOnMyOwnFacility" :selectedId="addedAddressId" :formDisabled="$attrs.selectAddressDisabled" @click_add_address="goToAddAddress" @@ -55,6 +56,11 @@ type: Boolean, default: null, }, + // When looking for facilities to import in the setup wizard + filterByOnMyOwnFacility: { + type: Boolean, + default: null, + }, }, data() { return { diff --git a/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/useDevices.js b/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/useDevices.js index 14ff55cc022..70842579cb3 100644 --- a/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/useDevices.js +++ b/kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/useDevices.js @@ -172,9 +172,14 @@ function useAsyncDeviceFilter(filterFunction) { * Produces a function that resolves with a boolean for a device that has the specified facility * @param {string|null} [id] * @param {bool|null} [learner_can_sign_up] + * @param {bool|null} [on_my_own_setup] * @return {function(NetworkLocation): Promise} */ -export function useDeviceFacilityFilter({ id = null, learner_can_sign_up = null }) { +export function useDeviceFacilityFilter({ + id = null, + learner_can_sign_up = null, + on_my_own_setup = null, +}) { const filters = {}; // If `id` is an empty string, we don't want to filter by that @@ -186,6 +191,10 @@ export function useDeviceFacilityFilter({ id = null, learner_can_sign_up = null filters.learner_can_sign_up = learner_can_sign_up; } + if (on_my_own_setup !== null) { + filters.on_my_own_setup = on_my_own_setup; + } + if (Object.keys(filters).length === 0) { return () => Promise.resolve(true); } diff --git a/kolibri/core/auth/serializers.py b/kolibri/core/auth/serializers.py index eae42791e4d..26918467f27 100644 --- a/kolibri/core/auth/serializers.py +++ b/kolibri/core/auth/serializers.py @@ -170,6 +170,7 @@ class Meta: class PublicFacilitySerializer(serializers.ModelSerializer): learner_can_login_with_no_password = serializers.SerializerMethodField() learner_can_sign_up = serializers.SerializerMethodField() + on_my_own_setup = serializers.SerializerMethodField() def get_learner_can_login_with_no_password(self, instance): return instance.dataset.learner_can_login_with_no_password @@ -177,6 +178,11 @@ def get_learner_can_login_with_no_password(self, instance): def get_learner_can_sign_up(self, instance): return instance.dataset.learner_can_sign_up + def get_on_my_own_setup(self, instance): + if instance.dataset.extra_fields is not None: + return instance.dataset.extra_fields.get("on_my_own_setup", False) + return False + class Meta: model = Facility fields = ( @@ -185,6 +191,7 @@ class Meta: "name", "learner_can_login_with_no_password", "learner_can_sign_up", + "on_my_own_setup", ) diff --git a/kolibri/plugins/setup_wizard/assets/src/views/onboarding-forms/SetUpLearningFacilityForm.vue b/kolibri/plugins/setup_wizard/assets/src/views/onboarding-forms/SetUpLearningFacilityForm.vue index d8c59ef38af..882d9cde080 100644 --- a/kolibri/plugins/setup_wizard/assets/src/views/onboarding-forms/SetUpLearningFacilityForm.vue +++ b/kolibri/plugins/setup_wizard/assets/src/views/onboarding-forms/SetUpLearningFacilityForm.vue @@ -19,6 +19,8 @@ />