Skip to content

Commit

Permalink
Avoid facilities that have been setup 'on my own' to be importable in…
Browse files Browse the repository at this point in the history
… the setup wizard
  • Loading branch information
José Redrejo committed Apr 18, 2024
1 parent 120e625 commit 6286585
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
);
}
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
:filterByFacilityId="filterByFacilityId"
:filterLODAvailable="filterLODAvailable"
:filterByFacilityCanSignUp="filterByFacilityCanSignUp"
:filterByOnMyOwnFacility="filterByOnMyOwnFacility"
:selectedId="addedAddressId"
:formDisabled="$attrs.selectAddressDisabled"
@click_add_address="goToAddAddress"
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>}
*/
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
Expand All @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions kolibri/core/auth/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,19 @@ 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

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 = (
Expand All @@ -185,6 +191,7 @@ class Meta:
"name",
"learner_can_login_with_no_password",
"learner_can_sign_up",
"on_my_own_setup",
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
/>
<SelectDeviceModalGroup
v-if="showSelectAddressModal"
:filterByFacilityCanSignUp="true"
:filterByOnMyOwnFacility="false"
@cancel="showSelectAddressModal = false"
@submit="handleContinueImport"
/>
Expand Down

0 comments on commit 6286585

Please sign in to comment.