diff --git a/scripts/langindex.json b/scripts/langindex.json
index 8986408a0..6d57287f7 100644
--- a/scripts/langindex.json
+++ b/scripts/langindex.json
@@ -1551,6 +1551,8 @@
"core.login.confirmdeletesite": "local_moodlemobileapp",
"core.login.connect": "local_moodlemobileapp",
"core.login.connecttomoodle": "local_moodlemobileapp",
+ "core.login.connecttomoodleapp": "local_moodlemobileapp",
+ "core.login.connecttoworkplaceapp": "local_moodlemobileapp",
"core.login.contactyouradministrator": "local_moodlemobileapp",
"core.login.contactyouradministratorissue": "local_moodlemobileapp",
"core.login.createaccount": "moodle",
@@ -1688,6 +1690,7 @@
"core.nopermissionerror": "local_moodlemobileapp",
"core.nopermissions": "error",
"core.noresults": "moodle",
+ "core.noselection": "form",
"core.notapplicable": "local_moodlemobileapp",
"core.notenrolledprofile": "moodle",
"core.notice": "moodle",
@@ -1795,6 +1798,8 @@
"core.settings.errorsyncsite": "local_moodlemobileapp",
"core.settings.estimatedfreespace": "local_moodlemobileapp",
"core.settings.filesystemroot": "local_moodlemobileapp",
+ "core.settings.fontsize": "local_moodlemobileapp",
+ "core.settings.fontsizecharacter": "block_accessibility/char",
"core.settings.general": "moodle",
"core.settings.language": "moodle",
"core.settings.license": "moodle",
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 6969e01bc..8d6af8af5 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -184,6 +184,8 @@ export const CORE_PROVIDERS: any[] = [
CoreCustomURLSchemesProvider
];
+export const WP_PROVIDER: any = null;
+
@NgModule({
declarations: [
MoodleMobileApp
diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json
index 59da47ae0..9ee8ac2c7 100644
--- a/src/assets/lang/en.json
+++ b/src/assets/lang/en.json
@@ -1547,6 +1547,8 @@
"core.login.confirmdeletesite": "Are you sure you want to delete the site {{sitename}}?",
"core.login.connect": "Connect!",
"core.login.connecttomoodle": "Connect to Moodle",
+ "core.login.connecttomoodleapp": "You are trying to connect to a regular Moodle site. Please download the official Moodle app to access this site.",
+ "core.login.connecttoworkplaceapp": "You are trying to connect to a Moodle Workplace site. Please download the Moodle Workplace app to access this site.",
"core.login.contactyouradministrator": "Contact your site administrator for further help.",
"core.login.contactyouradministratorissue": "Please ask your site administrator to check the following issue: {{$a}}",
"core.login.createaccount": "Create my new account",
@@ -1576,7 +1578,7 @@
"core.login.invalidurl": "Invalid URL specified",
"core.login.invalidvaluemax": "The maximum value is {{$a}}",
"core.login.invalidvaluemin": "The minimum value is {{$a}}",
- "core.login.legacymoodleversion": "You are trying to connect to an unsupported Moodle version. Please, download the Moodle Classic app to access this Moodle site.",
+ "core.login.legacymoodleversion": "You are trying to connect to an unsupported Moodle version. Please download the Moodle Classic app to access this Moodle site.",
"core.login.legacymoodleversiondesktop": "You are trying to connect to {{$a}}.
This site is running an outdated unsupported version of Moodle which will not work with this Moodle Desktop App.
If this is your site please contact your local moodle partner to get assistance to update it.
See our contact page to submit a request for assistance.",
"core.login.legacymoodleversiondesktopdownloadold": "
Alternatively, you can still access this site using an unsupported version of the app that can be downloaded from here.",
"core.login.localmobileunexpectedresponse": "Moodle Mobile Additional Features check returned an unexpected response. You will be authenticated using the standard mobile service.",
diff --git a/src/core/login/lang/en.json b/src/core/login/lang/en.json
index 8264d9196..4328c6d3e 100644
--- a/src/core/login/lang/en.json
+++ b/src/core/login/lang/en.json
@@ -11,6 +11,8 @@
"createaccount": "Create my new account",
"createuserandpass": "Choose your username and password",
"credentialsdescription": "Please provide your username and password to log in.",
+ "connecttomoodleapp": "You are trying to connect to a regular Moodle site. Please download the official Moodle app to access this site.",
+ "connecttoworkplaceapp": "You are trying to connect to a Moodle Workplace site. Please download the Moodle Workplace app to access this site.",
"emailconfirmsent": "
An email should have been sent to your address at {{$a}}
\n It contains easy instructions to complete your registration.
\n If you continue to have difficulty, contact the site administrator.
",
"emailconfirmsentnoemail": "An email should have been sent to your address.
It contains easy instructions to complete your registration.
If you continue to have difficulty, contact the site administrator.
",
"emailconfirmsentsuccess": "Confirmation email sent successfully",
@@ -35,7 +37,7 @@
"invalidurl": "Invalid URL specified",
"invalidvaluemax": "The maximum value is {{$a}}",
"invalidvaluemin": "The minimum value is {{$a}}",
- "legacymoodleversion": "You are trying to connect to an unsupported Moodle version. Please, download the Moodle Classic app to access this Moodle site.",
+ "legacymoodleversion": "You are trying to connect to an unsupported Moodle version. Please download the Moodle Classic app to access this Moodle site.",
"legacymoodleversiondesktop": "You are trying to connect to {{$a}}.
This site is running an outdated unsupported version of Moodle which will not work with this Moodle Desktop App.
If this is your site please contact your local moodle partner to get assistance to update it.
See our contact page to submit a request for assistance.",
"legacymoodleversiondesktopdownloadold": "
Alternatively, you can still access this site using an unsupported version of the app that can be downloaded from here.",
"localmobileunexpectedresponse": "Moodle Mobile Additional Features check returned an unexpected response. You will be authenticated using the standard mobile service.",
diff --git a/src/core/login/providers/helper.ts b/src/core/login/providers/helper.ts
index a494a74a4..9d46e536a 100644
--- a/src/core/login/providers/helper.ts
+++ b/src/core/login/providers/helper.ts
@@ -1029,34 +1029,81 @@ export class CoreLoginHelperProvider {
* @param {string} message The warning message.
*/
protected showLegacyNoticeModal(message: string): void {
- const isAndroid = this.platform.is('android'),
- isIOS = this.platform.is('ios'),
- isWindows = this.appProvider.isWindows(),
- isLinux = this.appProvider.isLinux(),
- buttons: any[] = [
+ let link;
+
+ if (this.appProvider.isWindows()) {
+ link = 'https://download.moodle.org/desktop/download.php?platform=windows&version=342';
+ } else if (this.appProvider.isLinux()) {
+ link = 'https://download.moodle.org/desktop/download.php?platform=linux&version=342&arch=' +
+ (this.appProvider.is64Bits() ? '64' : '32');
+ } else if (this.platform.is('android')) {
+ link = 'market://details?id=com.moodle.classic';
+ } else if (this.platform.is('ios')) {
+ link = 'itms-apps://itunes.apple.com/app/id1403448117';
+ }
+
+ this.showDownloadAppNoticeModal(message, link);
+ }
+
+ /**
+ * Show a modal warning the user that he should use the Workplace app.
+ *
+ * @param {string} message The warning message.
+ */
+ protected showWorkplaceNoticeModal(message: string): void {
+ let link;
+
+ if (this.platform.is('android')) {
+ link = 'market://details?id=com.moodle.workplace';
+ } else if (this.platform.is('ios')) {
+ link = 'itms-apps://itunes.apple.com/app/id1470929705';
+ }
+
+ this.showDownloadAppNoticeModal(message, link);
+ }
+
+ /**
+ * Show a modal warning the user that he should use the current Moodle app.
+ *
+ * @param {string} message The warning message.
+ */
+ protected showMoodleAppNoticeModal(message: string): void {
+ let link;
+
+ if (this.appProvider.isWindows()) {
+ link = 'https://download.moodle.org/desktop/download.php?platform=windows';
+ } else if (this.appProvider.isLinux()) {
+ link = 'https://download.moodle.org/desktop/download.php?platform=linux&arch=' +
+ (this.appProvider.is64Bits() ? '64' : '32');
+ } else if (this.appProvider.isMac()) {
+ link = 'itms-apps://itunes.apple.com/app/id1255924440';
+ } else if (this.platform.is('android')) {
+ link = 'market://details?id=com.moodle.moodlemobile';
+ } else if (this.platform.is('ios')) {
+ link = 'itms-apps://itunes.apple.com/app/id633359593';
+ }
+
+ this.showDownloadAppNoticeModal(message, link);
+ }
+
+ /**
+ * Show a modal warning the user that he should use a different app.
+ *
+ * @param {string} message The warning message.
+ * @param {string} link Link to the app to download if any.
+ */
+ protected showDownloadAppNoticeModal(message: string, link?: string): void {
+ const buttons: any[] = [
{
text: this.translate.instant('core.ok'),
role: 'cancel'
}
];
- if (isAndroid || isIOS || isWindows || isLinux) {
+ if (link) {
buttons.push({
text: this.translate.instant('core.download'),
handler: (): void => {
- let link;
-
- if (isWindows) {
- link = 'https://download.moodle.org/desktop/download.php?platform=windows&version=342';
- } else if (isLinux) {
- link = 'https://download.moodle.org/desktop/download.php?platform=linux&version=342&arch=' +
- (this.appProvider.is64Bits() ? '64' : '32');
- } else if (isAndroid) {
- link = 'market://details?id=com.moodle.classic';
- } else {
- link = 'itms-apps://itunes.apple.com/app/id1403448117';
- }
-
this.utils.openInBrowser(link);
}
});
@@ -1068,7 +1115,8 @@ export class CoreLoginHelperProvider {
});
alert.present().then(() => {
- if (!isAndroid && !isIOS) {
+ const isDevice = this.platform.is('android') || this.platform.is('ios');
+ if (!isDevice) {
// Treat all anchors so they don't override the app.
const alertMessageEl: HTMLElement = alert.pageRef().nativeElement.querySelector('.alert-message');
this.domUtils.treatAnchors(alertMessageEl);
@@ -1179,6 +1227,10 @@ export class CoreLoginHelperProvider {
this.showNotConfirmedModal(siteUrl, undefined, username, password);
} else if (error.errorcode == 'legacymoodleversion') {
this.showLegacyNoticeModal(this.textUtils.getErrorMessageFromError(error));
+ } else if (error.errorcode == 'connecttomoodleapp') {
+ this.showMoodleAppNoticeModal(this.textUtils.getErrorMessageFromError(error));
+ } else if (error.errorcode == 'connecttoworkplaceapp') {
+ this.showWorkplaceNoticeModal(this.textUtils.getErrorMessageFromError(error));
} else {
this.domUtils.showErrorModal(error);
}
diff --git a/src/providers/sites.ts b/src/providers/sites.ts
index b01a412d1..09e3fcb85 100644
--- a/src/providers/sites.ts
+++ b/src/providers/sites.ts
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-import { Injectable } from '@angular/core';
+import { Injectable, Injector } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { TranslateService } from '@ngx-translate/core';
import { CoreAppProvider } from './app';
@@ -28,6 +28,7 @@ import { CoreSite } from '@classes/site';
import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb';
import { Md5 } from 'ts-md5/dist/md5';
import { Location } from '@angular/common';
+import { WP_PROVIDER } from '@app/app.module';
/**
* Response of checking if a site exists and its configuration.
@@ -243,10 +244,14 @@ export class CoreSitesProvider {
];
// Constants to validate a site version.
+ protected WORKPLACE_APP = 3;
+ protected MOODLE_APP = 2;
protected VALID_VERSION = 1;
protected LEGACY_APP_VERSION = 0;
protected INVALID_VERSION = -1;
+ protected isWPApp: boolean;
+
protected logger;
protected services = {};
protected sessionRestored = false;
@@ -322,7 +327,7 @@ export class CoreSitesProvider {
constructor(logger: CoreLoggerProvider, private http: HttpClient, private sitesFactory: CoreSitesFactoryProvider,
private appProvider: CoreAppProvider, private translate: TranslateService, private urlUtils: CoreUrlUtilsProvider,
private eventsProvider: CoreEventsProvider, private textUtils: CoreTextUtilsProvider, private location: Location,
- private utils: CoreUtilsProvider) {
+ private utils: CoreUtilsProvider, private injector: Injector) {
this.logger = logger.getInstance('CoreSitesProvider');
this.appDB = appProvider.getDB();
@@ -651,30 +656,67 @@ export class CoreSitesProvider {
return siteId;
});
});
- } else if (result == this.LEGACY_APP_VERSION) {
- let errorKey = 'core.login.legacymoodleversion',
- params;
+ }
+
+ return this.treatInvalidAppVersion(result, siteUrl);
+ });
+ }
+
+ /**
+ * Having the result of isValidMoodleVersion, it treats the error message to be shown.
+ *
+ * @param {number} result Result returned by isValidMoodleVersion function.
+ * @param {string} siteUrl The site url.
+ * @param {string} siteId If site is already added, it will invalidate the token.
+ * @return {Promise} A promise rejected with the error info.
+ */
+ protected treatInvalidAppVersion(result: number, siteUrl: string, siteId?: string): Promise {
+ let errorCode,
+ errorKey,
+ errorExtra = '',
+ errorKeyParams;
+
+ switch (result) {
+ case this.LEGACY_APP_VERSION:
+ errorKey = 'core.login.legacymoodleversion';
+ errorCode = 'legacymoodleversion';
if (this.appProvider.isDesktop()) {
errorKey += 'desktop';
- params = {$a: siteUrl};
+ errorKeyParams = {$a: siteUrl};
}
- let error = this.translate.instant(errorKey, params);
if (this.appProvider.isWindows() || this.appProvider.isLinux()) {
- error += this.translate.instant('core.login.legacymoodleversiondesktopdownloadold');
+ errorExtra = this.translate.instant('core.login.legacymoodleversiondesktopdownloadold');
}
- return Promise.reject({
- error: error,
- errorcode: 'legacymoodleversion'
- });
- } else {
- return Promise.reject({
- error: this.translate.instant('core.login.invalidmoodleversion'),
- errorcode: 'invalidmoodleversion'
- });
- }
+ break;
+ case this.MOODLE_APP:
+ errorKey = 'core.login.connecttomoodleapp';
+ errorCode = 'connecttomoodleapp';
+ break;
+ case this.WORKPLACE_APP:
+ errorKey = 'core.login.connecttoworkplaceapp';
+ errorCode = 'connecttoworkplaceapp';
+ break;
+ default:
+ errorCode = 'invalidmoodleversion';
+ errorKey = 'core.login.invalidmoodleversion';
+ }
+
+ let promise;
+
+ if (siteId) {
+ promise = this.setSiteLoggedOut(siteId, true);
+ } else {
+ promise = Promise.resolve();
+ }
+
+ return promise.then(() => {
+ return Promise.reject({
+ error: this.translate.instant(errorKey, errorKeyParams) + errorExtra,
+ errorcode: errorCode
+ });
});
}
@@ -718,7 +760,7 @@ export class CoreSitesProvider {
* Check for the minimum required version.
*
* @param {any} info Site info.
- * @return {number} Either VALID_VERSION, LEGACY_APP_VERSION or INVALID_VERSION.
+ * @return {number} Either VALID_VERSION, LEGACY_APP_VERSION, WORKPLACE_APP, MOODLE_APP or INVALID_VERSION.
*/
protected isValidMoodleVersion(info: any): number {
if (!info) {
@@ -735,11 +777,9 @@ export class CoreSitesProvider {
const version = parseInt(info.version, 10);
if (!isNaN(version)) {
if (version >= version31) {
- return this.VALID_VERSION;
+ return this.validateWorkplaceVersion(info);
} else if (version >= version24) {
return this.LEGACY_APP_VERSION;
- } else {
- return this.INVALID_VERSION;
}
}
}
@@ -748,7 +788,7 @@ export class CoreSitesProvider {
const release = this.getReleaseNumber(info.release || '');
if (release) {
if (release >= release31) {
- return this.VALID_VERSION;
+ return this.validateWorkplaceVersion(info);
}
if (release >= release24) {
return this.LEGACY_APP_VERSION;
@@ -759,6 +799,33 @@ export class CoreSitesProvider {
return this.INVALID_VERSION;
}
+ /**
+ * Check if needs to be redirected to specific Workplace App or general Moodle App.
+ *
+ * @param {any} info Site info.
+ * @return {number} Either VALID_VERSION, WORKPLACE_APP or MOODLE_APP.
+ */
+ protected validateWorkplaceVersion(info: any): number {
+ const isWorkplace = !!info.functions && info.functions.some((func) => {
+ return func.name == 'tool_program_get_user_programs';
+ });
+
+ if (typeof this.isWPApp == 'undefined') {
+ this.isWPApp = !!WP_PROVIDER && WP_PROVIDER.name == 'AddonBlockProgramsOverviewModule' &&
+ !!this.injector.get(WP_PROVIDER, false);
+ }
+
+ if (!this.isWPApp && isWorkplace) {
+ return this.WORKPLACE_APP;
+ }
+
+ if (this.isWPApp && !isWorkplace) {
+ return this.MOODLE_APP;
+ }
+
+ return this.VALID_VERSION;
+ }
+
/**
* Returns the release number from site release info.
*
@@ -1279,9 +1346,10 @@ export class CoreSitesProvider {
return site.fetchSiteInfo().then((info) => {
site.setInfo(info);
- if (this.isLegacyMoodleByInfo(info)) {
+ const versionCheck = this.isValidMoodleVersion(info);
+ if (versionCheck != this.VALID_VERSION) {
// The Moodle version is not supported, reject.
- return Promise.reject(this.translate.instant('core.login.legacymoodleversion'));
+ return this.treatInvalidAppVersion(versionCheck, site.getURL(), site.getId());
}
// Try to get the site config.