Merge pull request #4233 from dpalou/MOBILE-4679

MOBILE-4679 dev: Display auto login info and part of tokens in dev page
main
Pau Ferrer Ocaña 2024-11-18 13:46:40 +01:00 committed by GitHub
commit 1afe19639c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 120 additions and 11 deletions

View File

@ -378,7 +378,7 @@ export class CoreSite extends CoreAuthenticatedSite {
*/ */
fixPluginfileURL(url: string): string { fixPluginfileURL(url: string): string {
const accessKey = this.tokenPluginFileWorks || this.tokenPluginFileWorks === undefined ? const accessKey = this.tokenPluginFileWorks || this.tokenPluginFileWorks === undefined ?
this.infos && this.infos.userprivateaccesskey : undefined; this.getFilesAccessKey() : undefined;
return CoreUrl.fixPluginfileURL(url, this.token || '', this.siteUrl, accessKey); return CoreUrl.fixPluginfileURL(url, this.token || '', this.siteUrl, accessKey);
} }
@ -685,12 +685,9 @@ export class CoreSite extends CoreAuthenticatedSite {
} }
if (this.lastAutoLogin > 0) { if (this.lastAutoLogin > 0) {
const timeBetweenRequests = await CoreUtils.ignoreErrors( const timeBetweenRequests = await this.getAutoLoginMinTimeBetweenRequests();
this.getConfig('tool_mobile_autologinmintimebetweenreq'),
CoreConstants.SECONDS_MINUTE * 6,
);
if (CoreTimeUtils.timestamp() - this.lastAutoLogin < Number(timeBetweenRequests)) { if (CoreTimeUtils.timestamp() - this.lastAutoLogin < timeBetweenRequests) {
// Not enough time has passed since last auto login. // Not enough time has passed since last auto login.
return url; return url;
} }
@ -775,7 +772,7 @@ export class CoreSite extends CoreAuthenticatedSite {
* @returns Promise resolved with boolean: whether it works or not. * @returns Promise resolved with boolean: whether it works or not.
*/ */
checkTokenPluginFile(url: string): Promise<boolean> { checkTokenPluginFile(url: string): Promise<boolean> {
if (!CoreUrl.canUseTokenPluginFile(url, this.siteUrl, this.infos && this.infos.userprivateaccesskey)) { if (!CoreUrl.canUseTokenPluginFile(url, this.siteUrl, this.getFilesAccessKey())) {
// Cannot use tokenpluginfile. // Cannot use tokenpluginfile.
return Promise.resolve(false); return Promise.resolve(false);
} else if (this.tokenPluginFileWorks !== undefined) { } else if (this.tokenPluginFileWorks !== undefined) {
@ -872,6 +869,39 @@ export class CoreSite extends CoreAuthenticatedSite {
}); });
} }
/**
* Get the access key to use to fetch files.
*
* @returns Access key.
*/
getFilesAccessKey(): string | undefined {
return this.infos?.userprivateaccesskey;
}
/**
* Get auto-login time between requests.
*
* @returns Time between requests.
*/
async getAutoLoginMinTimeBetweenRequests(): Promise<number> {
const timeBetweenRequests = await CoreUtils.ignoreErrors(
this.getConfig('tool_mobile_autologinmintimebetweenreq'),
CoreConstants.SECONDS_MINUTE * 6,
);
return Number(timeBetweenRequests);
}
/**
* Get last auto login time.
* This time is stored in memory, so restarting the app will reset it.
*
* @returns Last auto login time.
*/
getLastAutoLoginTime(): number {
return this.lastAutoLogin;
}
} }
/** /**

View File

@ -88,6 +88,53 @@
</ion-item> </ion-item>
<ng-container *ngIf="siteId"> <ng-container *ngIf="siteId">
<ion-item class="ion-text-wrap">
<ion-label>
<p class="item-heading">WebService token</p>
<p>{{ token }}</p>
</ion-label>
</ion-item>
<ion-item class="ion-text-wrap">
<ion-label>
<p class="item-heading">Private token</p>
@if (privateToken) {
<p>{{ privateToken }}</p>
} @else {
<p>---</p>
}
</ion-label>
</ion-item>
<ion-item class="ion-text-wrap">
<ion-label>
<p class="item-heading">Files access key</p>
@if (filesAccessKey) {
<p>{{ filesAccessKey }}</p>
} @else {
<p>---</p>
}
</ion-label>
</ion-item>
@if (privateToken) {
<ion-item class="ion-text-wrap" *ngIf="autoLoginTimeBetweenRequests">
<ion-label>
<p class="item-heading">Minimum time between auto-login requests</p>
<p>{{ autoLoginTimeBetweenRequests | coreDuration }}</p>
</ion-label>
</ion-item>
<ion-item class="ion-text-wrap">
<ion-label>
<p class="item-heading">Last auto login in this device</p>
@if (lastAutoLoginTime && lastAutoLoginTime > 0) {
<p>{{ lastAutoLoginTime | coreTimeAgo }}</p>
<ion-note class="core-text-sm">This value will reset when the app is restarted.</ion-note>
} @else {
<p>---</p>
}
</ion-label>
</ion-item>
}
<ion-item-divider> <ion-item-divider>
<ion-label> <ion-label>
<h2>Disabled features</h2> <h2>Disabled features</h2>

View File

@ -62,6 +62,13 @@ export class CoreSettingsDevPage implements OnInit {
siteId: string | undefined; siteId: string | undefined;
token?: string;
privateToken?: string;
filesAccessKey?: string;
autoLoginTimeBetweenRequests?: number;
lastAutoLoginTime?: number;
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
this.rtl = CorePlatform.isRTL; this.rtl = CorePlatform.isRTL;
this.RTLChanged(); this.RTLChanged();
@ -69,7 +76,8 @@ export class CoreSettingsDevPage implements OnInit {
this.forceSafeAreaMargins = document.documentElement.classList.contains('force-safe-area-margins'); this.forceSafeAreaMargins = document.documentElement.classList.contains('force-safe-area-margins');
this.safeAreaChanged(); this.safeAreaChanged();
this.siteId = CoreSites.getCurrentSite()?.getId(); const currentSite = CoreSites.getCurrentSite();
this.siteId = currentSite?.getId();
this.stagingSitesCount = CoreConstants.CONFIG.sites.filter((site) => site.staging).length; this.stagingSitesCount = CoreConstants.CONFIG.sites.filter((site) => site.staging).length;
@ -79,7 +87,7 @@ export class CoreSettingsDevPage implements OnInit {
} }
this.alwaysShowLoginForm = Boolean(await CoreConfig.get(ALWAYS_SHOW_LOGIN_FORM, 0)); this.alwaysShowLoginForm = Boolean(await CoreConfig.get(ALWAYS_SHOW_LOGIN_FORM, 0));
if (!this.siteId) { if (!currentSite) {
return; return;
} }
@ -91,6 +99,15 @@ export class CoreSettingsDevPage implements OnInit {
this.userToursEnabled = !CoreUserTours.isDisabled(); this.userToursEnabled = !CoreUserTours.isDisabled();
const privateToken = currentSite.getPrivateToken();
const filesAccessKey = currentSite.getFilesAccessKey();
this.token = '...' + currentSite.getToken().slice(-3);
this.privateToken = privateToken && ('...' + privateToken.slice(-3));
this.filesAccessKey = filesAccessKey && ('...' + filesAccessKey.slice(-3));
this.autoLoginTimeBetweenRequests = await currentSite.getAutoLoginMinTimeBetweenRequests();
this.lastAutoLoginTime = currentSite.getLastAutoLoginTime();
document.head.querySelectorAll('style').forEach((style) => { document.head.querySelectorAll('style').forEach((style) => {
if (this.siteId && style.id.endsWith(this.siteId)) { if (this.siteId && style.id.endsWith(this.siteId)) {
if (style.innerHTML.length > 0) { if (style.innerHTML.length > 0) {
@ -113,7 +130,7 @@ export class CoreSettingsDevPage implements OnInit {
version: plugin.version, version: plugin.version,
})); }));
const disabledFeatures = (await CoreSites.getCurrentSite()?.getPublicConfig())?.tool_mobile_disabledfeatures; const disabledFeatures = (await currentSite.getPublicConfig())?.tool_mobile_disabledfeatures;
this.disabledFeatures = disabledFeatures?.split(',').filter(feature => feature.trim().length > 0) ?? []; this.disabledFeatures = disabledFeatures?.split(',').filter(feature => feature.trim().length > 0) ?? [];
} }
@ -183,7 +200,12 @@ export class CoreSettingsDevPage implements OnInit {
* Copies site info. * Copies site info.
*/ */
copyInfo(): void { copyInfo(): void {
CoreText.copyToClipboard(JSON.stringify({ disabledFeatures: this.disabledFeatures, sitePlugins: this.sitePlugins })); CoreText.copyToClipboard(JSON.stringify({
disabledFeatures: this.disabledFeatures,
sitePlugins: this.sitePlugins,
autoLoginTimeBetweenRequests: this.autoLoginTimeBetweenRequests,
lastAutoLoginTime: this.lastAutoLoginTime,
}));
} }
/** /**

View File

@ -42,6 +42,16 @@ a {
font-weight: bold; font-weight: bold;
} }
.core-text-sm {
font: var(--mdl-typography-body-font-sm);
}
.core-text-md {
font: var(--mdl-typography-body-font-md);
}
.core-text-lg {
font: var(--mdl-typography-body-font-lg);
}
.img-responsive { .img-responsive {
display: block; display: block;
max-width: 100%; max-width: 100%;