Merge pull request #3072 from NoelDeMartin/MOBILE-3316
MOBILE-3316: Handle new user access errorsmain
commit
d6e38b3de1
|
@ -2332,6 +2332,7 @@
|
||||||
"core.userdeleted": "moodle",
|
"core.userdeleted": "moodle",
|
||||||
"core.userdetails": "moodle",
|
"core.userdetails": "moodle",
|
||||||
"core.usernotfullysetup": "error",
|
"core.usernotfullysetup": "error",
|
||||||
|
"core.usersuspended": "moodle",
|
||||||
"core.users": "moodle",
|
"core.users": "moodle",
|
||||||
"core.view": "moodle",
|
"core.view": "moodle",
|
||||||
"core.viewcode": "local_moodlemobileapp",
|
"core.viewcode": "local_moodlemobileapp",
|
||||||
|
|
|
@ -610,11 +610,17 @@ export class CoreSite {
|
||||||
CoreEvents.trigger(CoreEvents.SESSION_EXPIRED, {}, this.id);
|
CoreEvents.trigger(CoreEvents.SESSION_EXPIRED, {}, this.id);
|
||||||
// Change error message. Try to get data from cache, the event will handle the error.
|
// Change error message. Try to get data from cache, the event will handle the error.
|
||||||
error.message = Translate.instant('core.lostconnection');
|
error.message = Translate.instant('core.lostconnection');
|
||||||
} else if (error.errorcode === 'userdeleted') {
|
} else if (error.errorcode === 'userdeleted' || error.errorcode === 'wsaccessuserdeleted') {
|
||||||
// User deleted, trigger event.
|
// User deleted, trigger event.
|
||||||
CoreEvents.trigger(CoreEvents.USER_DELETED, { params: data }, this.id);
|
CoreEvents.trigger(CoreEvents.USER_DELETED, { params: data }, this.id);
|
||||||
error.message = Translate.instant('core.userdeleted');
|
error.message = Translate.instant('core.userdeleted');
|
||||||
|
|
||||||
|
throw new CoreWSError(error);
|
||||||
|
} else if (error.errorcode === 'wsaccessusersuspended') {
|
||||||
|
// User suspended, trigger event.
|
||||||
|
CoreEvents.trigger(CoreEvents.USER_SUSPENDED, { params: data }, this.id);
|
||||||
|
error.message = Translate.instant('core.usersuspended');
|
||||||
|
|
||||||
throw new CoreWSError(error);
|
throw new CoreWSError(error);
|
||||||
} else if (error.errorcode === 'forcepasswordchangenotice') {
|
} else if (error.errorcode === 'forcepasswordchangenotice') {
|
||||||
// Password Change Forced, trigger event. Try to get data from cache, the event will handle the error.
|
// Password Change Forced, trigger event. Try to get data from cache, the event will handle the error.
|
||||||
|
|
|
@ -88,6 +88,7 @@
|
||||||
<core-empty-box *ngIf="!user && !isDeleted && isEnrolled" icon="far-user" [message]=" 'core.user.detailsnotavailable' | translate">
|
<core-empty-box *ngIf="!user && !isDeleted && isEnrolled" icon="far-user" [message]=" 'core.user.detailsnotavailable' | translate">
|
||||||
</core-empty-box>
|
</core-empty-box>
|
||||||
<core-empty-box *ngIf="isDeleted" icon="far-user" [message]="'core.userdeleted' | translate"></core-empty-box>
|
<core-empty-box *ngIf="isDeleted" icon="far-user" [message]="'core.userdeleted' | translate"></core-empty-box>
|
||||||
|
<core-empty-box *ngIf="isSuspended" icon="far-user" [message]="'core.usersuspended' | translate"></core-empty-box>
|
||||||
<core-empty-box *ngIf="!isEnrolled" icon="far-user" [message]="'core.notenrolledprofile' | translate"></core-empty-box>
|
<core-empty-box *ngIf="!isEnrolled" icon="far-user" [message]="'core.notenrolledprofile' | translate"></core-empty-box>
|
||||||
</core-loading>
|
</core-loading>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
|
@ -53,6 +53,7 @@ export class CoreUserProfilePage implements OnInit, OnDestroy {
|
||||||
isLoadingHandlers = false;
|
isLoadingHandlers = false;
|
||||||
user?: CoreUserProfile;
|
user?: CoreUserProfile;
|
||||||
isDeleted = false;
|
isDeleted = false;
|
||||||
|
isSuspended = false;
|
||||||
isEnrolled = true;
|
isEnrolled = true;
|
||||||
rolesFormatted?: string;
|
rolesFormatted?: string;
|
||||||
actionHandlers: CoreUserProfileHandlerData[] = [];
|
actionHandlers: CoreUserProfileHandlerData[] = [];
|
||||||
|
@ -113,7 +114,8 @@ export class CoreUserProfilePage implements OnInit, OnDestroy {
|
||||||
try {
|
try {
|
||||||
await CoreUser.logView(this.userId, this.courseId, this.user.fullname);
|
await CoreUser.logView(this.userId, this.courseId, this.user.fullname);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.isDeleted = error?.errorcode === 'userdeleted';
|
this.isDeleted = error?.errorcode === 'userdeleted' || error?.errorcode === 'wsaccessuserdeleted';
|
||||||
|
this.isSuspended = error?.errorcode === 'wsaccessusersuspended';
|
||||||
this.isEnrolled = error?.errorcode !== 'notenrolledprofile';
|
this.isEnrolled = error?.errorcode !== 'notenrolledprofile';
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -22,7 +22,7 @@ import { CoreUserOffline } from './user-offline';
|
||||||
import { CoreLogger } from '@singletons/logger';
|
import { CoreLogger } from '@singletons/logger';
|
||||||
import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
|
import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
|
||||||
import { makeSingleton, Translate } from '@singletons';
|
import { makeSingleton, Translate } from '@singletons';
|
||||||
import { CoreEvents } from '@singletons/events';
|
import { CoreEvents, CoreEventSiteData, CoreEventUserDeletedData, CoreEventUserSuspendedData } from '@singletons/events';
|
||||||
import { CoreStatusWithWarningsWSResponse, CoreWSExternalWarning } from '@services/ws';
|
import { CoreStatusWithWarningsWSResponse, CoreWSExternalWarning } from '@services/ws';
|
||||||
import { CoreError } from '@classes/errors/error';
|
import { CoreError } from '@classes/errors/error';
|
||||||
import { USERS_TABLE_NAME, CoreUserDBRecord } from './database/user';
|
import { USERS_TABLE_NAME, CoreUserDBRecord } from './database/user';
|
||||||
|
@ -61,24 +61,8 @@ export class CoreUserProvider {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.logger = CoreLogger.getInstance('CoreUserProvider');
|
this.logger = CoreLogger.getInstance('CoreUserProvider');
|
||||||
|
|
||||||
CoreEvents.on(CoreEvents.USER_DELETED, (data) => {
|
CoreEvents.on(CoreEvents.USER_DELETED, data => this.handleUserKickedOutEvent(data));
|
||||||
// Search for userid in params.
|
CoreEvents.on(CoreEvents.USER_SUSPENDED, data => this.handleUserKickedOutEvent(data));
|
||||||
let userId = 0;
|
|
||||||
|
|
||||||
if (data.params.userid) {
|
|
||||||
userId = data.params.userid;
|
|
||||||
} else if (data.params.userids) {
|
|
||||||
userId = data.params.userids[0];
|
|
||||||
} else if (data.params.field === 'id' && data.params.values && data.params.values.length) {
|
|
||||||
userId = data.params.values[0];
|
|
||||||
} else if (data.params.userlist && data.params.userlist.length) {
|
|
||||||
userId = data.params.userlist[0].userid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userId > 0) {
|
|
||||||
this.deleteStoredUser(userId, data.siteId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -153,6 +137,32 @@ export class CoreUserProvider {
|
||||||
return result.profileimageurl!;
|
return result.profileimageurl!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle an event where a user was kicked out of the site.
|
||||||
|
*
|
||||||
|
* @param data Event data.
|
||||||
|
*/
|
||||||
|
async handleUserKickedOutEvent(
|
||||||
|
data: CoreEventSiteData & (CoreEventUserDeletedData | CoreEventUserSuspendedData),
|
||||||
|
): Promise<void> {
|
||||||
|
// Search for userid in params.
|
||||||
|
let userId = 0;
|
||||||
|
|
||||||
|
if (data.params.userid) {
|
||||||
|
userId = data.params.userid;
|
||||||
|
} else if (data.params.userids) {
|
||||||
|
userId = data.params.userids[0];
|
||||||
|
} else if (data.params.field === 'id' && data.params.values && data.params.values.length) {
|
||||||
|
userId = data.params.values[0];
|
||||||
|
} else if (data.params.userlist && data.params.userlist.length) {
|
||||||
|
userId = data.params.userlist[0].userid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userId > 0) {
|
||||||
|
await this.deleteStoredUser(userId, data.siteId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store user basic information in local DB to be retrieved if the WS call fails.
|
* Store user basic information in local DB to be retrieved if the WS call fails.
|
||||||
*
|
*
|
||||||
|
|
|
@ -327,6 +327,7 @@
|
||||||
"userdeleted": "This user account has been deleted",
|
"userdeleted": "This user account has been deleted",
|
||||||
"userdetails": "User details",
|
"userdetails": "User details",
|
||||||
"usernotfullysetup": "User not fully set-up",
|
"usernotfullysetup": "User not fully set-up",
|
||||||
|
"usersuspended": "This user account has been suspended",
|
||||||
"users": "Users",
|
"users": "Users",
|
||||||
"view": "View",
|
"view": "View",
|
||||||
"viewcode": "View code",
|
"viewcode": "View code",
|
||||||
|
|
|
@ -862,6 +862,7 @@ export class CoreUtilsProvider {
|
||||||
error.errorcode != 'userdeleted' && error.errorcode != 'upgraderunning' &&
|
error.errorcode != 'userdeleted' && error.errorcode != 'upgraderunning' &&
|
||||||
error.errorcode != 'forcepasswordchangenotice' && error.errorcode != 'usernotfullysetup' &&
|
error.errorcode != 'forcepasswordchangenotice' && error.errorcode != 'usernotfullysetup' &&
|
||||||
error.errorcode != 'sitepolicynotagreed' && error.errorcode != 'sitemaintenance' &&
|
error.errorcode != 'sitepolicynotagreed' && error.errorcode != 'sitemaintenance' &&
|
||||||
|
error.errorcode != 'wsaccessusersuspended' && error.errorcode != 'wsaccessuserdeleted' &&
|
||||||
!this.isExpiredTokenError(error)));
|
!this.isExpiredTokenError(error)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ export interface CoreEventsData {
|
||||||
[CoreEvents.COURSE_STATUS_CHANGED]: CoreEventCourseStatusChanged;
|
[CoreEvents.COURSE_STATUS_CHANGED]: CoreEventCourseStatusChanged;
|
||||||
[CoreEvents.PACKAGE_STATUS_CHANGED]: CoreEventPackageStatusChanged;
|
[CoreEvents.PACKAGE_STATUS_CHANGED]: CoreEventPackageStatusChanged;
|
||||||
[CoreEvents.USER_DELETED]: CoreEventUserDeletedData;
|
[CoreEvents.USER_DELETED]: CoreEventUserDeletedData;
|
||||||
|
[CoreEvents.USER_SUSPENDED]: CoreEventUserSuspendedData;
|
||||||
[CoreEvents.FORM_ACTION]: CoreEventFormActionData;
|
[CoreEvents.FORM_ACTION]: CoreEventFormActionData;
|
||||||
[CoreEvents.NOTIFICATION_SOUND_CHANGED]: CoreEventNotificationSoundChangedData;
|
[CoreEvents.NOTIFICATION_SOUND_CHANGED]: CoreEventNotificationSoundChangedData;
|
||||||
[CoreEvents.SELECT_COURSE_TAB]: CoreEventSelectCourseTabData;
|
[CoreEvents.SELECT_COURSE_TAB]: CoreEventSelectCourseTabData;
|
||||||
|
@ -85,6 +86,7 @@ export class CoreEvents {
|
||||||
static readonly MANUAL_COMPLETION_CHANGED = 'manual_completion_changed';
|
static readonly MANUAL_COMPLETION_CHANGED = 'manual_completion_changed';
|
||||||
static readonly COMPLETION_CHANGED = 'completion_changed';
|
static readonly COMPLETION_CHANGED = 'completion_changed';
|
||||||
static readonly USER_DELETED = 'user_deleted';
|
static readonly USER_DELETED = 'user_deleted';
|
||||||
|
static readonly USER_SUSPENDED = 'user_suspended';
|
||||||
static readonly PACKAGE_STATUS_CHANGED = 'package_status_changed';
|
static readonly PACKAGE_STATUS_CHANGED = 'package_status_changed';
|
||||||
static readonly COURSE_STATUS_CHANGED = 'course_status_changed';
|
static readonly COURSE_STATUS_CHANGED = 'course_status_changed';
|
||||||
static readonly SECTION_STATUS_CHANGED = 'section_status_changed';
|
static readonly SECTION_STATUS_CHANGED = 'section_status_changed';
|
||||||
|
@ -308,6 +310,14 @@ export type CoreEventUserDeletedData = {
|
||||||
params: any; // Params sent to the WS that failed.
|
params: any; // Params sent to the WS that failed.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data passed to USER_SUSPENDED event.
|
||||||
|
*/
|
||||||
|
export type CoreEventUserSuspendedData = {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
params: any; // Params sent to the WS that failed.
|
||||||
|
};
|
||||||
|
|
||||||
export enum CoreEventFormAction {
|
export enum CoreEventFormAction {
|
||||||
CANCEL = 'cancel',
|
CANCEL = 'cancel',
|
||||||
SUBMIT = 'submit',
|
SUBMIT = 'submit',
|
||||||
|
|
Loading…
Reference in New Issue