mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
User profile state (#438)
* user data * fix missing store selector * profile state * use ProfileStatus * remove tests * test fixes
This commit is contained in:
committed by
Denys Vuika
parent
9e08b8a232
commit
fec3f8aaf7
@@ -132,10 +132,10 @@ describe('Trash', () => {
|
||||
});
|
||||
|
||||
it('has the correct columns', () => {
|
||||
const labels = [ 'Name', 'Location', 'Size', 'Deleted', 'Deleted by' ];
|
||||
const labels = [ 'Name', 'Location', 'Size', 'Deleted'];
|
||||
const elements = labels.map(label => dataTable.getColumnHeaderByLabel(label));
|
||||
|
||||
expect(dataTable.getColumnHeaders().count()).toBe(5 + 1, 'Incorrect number of columns');
|
||||
expect(dataTable.getColumnHeaders().count()).toBe(4 + 1, 'Incorrect number of columns');
|
||||
|
||||
elements.forEach((element, index) => {
|
||||
expect(element.isPresent()).toBe(true, `"${labels[index]}" is missing`);
|
||||
|
@@ -70,6 +70,7 @@ import { SearchComponent } from './components/search/search.component';
|
||||
import { SettingsComponent } from './components/settings/settings.component';
|
||||
import { HybridAppConfigService } from './common/services/hybrid-app-config.service';
|
||||
import { PageTitleService as AcaPageTitleService } from './common/services/page-title.service';
|
||||
import { ProfileResolver } from './common/services/profile.resolver';
|
||||
|
||||
import { InfoDrawerComponent } from './components/info-drawer/info-drawer.component';
|
||||
import { EditFolderDirective } from './directives/edit-folder.directive';
|
||||
@@ -148,7 +149,8 @@ import { MaterialModule } from './material.module';
|
||||
BrowsingFilesService,
|
||||
ContentManagementService,
|
||||
NodeActionsService,
|
||||
NodePermissionService
|
||||
NodePermissionService,
|
||||
ProfileResolver
|
||||
],
|
||||
entryComponents: [
|
||||
NodeVersionsDialogComponent
|
||||
|
@@ -42,6 +42,8 @@ import { GenericErrorComponent } from './components/generic-error/generic-error.
|
||||
import { SearchComponent } from './components/search/search.component';
|
||||
import { SettingsComponent } from './components/settings/settings.component';
|
||||
|
||||
import { ProfileResolver } from './common/services/profile.resolver';
|
||||
|
||||
export const APP_ROUTES: Routes = [
|
||||
{
|
||||
path: 'login',
|
||||
@@ -60,6 +62,7 @@ export const APP_ROUTES: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: LayoutComponent,
|
||||
resolve: { profile: ProfileResolver },
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
|
56
src/app/common/services/profile.resolver.ts
Normal file
56
src/app/common/services/profile.resolver.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Store } from '@ngrx/store';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Resolve } from '@angular/router';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
|
||||
import { AppStore } from '../../store/states/app.state';
|
||||
import { SetUserAction } from '../../store/actions/user.actions';
|
||||
import { selectUser } from '../../store/selectors/app.selectors';
|
||||
import { PeopleContentService } from '@alfresco/adf-core';
|
||||
|
||||
@Injectable()
|
||||
export class ProfileResolver implements Resolve<any> {
|
||||
constructor(private store: Store<AppStore>, private peopleApi: PeopleContentService) { }
|
||||
|
||||
resolve(): Observable<any> {
|
||||
|
||||
this.init();
|
||||
|
||||
return this.profileLoaded();
|
||||
}
|
||||
|
||||
profileLoaded(): Observable<any> {
|
||||
return this.store.select(selectUser).take(1);
|
||||
}
|
||||
|
||||
init(): void {
|
||||
this.peopleApi.getCurrentPerson().subscribe((person: any) => {
|
||||
this.store.dispatch(new SetUserAction(person.entry));
|
||||
});
|
||||
}
|
||||
}
|
@@ -1,9 +1,9 @@
|
||||
<div title="{{ user?.id }}">
|
||||
<div class="current-user__full-name">{{ userName }}</div>
|
||||
<div class="current-user__full-name">{{ user?.userName }}</div>
|
||||
<div
|
||||
class="current-user__avatar am-avatar"
|
||||
[matMenuTriggerFor]="userMenu">
|
||||
{{ userInitials }}
|
||||
{{ user?.initials }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@@ -1,90 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { TestBed, async } from '@angular/core/testing';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { MatMenuModule } from '@angular/material';
|
||||
import {
|
||||
AlfrescoApiService,
|
||||
AppConfigService,
|
||||
StorageService,
|
||||
PeopleContentService,
|
||||
UserPreferencesService,
|
||||
AppConfigPipe
|
||||
} from '@alfresco/adf-core';
|
||||
|
||||
import { CurrentUserComponent } from './current-user.component';
|
||||
import { AppTestingModule } from '../../testing/app-testing.module';
|
||||
|
||||
describe('CurrentUserComponent', () => {
|
||||
let fixture;
|
||||
let component;
|
||||
let peopleApi: PeopleContentService;
|
||||
let user;
|
||||
|
||||
beforeEach(() => {
|
||||
user = { entry: { firstName: 'joe', lastName: 'doe' } };
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
AppTestingModule,
|
||||
MatMenuModule
|
||||
],
|
||||
declarations: [
|
||||
CurrentUserComponent,
|
||||
AppConfigPipe
|
||||
],
|
||||
providers: [
|
||||
AlfrescoApiService,
|
||||
AppConfigService,
|
||||
StorageService,
|
||||
PeopleContentService,
|
||||
UserPreferencesService
|
||||
],
|
||||
schemas: [ NO_ERRORS_SCHEMA ]
|
||||
})
|
||||
.compileComponents()
|
||||
.then(() => {
|
||||
fixture = TestBed.createComponent(CurrentUserComponent);
|
||||
component = fixture.componentInstance;
|
||||
peopleApi = TestBed.get(PeopleContentService);
|
||||
|
||||
spyOn(peopleApi, 'getCurrentPerson').and.returnValue(Observable.of(user));
|
||||
|
||||
fixture.detectChanges();
|
||||
});
|
||||
}));
|
||||
|
||||
it('updates user data', () => {
|
||||
expect(component.user).toBe(user.entry);
|
||||
});
|
||||
|
||||
it('get user initials', () => {
|
||||
expect(component.userInitials).toBe('jd');
|
||||
});
|
||||
});
|
@@ -24,9 +24,13 @@
|
||||
*/
|
||||
|
||||
import { Component, OnInit, OnDestroy, ViewEncapsulation } from '@angular/core';
|
||||
import { PeopleContentService } from '@alfresco/adf-core';
|
||||
import { Subscription } from 'rxjs/Rx';
|
||||
|
||||
import { Store } from '@ngrx/store';
|
||||
import { AppStore } from '../../store/states/app.state';
|
||||
import { selectUser } from '../../store/selectors/app.selectors';
|
||||
import { ProfileState } from '../../store/states/profile.state';
|
||||
|
||||
@Component({
|
||||
selector: 'aca-current-user',
|
||||
templateUrl: './current-user.component.html',
|
||||
@@ -36,39 +40,17 @@ import { Subscription } from 'rxjs/Rx';
|
||||
export class CurrentUserComponent implements OnInit, OnDestroy {
|
||||
private subscriptions: Subscription[] = [];
|
||||
|
||||
user: any = null;
|
||||
user: ProfileState;
|
||||
|
||||
constructor(
|
||||
private peopleApi: PeopleContentService
|
||||
) {}
|
||||
constructor(private store: Store<AppStore>) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.subscriptions = this.subscriptions.concat([
|
||||
this.peopleApi.getCurrentPerson().subscribe((person: any) => this.user = person.entry)
|
||||
this.store.select(selectUser).subscribe((user) => this.user = user)
|
||||
]);
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subscriptions.forEach(s => s.unsubscribe());
|
||||
}
|
||||
|
||||
get userFirstName(): string {
|
||||
const { user } = this;
|
||||
return user ? (user.firstName || '') : '';
|
||||
}
|
||||
|
||||
get userLastName(): string {
|
||||
const { user } = this;
|
||||
return user ? (user.lastName || '') : '';
|
||||
}
|
||||
|
||||
get userName(): string {
|
||||
const { userFirstName: first, userLastName: last } = this;
|
||||
return `${first} ${last}`;
|
||||
}
|
||||
|
||||
get userInitials(): string {
|
||||
const { userFirstName: first, userLastName: last } = this;
|
||||
return [ first[0], last[0] ].join('');
|
||||
}
|
||||
}
|
||||
|
@@ -82,7 +82,7 @@
|
||||
</data-column>
|
||||
|
||||
<data-column
|
||||
*ngIf="userIsAdmin"
|
||||
*ngIf="user.isAdmin"
|
||||
class="adf-data-table-cell--ellipsis"
|
||||
key="archivedByUser.displayName"
|
||||
title="APP.DOCUMENT_LIST.COLUMNS.DELETED_BY">
|
||||
|
@@ -24,20 +24,20 @@
|
||||
*/
|
||||
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { PeopleContentService } from '@alfresco/adf-core';
|
||||
import { ContentManagementService } from '../../common/services/content-management.service';
|
||||
import { PageComponent } from '../page.component';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { selectUser } from '../../store/selectors/app.selectors';
|
||||
import { AppStore } from '../../store/states/app.state';
|
||||
import { ProfileState } from '../../store/states/profile.state';
|
||||
|
||||
@Component({
|
||||
templateUrl: './trashcan.component.html'
|
||||
})
|
||||
export class TrashcanComponent extends PageComponent implements OnInit {
|
||||
userIsAdmin: boolean;
|
||||
user: ProfileState;
|
||||
|
||||
constructor(private contentManagementService: ContentManagementService,
|
||||
private peopleApi: PeopleContentService,
|
||||
store: Store<AppStore>) {
|
||||
super(store);
|
||||
}
|
||||
@@ -49,15 +49,7 @@ export class TrashcanComponent extends PageComponent implements OnInit {
|
||||
this.contentManagementService.nodesRestored.subscribe(() => this.reload()),
|
||||
this.contentManagementService.nodesPurged.subscribe(() => this.reload()),
|
||||
this.contentManagementService.nodesRestored.subscribe(() => this.reload()),
|
||||
this.peopleApi.getCurrentPerson().subscribe((user: any) => this.isUserAdmin(user))
|
||||
this.store.select(selectUser).subscribe((user) => this.user = user)
|
||||
);
|
||||
}
|
||||
|
||||
private isUserAdmin(user) {
|
||||
if (user && user.capabilities) {
|
||||
this.userIsAdmin = user.capabilities.isAdmin;
|
||||
} else {
|
||||
this.userIsAdmin = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -29,3 +29,4 @@ export * from './actions/snackbar.actions';
|
||||
export * from './actions/router.actions';
|
||||
export * from './actions/viewer.actions';
|
||||
export * from './actions/search.actions';
|
||||
export * from './actions/user.actions';
|
||||
|
33
src/app/store/actions/user.actions.ts
Normal file
33
src/app/store/actions/user.actions.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Action } from '@ngrx/store';
|
||||
|
||||
export const SET_USER = 'SET_USER';
|
||||
|
||||
export class SetUserAction implements Action {
|
||||
readonly type = SET_USER;
|
||||
constructor(public payload: any) { }
|
||||
}
|
@@ -33,7 +33,9 @@ import {
|
||||
SET_LOGO_PATH,
|
||||
SetLogoPathAction,
|
||||
SET_SELECTED_NODES,
|
||||
SetSelectedNodesAction
|
||||
SetSelectedNodesAction,
|
||||
SET_USER,
|
||||
SetUserAction
|
||||
} from '../actions';
|
||||
|
||||
export function appReducer(
|
||||
@@ -57,6 +59,11 @@ export function appReducer(
|
||||
action
|
||||
));
|
||||
break;
|
||||
case SET_USER:
|
||||
newState = updateUser(state, <SetUserAction>(
|
||||
action
|
||||
));
|
||||
break;
|
||||
default:
|
||||
newState = Object.assign({}, state);
|
||||
}
|
||||
@@ -85,6 +92,29 @@ function updateLogoPath(state: AppState, action: SetLogoPathAction): AppState {
|
||||
return newState;
|
||||
}
|
||||
|
||||
function updateUser(state: AppState, action: SetUserAction): AppState {
|
||||
const newState = Object.assign({}, state);
|
||||
const user = action.payload;
|
||||
|
||||
const id = user.id;
|
||||
const firstName = user.firstName || '';
|
||||
const lastName = user.lastName || '';
|
||||
const userName = `${firstName} ${lastName}`;
|
||||
const initials = [ firstName[0], lastName[0] ].join('');
|
||||
const isAdmin = user.capabilities ? user.capabilities.isAdmin : true;
|
||||
|
||||
newState.user = {
|
||||
firstName,
|
||||
lastName,
|
||||
userName,
|
||||
initials,
|
||||
isAdmin,
|
||||
id
|
||||
};
|
||||
|
||||
return newState;
|
||||
}
|
||||
|
||||
function updateSelectedNodes(
|
||||
state: AppState,
|
||||
action: SetSelectedNodesAction
|
||||
|
@@ -31,3 +31,4 @@ export const selectHeaderColor = createSelector(selectApp, (state: AppState) =>
|
||||
export const selectAppName = createSelector(selectApp, (state: AppState) => state.appName);
|
||||
export const selectLogoPath = createSelector(selectApp, (state: AppState) => state.logoPath);
|
||||
export const appSelection = createSelector(selectApp, (state: AppState) => state.selection);
|
||||
export const selectUser = createSelector(selectApp, (state: AppState) => state.user);
|
||||
|
@@ -24,18 +24,26 @@
|
||||
*/
|
||||
|
||||
import { SelectionState } from './selection.state';
|
||||
import { ProfileState } from './profile.state';
|
||||
|
||||
export interface AppState {
|
||||
appName: string;
|
||||
headerColor: string;
|
||||
logoPath: string;
|
||||
selection: SelectionState;
|
||||
user: ProfileState;
|
||||
}
|
||||
|
||||
export const INITIAL_APP_STATE: AppState = {
|
||||
appName: 'Alfresco Example Content Application',
|
||||
headerColor: '#2196F3',
|
||||
logoPath: 'assets/images/alfresco-logo-white.svg',
|
||||
user: {
|
||||
isAdmin: true, // 5.2.x
|
||||
id: null,
|
||||
firstName: '',
|
||||
lastName: ''
|
||||
},
|
||||
selection: {
|
||||
nodes: [],
|
||||
isEmpty: true,
|
||||
|
33
src/app/store/states/profile.state.ts
Normal file
33
src/app/store/states/profile.state.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
export interface ProfileState {
|
||||
id: string;
|
||||
isAdmin: boolean;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
userName?: string;
|
||||
initials?: string;
|
||||
}
|
Reference in New Issue
Block a user