fix blocked access for non admins

This commit is contained in:
Dan Percic 2021-07-01 13:15:19 +03:00
parent da6fc67b23
commit 5d3853ca48
3 changed files with 15 additions and 16 deletions

View File

@ -59,7 +59,7 @@ export class UserListingScreenComponent extends BaseListingComponent<User> imple
.toPromise();
}
await this._loadData(true);
await this._loadData();
});
}
@ -83,7 +83,7 @@ export class UserListingScreenComponent extends BaseListingComponent<User> imple
this._loadingService.start();
user.roles = this.userService.isActive(user) ? [] : ['RED_USER'];
await this._userControllerService.updateProfile(user, user.userId).toPromise();
await this._loadData(true);
await this._loadData();
this._avatars.find(item => item.userId === user.userId).detectChanges();
}
@ -103,9 +103,9 @@ export class UserListingScreenComponent extends BaseListingComponent<User> imple
return this.userService.getName(user);
}
private async _loadData(updateUserService = false) {
private async _loadData() {
this.allEntities = await this._userControllerService.getAllUsers().toPromise();
if (updateUserService) await this.userService.loadAllUsers();
await this.userService.loadAllUsers();
this._executeSearchImmediately();
this._computeStats();
this._loadingService.stop();

View File

@ -89,10 +89,6 @@ export class UserService {
return this._allRedUsers;
}
get allUsers(): User[] {
return this._allUsers;
}
get userId(): string {
return this._currentUser.id;
}
@ -116,16 +112,19 @@ export class UserService {
this._keycloakService.logout(window.location.origin + this._baseHref).then();
}
async loadAllUsersIfNecessary() {
async loadRedUsersIfNecessary() {
if (!this._allRedUsers) {
await this.loadAllUsers();
await this.loadRedUsers();
}
}
async loadRedUsers() {
const allRedUsers = await this._userControllerService.getUsers().toPromise();
this._allRedUsers = allRedUsers.filter(u => UserService._hasAnyRedRole(u));
}
async loadAllUsers() {
this._allUsers = await this._userControllerService.getAllUsers().toPromise();
this._allRedUsers = this._allUsers.filter(u => UserService._hasAnyRedRole(u));
return this._allUsers;
}
async loadCurrentUser() {
@ -144,11 +143,11 @@ export class UserService {
}
getUserById(id: string) {
return this._allUsers.find(u => u.userId === id);
return this._allUsers ? this._allUsers.find(u => u.userId === id) : this.getRedUserById(id);
}
getNameForId(userId: string) {
return this.getName(this.getRedUserById(userId) || this.getUserById(userId));
return this.getName(this.getUserById(userId));
}
getName(user?: User) {

View File

@ -15,11 +15,11 @@ export class AppStateGuard implements CanActivate {
async canActivate(route: ActivatedRouteSnapshot): Promise<boolean> {
if (this._userService.user.isUserAdmin) {
await this._userService.loadAllUsersIfNecessary();
await this._userService.loadRedUsersIfNecessary();
}
if (this._userService.user.isUser || this._userService.user.isAdmin) {
await this._userService.loadAllUsersIfNecessary();
await this._userService.loadRedUsersIfNecessary();
await this._appStateService.loadDossierTemplatesIfNecessary();
await this._appStateService.loadDictionaryDataIfNecessary();
}