2
0
Fork 0

MOBILE-4245 config: Add sites config list

main
Alfonso Salces 2023-02-22 12:50:06 +01:00
parent bac7811551
commit 101294349e
12 changed files with 49 additions and 48 deletions

View File

@ -85,8 +85,7 @@
"high": 120 "high": 120
}, },
"customurlscheme": "moodlemobile", "customurlscheme": "moodlemobile",
"siteurl": "", "sites": [],
"sitename": "",
"multisitesdisplay": "", "multisitesdisplay": "",
"sitefindersettings": {}, "sitefindersettings": {},
"onlyallowlistedsites": false, "onlyallowlistedsites": false,

View File

@ -61,6 +61,7 @@ import { finalize, map, mergeMap } from 'rxjs/operators';
import { firstValueFrom } from '../utils/rxjs'; import { firstValueFrom } from '../utils/rxjs';
import { CoreSiteError } from '@classes/errors/siteerror'; import { CoreSiteError } from '@classes/errors/siteerror';
import { CoreUserAuthenticatedSupportConfig } from '@features/user/classes/support/authenticated-support-config'; import { CoreUserAuthenticatedSupportConfig } from '@features/user/classes/support/authenticated-support-config';
import { CoreLoginHelper } from '@features/login/services/login-helper';
/** /**
* QR Code type enumeration. * QR Code type enumeration.
@ -290,12 +291,16 @@ export class CoreSite {
* @returns Site name. * @returns Site name.
*/ */
getSiteName(): string { getSiteName(): string {
if (CoreConstants.CONFIG.sitename) { if (this.infos?.sitename) {
// Overridden by config. return this.infos?.sitename;
return CoreConstants.CONFIG.sitename;
} else {
return this.infos?.sitename || '';
} }
// Fallback.
if (CoreLoginHelper.isUniqueFixedSite()) {
return CoreConstants.CONFIG.sites[0].name ;
}
return '';
} }
/** /**

View File

@ -56,7 +56,6 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
identityProviders?: CoreSiteIdentityProvider[]; identityProviders?: CoreSiteIdentityProvider[];
pageLoaded = false; pageLoaded = false;
isBrowserSSO = false; isBrowserSSO = false;
isFixedUrlSet = false;
showForgottenPassword = true; showForgottenPassword = true;
showScanQR = false; showScanQR = false;
loginAttempts = 0; loginAttempts = 0;
@ -99,9 +98,8 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
if (this.siteConfig) { if (this.siteConfig) {
this.treatSiteConfig(); this.treatSiteConfig();
} }
this.isFixedUrlSet = CoreLoginHelper.isFixedUrlSet();
if (this.isFixedUrlSet || !this.siteConfig) { if (CoreLoginHelper.isUniqueFixedSite() || !this.siteConfig) {
// Fixed URL or not siteConfig retrieved from params, we need to check if it uses browser SSO login. // Fixed URL or not siteConfig retrieved from params, we need to check if it uses browser SSO login.
this.checkSite(this.siteUrl, true); this.checkSite(this.siteUrl, true);
} else { } else {
@ -200,7 +198,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
*/ */
protected treatSiteConfig(): void { protected treatSiteConfig(): void {
if (this.siteConfig) { if (this.siteConfig) {
this.siteName = CoreConstants.CONFIG.sitename ? CoreConstants.CONFIG.sitename : this.siteConfig.sitename; this.siteName = this.siteConfig.sitename;
this.logoUrl = CoreLoginHelper.getLogoUrl(this.siteConfig); this.logoUrl = CoreLoginHelper.getLogoUrl(this.siteConfig);
this.authInstructions = this.siteConfig.authinstructions || Translate.instant('core.login.loginsteps'); this.authInstructions = this.siteConfig.authinstructions || Translate.instant('core.login.loginsteps');
this.showScanQR = CoreLoginHelper.displayQRInCredentialsScreen(this.siteConfig.tool_mobile_qrcodetype); this.showScanQR = CoreLoginHelper.displayQRInCredentialsScreen(this.siteConfig.tool_mobile_qrcodetype);

View File

@ -20,7 +20,6 @@ import { CoreDomUtils } from '@services/utils/dom';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreCountry, CoreUtils } from '@services/utils/utils'; import { CoreCountry, CoreUtils } from '@services/utils/utils';
import { CoreWS, CoreWSExternalWarning } from '@services/ws'; import { CoreWS, CoreWSExternalWarning } from '@services/ws';
import { CoreConstants } from '@/core/constants';
import { Translate } from '@singletons'; import { Translate } from '@singletons';
import { CoreSitePublicConfigResponse } from '@classes/site'; import { CoreSitePublicConfigResponse } from '@classes/site';
import { CoreUserProfileFieldDelegate } from '@features/user/services/user-profile-field-delegate'; import { CoreUserProfileFieldDelegate } from '@features/user/services/user-profile-field-delegate';
@ -235,7 +234,7 @@ export class CoreLoginEmailSignupPage implements OnInit {
*/ */
protected treatSiteConfig(): boolean { protected treatSiteConfig(): boolean {
if (this.siteConfig?.registerauth == 'email' && !CoreLoginHelper.isEmailSignupDisabled(this.siteConfig)) { if (this.siteConfig?.registerauth == 'email' && !CoreLoginHelper.isEmailSignupDisabled(this.siteConfig)) {
this.siteName = CoreConstants.CONFIG.sitename ? CoreConstants.CONFIG.sitename : this.siteConfig.sitename; this.siteName = this.siteConfig.sitename;
this.authInstructions = this.siteConfig.authinstructions; this.authInstructions = this.siteConfig.authinstructions;
this.ageDigitalConsentVerification = this.siteConfig.agedigitalconsentverification; this.ageDigitalConsentVerification = this.siteConfig.agedigitalconsentverification;
this.supportName = this.siteConfig.supportname; this.supportName = this.siteConfig.supportname;

View File

@ -18,12 +18,12 @@
<ion-content class="ion-padding" (keydown)="keyDown($event)" (keyup)="keyUp($event)"> <ion-content class="ion-padding" (keydown)="keyDown($event)" (keyup)="keyUp($event)">
<core-loading [hideUntil]="!showLoading"> <core-loading [hideUntil]="!showLoading">
<div class="list-item-limited-width"> <div class="list-item-limited-width">
<div class="ion-text-wrap ion-text-center ion-margin-bottom" [ngClass]="{'item-avatar-center': showSiteAvatar}"> <div class="ion-text-wrap ion-text-center ion-margin-bottom" [ngClass]="{'item-avatar-center': showUserAvatar}">
<!-- Show user avatar. --> <!-- Show user avatar. -->
<img *ngIf="showSiteAvatar" [src]="userAvatar" class="large-avatar" core-external-content [siteId]="siteId" <img *ngIf="showUserAvatar" [src]="userAvatar" class="large-avatar" core-external-content [siteId]="siteId"
alt="{{ 'core.pictureof' | translate:{$a: userFullName} }}" onError="this.src='assets/img/user-avatar.png'"> alt="{{ 'core.pictureof' | translate:{$a: userFullName} }}" onError="this.src='assets/img/user-avatar.png'">
<div class="core-login-site-logo" *ngIf="!showSiteAvatar"> <div class="core-login-site-logo" *ngIf="!showUserAvatar">
<!-- Show site logo or a default image. --> <!-- Show site logo or a default image. -->
<img *ngIf="logoUrl" [src]="logoUrl" role="presentation" onError="this.src='assets/img/login_logo.png'" alt=""> <img *ngIf="logoUrl" [src]="logoUrl" role="presentation" onError="this.src='assets/img/login_logo.png'" alt="">
<img *ngIf="!logoUrl" src="assets/img/login_logo.png" role="presentation" alt=""> <img *ngIf="!logoUrl" src="assets/img/login_logo.png" role="presentation" alt="">

View File

@ -31,6 +31,7 @@ import { CoreUserSupportConfig } from '@features/user/classes/support/support-co
import { CoreUserAuthenticatedSupportConfig } from '@features/user/classes/support/authenticated-support-config'; import { CoreUserAuthenticatedSupportConfig } from '@features/user/classes/support/authenticated-support-config';
import { Translate } from '@singletons'; import { Translate } from '@singletons';
import { SafeHtml } from '@angular/platform-browser'; import { SafeHtml } from '@angular/platform-browser';
import { CoreConstants } from '@/core/constants';
/** /**
* Page to enter the user password to reconnect to a site. * Page to enter the user password to reconnect to a site.
@ -53,7 +54,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
logoUrl?: string; logoUrl?: string;
identityProviders?: CoreSiteIdentityProvider[]; identityProviders?: CoreSiteIdentityProvider[];
showForgottenPassword = true; showForgottenPassword = true;
showSiteAvatar = false; showUserAvatar = false;
isBrowserSSO = false; isBrowserSSO = false;
isOAuth = false; isOAuth = false;
isLoggedOut: boolean; isLoggedOut: boolean;
@ -115,7 +116,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
this.isOAuth = site.isOAuth(); this.isOAuth = site.isOAuth();
// Show logo instead of avatar if it's a fixed site. // Show logo instead of avatar if it's a fixed site.
this.showSiteAvatar = !!this.userAvatar && !CoreLoginHelper.getFixedSites(); this.showUserAvatar = !!this.userAvatar && !CoreConstants.CONFIG.sites.length;
this.checkSiteConfig(site); this.checkSiteConfig(site);
@ -187,7 +188,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
// Check logoURL if user avatar is not set. // Check logoURL if user avatar is not set.
if (this.userAvatar?.startsWith(this.siteUrl + '/theme/image.php')) { if (this.userAvatar?.startsWith(this.siteUrl + '/theme/image.php')) {
this.showSiteAvatar = false; this.showUserAvatar = false;
} }
this.logoUrl = CoreLoginHelper.getLogoUrl(this.siteConfig); this.logoUrl = CoreLoginHelper.getLogoUrl(this.siteConfig);
} }

View File

@ -92,7 +92,7 @@ export class CoreLoginSitePage implements OnInit {
}; };
// Load fixed sites if they're set. // Load fixed sites if they're set.
if (CoreLoginHelper.hasSeveralFixedSites()) { if (CoreConstants.CONFIG.sites.length) {
url = this.initSiteSelector(); url = this.initSiteSelector();
} else if (CoreConstants.CONFIG.enableonboarding && !CorePlatform.isIOS()) { } else if (CoreConstants.CONFIG.enableonboarding && !CorePlatform.isIOS()) {
this.initOnboarding(); this.initOnboarding();
@ -137,7 +137,7 @@ export class CoreLoginSitePage implements OnInit {
* @returns URL of the first site. * @returns URL of the first site.
*/ */
protected initSiteSelector(): string { protected initSiteSelector(): string {
this.fixedSites = this.extendCoreLoginSiteInfo(<CoreLoginSiteInfoExtended[]> CoreLoginHelper.getFixedSites()); this.fixedSites = this.extendCoreLoginSiteInfo(<CoreLoginSiteInfoExtended[]> CoreConstants.CONFIG.sites);
this.siteSelector = 'list'; // In case it's not defined this.siteSelector = 'list'; // In case it's not defined
// Do not show images if none are set. // Do not show images if none are set.

View File

@ -379,9 +379,10 @@ export class CoreLoginHelperProvider {
* Get fixed site or sites. * Get fixed site or sites.
* *
* @returns Fixed site or list of fixed sites. * @returns Fixed site or list of fixed sites.
* @deprecated 4.2.0 use CoreConstants.CONFIG.sites instead.
*/ */
getFixedSites(): string | CoreLoginSiteInfo[] { getFixedSites(): string | CoreLoginSiteInfo[] {
return CoreConstants.CONFIG.siteurl; return CoreLoginHelper.isUniqueFixedSite() ? CoreConstants.CONFIG.sites[0].url : CoreConstants.CONFIG.sites;
} }
/** /**
@ -453,12 +454,9 @@ export class CoreLoginHelperProvider {
* @returns Path and params. * @returns Path and params.
*/ */
getAddSiteRouteInfo(showKeyboard?: boolean): [string, Params] { getAddSiteRouteInfo(showKeyboard?: boolean): [string, Params] {
if (this.isFixedUrlSet()) { if (CoreLoginHelper.isUniqueFixedSite()) {
// Fixed URL is set, go to credentials page. // Fixed URL is set, go to credentials page.
const fixedSites = this.getFixedSites(); return ['/login/credentials', { siteUrl: CoreConstants.CONFIG.sites[0].url }];
const url = typeof fixedSites == 'string' ? fixedSites : fixedSites[0].url;
return ['/login/credentials', { siteUrl: url }];
} }
return ['/login/site', { showKeyboard }]; return ['/login/site', { showKeyboard }];
@ -518,10 +516,10 @@ export class CoreLoginHelperProvider {
* Check if the app is configured to use several fixed URLs. * Check if the app is configured to use several fixed URLs.
* *
* @returns Whether there are several fixed URLs. * @returns Whether there are several fixed URLs.
* @deprecated 4.2.0 Use CoreConstants.CONFIG.sites.length > 1 instead.
*/ */
hasSeveralFixedSites(): boolean { hasSeveralFixedSites(): boolean {
return !!(CoreConstants.CONFIG.siteurl && Array.isArray(CoreConstants.CONFIG.siteurl) && return CoreConstants.CONFIG.sites.length > 1;
CoreConstants.CONFIG.siteurl.length > 1);
} }
/** /**
@ -557,13 +555,19 @@ export class CoreLoginHelperProvider {
* Check if the app is configured to use a fixed URL (only 1). * Check if the app is configured to use a fixed URL (only 1).
* *
* @returns Whether there is 1 fixed URL. * @returns Whether there is 1 fixed URL.
* @deprecated 4.2.0 Use isUniqueFixedSite instead.
*/ */
isFixedUrlSet(): boolean { isFixedUrlSet(): boolean {
if (Array.isArray(CoreConstants.CONFIG.siteurl)) { return this.isUniqueFixedSite();
return CoreConstants.CONFIG.siteurl.length == 1; }
}
return !!CoreConstants.CONFIG.siteurl; /**
* Check if the app is configured to use a fixed URL (only 1).
*
* @returns Whether there is 1 fixed URL.
*/
isUniqueFixedSite(): boolean {
return CoreConstants.CONFIG.sites.length === 1;
} }
/** /**
@ -606,13 +610,8 @@ export class CoreLoginHelperProvider {
* @returns Promise resolved with boolean: whether is one of the fixed sites. * @returns Promise resolved with boolean: whether is one of the fixed sites.
*/ */
async isSiteUrlAllowed(siteUrl: string, checkSiteFinder = true): Promise<boolean> { async isSiteUrlAllowed(siteUrl: string, checkSiteFinder = true): Promise<boolean> {
if (this.isFixedUrlSet()) { if (CoreConstants.CONFIG.sites.length) {
// Only 1 site allowed. return CoreConstants.CONFIG.sites.some((site) => CoreUrl.sameDomainAndPath(siteUrl, site.url));
return CoreUrl.sameDomainAndPath(siteUrl, <string> this.getFixedSites());
} else if (this.hasSeveralFixedSites()) {
const sites = <CoreLoginSiteInfo[]> this.getFixedSites();
return sites.some((site) => CoreUrl.sameDomainAndPath(siteUrl, site.url));
} else if (CoreConstants.CONFIG.multisitesdisplay == 'sitefinder' && CoreConstants.CONFIG.onlyallowlistedsites && } else if (CoreConstants.CONFIG.multisitesdisplay == 'sitefinder' && CoreConstants.CONFIG.onlyallowlistedsites &&
checkSiteFinder) { checkSiteFinder) {
// Call the sites finder to validate the site. // Call the sites finder to validate the site.
@ -1308,7 +1307,7 @@ export class CoreLoginHelperProvider {
return false; return false;
} }
if ((CoreConstants.CONFIG.displayqroncredentialscreen === undefined && this.isFixedUrlSet()) || if ((CoreConstants.CONFIG.displayqroncredentialscreen === undefined && CoreLoginHelper.isUniqueFixedSite()) ||
(CoreConstants.CONFIG.displayqroncredentialscreen !== undefined && (CoreConstants.CONFIG.displayqroncredentialscreen !== undefined &&
!!CoreConstants.CONFIG.displayqroncredentialscreen)) { !!CoreConstants.CONFIG.displayqroncredentialscreen)) {

View File

@ -27,6 +27,7 @@ import { CoreDomUtils } from '@services/utils/dom';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CorePlatform } from '@services/platform'; import { CorePlatform } from '@services/platform';
import { CoreNetwork } from '@services/network'; import { CoreNetwork } from '@services/network';
import { CoreLoginHelper } from '@features/login/services/login-helper';
/** /**
* Device Info to be shown and copied to clipboard. * Device Info to be shown and copied to clipboard.
@ -167,10 +168,10 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy {
} }
const currentSite = sitesProvider.getCurrentSite(); const currentSite = sitesProvider.getCurrentSite();
const firstUrl = CoreLoginHelper.isUniqueFixedSite() && CoreConstants.CONFIG.sites[0].url;
this.deviceInfo.siteUrl = (currentSite?.getURL()) || this.deviceInfo.siteUrl = currentSite?.getURL() || firstUrl || undefined;
(typeof CoreConstants.CONFIG.siteurl == 'string' && CoreConstants.CONFIG.siteurl) || undefined; this.deviceInfo.isPrefixedUrl = !!CoreConstants.CONFIG.sites.length;
this.deviceInfo.isPrefixedUrl = !!CoreConstants.CONFIG.siteurl;
this.deviceInfo.siteId = currentSite?.getId(); this.deviceInfo.siteId = currentSite?.getId();
this.deviceInfo.siteVersion = currentSite?.getInfo()?.release; this.deviceInfo.siteVersion = currentSite?.getInfo()?.release;

View File

@ -1261,7 +1261,7 @@ export class CoreSitesProvider {
siteUrl: site.siteUrl, siteUrl: site.siteUrl,
siteUrlWithoutProtocol: site.siteUrl.replace(/^https?:\/\//, '').toLowerCase(), siteUrlWithoutProtocol: site.siteUrl.replace(/^https?:\/\//, '').toLowerCase(),
fullName: siteInfo?.fullname, fullName: siteInfo?.fullname,
siteName: CoreConstants.CONFIG.sitename == '' ? siteInfo?.sitename: CoreConstants.CONFIG.sitename, siteName: siteInfo?.sitename,
avatar: siteInfo?.userpictureurl, avatar: siteInfo?.userpictureurl,
siteHomeId: siteInfo?.siteid || 1, siteHomeId: siteInfo?.siteid || 1,
loggedOut: !!site.loggedOut, loggedOut: !!site.loggedOut,

View File

@ -109,7 +109,7 @@ export class CoreUpdateManagerProvider {
* @returns Promise resolved when done. * @returns Promise resolved when done.
*/ */
protected async checkCurrentSiteAllowed(): Promise<void> { protected async checkCurrentSiteAllowed(): Promise<void> {
if (!CoreLoginHelper.getFixedSites()) { if (!CoreConstants.CONFIG.sites.length) {
return; return;
} }

View File

@ -42,8 +42,7 @@ export interface EnvironmentConfig {
zoomlevels: Record<CoreZoomLevel, number>; zoomlevels: Record<CoreZoomLevel, number>;
defaultZoomLevel?: CoreZoomLevel; // Set the default zoom level of the app. defaultZoomLevel?: CoreZoomLevel; // Set the default zoom level of the app.
customurlscheme: string; customurlscheme: string;
siteurl: string | CoreLoginSiteInfo[]; sites: CoreLoginSiteInfo[];
sitename: string;
multisitesdisplay: CoreLoginSiteSelectorListMethod; multisitesdisplay: CoreLoginSiteSelectorListMethod;
sitefindersettings: Partial<CoreLoginSiteFinderSettings>; sitefindersettings: Partial<CoreLoginSiteFinderSettings>;
onlyallowlistedsites: boolean; onlyallowlistedsites: boolean;