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 all commits
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 @@ -41,6 +41,8 @@
import WelcomeModal from './WelcomeModal';
import PermissionsChangeModal from './PermissionsChangeModal';

const facilityImported = 'FACILITY_IS_IMPORTED';

const Steps = Object.freeze({
WELCOME: 'WELCOME',
PERMISSIONS_CHANGE: 'PERMISSIONS_CHANGE',
Expand Down Expand Up @@ -70,12 +72,9 @@
},
computed: {
...mapGetters(['isUserLoggedIn']),
// Assume that if first facility has non-null 'last_successful_sync'
// field, then it was imported in Setup Wizard.
// This used to determine Select Source workflow to enter into
importedFacility() {
const [facility] = this.$store.state.core.facilities;
if (facility && facility.last_successful_sync !== null) {
if (facility && window.sessionStorage.getItem(facilityImported) === 'true') {
return facility;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const initialContext = {
importedUsers: [],
firstImportedLodUser: null,
facilitiesOnDeviceCount: null,
isImportedFacility: false,
};

export const wizardMachine = createMachine(
Expand Down Expand Up @@ -307,6 +308,7 @@ export const wizardMachine = createMachine(
on: {
BACK: 'selectSuperAdminAccountForm',
},
exit: 'setImportedFacility',
},
},
// Listener on the importFacility state; typically this would be above `states` but
Expand Down Expand Up @@ -537,6 +539,11 @@ export const wizardMachine = createMachine(
* This effectively resets the machine's state
*/
resetContext: assign(initialContext),
setImportedFacility: assign({
isImportedFacility: () => {
return true;
},
}),
},
guards: {
// Functions used to return a true/false value. When the functions are called, they are passed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,17 @@
},
resetFormAndRefocus() {
this.shouldValidate = false;
if (this.$refs.password) {
if (this.$refs.passwordTextbox) {
// If password was set to the facility.password in handler
if (this.selected.label !== this.facility.username) {
this.$refs.password.resetAndFocus();
this.$refs.passwordTextbox.resetAndFocus();
}
}
},
handleClickNextImportedUser() {
this.error = false;
if (!this.passwordValid) {
this.$refs.password.focus();
if (!this.passwordValid && 'passwordTextbox' in this.$refs) {
this.$refs.passwordTextbox.focus();
return;
}
return FacilityImportResource.grantsuperuserpermissions({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/>
<SelectDeviceModalGroup
v-if="showSelectAddressModal"
:filterByOnMyOwnFacility="false"
@cancel="showSelectAddressModal = false"
@submit="handleContinueImport"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@
})
.then(() => {
const welcomeDismissalKey = 'DEVICE_WELCOME_MODAL_DISMISSED';
const facilityImported = 'FACILITY_IS_IMPORTED';
window.sessionStorage.setItem(welcomeDismissalKey, false);
window.sessionStorage.setItem(
facilityImported,
this.wizardContext('isImportedFacility')
);

Lockr.rm('savedState'); // Clear out saved state machine
redirectBrowser();
Expand Down
Loading