MOBILE-2380 offline: Support disabling offline browsing
parent
a0864f1606
commit
5c4f11a9bf
|
@ -154,6 +154,11 @@ export class AddonModQuizPrefetchHandler extends CoreCourseModulePrefetchHandler
|
|||
* @return {boolean|Promise<boolean>} Whether the module can be downloaded. The promise should never be rejected.
|
||||
*/
|
||||
isDownloadable(module: any, courseId: number): boolean | Promise<boolean> {
|
||||
if (this.sitesProvider.getCurrentSite().isOfflineDisabled()) {
|
||||
// Don't allow downloading the quiz if offline is disabled to prevent wasting a lot of data when opening it.
|
||||
return false;
|
||||
}
|
||||
|
||||
const siteId = this.sitesProvider.getCurrentSiteId();
|
||||
|
||||
return this.quizProvider.getQuiz(courseId, module.id, false, siteId).then((quiz) => {
|
||||
|
|
|
@ -1492,7 +1492,8 @@ export class AddonModQuizProvider {
|
|||
* @return {boolean} Whether offline is enabled.
|
||||
*/
|
||||
isQuizOffline(quiz: any): boolean {
|
||||
return !!quiz.allowofflineattempts;
|
||||
// Don't allow downloading the quiz if offline is disabled to prevent wasting a lot of data when opening it.
|
||||
return !!quiz.allowofflineattempts && !this.sitesProvider.getCurrentSite().isOfflineDisabled();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -203,6 +203,7 @@ export class CoreSite {
|
|||
protected db: SQLiteDB;
|
||||
protected cleanUnicode = false;
|
||||
protected lastAutoLogin = 0;
|
||||
protected offlineDisabled = false;
|
||||
|
||||
/**
|
||||
* Create a site.
|
||||
|
@ -234,6 +235,7 @@ export class CoreSite {
|
|||
this.wsProvider = injector.get(CoreWSProvider);
|
||||
|
||||
this.logger = logger.getInstance('CoreWSProvider');
|
||||
this.calculateOfflineDisabled();
|
||||
|
||||
if (this.id) {
|
||||
this.initDB();
|
||||
|
@ -376,6 +378,7 @@ export class CoreSite {
|
|||
setConfig(config: any): void {
|
||||
config.tool_mobile_disabledfeatures = this.textUtils.treatDisabledFeatures(config.tool_mobile_disabledfeatures);
|
||||
this.config = config;
|
||||
this.calculateOfflineDisabled();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -530,6 +533,10 @@ export class CoreSite {
|
|||
const initialToken = this.token;
|
||||
data = data || {};
|
||||
|
||||
if (!this.appProvider.isOnline() && this.offlineDisabled) {
|
||||
return Promise.reject(this.wsProvider.createFakeWSError('core.errorofflinedisabled', true));
|
||||
}
|
||||
|
||||
// Check if the method is available, use a prefixed version if possible.
|
||||
// We ignore this check when we do not have the site info, as the list of functions is not loaded yet.
|
||||
if (this.getInfo() && !this.wsAvailable(method, false)) {
|
||||
|
@ -560,6 +567,13 @@ export class CoreSite {
|
|||
wsPreSets.cleanUnicode = false;
|
||||
}
|
||||
|
||||
if (this.offlineDisabled) {
|
||||
// Offline is disabled, don't use cache.
|
||||
preSets.getFromCache = false;
|
||||
preSets.saveToCache = false;
|
||||
preSets.emergencyCache = false;
|
||||
}
|
||||
|
||||
// Enable text filtering by default.
|
||||
data.moodlewssettingfilter = preSets.filter === false ? false : true;
|
||||
data.moodlewssettingfileurl = preSets.rewriteurls === false ? false : true;
|
||||
|
@ -1351,6 +1365,22 @@ export class CoreSite {
|
|||
return !!disabledFeatures.match(regEx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate if offline is disabled in the site.
|
||||
*/
|
||||
calculateOfflineDisabled(): void {
|
||||
this.offlineDisabled = this.isFeatureDisabled('NoDelegate_CoreOffline');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether offline is disabled in the site.
|
||||
*
|
||||
* @return {boolean} Whether it's disabled.
|
||||
*/
|
||||
isOfflineDisabled(): boolean {
|
||||
return this.offlineDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the site version is greater than one or several versions.
|
||||
* This function accepts a string or an array of strings. If array, the last version must be the highest.
|
||||
|
|
|
@ -77,6 +77,7 @@
|
|||
"errorinvalidform": "The form contains invalid data. Please make sure to fill all required fields and that the data is valid.",
|
||||
"errorinvalidresponse": "Invalid response received. Please contact your Moodle site administrator if the error persists.",
|
||||
"errorloadingcontent": "Error loading content.",
|
||||
"errorofflinedisabled": "Offline browsing is disabled on your site. You need to be connected to the internet to use the app.",
|
||||
"erroropenfilenoapp": "Error opening the file: no app found to open this kind of file.",
|
||||
"erroropenfilenoextension": "Error opening the file: the file doesn't have extension.",
|
||||
"erroropenpopup": "This activity is trying to open a popup. This is not supported in this app.",
|
||||
|
|
Loading…
Reference in New Issue