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

Do a correct check to know if the facility has been imported #12077

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to filter by this? We should be able to import facilities even if they don't allow sign up, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, it was a unneeded code I left when testing it, but deleted it in another commit a few seconds after this one. If you look at the complete PR code this line is not there 😉

:filterByOnMyOwnFacility="false"
@cancel="showSelectAddressModal = false"
@submit="handleContinueImport"
/>
Expand Down
Loading