MOBILE-2317 user: Delete user from cache when deleted form site
parent
d7c6c25292
commit
09e07c31fe
|
@ -17,6 +17,7 @@ import { TranslateService } from '@ngx-translate/core';
|
|||
import { CoreSitesProvider } from '../../../../providers/sites';
|
||||
import { CoreDomUtilsProvider } from '../../../../providers/utils/dom';
|
||||
import { CoreTextUtilsProvider } from '../../../../providers/utils/text';
|
||||
import { CoreUserProvider } from '../../../user/providers/user';
|
||||
|
||||
/**
|
||||
* Component to handle activity completion. It shows a checkbox with the current status, and allows manually changing
|
||||
|
@ -39,8 +40,8 @@ export class CoreCourseModuleCompletionComponent implements OnChanges {
|
|||
completionImage: string;
|
||||
completionDescription: string;
|
||||
|
||||
constructor(private textUtils: CoreTextUtilsProvider, private translate: TranslateService,
|
||||
private domUtils: CoreDomUtilsProvider, private sitesProvider: CoreSitesProvider) {
|
||||
constructor(private textUtils: CoreTextUtilsProvider, private domUtils: CoreDomUtilsProvider,
|
||||
private translate: TranslateService, private sitesProvider: CoreSitesProvider, private userProvider: CoreUserProvider) {
|
||||
this.completionChanged = new EventEmitter();
|
||||
}
|
||||
|
||||
|
@ -130,13 +131,13 @@ export class CoreCourseModuleCompletionComponent implements OnChanges {
|
|||
if (this.completion.overrideby > 0) {
|
||||
langKey += '-override';
|
||||
|
||||
// @todo: Get user profile.
|
||||
// promise = $mmUser.getProfile(scope.completion.overrideby, scope.completion.courseId, true).then(function(profile) {
|
||||
// return {
|
||||
// overrideuser: profile.fullname,
|
||||
// modname: modNameFormatted
|
||||
// };
|
||||
// });
|
||||
promise = this.userProvider.getProfile(this.completion.overrideby, this.completion.courseId, true).then(
|
||||
(profile) => {
|
||||
return {
|
||||
overrideuser: profile.fullname,
|
||||
modname: modNameFormatted
|
||||
};
|
||||
});
|
||||
} else {
|
||||
promise = Promise.resolve(modNameFormatted);
|
||||
}
|
||||
|
|
|
@ -79,6 +79,32 @@ export class CoreUserProvider {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Store user basic information in local DB to be retrieved if the WS call fails.
|
||||
*
|
||||
* @param {number} userId User ID.
|
||||
* @param {string} [siteId] ID of the site the event belongs to. If not defined, use current site.
|
||||
* @return {Promise<any>} Promise resolve when the user is deleted.
|
||||
*/
|
||||
deleteStoredUser(userId: number, siteId?: string): Promise<any> {
|
||||
if (isNaN(userId)) {
|
||||
return Promise.reject(null);
|
||||
}
|
||||
|
||||
let promises = [];
|
||||
|
||||
siteId = siteId || this.sitesProvider.getCurrentSiteId();
|
||||
|
||||
// Invalidate WS calls.
|
||||
promises.push(this.invalidateUserCache(userId, siteId));
|
||||
|
||||
promises.push(this.sitesProvider.getSite(siteId).then((site) => {
|
||||
return site.getDb().deleteRecords(this.USERS_TABLE, { id: userId });
|
||||
}));
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user profile. The type of profile retrieved depends on the params.
|
||||
*
|
||||
|
|
|
@ -18,6 +18,8 @@ import { CoreUserProfileFieldDelegate } from './providers/user-profile-field-del
|
|||
import { CoreUserProvider } from './providers/user';
|
||||
import { CoreUserHelperProvider } from './providers/helper';
|
||||
import { CoreUserProfileMailHandler } from './providers/user-handler';
|
||||
import { CoreEventsProvider } from '../../providers/events';
|
||||
import { CoreSitesProvider } from '../../providers/sites';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
|
@ -33,7 +35,27 @@ import { CoreUserProfileMailHandler } from './providers/user-handler';
|
|||
]
|
||||
})
|
||||
export class CoreUserModule {
|
||||
constructor(userDelegate: CoreUserDelegate, userProfileMailHandler: CoreUserProfileMailHandler) {
|
||||
constructor(userDelegate: CoreUserDelegate, userProfileMailHandler: CoreUserProfileMailHandler,
|
||||
eventsProvider: CoreEventsProvider, sitesProvider: CoreSitesProvider, userProvider: CoreUserProvider) {
|
||||
userDelegate.registerHandler(userProfileMailHandler);
|
||||
|
||||
eventsProvider.on(CoreEventsProvider.USER_DELETED, (data) => {
|
||||
// Search for userid in params.
|
||||
let params = data.params,
|
||||
userId = 0;
|
||||
if (params.userid) {
|
||||
userId = params.userid;
|
||||
} else if (params.userids) {
|
||||
userId = params.userids[0];
|
||||
} else if (params.field === 'id' && params.values && params.values.length) {
|
||||
userId = params.values[0];
|
||||
} else if (params.userlist && params.userlist.length) {
|
||||
userId = params.userlist[0].userid;
|
||||
}
|
||||
|
||||
if (userId > 0) {
|
||||
userProvider.deleteStoredUser(userId, data.siteId);
|
||||
}
|
||||
}, sitesProvider.getCurrentSiteId());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue