[ACA-2351] allow rules access user group membership (#1071)

This commit is contained in:
Denys Vuika
2019-04-13 07:45:58 +01:00
committed by GitHub
parent fcb077d803
commit 802360db17
3 changed files with 21 additions and 9 deletions

View File

@@ -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 })
);
});
}

View File

@@ -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 {

View File

@@ -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 = (<any>user).capabilities;
const isAdmin = capabilities ? capabilities.isAdmin : true;
newState.user = {
// todo: remove <any>
newState.user = <any>{
firstName,
lastName,
userName,
initials,
isAdmin,
id
id,
groups
};
return newState;