Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [AAE-5961] added stories and mock files * [AAE-5961] added interface for identity group service * [AAE-5961] added few stories * [AAE-5961] added mock for roles, syntax improvements * [AAE-5961] improved syntax, removed redundant storybook config files * [AAE-5961] renamed service interface * [AAE-5961] removed unused declarations * [AAE-5961] exported interface from core * [AAE-5961] restored config files for process cloud lib * [AAE-5961] improved syntax
- Loading branch information
Showing
5 changed files
with
302 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*! | ||
* @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 { Observable } from 'rxjs'; | ||
import { | ||
IdentityGroupModel, | ||
IdentityGroupQueryResponse, | ||
IdentityGroupCountModel, | ||
IdentityGroupQueryCloudRequestModel, | ||
IdentityGroupSearchParam | ||
} from '../models/identity-group.model'; | ||
import { IdentityRoleModel } from '../models/identity-role.model'; | ||
|
||
export interface IdentityGroupServiceInterface { | ||
|
||
getGroups(): Observable<IdentityGroupModel[]>; | ||
getAvailableRoles(groupId: string): Observable<IdentityRoleModel[]>; | ||
getAssignedRoles(groupId: string): Observable<IdentityRoleModel[]>; | ||
assignRoles(groupId: string, roles: IdentityRoleModel[]): Observable<any>; | ||
removeRoles(groupId: string, roles: IdentityRoleModel[]): Observable<any>; | ||
getEffectiveRoles(groupId: string): Observable<IdentityRoleModel[]>; | ||
queryGroups(requestQuery: IdentityGroupQueryCloudRequestModel): Observable<IdentityGroupQueryResponse>; | ||
getTotalGroupsCount(): Observable<IdentityGroupCountModel>; | ||
createGroup(newGroup: IdentityGroupModel): Observable<any>; | ||
updateGroup(groupId: string, updatedGroup: IdentityGroupModel); | ||
deleteGroup(groupId: string): Observable<any>; | ||
findGroupsByName(searchParams: IdentityGroupSearchParam): Observable<IdentityGroupModel[]>; | ||
getGroupRoles(groupId: string): Observable<IdentityRoleModel[]>; | ||
checkGroupHasRole(groupId: string, roleNames: string[]): Observable<boolean>; | ||
getClientIdByApplicationName(applicationName: string): Observable<string>; | ||
getClientRoles(groupId: string, clientId: string): Observable<IdentityRoleModel[]>; | ||
checkGroupHasClientApp(groupId: string, clientId: string): Observable<boolean>; | ||
checkGroupHasAnyClientAppRole(groupId: string, clientId: string, roleNames: string[]): Observable<boolean>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
lib/process-services-cloud/src/lib/group/components/group-cloud.component.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/*! | ||
* @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 { IdentityGroupService, mockIdentityGroups } 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 { | ||
component: GroupCloudComponent, | ||
title: 'Process Services Cloud/Components/Group', | ||
decorators: [ | ||
moduleMetadata({ | ||
imports: [ProcessServicesCloudStoryModule, GroupCloudModule], | ||
providers: [ | ||
{ provide: IdentityGroupService, useClass: IdentityGroupServiceMock } | ||
] | ||
}) | ||
], | ||
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<GroupCloudComponent> = (args: GroupCloudComponent) => ({ | ||
props: args | ||
}); | ||
|
||
export const primary = template.bind({}); | ||
primary.args = { | ||
appName: 'app', | ||
mode: 'single', | ||
preSelectGroups: [], | ||
readOnly: false, | ||
roles: [], | ||
title: 'Groups', | ||
validate: false | ||
}; | ||
|
||
export const validPreselectedGroups = template.bind({}); | ||
validPreselectedGroups.args = { | ||
...primary.args, | ||
validate: true, | ||
mode: 'multiple', | ||
preSelectGroups: mockIdentityGroups | ||
}; | ||
|
||
export const mandatoryPreselectedGroups = template.bind({}); | ||
mandatoryPreselectedGroups.args = { | ||
...primary.args, | ||
validate: true, | ||
mode: 'multiple', | ||
preSelectGroups: [{ id: 'mock-group-id-1', name: 'Mock Group 1', path: '/mock', subGroups: [], readonly: true }, | ||
{ id: 'mock-group-id-2', name: 'Mock Group 2', path: '', subGroups: [] }, | ||
{ id: 'mock-group-id-3', name: 'Mock Group 3', path: '', subGroups: [], readonly: true }] | ||
}; | ||
|
||
export const invalidPreselectedGroups = template.bind({}); | ||
invalidPreselectedGroups.args = { | ||
...primary.args, | ||
validate: true, | ||
mode: 'multiple', | ||
preSelectGroups: [{ id: 'invalid-group', name: 'invalid groups' }] | ||
}; | ||
|
||
export const adminRoleGroups = template.bind({}); | ||
adminRoleGroups.args = { | ||
...primary.args, | ||
roles: 'admin' | ||
}; | ||
|
||
export const invalidOrEmptyAppName = template.bind({}); | ||
invalidOrEmptyAppName.args = { | ||
...primary.args, | ||
appName: undefined | ||
}; |
146 changes: 146 additions & 0 deletions
146
lib/process-services-cloud/src/lib/group/mock/identity-group.service.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/*! | ||
* @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; | ||
}) | ||
); | ||
} | ||
} |