mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-3540] Start Task Cloud by cli (#3954)
* [ADF-3538] start creating new folder for cloud components * [ADF-3538] added new package to the script and the builds * [ADF-3538] added some more changes to scripts * [ADF-3538] - starting the new package * Add a cloud component as example * Skip the scss style * remove useless codes * Add i18n example * remove useless code * Simplify the hello component Fix the wrong path * add the app-list-cloud-component add the app-details-cloud-component * Fix process service cloud path * Remove useless file * [ADF-3540] Start Task Component APS2 * Generated startTaskCloudModule * Generated start-task-cloud component by cli * Used start-task-cloud in the demo shell * * Added FormModule instead of CoreModule * Added StartTaskTestingModule * Refactored startTaskCloud Component * * Used FlexLayout * Used Keylock api to fetch users * Removed all css * Refactored start-task-cloud component * Removed form field from the starttask form * Created UsedCloud model * Added unit test to the recent changes * Added mock objects * * Added unit test to the startTaskCloud component * * Added documentation about startTaskCLoud component * Changed runtimeBundle to appName * Changed defaultTaskName to name * * Generated people-cloud component * Created initialUserName pipe * * Fetching roles by userId * Filtering Users with required roles * Removed duplicates * Generated initial-user-name pipe * Generated people-cloud component * Created roleCloud module * * Rebased with development branch * Created start-task-cloud-demo component in the demo-shell * * Added unit tests to the start-task-cloud service * Added unit test to the people-cloud component and userInitail pipe * Updated start-task unit tests to the recent changes * Created mock data * * Updated people-cloud component with error message* Updated unit tests * * Included StartTaskCloud component in the demoShell* Created startTask demo component* Added create task button in the tasklist demo component * * Added lodash * * Fixed lodash import * Add the start task into the cloud demo * Fix the lodash import and @type * Show the My task once the task has been created * first change * [ADF-3540] Improved start task component * [ADF-3540] Fixed expression changed error * [ADF-3540] Refactored code * [ADF-3540] Fix lodash import error * [ADF-3540] Remove lodash dependency * [ADF-3540] Refatored code * tmp * [ADF-3540] Show/Hide current user as part of list * [ADF-3340] Assign new task to current user when no assignee selected * [ADF-3540] Rebased the latest changes * [ADF-3540] Refactored code * [ADF-3540] Improved user search logic for people component * [ADF-3540] Moved user services to Core module * [ADF-3540] Modified translation keys * Add process-services-cloud into the license rule * Fix wrong import for prod build * Add license header * Fix unit tests * Fix proxy karma for content * Fix proxy karma for process services * Fix proxy karma for process cloud
This commit is contained in:
committed by
Eugenio Romano
parent
5bea17fa6c
commit
2f0f33643b
28
lib/core/userinfo/models/identity-role.model.ts
Normal file
28
lib/core/userinfo/models/identity-role.model.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export class IdentityRoleModel {
|
||||
|
||||
id: string;
|
||||
name: string;
|
||||
|
||||
constructor(obj?: any) {
|
||||
if (obj) {
|
||||
this.id = obj.id || null;
|
||||
this.name = obj.name || null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
export class IdentityUserModel {
|
||||
|
||||
id: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
|
@@ -22,5 +22,6 @@ export * from './services/identity-user.service';
|
||||
export * from './models/bpm-user.model';
|
||||
export * from './models/ecm-user.model';
|
||||
export * from './models/identity-user.model';
|
||||
export * from './models/identity-role.model';
|
||||
|
||||
export * from './userinfo.module';
|
||||
|
@@ -16,13 +16,31 @@
|
||||
*/
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { throwError, of } from 'rxjs';
|
||||
import { IdentityUserService } from '../services/identity-user.service';
|
||||
import { setupTestBed } from '../../testing/setupTestBed';
|
||||
import { CoreModule } from '../../core.module';
|
||||
import { mockToken } from './../../mock/jwt-helper.service.spec';
|
||||
import { IdentityUserModel } from '../models/identity-user.model';
|
||||
import { IdentityRoleModel } from '../models/identity-role.model';
|
||||
|
||||
describe('IdentityUserService', () => {
|
||||
|
||||
const mockUsers = [
|
||||
{ id: 'fake-id-1', username: 'first-name-1 last-name-1', firstName: 'first-name-1', lastName: 'last-name-1', email: 'abc@xyz.com' },
|
||||
{ id: 'fake-id-2', username: 'first-name-2 last-name-2', firstName: 'first-name-2', lastName: 'last-name-2', email: 'abcd@xyz.com'},
|
||||
{ id: 'fake-id-3', username: 'first-name-3 last-name-3', firstName: 'first-name-3', lastName: 'last-name-3', email: 'abcde@xyz.com' }
|
||||
];
|
||||
|
||||
const mockRoles = [
|
||||
{ id: 'id-1', name: 'MOCK-ADMIN-ROLE'},
|
||||
{ id: 'id-2', name: 'MOCK-USER-ROLE'},
|
||||
{ id: 'id-3', name: 'MOCK_MODELER-ROLE' },
|
||||
{ id: 'id-4', name: 'MOCK-ROLE-1' },
|
||||
{ id: 'id-5', name: 'MOCK-ROLE-2'}
|
||||
];
|
||||
|
||||
let service: IdentityUserService;
|
||||
|
||||
setupTestBed({
|
||||
@@ -46,7 +64,7 @@ describe('IdentityUserService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should able to fetch identity user info from Jwt token', (done) => {
|
||||
it('should fetch identity user info from Jwt token', (done) => {
|
||||
localStorage.setItem('access_token', mockToken);
|
||||
service.getCurrentUserInfo().subscribe(
|
||||
(user) => {
|
||||
@@ -58,4 +76,149 @@ describe('IdentityUserService', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fetch users ', (done) => {
|
||||
spyOn(service, 'getUsers').and.returnValue(of(mockUsers));
|
||||
service.getUsers().subscribe(
|
||||
(res: IdentityUserModel[]) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res[0].id).toEqual('fake-id-1');
|
||||
expect(res[0].username).toEqual('first-name-1 last-name-1');
|
||||
expect(res[1].id).toEqual('fake-id-2');
|
||||
expect(res[1].username).toEqual('first-name-2 last-name-2');
|
||||
expect(res[2].id).toEqual('fake-id-3');
|
||||
expect(res[2].username).toEqual('first-name-3 last-name-3');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('Should not fetch users if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'getUsers').and.returnValue(throwError(errorResponse));
|
||||
service.getUsers()
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not users');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should fetch roles by userId', (done) => {
|
||||
spyOn(service, 'getUserRoles').and.returnValue(of(mockRoles));
|
||||
service.getUserRoles('mock-user-id').subscribe(
|
||||
(res: IdentityRoleModel[]) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res[0].name).toEqual('MOCK-ADMIN-ROLE');
|
||||
expect(res[1].name).toEqual('MOCK-USER-ROLE');
|
||||
expect(res[4].name).toEqual('MOCK-ROLE-2');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('Should not fetch roles if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'getUserRoles').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.getUserRoles('mock-user-id')
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not users');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should fetch users by roles', (done) => {
|
||||
spyOn(service, 'getUsers').and.returnValue(of(mockUsers));
|
||||
spyOn(service, 'getUserRoles').and.returnValue(of(mockRoles));
|
||||
|
||||
service.getUsersByRolesWithCurrentUser([mockRoles[0].name]).then(
|
||||
(res: IdentityUserModel[]) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res[0].id).toEqual('fake-id-1');
|
||||
expect(res[0].username).toEqual('first-name-1 last-name-1');
|
||||
expect(res[1].id).toEqual('fake-id-2');
|
||||
expect(res[1].username).toEqual('first-name-2 last-name-2');
|
||||
expect(res[2].id).toEqual('fake-id-3');
|
||||
expect(res[2].username).toEqual('first-name-3 last-name-3');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('Should not fetch users by roles if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'getUsers').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.getUsersByRolesWithCurrentUser([mockRoles[0].name])
|
||||
.catch(
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
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]));
|
||||
|
||||
service.getUsersByRolesWithoutCurrentUser([mockRoles[0].name]).then(
|
||||
(res: IdentityUserModel[]) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res[0].id).toEqual('fake-id-2');
|
||||
expect(res[0].username).toEqual('first-name-2 last-name-2');
|
||||
expect(res[1].id).toEqual('fake-id-3');
|
||||
expect(res[1].username).toEqual('first-name-3 last-name-3');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -16,9 +16,14 @@
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { of, Observable } from 'rxjs';
|
||||
import { of, Observable, from } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { IdentityUserModel } from '../models/identity-user.model';
|
||||
import { JwtHelperService } from './../../services/jwt-helper.service';
|
||||
import { JwtHelperService } from '../../services/jwt-helper.service';
|
||||
import { AppConfigService } from '../../app-config/app-config.service';
|
||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
||||
import { IdentityRoleModel } from '../models/identity-role.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -30,7 +35,10 @@ export class IdentityUserService {
|
||||
static USER_ACCESS_TOKEN = 'access_token';
|
||||
static USER_PREFERRED_USERNAME = 'preferred_username';
|
||||
|
||||
constructor(private helper: JwtHelperService) {}
|
||||
constructor(
|
||||
private helper: JwtHelperService,
|
||||
private apiService: AlfrescoApiService,
|
||||
private appConfigService: AppConfigService) {}
|
||||
|
||||
getCurrentUserInfo(): Observable<IdentityUserModel> {
|
||||
const fullName = this.getValueFromToken<string>(IdentityUserService.USER_NAME);
|
||||
@@ -50,4 +58,93 @@ export class IdentityUserService {
|
||||
}
|
||||
return <T> value;
|
||||
}
|
||||
|
||||
getUsers(): Observable<IdentityUserModel[]> {
|
||||
const url = this.buildUserUrl();
|
||||
const httpMethod = 'GET', pathParams = {}, queryParams = {}, bodyParam = {}, headerParams = {},
|
||||
formParams = {}, authNames = [], contentTypes = ['application/json'], accepts = ['application/json'];
|
||||
|
||||
return from(this.apiService.getInstance().oauth2Auth.callCustomApi(
|
||||
url, httpMethod, pathParams, queryParams,
|
||||
headerParams, formParams, bodyParam, authNames,
|
||||
contentTypes, accepts, Object, null, null)
|
||||
).pipe(
|
||||
map((response: IdentityUserModel[]) => {
|
||||
return response;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
getUserRoles(userId: string): Observable<IdentityRoleModel[]> {
|
||||
const url = this.buildRolesUrl(userId);
|
||||
const httpMethod = 'GET', pathParams = {}, queryParams = {}, bodyParam = {}, headerParams = {},
|
||||
formParams = {}, authNames = [], contentTypes = ['application/json'], accepts = ['application/json'];
|
||||
|
||||
return from(this.apiService.getInstance().oauth2Auth.callCustomApi(
|
||||
url, httpMethod, pathParams, queryParams,
|
||||
headerParams, formParams, bodyParam, authNames,
|
||||
contentTypes, accepts, Object, null, null)
|
||||
).pipe(
|
||||
map((response: IdentityRoleModel[]) => {
|
||||
return response;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
async getUsersByRolesWithCurrentUser(roleNames: string[]): Promise<IdentityUserModel[]> {
|
||||
const filteredUsers: IdentityUserModel[] = [];
|
||||
if (roleNames && roleNames.length > 0) {
|
||||
const users = await this.getUsers().toPromise();
|
||||
|
||||
for (let i = 0; i < users.length; i++) {
|
||||
const hasAnyRole = await this.userHasAnyRole(users[i].id, roleNames);
|
||||
if (hasAnyRole) {
|
||||
filteredUsers.push(users[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filteredUsers;
|
||||
}
|
||||
|
||||
async getUsersByRolesWithoutCurrentUser(roleNames: string[]): Promise<IdentityUserModel[]> {
|
||||
const filteredUsers: IdentityUserModel[] = [];
|
||||
if (roleNames && roleNames.length > 0) {
|
||||
const currentUser = await this.getCurrentUserInfo().toPromise();
|
||||
let users = await this.getUsers().toPromise();
|
||||
|
||||
users = users.filter((user) => { return user.username !== currentUser.username; });
|
||||
|
||||
for (let i = 0; i < users.length; i++) {
|
||||
const hasAnyRole = await this.userHasAnyRole(users[i].id, roleNames);
|
||||
if (hasAnyRole) {
|
||||
filteredUsers.push(users[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filteredUsers;
|
||||
}
|
||||
|
||||
private async userHasAnyRole(userId: string, roleNames: string[]): Promise<boolean> {
|
||||
const userRoles = await this.getUserRoles(userId).toPromise();
|
||||
const hasAnyRole = roleNames.some((roleName) => {
|
||||
const filteredRoles = userRoles.filter((userRole) => {
|
||||
return userRole.name.toLocaleLowerCase() === roleName.toLocaleLowerCase();
|
||||
});
|
||||
|
||||
return filteredRoles.length > 0;
|
||||
});
|
||||
|
||||
return hasAnyRole;
|
||||
}
|
||||
|
||||
private buildUserUrl(): any {
|
||||
return `${this.appConfigService.get('bpmHost')}/auth/admin/realms/springboot/users`;
|
||||
}
|
||||
|
||||
private buildRolesUrl(userId: string): any {
|
||||
return `${this.appConfigService.get('bpmHost')}/auth/admin/realms/springboot/users/${userId}/role-mappings/realm/composite`;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user