Fix process cloud page (#4075)

* Fix process cloud page

* Use FilterParamModel

* Rollback method

* Fix core unit test related to identity service

* Fix process filters cloud
Get user info from different keys

* Select the my-task filter in case the task has been created

* Add family_name and given_name to the jwt token
This commit is contained in:
Maurizio Vitale
2018-12-12 15:43:57 +00:00
committed by Eugenio Romano
parent 511087f6b1
commit e241779f3a
29 changed files with 261 additions and 240 deletions

View File

@@ -548,7 +548,7 @@ describe('User info component', () => {
beforeEach(async(() => {
spyOn(authService, 'isOauth').and.returnValue(true);
spyOn(authService, 'isLoggedIn').and.returnValue(true);
getCurrentUserInfoStub = spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue(of(identityUserMock));
getCurrentUserInfoStub = spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue(identityUserMock);
}));
it('should able to fetch identity userInfo', async(() => {
@@ -583,7 +583,7 @@ describe('User info component', () => {
it('should show last name if first name is null', async(() => {
fixture.detectChanges();
let fakeIdentityUser: IdentityUserModel = new IdentityUserModel(identityUserWithOutFirstNameMock);
getCurrentUserInfoStub.and.returnValue(of(fakeIdentityUser));
getCurrentUserInfoStub.and.returnValue(fakeIdentityUser);
fixture.detectChanges();
fixture.whenStable().then(() => {

View File

@@ -23,7 +23,7 @@ import { IdentityUserModel } from './../models/identity-user.model';
import { BpmUserService } from './../services/bpm-user.service';
import { EcmUserService } from './../services/ecm-user.service';
import { IdentityUserService } from '../services/identity-user.service';
import { Observable } from 'rxjs';
import { of, Observable } from 'rxjs';
@Component({
selector: 'adf-userinfo',
@@ -100,7 +100,7 @@ export class UserInfoComponent implements OnInit {
}
loadIdentityUserInfo() {
this.identityUser$ = this.identityUserService.getCurrentUserInfo();
this.identityUser$ = of(this.identityUserService.getCurrentUserInfo());
}
stopClosing(event) {

View File

@@ -64,17 +64,14 @@ describe('IdentityUserService', () => {
});
});
it('should fetch identity user info from Jwt token', (done) => {
it('should fetch identity user info from Jwt token', () => {
localStorage.setItem('access_token', mockToken);
service.getCurrentUserInfo().subscribe(
(user) => {
expect(user).toBeDefined();
expect(user.firstName).toEqual('John');
expect(user.lastName).toEqual('Doe');
expect(user.email).toEqual('johnDoe@gmail.com');
expect(user.username).toEqual('johnDoe1');
done();
});
const user = service.getCurrentUserInfo();
expect(user).toBeDefined();
expect(user.firstName).toEqual('John');
expect(user.lastName).toEqual('Doe');
expect(user.email).toEqual('johnDoe@gmail.com');
expect(user.username).toEqual('johnDoe1');
});
it('should fetch users ', (done) => {
@@ -189,7 +186,7 @@ describe('IdentityUserService', () => {
it('should fetch users by roles without current user', (done) => {
spyOn(service, 'getUsers').and.returnValue(of(mockUsers));
spyOn(service, 'getUserRoles').and.returnValue(of(mockRoles));
spyOn(service, 'getCurrentUserInfo').and.returnValue(of(mockUsers[0]));
spyOn(service, 'getCurrentUserInfo').and.returnValue(mockUsers[0]);
service.getUsersByRolesWithoutCurrentUser([mockRoles[0].name]).then(
(res: IdentityUserModel[]) => {
@@ -202,23 +199,4 @@ describe('IdentityUserService', () => {
}
);
});
it('Should not fetch users by roles without current user if error occurred', (done) => {
const errorResponse = new HttpErrorResponse({
error: 'Mock Error',
status: 404, statusText: 'Not Found'
});
spyOn(service, 'getCurrentUserInfo').and.returnValue(throwError(errorResponse));
service.getUsersByRolesWithoutCurrentUser([mockRoles[0].name])
.catch(
(error) => {
expect(error.status).toEqual(404);
expect(error.statusText).toEqual('Not Found');
expect(error.error).toEqual('Mock Error');
done();
}
);
});
});

View File

@@ -16,7 +16,7 @@
*/
import { Injectable } from '@angular/core';
import { of, Observable, from } from 'rxjs';
import { Observable, from } from 'rxjs';
import { map } from 'rxjs/operators';
import { IdentityUserModel } from '../models/identity-user.model';
@@ -31,6 +31,8 @@ import { IdentityRoleModel } from '../models/identity-role.model';
export class IdentityUserService {
static USER_NAME = 'name';
static FAMILY_NAME = 'family_name';
static GIVEN_NAME = 'given_name';
static USER_EMAIL = 'email';
static USER_ACCESS_TOKEN = 'access_token';
static USER_PREFERRED_USERNAME = 'preferred_username';
@@ -40,13 +42,13 @@ export class IdentityUserService {
private apiService: AlfrescoApiService,
private appConfigService: AppConfigService) {}
getCurrentUserInfo(): Observable<IdentityUserModel> {
const fullName = this.getValueFromToken<string>(IdentityUserService.USER_NAME);
getCurrentUserInfo(): IdentityUserModel {
const familyName = this.getValueFromToken<string>(IdentityUserService.FAMILY_NAME);
const givenName = this.getValueFromToken<string>(IdentityUserService.GIVEN_NAME);
const email = this.getValueFromToken<string>(IdentityUserService.USER_EMAIL);
const username = this.getValueFromToken<string>(IdentityUserService.USER_PREFERRED_USERNAME);
const nameParts = fullName.split(' ');
const user = { firstName: nameParts[0], lastName: nameParts[1], email: email, username: username };
return of(new IdentityUserModel(user));
const user = { firstName: givenName, lastName: familyName, email: email, username: username };
return new IdentityUserModel(user);
}
getValueFromToken<T>(key: string): T {
@@ -110,7 +112,7 @@ export class IdentityUserService {
async getUsersByRolesWithoutCurrentUser(roleNames: string[]): Promise<IdentityUserModel[]> {
const filteredUsers: IdentityUserModel[] = [];
if (roleNames && roleNames.length > 0) {
const currentUser = await this.getCurrentUserInfo().toPromise();
const currentUser = this.getCurrentUserInfo();
let users = await this.getUsers().toPromise();
users = users.filter((user) => { return user.username !== currentUser.username; });