mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-10-01 14:41:14 +00:00
[ACA-2351] allow rules access user group membership (#1071)
This commit is contained in:
@@ -50,7 +50,7 @@ import {
|
|||||||
} from './store/states/app.state';
|
} from './store/states/app.state';
|
||||||
import { filter, takeUntil } from 'rxjs/operators';
|
import { filter, takeUntil } from 'rxjs/operators';
|
||||||
import { ContentApiService } from './services/content-api.service';
|
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 { AppService } from './services/app.service';
|
||||||
import { Subject } from 'rxjs';
|
import { Subject } from 'rxjs';
|
||||||
|
|
||||||
@@ -129,7 +129,6 @@ export class AppComponent implements OnInit, OnDestroy {
|
|||||||
if (isReady) {
|
if (isReady) {
|
||||||
this.loadRepositoryStatus();
|
this.loadRepositoryStatus();
|
||||||
this.loadUserProfile();
|
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.contentApi.getPerson('-me-').subscribe(person => {
|
||||||
this.store.dispatch(new SetUserProfileAction(person.entry));
|
this.store.dispatch(
|
||||||
|
new SetUserProfileAction({ person: person.entry, groups })
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Action } from '@ngrx/store';
|
import { Action } from '@ngrx/store';
|
||||||
import { Node, Person } from '@alfresco/js-api';
|
import { Node, Person, Group } from '@alfresco/js-api';
|
||||||
import { AppState } from '../states';
|
import { AppState } from '../states';
|
||||||
|
|
||||||
export const SET_INITIAL_STATE = 'SET_INITIAL_STATE';
|
export const SET_INITIAL_STATE = 'SET_INITIAL_STATE';
|
||||||
@@ -59,7 +59,7 @@ export class SetCurrentUrlAction implements Action {
|
|||||||
|
|
||||||
export class SetUserProfileAction implements Action {
|
export class SetUserProfileAction implements Action {
|
||||||
readonly type = SET_USER_PROFILE;
|
readonly type = SET_USER_PROFILE;
|
||||||
constructor(public payload: Person) {}
|
constructor(public payload: { person: Person; groups: Group[] }) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ToggleInfoDrawerAction implements Action {
|
export class ToggleInfoDrawerAction implements Action {
|
||||||
|
@@ -131,7 +131,8 @@ function updateLanguagePicker(
|
|||||||
|
|
||||||
function updateUser(state: AppState, action: SetUserProfileAction): AppState {
|
function updateUser(state: AppState, action: SetUserProfileAction): AppState {
|
||||||
const newState = Object.assign({}, state);
|
const newState = Object.assign({}, state);
|
||||||
const user = action.payload;
|
const user = action.payload.person;
|
||||||
|
const groups = [...(action.payload.groups || [])];
|
||||||
|
|
||||||
const id = user.id;
|
const id = user.id;
|
||||||
const firstName = user.firstName || '';
|
const firstName = user.firstName || '';
|
||||||
@@ -142,13 +143,15 @@ function updateUser(state: AppState, action: SetUserProfileAction): AppState {
|
|||||||
const capabilities = (<any>user).capabilities;
|
const capabilities = (<any>user).capabilities;
|
||||||
const isAdmin = capabilities ? capabilities.isAdmin : true;
|
const isAdmin = capabilities ? capabilities.isAdmin : true;
|
||||||
|
|
||||||
newState.user = {
|
// todo: remove <any>
|
||||||
|
newState.user = <any>{
|
||||||
firstName,
|
firstName,
|
||||||
lastName,
|
lastName,
|
||||||
userName,
|
userName,
|
||||||
initials,
|
initials,
|
||||||
isAdmin,
|
isAdmin,
|
||||||
id
|
id,
|
||||||
|
groups
|
||||||
};
|
};
|
||||||
|
|
||||||
return newState;
|
return newState;
|
||||||
|
Reference in New Issue
Block a user