Skip to content

Commit

Permalink
[AAE-5960] Storybook stories for PeopleCloud component (#7313)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
tomgny committed Oct 22, 2021
1 parent a31f86f commit d3f99a7
Show file tree
Hide file tree
Showing 14 changed files with 486 additions and 47 deletions.
14 changes: 7 additions & 7 deletions docs/core/services/identity-user.service.md
Expand Up @@ -18,10 +18,10 @@ Gets OAuth2 personal details and roles for users and performs CRUD operations on
- _userId:_ `string` - Id of the user.
- _roles:_ [`IdentityRoleModel`](../../../lib/core/models/identity-role.model.ts)`[]` - Array of roles.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<any>` - Empty response when the role assigned.
- **changePassword**(userId: `string`, newPassword: [`IdentityUserPasswordModel`](../../../lib/core/services/identity-user.service.ts)): [`Observable`](http://reactivex.io/documentation/observable.html)`<any>`<br/>
- **changePassword**(userId: `string`, newPassword: [`IdentityUserPasswordModel`](../../../lib/core/services/identity-user.interface.ts)): [`Observable`](http://reactivex.io/documentation/observable.html)`<any>`<br/>
Changes user password.
- _userId:_ `string` - Id of the user.
- _newPassword:_ [`IdentityUserPasswordModel`](../../../lib/core/services/identity-user.service.ts) -
- _newPassword:_ [`IdentityUserPasswordModel`](../../../lib/core/services/identity-user.interface.ts) -
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<any>` - Empty response when the password changed.
- **checkUserHasAnyApplicationRole**(userId: `string`, applicationName: `string`, roleNames: `string[]`): [`Observable`](http://reactivex.io/documentation/observable.html)`<boolean>`<br/>
Checks if a user has any application role.
Expand Down Expand Up @@ -120,19 +120,19 @@ Gets OAuth2 personal details and roles for users and performs CRUD operations on
Gets an array of users (not including the current user) who have any of the roles in the supplied list.
- _roleNames:_ `string[]` - List of role names to look for
- **Returns** [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)`<`[`IdentityUserModel`](../../../lib/core/models/identity-user.model.ts)`[]>` - Array of user info objects
- **joinGroup**(joinGroupRequest: [`IdentityJoinGroupRequestModel`](../../../lib/core/services/identity-user.service.ts)): [`Observable`](http://reactivex.io/documentation/observable.html)`<any>`<br/>
- **joinGroup**(joinGroupRequest: [`IdentityJoinGroupRequestModel`](../../../lib/core/services/identity-user.interface.ts)): [`Observable`](http://reactivex.io/documentation/observable.html)`<any>`<br/>
Joins group.
- _joinGroupRequest:_ [`IdentityJoinGroupRequestModel`](../../../lib/core/services/identity-user.service.ts) - Details of join group request (IdentityJoinGroupRequestModel).
- _joinGroupRequest:_ [`IdentityJoinGroupRequestModel`](../../../lib/core/services/identity-user.interface.ts) - Details of join group request (IdentityJoinGroupRequestModel).
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<any>` - Empty response when the user joined the group.
- **leaveGroup**(userId: `any`, groupId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<any>`<br/>
Leaves group.
- _userId:_ `any` - Id of the user.
- _groupId:_ `string` - Id of the group.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<any>` - Empty response when the user left the group.
- **queryUsers**(requestQuery: [`IdentityUserQueryCloudRequestModel`](../../../lib/core/services/identity-user.service.ts)): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`IdentityUserQueryResponse`](../../../lib/core/services/identity-user.service.ts)`>`<br/>
- **queryUsers**(requestQuery: [`IdentityUserQueryCloudRequestModel`](../../../lib/core/services/identity-user.interface.ts)): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`IdentityUserQueryResponse`](../../../lib/core/services/identity-user.interface.ts)`>`<br/>
Gets details for all users.
- _requestQuery:_ [`IdentityUserQueryCloudRequestModel`](../../../lib/core/services/identity-user.service.ts) -
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`IdentityUserQueryResponse`](../../../lib/core/services/identity-user.service.ts)`>` - Array of user information objects.
- _requestQuery:_ [`IdentityUserQueryCloudRequestModel`](../../../lib/core/services/identity-user.interface.ts) -
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`IdentityUserQueryResponse`](../../../lib/core/services/identity-user.interface.ts)`>` - Array of user information objects.
- **removeRoles**(userId: `string`, removedRoles: [`IdentityRoleModel`](../../../lib/core/models/identity-role.model.ts)`[]`): [`Observable`](http://reactivex.io/documentation/observable.html)`<any>`<br/>
Removes assigned roles.
- _userId:_ `string` - Id of the user.
Expand Down
2 changes: 1 addition & 1 deletion lib/core/mock/identity-user.service.mock.ts
Expand Up @@ -18,7 +18,7 @@
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';
import { IdentityJoinGroupRequestModel } from '../services/identity-user.service.interface';

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'};
Expand Down
77 changes: 77 additions & 0 deletions lib/core/services/identity-user.service.interface.ts
@@ -0,0 +1,77 @@
/*!
* @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 { Pagination } from '@alfresco/js-api';
import { Observable } from 'rxjs';
import { IdentityGroupModel } from '../models/identity-group.model';
import { IdentityRoleModel } from '../models/identity-role.model';
import { IdentityUserModel } from '../models/identity-user.model';

export interface IdentityUserQueryResponse {

entries: IdentityUserModel[];
pagination: Pagination;
}

export interface IdentityUserPasswordModel {
type?: string;
value?: string;
temporary?: boolean;
}

export interface IdentityUserQueryCloudRequestModel {
first: number;
max: number;
}

export interface IdentityJoinGroupRequestModel {
realm: string;
userId: string;
groupId: string;
}

export interface IdentityUserServiceInterface {
getCurrentUserInfo(): IdentityUserModel;
findUsersByName(search: string): Observable<IdentityUserModel[]>;
findUserByUsername(username: string): Observable<IdentityUserModel[]>;
findUserByEmail(email: string): Observable<IdentityUserModel[]>;
getClientRoles(userId: string, clientId: string): Observable<any[]>;
checkUserHasClientApp(userId: string, clientId: string): Observable<boolean>;
checkUserHasAnyClientAppRole(userId: string, clientId: string, roleNames: string[]): Observable<boolean>;
getClientIdByApplicationName(applicationName: string): Observable<string>;
checkUserHasApplicationAccess(userId: string, applicationName: string): Observable<boolean>;
checkUserHasAnyApplicationRole(userId: string, applicationName: string, roleNames: string[]): Observable<boolean>;
getUsers(): Observable<IdentityUserModel[]>;
getUserRoles(userId: string): Observable<IdentityRoleModel[]>;
getUsersByRolesWithCurrentUser(roleNames: string[]): Promise<IdentityUserModel[]>;
getUsersByRolesWithoutCurrentUser(roleNames: string[]): Promise<IdentityUserModel[]>;
checkUserHasRole(userId: string, roleNames: string[]): Observable<boolean>;
queryUsers(requestQuery: IdentityUserQueryCloudRequestModel): Observable<IdentityUserQueryResponse>;
getTotalUsersCount(): Observable<number>;
createUser(newUser: IdentityUserModel): Observable<any>;
updateUser(userId: string, updatedUser: IdentityUserModel): Observable<any>;
deleteUser(userId: string): Observable<any>;
changePassword(userId: string, newPassword: IdentityUserPasswordModel): Observable<any>;
getInvolvedGroups(userId: string): Observable<IdentityGroupModel[]>;
joinGroup(joinGroupRequest: IdentityJoinGroupRequestModel): Observable<any>;
leaveGroup(userId: any, groupId: string): Observable<any>;
getAvailableRoles(userId: string): Observable<IdentityRoleModel[]>;
getAssignedRoles(userId: string): Observable<IdentityRoleModel[]>;
getEffectiveRoles(userId: string): Observable<IdentityRoleModel[]>;
assignRoles(userId: string, roles: IdentityRoleModel[]): Observable<any>;
removeRoles(userId: string, removedRoles: IdentityRoleModel[]): Observable<any>;
}
27 changes: 2 additions & 25 deletions lib/core/services/identity-user.service.ts
Expand Up @@ -15,44 +15,21 @@
* limitations under the License.
*/

import { Pagination } from '@alfresco/js-api';
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { AppConfigService } from '../app-config/app-config.service';
import { IdentityGroupModel } from '../models/identity-group.model';
import { IdentityRoleModel } from '../models/identity-role.model';
import { IdentityUserModel } from '../models/identity-user.model';
import { IdentityJoinGroupRequestModel, IdentityUserServiceInterface, IdentityUserPasswordModel, IdentityUserQueryCloudRequestModel, IdentityUserQueryResponse } from './identity-user.service.interface';
import { JwtHelperService } from './jwt-helper.service';
import { OAuth2Service } from './oauth2.service';

export interface IdentityUserQueryResponse {

entries: IdentityUserModel[];
pagination: Pagination;
}

export interface IdentityUserPasswordModel {
type?: string;
value?: string;
temporary?: boolean;
}

export interface IdentityUserQueryCloudRequestModel {
first: number;
max: number;
}

export interface IdentityJoinGroupRequestModel {
realm: string;
userId: string;
groupId: string;
}

@Injectable({
providedIn: 'root'
})
export class IdentityUserService {
export class IdentityUserService implements IdentityUserServiceInterface {

constructor(
private jwtHelperService: JwtHelperService,
Expand Down
1 change: 1 addition & 0 deletions lib/core/services/public-api.ts
Expand Up @@ -65,3 +65,4 @@ export * from './version-compatibility.service';
export * from './auth-bearer.interceptor';
export * from './oauth2.service';
export * from './language.service';
export * from './identity-user.service.interface';
Expand Up @@ -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;

Expand Down
Expand Up @@ -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;

Expand Down
Expand Up @@ -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 {
Expand Down
@@ -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 comments on commit d3f99a7

Please sign in to comment.