diff --git a/src/app/app.component.ts b/src/app/app.component.ts index f2a9db21e..f78f01bd7 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -50,7 +50,7 @@ import { } from './store/states/app.state'; import { filter, takeUntil } from 'rxjs/operators'; import { ContentApiService } from './services/content-api.service'; -import { DiscoveryEntry } from '@alfresco/js-api'; +import { DiscoveryEntry, GroupsApi, Group } from '@alfresco/js-api'; import { AppService } from './services/app.service'; import { Subject } from 'rxjs'; @@ -129,7 +129,6 @@ export class AppComponent implements OnInit, OnDestroy { if (isReady) { this.loadRepositoryStatus(); this.loadUserProfile(); - // todo: load external auth-enabled plugins here } }); } @@ -149,9 +148,19 @@ export class AppComponent implements OnInit, OnDestroy { }); } - private loadUserProfile() { + private async loadUserProfile() { + const groupsApi = new GroupsApi(this.alfrescoApiService.getInstance()); + const paging = await groupsApi.listGroupMembershipsForPerson('-me-'); + const groups: Group[] = []; + + if (paging && paging.list && paging.list.entries) { + groups.push(...paging.list.entries.map(obj => obj.entry)); + } + this.contentApi.getPerson('-me-').subscribe(person => { - this.store.dispatch(new SetUserProfileAction(person.entry)); + this.store.dispatch( + new SetUserProfileAction({ person: person.entry, groups }) + ); }); } diff --git a/src/app/store/actions/app.actions.ts b/src/app/store/actions/app.actions.ts index f11c4eb76..a45dafa25 100644 --- a/src/app/store/actions/app.actions.ts +++ b/src/app/store/actions/app.actions.ts @@ -24,7 +24,7 @@ */ import { Action } from '@ngrx/store'; -import { Node, Person } from '@alfresco/js-api'; +import { Node, Person, Group } from '@alfresco/js-api'; import { AppState } from '../states'; export const SET_INITIAL_STATE = 'SET_INITIAL_STATE'; @@ -59,7 +59,7 @@ export class SetCurrentUrlAction implements Action { export class SetUserProfileAction implements Action { readonly type = SET_USER_PROFILE; - constructor(public payload: Person) {} + constructor(public payload: { person: Person; groups: Group[] }) {} } export class ToggleInfoDrawerAction implements Action { diff --git a/src/app/store/reducers/app.reducer.ts b/src/app/store/reducers/app.reducer.ts index 7bbcdfb24..4f376f50c 100644 --- a/src/app/store/reducers/app.reducer.ts +++ b/src/app/store/reducers/app.reducer.ts @@ -131,7 +131,8 @@ function updateLanguagePicker( function updateUser(state: AppState, action: SetUserProfileAction): AppState { const newState = Object.assign({}, state); - const user = action.payload; + const user = action.payload.person; + const groups = [...(action.payload.groups || [])]; const id = user.id; const firstName = user.firstName || ''; @@ -142,13 +143,15 @@ function updateUser(state: AppState, action: SetUserProfileAction): AppState { const capabilities = (user).capabilities; const isAdmin = capabilities ? capabilities.isAdmin : true; - newState.user = { + // todo: remove + newState.user = { firstName, lastName, userName, initials, isAdmin, - id + id, + groups }; return newState;