MOBILE-4245 config: Add sites config list
This commit is contained in:
		
							parent
							
								
									bac7811551
								
							
						
					
					
						commit
						101294349e
					
				| @ -85,8 +85,7 @@ | ||||
|         "high": 120 | ||||
|     }, | ||||
|     "customurlscheme": "moodlemobile", | ||||
|     "siteurl": "", | ||||
|     "sitename": "", | ||||
|     "sites": [], | ||||
|     "multisitesdisplay": "", | ||||
|     "sitefindersettings": {}, | ||||
|     "onlyallowlistedsites": false, | ||||
|  | ||||
| @ -61,6 +61,7 @@ import { finalize, map, mergeMap } from 'rxjs/operators'; | ||||
| import { firstValueFrom } from '../utils/rxjs'; | ||||
| import { CoreSiteError } from '@classes/errors/siteerror'; | ||||
| import { CoreUserAuthenticatedSupportConfig } from '@features/user/classes/support/authenticated-support-config'; | ||||
| import { CoreLoginHelper } from '@features/login/services/login-helper'; | ||||
| 
 | ||||
| /** | ||||
|  * QR Code type enumeration. | ||||
| @ -290,12 +291,16 @@ export class CoreSite { | ||||
|      * @returns Site name. | ||||
|      */ | ||||
|     getSiteName(): string { | ||||
|         if (CoreConstants.CONFIG.sitename) { | ||||
|             // Overridden by config.
 | ||||
|             return CoreConstants.CONFIG.sitename; | ||||
|         } else { | ||||
|             return this.infos?.sitename || ''; | ||||
|         if (this.infos?.sitename) { | ||||
|             return this.infos?.sitename; | ||||
|         } | ||||
| 
 | ||||
|         // Fallback.
 | ||||
|         if (CoreLoginHelper.isUniqueFixedSite()) { | ||||
|             return CoreConstants.CONFIG.sites[0].name ; | ||||
|         } | ||||
| 
 | ||||
|         return ''; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -56,7 +56,6 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy { | ||||
|     identityProviders?: CoreSiteIdentityProvider[]; | ||||
|     pageLoaded = false; | ||||
|     isBrowserSSO = false; | ||||
|     isFixedUrlSet = false; | ||||
|     showForgottenPassword = true; | ||||
|     showScanQR = false; | ||||
|     loginAttempts = 0; | ||||
| @ -99,9 +98,8 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy { | ||||
|         if (this.siteConfig) { | ||||
|             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.
 | ||||
|             this.checkSite(this.siteUrl, true); | ||||
|         } else { | ||||
| @ -200,7 +198,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy { | ||||
|      */ | ||||
|     protected treatSiteConfig(): void { | ||||
|         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.authInstructions = this.siteConfig.authinstructions || Translate.instant('core.login.loginsteps'); | ||||
|             this.showScanQR = CoreLoginHelper.displayQRInCredentialsScreen(this.siteConfig.tool_mobile_qrcodetype); | ||||
|  | ||||
| @ -20,7 +20,6 @@ import { CoreDomUtils } from '@services/utils/dom'; | ||||
| import { CoreTextUtils } from '@services/utils/text'; | ||||
| import { CoreCountry, CoreUtils } from '@services/utils/utils'; | ||||
| import { CoreWS, CoreWSExternalWarning } from '@services/ws'; | ||||
| import { CoreConstants } from '@/core/constants'; | ||||
| import { Translate } from '@singletons'; | ||||
| import { CoreSitePublicConfigResponse } from '@classes/site'; | ||||
| import { CoreUserProfileFieldDelegate } from '@features/user/services/user-profile-field-delegate'; | ||||
| @ -235,7 +234,7 @@ export class CoreLoginEmailSignupPage implements OnInit { | ||||
|      */ | ||||
|     protected treatSiteConfig(): boolean { | ||||
|         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.ageDigitalConsentVerification = this.siteConfig.agedigitalconsentverification; | ||||
|             this.supportName = this.siteConfig.supportname; | ||||
|  | ||||
| @ -18,12 +18,12 @@ | ||||
| <ion-content class="ion-padding" (keydown)="keyDown($event)" (keyup)="keyUp($event)"> | ||||
|     <core-loading [hideUntil]="!showLoading"> | ||||
|         <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. --> | ||||
|                 <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'"> | ||||
| 
 | ||||
|                 <div class="core-login-site-logo" *ngIf="!showSiteAvatar"> | ||||
|                 <div class="core-login-site-logo" *ngIf="!showUserAvatar"> | ||||
|                     <!-- 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="assets/img/login_logo.png" role="presentation" alt=""> | ||||
|  | ||||
| @ -31,6 +31,7 @@ import { CoreUserSupportConfig } from '@features/user/classes/support/support-co | ||||
| import { CoreUserAuthenticatedSupportConfig } from '@features/user/classes/support/authenticated-support-config'; | ||||
| import { Translate } from '@singletons'; | ||||
| import { SafeHtml } from '@angular/platform-browser'; | ||||
| import { CoreConstants } from '@/core/constants'; | ||||
| 
 | ||||
| /** | ||||
|  * Page to enter the user password to reconnect to a site. | ||||
| @ -53,7 +54,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy { | ||||
|     logoUrl?: string; | ||||
|     identityProviders?: CoreSiteIdentityProvider[]; | ||||
|     showForgottenPassword = true; | ||||
|     showSiteAvatar = false; | ||||
|     showUserAvatar = false; | ||||
|     isBrowserSSO = false; | ||||
|     isOAuth = false; | ||||
|     isLoggedOut: boolean; | ||||
| @ -115,7 +116,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy { | ||||
|             this.isOAuth = site.isOAuth(); | ||||
| 
 | ||||
|             // 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); | ||||
| 
 | ||||
| @ -187,7 +188,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy { | ||||
| 
 | ||||
|         // Check logoURL if user avatar is not set.
 | ||||
|         if (this.userAvatar?.startsWith(this.siteUrl + '/theme/image.php')) { | ||||
|             this.showSiteAvatar = false; | ||||
|             this.showUserAvatar = false; | ||||
|         } | ||||
|         this.logoUrl = CoreLoginHelper.getLogoUrl(this.siteConfig); | ||||
|     } | ||||
|  | ||||
| @ -92,7 +92,7 @@ export class CoreLoginSitePage implements OnInit { | ||||
|         }; | ||||
| 
 | ||||
|         // Load fixed sites if they're set.
 | ||||
|         if (CoreLoginHelper.hasSeveralFixedSites()) { | ||||
|         if (CoreConstants.CONFIG.sites.length) { | ||||
|             url = this.initSiteSelector(); | ||||
|         } else if (CoreConstants.CONFIG.enableonboarding && !CorePlatform.isIOS()) { | ||||
|             this.initOnboarding(); | ||||
| @ -137,7 +137,7 @@ export class CoreLoginSitePage implements OnInit { | ||||
|      * @returns URL of the first site. | ||||
|      */ | ||||
|     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
 | ||||
| 
 | ||||
|         // Do not show images if none are set.
 | ||||
|  | ||||
| @ -379,9 +379,10 @@ export class CoreLoginHelperProvider { | ||||
|      * Get fixed site or sites. | ||||
|      * | ||||
|      * @returns Fixed site or list of fixed sites. | ||||
|      * @deprecated 4.2.0 use CoreConstants.CONFIG.sites instead. | ||||
|      */ | ||||
|     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. | ||||
|      */ | ||||
|     getAddSiteRouteInfo(showKeyboard?: boolean): [string, Params] { | ||||
|         if (this.isFixedUrlSet()) { | ||||
|         if (CoreLoginHelper.isUniqueFixedSite()) { | ||||
|             // Fixed URL is set, go to credentials page.
 | ||||
|             const fixedSites = this.getFixedSites(); | ||||
|             const url = typeof fixedSites == 'string' ? fixedSites : fixedSites[0].url; | ||||
| 
 | ||||
|             return ['/login/credentials', { siteUrl: url }]; | ||||
|             return ['/login/credentials', { siteUrl: CoreConstants.CONFIG.sites[0].url }]; | ||||
|         } | ||||
| 
 | ||||
|         return ['/login/site', { showKeyboard }]; | ||||
| @ -518,10 +516,10 @@ export class CoreLoginHelperProvider { | ||||
|      * Check if the app is configured to use several fixed URLs. | ||||
|      * | ||||
|      * @returns Whether there are several fixed URLs. | ||||
|      * @deprecated 4.2.0 Use CoreConstants.CONFIG.sites.length > 1 instead. | ||||
|      */ | ||||
|     hasSeveralFixedSites(): boolean { | ||||
|         return !!(CoreConstants.CONFIG.siteurl && Array.isArray(CoreConstants.CONFIG.siteurl) && | ||||
|             CoreConstants.CONFIG.siteurl.length > 1); | ||||
|         return CoreConstants.CONFIG.sites.length > 1; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -557,13 +555,19 @@ export class CoreLoginHelperProvider { | ||||
|      * Check if the app is configured to use a fixed URL (only 1). | ||||
|      * | ||||
|      * @returns Whether there is 1 fixed URL. | ||||
|      * @deprecated 4.2.0 Use isUniqueFixedSite instead. | ||||
|      */ | ||||
|     isFixedUrlSet(): boolean { | ||||
|         if (Array.isArray(CoreConstants.CONFIG.siteurl)) { | ||||
|             return CoreConstants.CONFIG.siteurl.length == 1; | ||||
|         } | ||||
|         return this.isUniqueFixedSite(); | ||||
|     } | ||||
| 
 | ||||
|         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. | ||||
|      */ | ||||
|     async isSiteUrlAllowed(siteUrl: string, checkSiteFinder = true): Promise<boolean> { | ||||
|         if (this.isFixedUrlSet()) { | ||||
|             // Only 1 site allowed.
 | ||||
|             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)); | ||||
|         if (CoreConstants.CONFIG.sites.length) { | ||||
|             return CoreConstants.CONFIG.sites.some((site) => CoreUrl.sameDomainAndPath(siteUrl, site.url)); | ||||
|         } else if (CoreConstants.CONFIG.multisitesdisplay == 'sitefinder' && CoreConstants.CONFIG.onlyallowlistedsites && | ||||
|                 checkSiteFinder) { | ||||
|             // Call the sites finder to validate the site.
 | ||||
| @ -1308,7 +1307,7 @@ export class CoreLoginHelperProvider { | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         if ((CoreConstants.CONFIG.displayqroncredentialscreen === undefined && this.isFixedUrlSet()) || | ||||
|         if ((CoreConstants.CONFIG.displayqroncredentialscreen === undefined && CoreLoginHelper.isUniqueFixedSite()) || | ||||
|             (CoreConstants.CONFIG.displayqroncredentialscreen !== undefined && | ||||
|                 !!CoreConstants.CONFIG.displayqroncredentialscreen)) { | ||||
| 
 | ||||
|  | ||||
| @ -27,6 +27,7 @@ import { CoreDomUtils } from '@services/utils/dom'; | ||||
| import { CoreNavigator } from '@services/navigator'; | ||||
| import { CorePlatform } from '@services/platform'; | ||||
| import { CoreNetwork } from '@services/network'; | ||||
| import { CoreLoginHelper } from '@features/login/services/login-helper'; | ||||
| 
 | ||||
| /** | ||||
|  * Device Info to be shown and copied to clipboard. | ||||
| @ -167,10 +168,10 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy { | ||||
|         } | ||||
| 
 | ||||
|         const currentSite = sitesProvider.getCurrentSite(); | ||||
|         const firstUrl = CoreLoginHelper.isUniqueFixedSite() && CoreConstants.CONFIG.sites[0].url; | ||||
| 
 | ||||
|         this.deviceInfo.siteUrl = (currentSite?.getURL()) || | ||||
|             (typeof CoreConstants.CONFIG.siteurl == 'string' && CoreConstants.CONFIG.siteurl) || undefined; | ||||
|         this.deviceInfo.isPrefixedUrl = !!CoreConstants.CONFIG.siteurl; | ||||
|         this.deviceInfo.siteUrl = currentSite?.getURL() || firstUrl || undefined; | ||||
|         this.deviceInfo.isPrefixedUrl = !!CoreConstants.CONFIG.sites.length; | ||||
|         this.deviceInfo.siteId = currentSite?.getId(); | ||||
|         this.deviceInfo.siteVersion = currentSite?.getInfo()?.release; | ||||
| 
 | ||||
|  | ||||
| @ -1261,7 +1261,7 @@ export class CoreSitesProvider { | ||||
|                     siteUrl: site.siteUrl, | ||||
|                     siteUrlWithoutProtocol: site.siteUrl.replace(/^https?:\/\//, '').toLowerCase(), | ||||
|                     fullName: siteInfo?.fullname, | ||||
|                     siteName: CoreConstants.CONFIG.sitename == '' ? siteInfo?.sitename: CoreConstants.CONFIG.sitename, | ||||
|                     siteName: siteInfo?.sitename, | ||||
|                     avatar: siteInfo?.userpictureurl, | ||||
|                     siteHomeId: siteInfo?.siteid || 1, | ||||
|                     loggedOut: !!site.loggedOut, | ||||
|  | ||||
| @ -109,7 +109,7 @@ export class CoreUpdateManagerProvider { | ||||
|      * @returns Promise resolved when done. | ||||
|      */ | ||||
|     protected async checkCurrentSiteAllowed(): Promise<void> { | ||||
|         if (!CoreLoginHelper.getFixedSites()) { | ||||
|         if (!CoreConstants.CONFIG.sites.length) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										3
									
								
								src/types/config.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								src/types/config.d.ts
									
									
									
									
										vendored
									
									
								
							| @ -42,8 +42,7 @@ export interface EnvironmentConfig { | ||||
|     zoomlevels: Record<CoreZoomLevel, number>; | ||||
|     defaultZoomLevel?: CoreZoomLevel; // Set the default zoom level of the app.
 | ||||
|     customurlscheme: string; | ||||
|     siteurl: string | CoreLoginSiteInfo[]; | ||||
|     sitename: string; | ||||
|     sites: CoreLoginSiteInfo[]; | ||||
|     multisitesdisplay: CoreLoginSiteSelectorListMethod; | ||||
|     sitefindersettings: Partial<CoreLoginSiteFinderSettings>; | ||||
|     onlyallowlistedsites: boolean; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user