mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-5960] Storybook stories for PeopleCloud component (#7313)
* [AAE-5953] solved rebase conflict :wq * [AAE-5953] solved rebase conflict * [AAE-5953] added form cloud service interface * [AAE-5953] fixed lint errors * [AAE-5953] migrated stories and mocks * [AAE-5953] migrated task cloud service mock * [AAE-5953] migrated task cloud service mock * [AAE-5953] removed redundant mock * [AAE-5953] refactored and moved mocks * [AAE-5953] refactor modules import * [AAE-5960] added stories file and service mock * [AAE-5960] fixed validation mock * [AAE-5960] added story for user role * [AAE-5960] removed uunused properties from primary story * [AAE-5960] added interface to mock and live identity user service * [AAE-5960] added mandatory preselected users story * [AAE-5960] syntax improvements * [AAE-5960] fixed default value for roles control * [AAE-5960] refactored imports * [AAE-5960] improve syntax * [AAE-5960] refactored services name * [AAE-5960] removed deprecated argTypes defaultValue * [AAE-5960] exported new interface from core * [AAE-5960] fixed import issue with identity user mock service in core * [AAE-5960] fixed issue with viewer component test
This commit is contained in:
@@ -24,9 +24,9 @@ import { TaskDetailsCloudModel } from '../../task/public-api';
|
||||
import { taskDetailsContainer } from '../../task/task-header/mocks/task-details-cloud.mock';
|
||||
import { fakeCloudForm } from '../mocks/cloud-form.mock';
|
||||
import { TaskVariableCloud } from '../models/task-variable-cloud.model';
|
||||
import { FormCloudInterface } from '../services/form-cloud.interface';
|
||||
import { FormCloudServiceInterface } from '../services/form-cloud.service.interface';
|
||||
|
||||
export class FormCloudServiceMock implements FormCloudInterface {
|
||||
export class FormCloudServiceMock implements FormCloudServiceInterface {
|
||||
|
||||
uploadApi: UploadApi;
|
||||
|
||||
|
@@ -22,7 +22,7 @@ import { TaskVariableCloud } from '../models/task-variable-cloud.model';
|
||||
import { FormContent } from '../../services/form-fields.interfaces';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
export interface FormCloudInterface {
|
||||
export interface FormCloudServiceInterface {
|
||||
|
||||
uploadApi: UploadApi;
|
||||
|
@@ -30,12 +30,12 @@ import { CompleteFormRepresentation, UploadApi } from '@alfresco/js-api';
|
||||
import { TaskVariableCloud } from '../models/task-variable-cloud.model';
|
||||
import { BaseCloudService } from '../../services/base-cloud.service';
|
||||
import { FormContent } from '../../services/form-fields.interfaces';
|
||||
import { FormCloudInterface } from './form-cloud.interface';
|
||||
import { FormCloudServiceInterface } from './form-cloud.service.interface';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class FormCloudService extends BaseCloudService implements FormCloudInterface {
|
||||
export class FormCloudService extends BaseCloudService implements FormCloudServiceInterface {
|
||||
|
||||
private _uploadApi;
|
||||
get uploadApi(): UploadApi {
|
||||
|
@@ -0,0 +1,121 @@
|
||||
/*!
|
||||
* @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 { Meta, moduleMetadata, Story } from '@storybook/angular';
|
||||
import { IdentityUserService } 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 {
|
||||
component: PeopleCloudComponent,
|
||||
title: 'Process Services Cloud/Components/People',
|
||||
decorators: [
|
||||
moduleMetadata({
|
||||
imports: [ProcessServicesCloudStoryModule, PeopleCloudModule],
|
||||
providers: [
|
||||
{ provide: IdentityUserService, useClass: IdentityUserServiceMock }
|
||||
]
|
||||
})
|
||||
],
|
||||
argTypes: {
|
||||
appName: { table: { disable: true } },
|
||||
mode: {
|
||||
options: ['single', 'multiple'],
|
||||
control: 'radio'
|
||||
},
|
||||
roles: {
|
||||
options: ['empty', 'user', 'admin'],
|
||||
control: 'radio',
|
||||
mapping: {
|
||||
empty: [],
|
||||
user: ['MOCK-USER-ROLE'],
|
||||
admin: ['MOCK-ADMIN-ROLE']
|
||||
}
|
||||
}
|
||||
}
|
||||
} as Meta;
|
||||
|
||||
const template: Story<PeopleCloudComponent> = (args: PeopleCloudComponent) => ({
|
||||
props: args
|
||||
});
|
||||
|
||||
export const primary = template.bind({});
|
||||
primary.args = {
|
||||
appName: 'app',
|
||||
excludedUsers: [],
|
||||
mode: 'single',
|
||||
preSelectUsers: [],
|
||||
readOnly: false,
|
||||
roles: [],
|
||||
title: 'Users',
|
||||
validate: false
|
||||
};
|
||||
|
||||
export const validPreselectedUsers = template.bind({});
|
||||
validPreselectedUsers.args = {
|
||||
...primary.args,
|
||||
validate: true,
|
||||
mode: 'multiple',
|
||||
preSelectUsers: mockUsers
|
||||
};
|
||||
|
||||
export const mandatoryPreselectedUsers = template.bind({});
|
||||
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' }]
|
||||
};
|
||||
|
||||
export const invalidPreselectedUsers = template.bind({});
|
||||
invalidPreselectedUsers.args = {
|
||||
...primary.args,
|
||||
validate: true,
|
||||
mode: 'multiple',
|
||||
preSelectUsers: [{ id: 'invalid-user', username: 'invalid user', firstName: 'invalid', lastName: 'user', email: 'invalid@xyz.com' }]
|
||||
};
|
||||
|
||||
export const excludedUsers = template.bind({});
|
||||
excludedUsers.args = {
|
||||
...primary.args,
|
||||
excludedUsers: [
|
||||
{ id: 'fake-id-2' },
|
||||
{ id: 'fake-id-3' }
|
||||
]
|
||||
};
|
||||
|
||||
export const adminRoleUser = template.bind({});
|
||||
adminRoleUser.args = {
|
||||
...primary.args,
|
||||
roles: 'admin'
|
||||
};
|
||||
|
||||
export const noUsers = template.bind({});
|
||||
noUsers.args = {
|
||||
...primary.args,
|
||||
excludedUsers: mockUsers
|
||||
};
|
||||
|
||||
export const invalidOrEmptyAppName = template.bind({});
|
||||
invalidOrEmptyAppName.args = {
|
||||
...primary.args,
|
||||
appName: null
|
||||
};
|
@@ -0,0 +1,265 @@
|
||||
/*!
|
||||
* @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([]);
|
||||
}
|
||||
}
|
@@ -23,12 +23,12 @@ import { TaskDetailsCloudModel } from '../start-task/public-api';
|
||||
import { taskDetailsContainer } from '../task-header/mocks/task-details-cloud.mock';
|
||||
import { ProcessDefinitionCloud } from '../../models/process-definition-cloud.model';
|
||||
import { StartTaskCloudRequestModel } from '../start-task/models/start-task-cloud-request.model';
|
||||
import { TaskCloudInterface } from '../services/task-cloud.interface';
|
||||
import { TaskCloudServiceInterface } from '../services/task-cloud.service.interface';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TaskCloudServiceMock implements TaskCloudInterface {
|
||||
export class TaskCloudServiceMock implements TaskCloudServiceInterface {
|
||||
|
||||
currentUserMock = 'AssignedTaskUser';
|
||||
dataChangesDetected$ = new Subject();
|
||||
|
@@ -21,7 +21,7 @@ import { ProcessDefinitionCloud } from '../../models/process-definition-cloud.mo
|
||||
import { TaskPriorityOption } from '../models/task.model';
|
||||
import { StartTaskCloudRequestModel } from '../start-task/models/start-task-cloud-request.model';
|
||||
import { TaskDetailsCloudModel } from '../start-task/models/task-details-cloud.model';
|
||||
export interface TaskCloudInterface {
|
||||
export interface TaskCloudServiceInterface {
|
||||
|
||||
dataChangesDetected$: Subject<unknown>;
|
||||
priorities: TaskPriorityOption[];
|
@@ -24,12 +24,12 @@ import { BaseCloudService } from '../../services/base-cloud.service';
|
||||
import { StartTaskCloudRequestModel } from '../start-task/models/start-task-cloud-request.model';
|
||||
import { ProcessDefinitionCloud } from '../../models/process-definition-cloud.model';
|
||||
import { DEFAULT_TASK_PRIORITIES, TaskPriorityOption, TASK_ASSIGNED_STATE, TASK_CREATED_STATE } from '../models/task.model';
|
||||
import { TaskCloudInterface } from './task-cloud.interface';
|
||||
import { TaskCloudServiceInterface } from './task-cloud.service.interface';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TaskCloudService extends BaseCloudService implements TaskCloudInterface {
|
||||
export class TaskCloudService extends BaseCloudService implements TaskCloudServiceInterface {
|
||||
|
||||
dataChangesDetected$ = new Subject();
|
||||
|
||||
|
@@ -39,10 +39,8 @@ export default {
|
||||
}
|
||||
} as Meta;
|
||||
|
||||
const template: Story<TaskHeaderCloudComponent> = (args) => ({
|
||||
props: {
|
||||
...args
|
||||
}
|
||||
const template: Story<TaskHeaderCloudComponent> = (args: TaskHeaderCloudComponent) => ({
|
||||
props: args
|
||||
});
|
||||
|
||||
export const assignedAndEditable = template.bind({});
|
||||
|
Reference in New Issue
Block a user