How do I force my app end-users to update to a release after I have deployed?
One way to force an app update is to keep a model reserved for system settings, and store the minimum required version in that model, e.g.:
<model name="settings" label="SYSTEM : Settings">
<field name="minimum_version" label="Minimum Version" type="text" />
<display>{minimum_version}</display>
</model>
Create only one of these objects in the back-end data browser, and store the app version you want your users to be on.
In your main
view, require a user to make an OnlineDB
call to check for the latest version and ensure it matches the users current app version. There is a major drawback in that this code must be implemented from day one, and it restricts offline usage without more extensive logic allowing the user to work around.
Another way to do this is using a CloudCode task. See the following snippet:
for (let device of user_devices) {
// Access backend for each user_device
let env = await fetch(`${url}/objects/user_device/` + device.id + `.json`, {
headers: {Authorization: auth}
});
// Convert env variable to text and set to response
let response = await env.text();
// Parse response text to JSON
let user_json = JSON.parse(response);
// Run unenroll function
await unenroll(device, user_json, url, auth);
}
async function unenroll(user_device, user_json, url, auth) {
if (user_json.enrollment.enrolled === false) {
user_device.enrolled_at = null;
await user_device.save();
return console.log(user_device.name + " successfully unenrolled!");
}
// Check if container version is greater than, e.g.: 4.15.0 via user_json.enrollment.journey_launcher_version
var version = [4,15,0];
var user_version = user_json.enrollment.journey_launcher_version === undefined || user_json.enrollment.journey_launcher_version === null ? [] : user_json.enrollment.journey_launcher_version.split('.');
// var user_version = [4,15,0];
// Check if enrolled
if (user_version.length === 0) {
console.log(user_device.name + ' is probably already un-enrolled. Resetting enrolled_at to null.');
user_device.enrolled_at = null;
await user_device.save();
return;
} else if ( // Check if user's container version is greater than 4.15.0
(Number(user_version[0]) > version[0]) ||
(Number(user_version[0]) == version[0] && Number(user_version[1]) > version[1]) ||
(Number(user_version[0]) == version[0] && Number(user_version[1]) == version[1] && Number(user_version[2]) >= version[2])
) {
console.log(user_device.name + " can be un-enrolled. Un-enrolling device now...");
var req = await fetch(url + '/objects/user_device/' + user_device.id + '/re_enroll.json', {
method: 'POST',
headers: {'Authorization': auth}
});
// Determine response of the post request
var response = await req.text();
// Format response to JSON
var response_json = JSON.parse(response);
// Evaluate JSON-formatted response
if(response_json.success) {
user_device.enrolled_at = null;
await user_device.save();
return console.log(user_device.name + " successfully unenrolled!");
} else {
throw new Error('Failed to un-enroll user device: ' + response_json);
}
} else {
// Container version is less than 4.15.0
console.log(user_device.name + " container version does not meet minimum requirements.")
}
}
1 Like
Is there a way to un enrol a specific user by choice?