mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
[AAE-6389] Remove duplicated identity user service mock (#7373)
* [AAE-6389] removed duplicate services and refactored existing * [AAE-6389] improved and moved mocks to proper files * [AAE-6389] fixed circular dependency
This commit is contained in:
parent
5618ed7000
commit
a40de80658
76
lib/core/mock/identity-group.mock.ts
Normal file
76
lib/core/mock/identity-group.mock.ts
Normal file
@ -0,0 +1,76 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
import { IdentityGroupModel, IdentityGroupCountModel } from '../models/identity-group.model';
|
||||
import { IdentityRoleModel } from '../models/identity-role.model';
|
||||
import { IdentityJoinGroupRequestModel } from '../services/identity-user.service.interface';
|
||||
|
||||
export const mockIdentityGroup1 = <IdentityGroupModel> {
|
||||
id: 'mock-group-id-1', name: 'Mock Group 1', path: '/mock', subGroups: []
|
||||
};
|
||||
|
||||
export const mockIdentityGroup2 = <IdentityGroupModel> {
|
||||
id: 'mock-group-id-2', name: 'Mock Group 2', path: '', subGroups: []
|
||||
};
|
||||
|
||||
export const mockIdentityGroup3 = <IdentityGroupModel> {
|
||||
id: 'mock-group-id-3', name: 'Mock Group 3', path: '', subGroups: []
|
||||
};
|
||||
|
||||
export const mockIdentityGroup4 = <IdentityGroupModel> {
|
||||
id: 'mock-group-id-4', name: 'Mock Group 4', path: '', subGroups: []
|
||||
};
|
||||
|
||||
export const mockIdentityGroup5 = <IdentityGroupModel> {
|
||||
id: 'mock-group-id-5', name: 'Mock Group 5', path: '', subGroups: []
|
||||
};
|
||||
|
||||
export const mockIdentityGroupsCount = <IdentityGroupCountModel> { count: 10 };
|
||||
|
||||
export const mockIdentityGroups = [
|
||||
mockIdentityGroup1, mockIdentityGroup2, mockIdentityGroup3, mockIdentityGroup4, mockIdentityGroup5
|
||||
];
|
||||
|
||||
export const roleMappingMock = [
|
||||
{ id: 'role-id-1', name: 'role-name-1' }, { id: 'role-id-2', name: 'role-name-2' }
|
||||
];
|
||||
|
||||
export const mockIdentityRoles = [
|
||||
new IdentityRoleModel({id: 'mock-role-id', name: 'MOCK-ADMIN-ROLE'}),
|
||||
new IdentityRoleModel({id: 'mock-role-id', name: 'MOCK-USER-ROLE'}),
|
||||
new IdentityRoleModel({id: 'mock-role-id', name: 'MOCK-ROLE-1'})
|
||||
];
|
||||
|
||||
export const clientRoles: IdentityRoleModel[] = [
|
||||
new IdentityRoleModel({ name: 'MOCK-ADMIN-ROLE' }),
|
||||
new IdentityRoleModel({ name: 'MOCK-USER-ROLE' })
|
||||
];
|
||||
|
||||
export const mockJoinGroupRequest: IdentityJoinGroupRequestModel = {userId: 'mock-hser-id', groupId: 'mock-group-id', realm: 'mock-realm-name'};
|
||||
|
||||
export const mockGroup1 = <IdentityGroupModel> {
|
||||
id: 'mock-group-id-1', name: 'Mock Group 1', path: '/mock', subGroups: []
|
||||
};
|
||||
|
||||
export const mockGroup2 = <IdentityGroupModel> {
|
||||
id: 'mock-group-id-2', name: 'Mock Group 2', path: '', subGroups: []
|
||||
};
|
||||
|
||||
export const mockGroups = [
|
||||
<IdentityGroupModel> { id: 'mock-group-id-1', name: 'Mock Group 1', path: '/mock', subGroups: [] },
|
||||
<IdentityGroupModel> { id: 'mock-group-id-2', name: 'Mock Group 2', path: '', subGroups: [] }
|
||||
];
|
@ -15,104 +15,131 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { IdentityGroupModel, IdentityGroupCountModel } from '../models/identity-group.model';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { mockIdentityGroups, mockIdentityGroupsCount, mockIdentityRoles } from './identity-group.mock';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { IdentityGroupServiceInterface } from '../services/identity-group.interface';
|
||||
import {
|
||||
IdentityGroupModel,
|
||||
IdentityGroupQueryResponse,
|
||||
IdentityGroupQueryCloudRequestModel,
|
||||
IdentityGroupSearchParam,
|
||||
IdentityGroupCountModel
|
||||
} from '../models/identity-group.model';
|
||||
import { IdentityRoleModel } from '../models/identity-role.model';
|
||||
|
||||
export const mockIdentityGroup1 = <IdentityGroupModel> {
|
||||
id: 'mock-group-id-1', name: 'Mock Group 1', path: '/mock', subGroups: []
|
||||
};
|
||||
Injectable({ providedIn: 'root' });
|
||||
export class IdentityGroupServiceMock implements IdentityGroupServiceInterface {
|
||||
|
||||
export const mockIdentityGroup2 = <IdentityGroupModel> {
|
||||
id: 'mock-group-id-2', name: 'Mock Group 2', path: '', subGroups: []
|
||||
};
|
||||
|
||||
export const mockIdentityGroup3 = <IdentityGroupModel> {
|
||||
id: 'mock-group-id-3', name: 'Mock Group 3', path: '', subGroups: []
|
||||
};
|
||||
|
||||
export const mockIdentityGroup4 = <IdentityGroupModel> {
|
||||
id: 'mock-group-id-4', name: 'Mock Group 4', path: '', subGroups: []
|
||||
};
|
||||
|
||||
export const mockIdentityGroup5 = <IdentityGroupModel> {
|
||||
id: 'mock-group-id-5', name: 'Mock Group 5', path: '', subGroups: []
|
||||
};
|
||||
|
||||
export const mockIdentityGroupsCount = <IdentityGroupCountModel> { count: 10 };
|
||||
|
||||
export const mockIdentityGroups = [
|
||||
mockIdentityGroup1, mockIdentityGroup2, mockIdentityGroup3, mockIdentityGroup4, mockIdentityGroup5
|
||||
];
|
||||
|
||||
export const mockApplicationDetails = {id: 'mock-app-id', name: 'mock-app-name'};
|
||||
|
||||
export const roleMappingMock = [
|
||||
{ id: 'role-id-1', name: 'role-name-1' }, { id: 'role-id-2', name: 'role-name-2' }
|
||||
];
|
||||
|
||||
export const roleMappingApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve(roleMappingMock);
|
||||
getGroups(): Observable<IdentityGroupModel[]> {
|
||||
return of(mockIdentityGroups);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const noRoleMappingApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve([]);
|
||||
getAvailableRoles(_groupId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockIdentityRoles);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const groupsMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve(mockIdentityGroups);
|
||||
getAssignedRoles(_groupId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockIdentityRoles);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const createGroupMappingApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
assignRoles(_groupId: string, _roles: IdentityRoleModel[]): Observable<any> {
|
||||
return of();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const updateGroupMappingApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
removeRoles(_groupId: string, _roles: IdentityRoleModel[]): Observable<any> {
|
||||
return of();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteGroupMappingApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
getEffectiveRoles(_groupId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockIdentityRoles);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const applicationDetailsMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve([mockApplicationDetails]);
|
||||
queryGroups(_requestQuery: IdentityGroupQueryCloudRequestModel): Observable<IdentityGroupQueryResponse> {
|
||||
return of();
|
||||
}
|
||||
|
||||
getTotalGroupsCount(): Observable<IdentityGroupCountModel> {
|
||||
return of(mockIdentityGroupsCount);
|
||||
}
|
||||
};
|
||||
|
||||
export const mockIdentityRoles = [
|
||||
new IdentityRoleModel({id: 'mock-role-id', name: 'MOCK-ADMIN-ROLE'}),
|
||||
new IdentityRoleModel({id: 'mock-role-id', name: 'MOCK-USER-ROLE'}),
|
||||
new IdentityRoleModel({id: 'mock-role-id', name: 'MOCK-ROLE-1'})
|
||||
];
|
||||
createGroup(_newGroup: IdentityGroupModel): Observable<any> {
|
||||
return of();
|
||||
}
|
||||
|
||||
export const clientRoles: IdentityRoleModel[] = [
|
||||
new IdentityRoleModel({ name: 'MOCK-ADMIN-ROLE' }),
|
||||
new IdentityRoleModel({ name: 'MOCK-USER-ROLE' })
|
||||
];
|
||||
updateGroup(_groupId: string, _updatedGroup: IdentityGroupModel): Observable<any> {
|
||||
return of();
|
||||
}
|
||||
|
||||
deleteGroup(_groupId: string): Observable<any> {
|
||||
return of();
|
||||
}
|
||||
|
||||
findGroupsByName(searchParams: IdentityGroupSearchParam): Observable<IdentityGroupModel[]> {
|
||||
if (searchParams.name === '') {
|
||||
return of([]);
|
||||
}
|
||||
|
||||
return of(mockIdentityGroups.filter(group =>
|
||||
group.name.toUpperCase().includes(searchParams.name.toUpperCase())
|
||||
));
|
||||
}
|
||||
|
||||
getGroupRoles(_groupId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockIdentityRoles);
|
||||
}
|
||||
|
||||
checkGroupHasRole(groupId: string, roleNames: string[]): Observable<boolean> {
|
||||
return this.getGroupRoles(groupId).pipe(map((groupRoles) => {
|
||||
let hasRole = false;
|
||||
if (groupRoles?.length > 0) {
|
||||
roleNames.forEach((roleName: string) => {
|
||||
const role = groupRoles.find(({ name }) => roleName === name);
|
||||
if (role) {
|
||||
hasRole = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
return hasRole;
|
||||
}));
|
||||
}
|
||||
|
||||
getClientIdByApplicationName(_applicationName: string): Observable<string> {
|
||||
return of('fake-client-id');
|
||||
}
|
||||
|
||||
getClientRoles(groupId: string, _clientId: string): Observable<IdentityRoleModel[]> {
|
||||
if (['mock-group-id-1', 'mock-group-id-2'].includes(groupId)) {
|
||||
return of([{ id: 'mock-role-id', name: 'MOCK-ADMIN-ROLE' }]);
|
||||
}
|
||||
|
||||
return of([{ id: 'mock-role-id', name: 'MOCK-USER-ROLE' }]);
|
||||
}
|
||||
|
||||
checkGroupHasClientApp(groupId: string, clientId: string): Observable<boolean> {
|
||||
return this.getClientRoles(groupId, clientId).pipe(
|
||||
map((response) => response && response.length > 0)
|
||||
);
|
||||
}
|
||||
|
||||
checkGroupHasAnyClientAppRole(groupId: string, clientId: string, roleNames: string[]): Observable<boolean> {
|
||||
return this.getClientRoles(groupId, clientId).pipe(
|
||||
map((clientRoles: any[]) => {
|
||||
let hasRole = false;
|
||||
if (clientRoles.length > 0) {
|
||||
roleNames.forEach((roleName) => {
|
||||
const role = clientRoles.find(({ name }) => name === roleName);
|
||||
|
||||
if (role) {
|
||||
hasRole = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
return hasRole;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
54
lib/core/mock/identity-user.mock.ts
Normal file
54
lib/core/mock/identity-user.mock.ts
Normal file
@ -0,0 +1,54 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
import { IdentityUserModel } from '../models/identity-user.model';
|
||||
import { IdentityRoleModel } from '../models/identity-role.model';
|
||||
|
||||
export const mockIdentityUser1: IdentityUserModel = { id: 'mock-user-id-1', username: 'userName1', firstName: 'first-name-1', lastName: 'last-name-1', email: 'abc@xyz.com' };
|
||||
export const mockIdentityUser2: IdentityUserModel = { id: 'mock-user-id-2', username: 'userName2', firstName: 'first-name-2', lastName: 'last-name-2', email: 'abcd@xyz.com'};
|
||||
export const mockIdentityUser3: IdentityUserModel = { id: 'mock-user-id-3', username: 'userName3', firstName: 'first-name-3', lastName: 'last-name-3', email: 'abcde@xyz.com' };
|
||||
export const mockIdentityUser4: IdentityUserModel = { id: 'mock-user-id-4', username: 'userName4', firstName: 'first-name-4', lastName: 'last-name-4', email: 'abcde@xyz.com' };
|
||||
export let mockIdentityUser5: IdentityUserModel = { id: 'mock-user-id-5', username: 'userName5', firstName: 'first-name-5', lastName: 'last-name-5', email: 'abcde@xyz.com' };
|
||||
|
||||
export const mockIdentityUsers: IdentityUserModel[] = [
|
||||
mockIdentityUser1,
|
||||
mockIdentityUser2,
|
||||
mockIdentityUser3,
|
||||
mockIdentityUser4,
|
||||
mockIdentityUser5
|
||||
];
|
||||
|
||||
export const mockIdentityRole = new IdentityRoleModel({ id: 'id-1', name: 'MOCK-ADMIN-ROLE'});
|
||||
|
||||
export const mockAvailableRoles = [
|
||||
new IdentityRoleModel({ id: 'mock-role-id-1', name: 'MOCK-ADMIN-ROLE'}),
|
||||
new IdentityRoleModel({ id: 'mock-role-id-2', name: 'MOCK-USER-ROLE'}),
|
||||
new IdentityRoleModel({ id: 'mock-role-id-3', name: 'MOCK_MODELER-ROLE' }),
|
||||
new IdentityRoleModel({ id: 'mock-role-id-5', name: 'MOCK-ROLE-2'})
|
||||
];
|
||||
|
||||
export const mockAssignedRoles = [
|
||||
new IdentityRoleModel({ id: 'mock-role-id-1', name: 'MOCK-ADMIN-ROLE'}),
|
||||
new IdentityRoleModel({ id: 'mock-role-id-2', name: 'MOCK_MODELER-ROLE' }),
|
||||
new IdentityRoleModel({ id: 'mock-role-id-3', name: 'MOCK-ROLE-1' })
|
||||
];
|
||||
|
||||
export const mockEffectiveRoles = [
|
||||
new IdentityRoleModel({id: 'mock-role-id-1', name: 'MOCK-ACTIVE-ADMIN-ROLE'}),
|
||||
new IdentityRoleModel({id: 'mock-role-id-2', name: 'MOCK-ACTIVE-USER-ROLE'}),
|
||||
new IdentityRoleModel({id: 'mock-role-id-3', name: 'MOCK-ROLE-1'})
|
||||
];
|
@ -15,153 +15,251 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { IdentityGroupModel } from '../models/identity-group.model';
|
||||
import { IdentityUserModel } from '../models/identity-user.model';
|
||||
import { IdentityRoleModel } from '../models/identity-role.model';
|
||||
import { IdentityGroupModel } from '../models/identity-group.model';
|
||||
import { IdentityJoinGroupRequestModel } from '../services/identity-user.service.interface';
|
||||
import {
|
||||
IdentityUserServiceInterface,
|
||||
IdentityUserQueryCloudRequestModel,
|
||||
IdentityUserQueryResponse,
|
||||
IdentityUserPasswordModel,
|
||||
IdentityJoinGroupRequestModel
|
||||
} from '../services/identity-user.service.interface';
|
||||
import { mockIdentityGroups } from '../mock/identity-group.mock';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { mockAssignedRoles, mockAvailableRoles, mockEffectiveRoles, mockIdentityUser1, mockIdentityUsers } from './identity-user.mock';
|
||||
|
||||
export const mockIdentityUser1: IdentityUserModel = { id: 'mock-user-id-1', username: 'userName1', firstName: 'first-name-1', lastName: 'last-name-1', email: 'abc@xyz.com' };
|
||||
export const mockIdentityUser2: IdentityUserModel = { id: 'mock-user-id-2', username: 'userName2', firstName: 'first-name-2', lastName: 'last-name-2', email: 'abcd@xyz.com'};
|
||||
export const mockIdentityUser3: IdentityUserModel = { id: 'mock-user-id-3', username: 'userName3', firstName: 'first-name-3', lastName: 'last-name-3', email: 'abcde@xyz.com' };
|
||||
export const mockIdentityUser4: IdentityUserModel = { id: 'mock-user-id-4', username: 'userName4', firstName: 'first-name-4', lastName: 'last-name-4', email: 'abcde@xyz.com' };
|
||||
export let mockIdentityUser5: IdentityUserModel = { id: 'mock-user-id-5', username: 'userName5', firstName: 'first-name-5', lastName: 'last-name-5', email: 'abcde@xyz.com' };
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class IdentityUserServiceMock implements IdentityUserServiceInterface {
|
||||
|
||||
export const mockIdentityUsers: IdentityUserModel[] = [
|
||||
mockIdentityUser1,
|
||||
mockIdentityUser2,
|
||||
mockIdentityUser3,
|
||||
mockIdentityUser4,
|
||||
mockIdentityUser5
|
||||
];
|
||||
getCurrentUserInfo(): IdentityUserModel {
|
||||
return mockIdentityUser1;
|
||||
}
|
||||
|
||||
export const mockIdentityRole = new IdentityRoleModel({ id: 'id-1', name: 'MOCK-ADMIN-ROLE'});
|
||||
findUsersByName(search: string): Observable<IdentityUserModel[]> {
|
||||
if (search === '') {
|
||||
return of([]);
|
||||
}
|
||||
|
||||
export const mockAvailableRoles = [
|
||||
new IdentityRoleModel({ id: 'mock-role-id-1', name: 'MOCK-ADMIN-ROLE'}),
|
||||
new IdentityRoleModel({ id: 'mock-role-id-2', name: 'MOCK-USER-ROLE'}),
|
||||
new IdentityRoleModel({ id: 'mock-role-id-3', name: 'MOCK_MODELER-ROLE' }),
|
||||
new IdentityRoleModel({ id: 'mock-role-id-5', name: 'MOCK-ROLE-2'})
|
||||
];
|
||||
return of(mockIdentityUsers.filter(user =>
|
||||
user.username.toUpperCase().includes(search.toUpperCase())
|
||||
));
|
||||
}
|
||||
|
||||
export const mockAssignedRoles = [
|
||||
new IdentityRoleModel({ id: 'mock-role-id-1', name: 'MOCK-ADMIN-ROLE'}),
|
||||
new IdentityRoleModel({ id: 'mock-role-id-2', name: 'MOCK_MODELER-ROLE' }),
|
||||
new IdentityRoleModel({ id: 'mock-role-id-3', name: 'MOCK-ROLE-1' })
|
||||
];
|
||||
findUserByUsername(username: string): Observable<IdentityUserModel[]> {
|
||||
if (username === '') {
|
||||
return of([]);
|
||||
}
|
||||
|
||||
export const mockEffectiveRoles = [
|
||||
new IdentityRoleModel({id: 'mock-role-id-1', name: 'MOCK-ACTIVE-ADMIN-ROLE'}),
|
||||
new IdentityRoleModel({id: 'mock-role-id-2', name: 'MOCK-ACTIVE-USER-ROLE'}),
|
||||
new IdentityRoleModel({id: 'mock-role-id-3', name: 'MOCK-ROLE-1'})
|
||||
];
|
||||
return of(mockIdentityUsers.filter(user => user.username === username));
|
||||
}
|
||||
|
||||
export const mockJoinGroupRequest: IdentityJoinGroupRequestModel = {userId: 'mock-hser-id', groupId: 'mock-group-id', realm: 'mock-realm-name'};
|
||||
findUserByEmail(email: string): Observable<IdentityUserModel[]> {
|
||||
if (email === '') {
|
||||
return of([]);
|
||||
}
|
||||
|
||||
export const mockGroup1 = <IdentityGroupModel> {
|
||||
id: 'mock-group-id-1', name: 'Mock Group 1', path: '/mock', subGroups: []
|
||||
};
|
||||
return of(mockIdentityUsers.filter(user => user.email === email));
|
||||
}
|
||||
|
||||
export const mockGroup2 = <IdentityGroupModel> {
|
||||
id: 'mock-group-id-2', name: 'Mock Group 2', path: '', subGroups: []
|
||||
};
|
||||
findUserById(id: string): Observable<any> {
|
||||
if (id === '') {
|
||||
return of([]);
|
||||
}
|
||||
|
||||
export const mockGroups = [
|
||||
<IdentityGroupModel> { id: 'mock-group-id-1', name: 'Mock Group 1', path: '/mock', subGroups: [] },
|
||||
<IdentityGroupModel> { id: 'mock-group-id-2', name: 'Mock Group 2', path: '', subGroups: [] }
|
||||
];
|
||||
return of(mockIdentityUsers.find(user => user.id === id));
|
||||
}
|
||||
|
||||
export const queryUsersMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve(mockIdentityUsers);
|
||||
getClientRoles(userId: string, _clientId: string): Observable<any[]> {
|
||||
if (userId === 'mock-user-id-1') {
|
||||
return of([{ id: 'id-1', name: 'MOCK-ADMIN-ROLE' }]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const createUserMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
return of([{ id: 'id-2', name: 'MOCK-USER-ROLE' }]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const updateUserMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
checkUserHasClientApp(userId: string, clientId: string): Observable<boolean> {
|
||||
return this.getClientRoles(userId, clientId).pipe(
|
||||
map((clientRoles) => clientRoles.length > 0)
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteUserMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
checkUserHasAnyClientAppRole(userId: string, clientId: string, roleNames: string[]): Observable<boolean> {
|
||||
return this.getClientRoles(userId, clientId).pipe(
|
||||
map((clientRoles: any[]) => {
|
||||
let hasRole = false;
|
||||
if (clientRoles.length > 0) {
|
||||
roleNames.forEach((roleName) => {
|
||||
const role = clientRoles.find(({ name }) => name === roleName);
|
||||
|
||||
export const getInvolvedGroupsMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve(mockGroups);
|
||||
if (role) {
|
||||
hasRole = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
return hasRole;
|
||||
})
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const joinGroupMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
getClientIdByApplicationName(_applicationName: string): Observable<string> {
|
||||
return of('mock-user-id-1');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const leaveGroupMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
checkUserHasApplicationAccess(userId: string, applicationName: string): Observable<boolean> {
|
||||
return this.getClientIdByApplicationName(applicationName).pipe(
|
||||
switchMap((clientId: string) => {
|
||||
return this.checkUserHasClientApp(userId, clientId);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getAvailableRolesMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve(mockAvailableRoles);
|
||||
checkUserHasAnyApplicationRole(userId: string, applicationName: string, roleNames: string[]): Observable<boolean> {
|
||||
return this.getClientIdByApplicationName(applicationName).pipe(
|
||||
switchMap((clientId: string) => {
|
||||
return this.checkUserHasAnyClientAppRole(userId, clientId, roleNames);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getAssignedRolesMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve(mockAssignedRoles);
|
||||
getUsers(): Observable<IdentityUserModel[]> {
|
||||
return of(mockIdentityUsers);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getEffectiveRolesMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve(mockEffectiveRoles);
|
||||
getUserRoles(_userId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockAvailableRoles);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const assignRolesMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
async getUsersByRolesWithCurrentUser(roleNames: string[]): Promise<IdentityUserModel[]> {
|
||||
const filteredUsers: IdentityUserModel[] = [];
|
||||
if (roleNames && roleNames.length > 0) {
|
||||
const users = await this.getUsers().toPromise();
|
||||
|
||||
export const removeRolesMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
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 = this.getCurrentUserInfo();
|
||||
let users = await this.getUsers().toPromise();
|
||||
|
||||
users = users.filter(({ username }) => 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;
|
||||
}
|
||||
|
||||
checkUserHasRole(userId: string, roleNames: string[]): Observable<boolean> {
|
||||
return this.getUserRoles(userId).pipe(map((userRoles: IdentityRoleModel[]) => {
|
||||
let hasRole = false;
|
||||
if (userRoles && userRoles.length > 0) {
|
||||
roleNames.forEach((roleName: string) => {
|
||||
const role = userRoles.find(({ name }) => roleName === name);
|
||||
if (role) {
|
||||
hasRole = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
return hasRole;
|
||||
}));
|
||||
}
|
||||
|
||||
queryUsers(_requestQuery: IdentityUserQueryCloudRequestModel): Observable<IdentityUserQueryResponse> {
|
||||
return of();
|
||||
}
|
||||
|
||||
getTotalUsersCount(): Observable<number> {
|
||||
return of(mockIdentityUsers.length);
|
||||
}
|
||||
|
||||
createUser(newUser: IdentityUserModel): Observable<any> {
|
||||
window.alert(`Create new user: ${newUser}`);
|
||||
return of([]);
|
||||
}
|
||||
|
||||
updateUser(userId: string, updatedUser: IdentityUserModel): Observable<any> {
|
||||
window.alert(`Update user: ${updatedUser} with ID: ${userId}`);
|
||||
return of([]);
|
||||
}
|
||||
|
||||
deleteUser(userId: string): Observable<any> {
|
||||
window.alert(`Delete user with ID: ${userId}`);
|
||||
return of([]);
|
||||
}
|
||||
|
||||
changePassword(userId: string, newPassword: IdentityUserPasswordModel): Observable<any> {
|
||||
window.alert(`New password: ${newPassword} for user with ID: ${userId}`);
|
||||
return of([]);
|
||||
}
|
||||
|
||||
getInvolvedGroups(_userId: string): Observable<IdentityGroupModel[]> {
|
||||
return of(mockIdentityGroups);
|
||||
}
|
||||
|
||||
joinGroup(joinGroupRequest: IdentityJoinGroupRequestModel): Observable<any> {
|
||||
window.alert(`Join group request: ${joinGroupRequest}`);
|
||||
return of([]);
|
||||
}
|
||||
|
||||
leaveGroup(userId: any, groupId: string): Observable<any> {
|
||||
window.alert(`Leave group: ${groupId} for user with ID: ${userId}`);
|
||||
return of([]);
|
||||
}
|
||||
|
||||
getAvailableRoles(_userId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockAvailableRoles);
|
||||
}
|
||||
|
||||
getAssignedRoles(_userId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockAssignedRoles);
|
||||
}
|
||||
|
||||
getEffectiveRoles(_userId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockEffectiveRoles);
|
||||
}
|
||||
|
||||
assignRoles(userId: string, roles: IdentityRoleModel[]): Observable<any> {
|
||||
window.alert(`Assign roles: ${roles} for user with ID: ${userId}`);
|
||||
return of([]);
|
||||
}
|
||||
|
||||
removeRoles(userId: string, removedRoles: IdentityRoleModel[]): Observable<any> {
|
||||
window.alert(`Remove roles: ${removedRoles} for user with ID: ${userId}`);
|
||||
return of([]);
|
||||
}
|
||||
}
|
||||
|
171
lib/core/mock/oauth2.service.mock.ts
Normal file
171
lib/core/mock/oauth2.service.mock.ts
Normal file
@ -0,0 +1,171 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
import { mockGroups, mockIdentityGroups, roleMappingMock } from './identity-group.mock';
|
||||
import { mockAssignedRoles, mockAvailableRoles, mockEffectiveRoles, mockIdentityUsers } from './identity-user.mock';
|
||||
|
||||
export const queryUsersMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve(mockIdentityUsers);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const createUserMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const updateUserMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteUserMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getInvolvedGroupsMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve(mockGroups);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const joinGroupMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const leaveGroupMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getAvailableRolesMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve(mockAvailableRoles);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getAssignedRolesMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve(mockAssignedRoles);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getEffectiveRolesMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve(mockEffectiveRoles);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const assignRolesMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const removeRolesMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const roleMappingApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve(roleMappingMock);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const noRoleMappingApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const groupsMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve(mockIdentityGroups);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const createGroupMappingApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const updateGroupMappingApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteGroupMappingApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const applicationDetailsMockApi: any = {
|
||||
oauth2Auth: {
|
||||
callCustomApi: () => {
|
||||
return Promise.resolve([{id: 'mock-app-id', name: 'mock-app-name'}]);
|
||||
}
|
||||
}
|
||||
};
|
@ -37,4 +37,7 @@ export * from './form/start-form.component.mock';
|
||||
export * from './form/form.service.mock';
|
||||
export * from './form/widget-visibility.service.mock';
|
||||
export * from './jwt-helper.service.spec';
|
||||
export * from './identity-group.mock';
|
||||
export * from './identity-user.mock';
|
||||
export * from './identity-group.service.mock';
|
||||
export * from './identity-user.service.mock';
|
||||
|
@ -24,20 +24,22 @@ import { IdentityGroupSearchParam } from '../models/identity-group.model';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { throwError, of } from 'rxjs';
|
||||
import {
|
||||
noRoleMappingApi,
|
||||
mockIdentityRoles,
|
||||
groupsMockApi,
|
||||
roleMappingApi,
|
||||
clientRoles,
|
||||
applicationDetailsMockApi,
|
||||
mockIdentityGroup1,
|
||||
createGroupMappingApi,
|
||||
updateGroupMappingApi,
|
||||
deleteGroupMappingApi,
|
||||
mockIdentityGroupsCount
|
||||
} from '../mock/identity-group.service.mock';
|
||||
} from '../mock/identity-group.mock';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import {
|
||||
applicationDetailsMockApi,
|
||||
createGroupMappingApi,
|
||||
deleteGroupMappingApi,
|
||||
groupsMockApi,
|
||||
noRoleMappingApi,
|
||||
roleMappingApi,
|
||||
updateGroupMappingApi
|
||||
} from '../mock/oauth2.service.mock';
|
||||
|
||||
describe('IdentityGroupService', () => {
|
||||
let service: IdentityGroupService;
|
||||
|
@ -210,7 +210,7 @@ export class IdentityGroupService implements IdentityGroupServiceInterface {
|
||||
checkGroupHasRole(groupId: string, roleNames: string[]): Observable<boolean> {
|
||||
return this.getGroupRoles(groupId).pipe(map((groupRoles) => {
|
||||
let hasRole = false;
|
||||
if (groupRoles && groupRoles.length > 0) {
|
||||
if (groupRoles?.length > 0) {
|
||||
roleNames.forEach((roleName: string) => {
|
||||
const role = groupRoles.find(({ name }) => roleName === name);
|
||||
if (role) {
|
||||
|
@ -46,6 +46,7 @@ export interface IdentityJoinGroupRequestModel {
|
||||
|
||||
export interface IdentityUserServiceInterface {
|
||||
getCurrentUserInfo(): IdentityUserModel;
|
||||
findUserById(id: string): Observable<any>;
|
||||
findUsersByName(search: string): Observable<IdentityUserModel[]>;
|
||||
findUserByUsername(username: string): Observable<IdentityUserModel[]>;
|
||||
findUserByEmail(email: string): Observable<IdentityUserModel[]>;
|
||||
|
@ -19,24 +19,12 @@ import { TestBed } from '@angular/core/testing';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { throwError, of } from 'rxjs';
|
||||
import {
|
||||
queryUsersMockApi,
|
||||
createUserMockApi,
|
||||
mockIdentityUser1,
|
||||
updateUserMockApi,
|
||||
mockIdentityUser2,
|
||||
deleteUserMockApi,
|
||||
getInvolvedGroupsMockApi,
|
||||
joinGroupMockApi,
|
||||
leaveGroupMockApi,
|
||||
getAvailableRolesMockApi,
|
||||
getAssignedRolesMockApi,
|
||||
getEffectiveRolesMockApi,
|
||||
assignRolesMockApi,
|
||||
mockIdentityRole,
|
||||
removeRolesMockApi,
|
||||
mockIdentityUsers,
|
||||
mockJoinGroupRequest
|
||||
} from 'core/mock/identity-user.service.mock';
|
||||
mockIdentityUsers
|
||||
} from '../mock/identity-user.mock';
|
||||
import { mockJoinGroupRequest } from '../mock/identity-group.mock';
|
||||
import { IdentityUserService } from '../services/identity-user.service';
|
||||
import { setupTestBed } from '../testing/setup-test-bed';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
@ -44,6 +32,20 @@ import { mockToken } from '../mock/jwt-helper.service.spec';
|
||||
import { IdentityRoleModel } from '../models/identity-role.model';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import {
|
||||
assignRolesMockApi,
|
||||
createUserMockApi,
|
||||
deleteUserMockApi,
|
||||
getAssignedRolesMockApi,
|
||||
getAvailableRolesMockApi,
|
||||
getEffectiveRolesMockApi,
|
||||
getInvolvedGroupsMockApi,
|
||||
joinGroupMockApi,
|
||||
leaveGroupMockApi,
|
||||
queryUsersMockApi,
|
||||
removeRolesMockApi,
|
||||
updateUserMockApi
|
||||
} from '../mock/oauth2.service.mock';
|
||||
|
||||
describe('IdentityUserService', () => {
|
||||
|
||||
|
@ -16,10 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Meta, moduleMetadata, Story } from '@storybook/angular';
|
||||
import { IdentityGroupService, mockIdentityGroups } from '@alfresco/adf-core';
|
||||
import { IdentityGroupService, mockIdentityGroups, IdentityGroupServiceMock } from '@alfresco/adf-core';
|
||||
import { GroupCloudModule } from '../group-cloud.module';
|
||||
import { GroupCloudComponent } from './group-cloud.component';
|
||||
import { IdentityGroupServiceMock } from '../mock/identity-group.service.mock';
|
||||
import { ProcessServicesCloudStoryModule } from '../../testing/process-services-cloud-story.module';
|
||||
|
||||
export default {
|
||||
|
@ -1,146 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
IdentityGroupCountModel,
|
||||
IdentityGroupModel,
|
||||
IdentityGroupQueryCloudRequestModel,
|
||||
IdentityGroupQueryResponse,
|
||||
IdentityGroupSearchParam,
|
||||
IdentityRoleModel,
|
||||
mockIdentityGroups,
|
||||
mockIdentityRoles,
|
||||
IdentityGroupServiceInterface
|
||||
} from '@alfresco/adf-core';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
Injectable({ providedIn: 'root' });
|
||||
export class IdentityGroupServiceMock implements IdentityGroupServiceInterface {
|
||||
|
||||
getGroups(): Observable<IdentityGroupModel[]> {
|
||||
return of(mockIdentityGroups);
|
||||
}
|
||||
|
||||
getAvailableRoles(_groupId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockIdentityRoles);
|
||||
}
|
||||
|
||||
getAssignedRoles(_groupId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockIdentityRoles);
|
||||
}
|
||||
|
||||
assignRoles(_groupId: string, _roles: IdentityRoleModel[]): Observable<any> {
|
||||
return of();
|
||||
}
|
||||
|
||||
removeRoles(_groupId: string, _roles: IdentityRoleModel[]): Observable<any> {
|
||||
return of();
|
||||
}
|
||||
|
||||
getEffectiveRoles(_groupId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockIdentityRoles);
|
||||
}
|
||||
|
||||
queryGroups(_requestQuery: IdentityGroupQueryCloudRequestModel): Observable<IdentityGroupQueryResponse> {
|
||||
return of();
|
||||
}
|
||||
|
||||
getTotalGroupsCount(): Observable<IdentityGroupCountModel> {
|
||||
return of({ count: mockIdentityGroups.length });
|
||||
}
|
||||
|
||||
createGroup(_newGroup: IdentityGroupModel): Observable<any> {
|
||||
return of();
|
||||
}
|
||||
|
||||
updateGroup(_groupId: string, _updatedGroup: IdentityGroupModel): Observable<any> {
|
||||
return of();
|
||||
}
|
||||
|
||||
deleteGroup(_groupId: string): Observable<any> {
|
||||
return of();
|
||||
}
|
||||
|
||||
findGroupsByName(searchParams: IdentityGroupSearchParam): Observable<IdentityGroupModel[]> {
|
||||
if (searchParams.name === '') {
|
||||
return of([]);
|
||||
}
|
||||
|
||||
return of(mockIdentityGroups.filter(group =>
|
||||
group.name.toUpperCase().includes(searchParams.name.toUpperCase())
|
||||
));
|
||||
}
|
||||
|
||||
getGroupRoles(_groupId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockIdentityRoles);
|
||||
}
|
||||
|
||||
checkGroupHasRole(groupId: string, roleNames: string[]): Observable<boolean> {
|
||||
return this.getGroupRoles(groupId).pipe(map((groupRoles) => {
|
||||
let hasRole = false;
|
||||
if (groupRoles && groupRoles.length > 0) {
|
||||
roleNames.forEach((roleName: string) => {
|
||||
const role = groupRoles.find(({ name }) => roleName === name);
|
||||
if (role) {
|
||||
hasRole = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
return hasRole;
|
||||
}));
|
||||
}
|
||||
|
||||
getClientIdByApplicationName(_applicationName: string): Observable<string> {
|
||||
return of('fake-client-id');
|
||||
}
|
||||
|
||||
getClientRoles(groupId: string, _clientId: string): Observable<IdentityRoleModel[]> {
|
||||
if (['mock-group-id-1', 'mock-group-id-2'].includes(groupId)) {
|
||||
return of([{ id: 'mock-role-id', name: 'MOCK-ADMIN-ROLE' }]);
|
||||
}
|
||||
|
||||
return of([{ id: 'mock-role-id', name: 'MOCK-USER-ROLE' }]);
|
||||
}
|
||||
|
||||
checkGroupHasClientApp(groupId: string, clientId: string): Observable<boolean> {
|
||||
return this.getClientRoles(groupId, clientId).pipe(
|
||||
map((response) => response && response.length > 0)
|
||||
);
|
||||
}
|
||||
|
||||
checkGroupHasAnyClientAppRole(groupId: string, clientId: string, roleNames: string[]): Observable<boolean> {
|
||||
return this.getClientRoles(groupId, clientId).pipe(
|
||||
map((clientRoles: any[]) => {
|
||||
let hasRole = false;
|
||||
if (clientRoles.length > 0) {
|
||||
roleNames.forEach((roleName) => {
|
||||
const role = clientRoles.find(({ name }) => name === roleName);
|
||||
|
||||
if (role) {
|
||||
hasRole = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
return hasRole;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
@ -16,11 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Meta, moduleMetadata, Story } from '@storybook/angular';
|
||||
import { IdentityUserService } from '@alfresco/adf-core';
|
||||
import { IdentityUserService, IdentityUserServiceMock, mockIdentityUsers } from '@alfresco/adf-core';
|
||||
import { PeopleCloudComponent } from './people-cloud.component';
|
||||
import { PeopleCloudModule } from '../people-cloud.module';
|
||||
import { IdentityUserServiceMock } from '../mock/identity-user.service.mock';
|
||||
import { mockUsers } from '../mock/user-cloud.mock';
|
||||
import { ProcessServicesCloudStoryModule } from '../../testing/process-services-cloud-story.module';
|
||||
|
||||
export default {
|
||||
@ -73,7 +71,7 @@ validPreselectedUsers.args = {
|
||||
...primary.args,
|
||||
validate: true,
|
||||
mode: 'multiple',
|
||||
preSelectUsers: mockUsers
|
||||
preSelectUsers: mockIdentityUsers
|
||||
};
|
||||
|
||||
export const mandatoryPreselectedUsers = template.bind({});
|
||||
@ -81,8 +79,8 @@ mandatoryPreselectedUsers.args = {
|
||||
...primary.args,
|
||||
validate: true,
|
||||
mode: 'multiple',
|
||||
preSelectUsers: [{ id: 'fake-id-1', username: 'first-name-1 last-name-1', firstName: 'first-name-1', lastName: 'last-name-1', email: 'abc@xyz.com', readonly: true },
|
||||
{ id: 'fake-id-2', username: 'first-name-2 last-name-2', firstName: 'first-name-2', lastName: 'last-name-2', email: 'abcd@xyz.com' }]
|
||||
preSelectUsers: [{ id: 'mock-user-id-1', username: 'userName1', firstName: 'first-name-1', lastName: 'last-name-1', email: 'abc@xyz.com', readonly: true },
|
||||
{ id: 'mock-user-id-2', username: 'userName2', firstName: 'first-name-2', lastName: 'last-name-2', email: 'abcd@xyz.com' }]
|
||||
};
|
||||
|
||||
export const invalidPreselectedUsers = template.bind({});
|
||||
@ -97,8 +95,8 @@ export const excludedUsers = template.bind({});
|
||||
excludedUsers.args = {
|
||||
...primary.args,
|
||||
excludedUsers: [
|
||||
{ id: 'fake-id-2' },
|
||||
{ id: 'fake-id-3' }
|
||||
{ id: 'mock-user-id-2' },
|
||||
{ id: 'mock-user-id-3' }
|
||||
]
|
||||
};
|
||||
|
||||
@ -111,7 +109,7 @@ adminRoleUser.args = {
|
||||
export const noUsers = template.bind({});
|
||||
noUsers.args = {
|
||||
...primary.args,
|
||||
excludedUsers: mockUsers
|
||||
excludedUsers: mockIdentityUsers
|
||||
};
|
||||
|
||||
export const invalidOrEmptyAppName = template.bind({});
|
||||
|
@ -1,265 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
IdentityGroupModel,
|
||||
IdentityRoleModel,
|
||||
IdentityUserModel,
|
||||
mockIdentityGroups,
|
||||
IdentityJoinGroupRequestModel,
|
||||
IdentityUserServiceInterface,
|
||||
IdentityUserPasswordModel,
|
||||
IdentityUserQueryCloudRequestModel,
|
||||
IdentityUserQueryResponse
|
||||
} from '@alfresco/adf-core';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { cloudMockUser, mockRoles, mockUsers } from './user-cloud.mock';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class IdentityUserServiceMock implements IdentityUserServiceInterface {
|
||||
|
||||
getCurrentUserInfo(): IdentityUserModel {
|
||||
return cloudMockUser;
|
||||
}
|
||||
|
||||
findUsersByName(search: string): Observable<IdentityUserModel[]> {
|
||||
if (search === '') {
|
||||
return of([]);
|
||||
}
|
||||
|
||||
return of(mockUsers.filter(user =>
|
||||
user.username.toUpperCase().includes(search.toUpperCase())
|
||||
));
|
||||
}
|
||||
|
||||
findUserByUsername(username: string): Observable<IdentityUserModel[]> {
|
||||
if (username === '') {
|
||||
return of([]);
|
||||
}
|
||||
|
||||
return of(mockUsers.filter(user => user.username === username));
|
||||
}
|
||||
|
||||
findUserByEmail(email: string): Observable<IdentityUserModel[]> {
|
||||
if (email === '') {
|
||||
return of([]);
|
||||
}
|
||||
|
||||
return of(mockUsers.filter(user => user.email === email));
|
||||
}
|
||||
|
||||
findUserById(id: string): Observable<any> {
|
||||
if (id === '') {
|
||||
return of([]);
|
||||
}
|
||||
|
||||
return of(mockUsers.find(user => user.id === id));
|
||||
}
|
||||
|
||||
getClientRoles(userId: string, _clientId: string): Observable<any[]> {
|
||||
if (userId === 'fake-id-1') {
|
||||
return of([{ id: 'id-1', name: 'MOCK-ADMIN-ROLE' }]);
|
||||
}
|
||||
|
||||
return of([{ id: 'id-2', name: 'MOCK-USER-ROLE' }]);
|
||||
}
|
||||
|
||||
checkUserHasClientApp(userId: string, clientId: string): Observable<boolean> {
|
||||
return this.getClientRoles(userId, clientId).pipe(
|
||||
map((clientRoles) => clientRoles.length > 0)
|
||||
);
|
||||
}
|
||||
|
||||
checkUserHasAnyClientAppRole(userId: string, clientId: string, roleNames: string[]): Observable<boolean> {
|
||||
return this.getClientRoles(userId, clientId).pipe(
|
||||
map((clientRoles: any[]) => {
|
||||
let hasRole = false;
|
||||
if (clientRoles.length > 0) {
|
||||
roleNames.forEach((roleName) => {
|
||||
const role = clientRoles.find(({ name }) => name === roleName);
|
||||
|
||||
if (role) {
|
||||
hasRole = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
return hasRole;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
getClientIdByApplicationName(_applicationName: string): Observable<string> {
|
||||
return of('fake-id-1');
|
||||
}
|
||||
|
||||
checkUserHasApplicationAccess(userId: string, applicationName: string): Observable<boolean> {
|
||||
return this.getClientIdByApplicationName(applicationName).pipe(
|
||||
switchMap((clientId: string) => {
|
||||
return this.checkUserHasClientApp(userId, clientId);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
checkUserHasAnyApplicationRole(userId: string, applicationName: string, roleNames: string[]): Observable<boolean> {
|
||||
return this.getClientIdByApplicationName(applicationName).pipe(
|
||||
switchMap((clientId: string) => {
|
||||
return this.checkUserHasAnyClientAppRole(userId, clientId, roleNames);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
getUsers(): Observable<IdentityUserModel[]> {
|
||||
return of(mockUsers);
|
||||
}
|
||||
|
||||
getUserRoles(_userId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockRoles);
|
||||
}
|
||||
|
||||
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 = this.getCurrentUserInfo();
|
||||
let users = await this.getUsers().toPromise();
|
||||
|
||||
users = users.filter(({ username }) => 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;
|
||||
}
|
||||
|
||||
checkUserHasRole(userId: string, roleNames: string[]): Observable<boolean> {
|
||||
return this.getUserRoles(userId).pipe(map((userRoles: IdentityRoleModel[]) => {
|
||||
let hasRole = false;
|
||||
if (userRoles && userRoles.length > 0) {
|
||||
roleNames.forEach((roleName: string) => {
|
||||
const role = userRoles.find(({ name }) => roleName === name);
|
||||
if (role) {
|
||||
hasRole = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
return hasRole;
|
||||
}));
|
||||
}
|
||||
|
||||
queryUsers(_requestQuery: IdentityUserQueryCloudRequestModel): Observable<IdentityUserQueryResponse> {
|
||||
return of();
|
||||
}
|
||||
|
||||
getTotalUsersCount(): Observable<number> {
|
||||
return of(mockUsers.length);
|
||||
}
|
||||
|
||||
createUser(newUser: IdentityUserModel): Observable<any> {
|
||||
window.alert(`Create new user: ${newUser}`);
|
||||
return of([]);
|
||||
}
|
||||
|
||||
updateUser(userId: string, updatedUser: IdentityUserModel): Observable<any> {
|
||||
window.alert(`Update user: ${updatedUser} with ID: ${userId}`);
|
||||
return of([]);
|
||||
}
|
||||
|
||||
deleteUser(userId: string): Observable<any> {
|
||||
window.alert(`Delete user with ID: ${userId}`);
|
||||
return of([]);
|
||||
}
|
||||
|
||||
changePassword(userId: string, newPassword: IdentityUserPasswordModel): Observable<any> {
|
||||
window.alert(`New password: ${newPassword} for user with ID: ${userId}`);
|
||||
return of([]);
|
||||
}
|
||||
|
||||
getInvolvedGroups(_userId: string): Observable<IdentityGroupModel[]> {
|
||||
return of(mockIdentityGroups);
|
||||
}
|
||||
|
||||
joinGroup(joinGroupRequest: IdentityJoinGroupRequestModel): Observable<any> {
|
||||
window.alert(`Join group request: ${joinGroupRequest}`);
|
||||
return of([]);
|
||||
}
|
||||
|
||||
leaveGroup(userId: any, groupId: string): Observable<any> {
|
||||
window.alert(`Leave group: ${groupId} for user with ID: ${userId}`);
|
||||
return of([]);
|
||||
}
|
||||
|
||||
getAvailableRoles(_userId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockRoles);
|
||||
}
|
||||
|
||||
getAssignedRoles(_userId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockRoles);
|
||||
}
|
||||
|
||||
getEffectiveRoles(_userId: string): Observable<IdentityRoleModel[]> {
|
||||
return of(mockRoles);
|
||||
}
|
||||
|
||||
assignRoles(userId: string, roles: IdentityRoleModel[]): Observable<any> {
|
||||
window.alert(`Assign roles: ${roles} for user with ID: ${userId}`);
|
||||
return of([]);
|
||||
}
|
||||
|
||||
removeRoles(userId: string, removedRoles: IdentityRoleModel[]): Observable<any> {
|
||||
window.alert(`Remove roles: ${removedRoles} for user with ID: ${userId}`);
|
||||
return of([]);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user