[ACS-4571] Move SecurityControlsService to ADF Content Lib (#8286)

* [ACS-4571] move SecurityControlsService to ADF content lib

* [ACS-4571] build fix

* [ACS-4571] build fix

* [ACS-4571] build fix

* [ACS-4571] resolved ts-ignore in unit-tests

* [ACS-4571] renamed AdminCcSecurityControlsServicesModule to SecurityControlsServiceModule

* [ACS-4571] return types added

* [ACS-4571] added docs for SecurityControlsService

* [ACS-4571] docs typo fix

* [ACS-4571] docs typo fix

* [ACS-4571] linting

* [ACS-4571] fixed failing test

* [ACS-4571] added missing unit tests

* [ACS-4571] linting

* [ACS-4571] set the default maxItems to UserPreferencesService.paginationSize

* [ACS-4571] changed createSecurityMarks() return type

* [ACS-4571] moved import line up

* [ACS-4571] finish loading status in some functions
This commit is contained in:
Nikita Maliarchuk
2023-02-23 18:44:32 +01:00
committed by GitHub
parent 25d85c7890
commit d26593e4d8
15 changed files with 1085 additions and 2 deletions

View File

@@ -0,0 +1,79 @@
---
Title: Security Controls service
Added: v2.0.0
Status: Active
Last reviewed: 2023-02-21
---
# [Security Controls service](../../../lib/content-services/src/lib/security/services/security-controls-groups-marks-security.service.ts "Defined in security-controls-groups-marks-security.service.ts")
Manages security groups & marks in Content Services.
## Class members
### Methods
- **getSecurityGroup**(skipCount?: `number`, maxItems?: `number`, include?: `string`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)`<SecurityControlsGroupResponse>`<br/>
Get security groups.
- _skipCount:_ `number` - The number of entities that exist in the collection before those included in this list.
- _maxItems:_ `number` - The maximum number of items to return in the list.
- _include:_ `string` - Additional information about the security group.
- **Returns** [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)`<SecurityControlsGroupResponse>`
- **createSecurityGroup**(input: `SecurityGroupBody`): [`Observable`](http://reactivex.io/documentation/observable.html)`<SecurityGroupEntry>`<br/>
Creates a security group.
- _input:_ `SecurityGroupBody` - Security group.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<SecurityGroupEntry>`
- **createSecurityMarks**(securityGroupId: `string`, input: `SecurityMarkBody[]`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)`<SecurityMarkPaging | SecurityMarkEntry>`<br/>
Create security marks.
- _securityGroupId:_ `string` - The key for the security group id.
- _SecurityMarkBody:_ `SecurityMarkBody[]` - Node security marks list.
- **Returns** [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)`<SecurityMarkPaging | SecurityMarkEntry>`
- **getSecurityMark**(securityGroupId: `string`, skipCount?: `number`, include?: `string`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)`<SecurityControlsMarkResponse>`<br/>
Get security mark value.
- _securityGroupId:_ `string` - The key for the security group id.
- _skipCount:_ `number` - The number of entities that exist in the collection before those included in this list.
- _include:_ `string` - The key for the security mark is in use or not.
- **Returns** [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)`<SecurityControlsMarkResponse>`
- **updateSecurityGroup**(securityGroupId: `string`, input: `SecurityGroupBody`, opts?: `any`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)`<SecurityGroupEntry>`<br/>
Update a security groups information.
- _securityGroupId:_ `string` - The key of security group id for which info is required.
- _input:_ `SecurityGroupBody` - Security group.
- _opts:_ `any` - (Optional) Extra options supported by JS-API.
- **Returns** [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)`<SecurityGroupEntry>`
- **updateSecurityMark**(securityGroupId: `string`, securityMarkId: `string`, input: `SecurityMarkBody`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)`<SecurityMarkEntry>`<br/>
Updates Security Mark value.
- _securityGroupId:_ `string` - The key for the security group id.
- _securityMarkId:_ `string` - The key for the security mark is in use or not.
- _input:_ `SecurityMarkBody` - Security mark.
- **Returns** [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)`<SecurityMarkEntry>`
- **deleteSecurityGroup**(securityGroupId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<SecurityGroupEntry>`<br/>
Delete security group.
- _securityGroupId:_ `string` - The key for the security group id.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<SecurityGroupEntry>`
- **deleteSecurityMark**(securityGroupId: `string`, securityMarkId: `string`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)`<SecurityMarkEntry>`<br/>
Delete security mark.
- _securityGroupId:_ `string` - The key for the security group id.
- _securityMarkId:_ `string` - The key for the security mark id.
- **Returns** [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)`<SecurityMarkEntry>`
- **getClearancesForAuthority**(authorityName: `string`, skipCount?: `number`, maxItems?: `number`): [`Observable`](http://reactivex.io/documentation/observable.html)`<AuthorityClearanceGroupPaging>`<br/>
Get the authority clearances for a single user/group.
- _authorityName:_ `string` - The name for the authority for which the clearance is to be fetched.
- _skipCount:_ `number` - The number of entities that exist in the collection before those included in this list.
- _maxItems:_ `number` - The maximum number of items to return in the list.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<AuthorityClearanceGroupPaging>`
- **updateClearancesForAuthority**(authorityName: `string`, securityMarksList: `NodeSecurityMarkBody[]`): [`Observable`](http://reactivex.io/documentation/observable.html)`<SecurityMarkEntry | SecurityMarkPaging>`<br/>
Updates the authority clearance.
- _authorityName:_ `string` - The name for the authority for which the clearance is to be updated.
- _securityMarksList:_ `NodeSecurityMarkBody[]` - Node security marks list.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<SecurityMarkEntry | SecurityMarkPaging>`
## Properties
| Name | Type | Description |
| ---- | ---- |--------------------------|
| groupsPaginated$ | [`Observable`](http://reactivex.io/documentation/observable.html)`<SecurityControlsGroupResponse>` | Current paginated groups. |
| marksPaginated$ | [`Observable`](http://reactivex.io/documentation/observable.html)`<SecurityControlsMarkResponse>` | Current paginated marks. |
| reloadSecurityControls$ | [`Observable`](http://reactivex.io/documentation/observable.html)`<void>` | |
| reloadAuthorityClearance$ | [`Observable`](http://reactivex.io/documentation/observable.html)`<void>` | |
| loading$ | [`Observable`](http://reactivex.io/documentation/observable.html)`<boolean>` | Current loading state. |

View File

@@ -49,6 +49,7 @@ import { NodeCommentsModule } from './node-comments/node-comments.module';
import { TreeModule } from './tree/tree.module'; import { TreeModule } from './tree/tree.module';
import { AlfrescoViewerModule } from './viewer/alfresco-viewer.module'; import { AlfrescoViewerModule } from './viewer/alfresco-viewer.module';
import { ContentUserInfoModule } from './content-user-info/content-user-info.module'; import { ContentUserInfoModule } from './content-user-info/content-user-info.module';
import { SecurityControlsServiceModule } from './security/services/security-controls-service.module';
@NgModule({ @NgModule({
imports: [ imports: [
@@ -82,7 +83,8 @@ import { ContentUserInfoModule } from './content-user-info/content-user-info.mod
NodeCommentsModule, NodeCommentsModule,
TreeModule, TreeModule,
SearchTextModule, SearchTextModule,
AlfrescoViewerModule AlfrescoViewerModule,
SecurityControlsServiceModule
], ],
providers: [ providers: [
{ {
@@ -120,7 +122,8 @@ import { ContentUserInfoModule } from './content-user-info/content-user-info.mod
NodeCommentsModule, NodeCommentsModule,
TreeModule, TreeModule,
SearchTextModule, SearchTextModule,
AlfrescoViewerModule AlfrescoViewerModule,
SecurityControlsServiceModule
] ]
}) })
export class ContentModule { export class ContentModule {

View File

@@ -0,0 +1,18 @@
/*!
* @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.
*/
export * from './public-api';

View File

@@ -0,0 +1,19 @@
/*!
* @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.
*/
export * from './services/security-controls-groups-marks-security.service';
export * from './services/security-controls-service.module';

View File

@@ -0,0 +1,41 @@
/*!
* @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 { AuthorityClearanceGroupPaging } from '@alfresco/js-api';
export const fakeAuthorityClearanceApiResponse: AuthorityClearanceGroupPaging = {
'list': {
'pagination': {
'count': 1,
'hasMoreItems': false,
'totalItems': 1,
'skipCount': 0,
'maxItems': 10
},
'entries': [
{
'entry': {
'id': 'test-id',
'displayLabel': 'test-displayLabel',
'systemGroup': false,
'type': 'test-type',
'marks': []
}
}
]
}
};

View File

@@ -0,0 +1,74 @@
/*!
* @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 { SecurityGroupBody, SecurityGroupPaging } from '@alfresco/js-api';
export const fakeGroupsApiResponse: SecurityGroupPaging = {
list: {
pagination: {
count: 4,
hasMoreItems: false,
maxItems: 5,
skipCount: 0,
totalItems: 4
},
entries: [
{
entry: {
groupName: 'Classification',
groupType: 'HIERARCHICAL',
id: 'classification',
inUse: true,
systemGroup: true
}
},
{
entry: {
groupName: 'SG1',
groupType: 'USER_REQUIRES_ALL',
id: 'd2b11d9f-2707-439f-a7c6-e7872f395553',
inUse: true,
systemGroup: true
}
},
{
entry: {
groupName: 'SG2',
groupType: 'USER_REQUIRES_ALL',
id: '1b77a32d-6b8b-4a37-b195-7f2ff2fe4ed3',
inUse: true,
systemGroup: true
}
},
{
entry: {
groupName: 'SG3',
groupType: 'USER_REQUIRES_ALL',
id: '709791f8-22dc-428a-82dd-daf3e1aa8a60',
inUse: true,
systemGroup: true
}
}
]
}
};
export const createNewSecurityGroupMock: SecurityGroupBody = {
groupName: 'TestGroup',
groupType: 'HIERARCHICAL'
};

View File

@@ -0,0 +1,51 @@
/*!
* @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 { SecurityMarkPaging, SecurityMarkEntry, SecurityMarkBody } from '@alfresco/js-api';
export const fakeMarksApiResponse: SecurityMarkPaging = {
'list': {
'pagination': {
'count': 1,
'hasMoreItems': false,
'totalItems': 1,
'skipCount': 0,
'maxItems': 10
},
'entries': [
{
'entry': {
'groupId': 'eddf6269-ceba-42c6-b979-9ac445d29a94',
'name': 'securityMark1',
'id': 'ffBOeOJJ'
}
}
]
}
};
export const fakeCreateMarksApiResponse: SecurityMarkEntry = {
entry: {
groupId: 'e7b83b84-bb48-46fc-8e64-4b6be910906c',
name: 'securityMark1',
id: 'ffBOeOJJ'
}
};
export const createNewSecurityMarkMock: SecurityMarkBody[] = [{
name: 'securityMark1'
}];

View File

@@ -0,0 +1,26 @@
/*!
* @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 { SecurityMark } from '@alfresco/js-api';
export interface SecurityControlsGroupInfoResponse {
id: string;
groupName: string;
groupType: string;
inUse: boolean;
marks: SecurityMark[];
}

View File

@@ -0,0 +1,25 @@
/*!
* @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 { PaginationModel } from '@alfresco/adf-core';
import { Observable } from 'rxjs';
import { SecurityControlsGroupInfoResponse } from './security-controls-group-info-response.interface';
export interface SecurityControlsGroupListResponse {
pagination: PaginationModel;
entries: Observable<SecurityControlsGroupInfoResponse[]>;
}

View File

@@ -0,0 +1,24 @@
/*!
* @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 { PaginationModel } from '@alfresco/adf-core';
import { SecurityGroup } from '@alfresco/js-api';
export interface SecurityControlsGroupResponse {
pagination: PaginationModel;
entries: SecurityGroup[];
}

View File

@@ -0,0 +1,24 @@
/*!
* @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 { PaginationModel } from '@alfresco/adf-core';
import { SecurityMark } from '@alfresco/js-api';
export interface SecurityControlsMarkResponse {
pagination: PaginationModel;
entries: SecurityMark[];
}

View File

@@ -0,0 +1,307 @@
/*!
* @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 { TestBed } from '@angular/core/testing';
import { CoreTestingModule } from '@alfresco/adf-core';
import { SecurityControlsService } from './security-controls-groups-marks-security.service';
import { fakeAuthorityClearanceApiResponse } from './mock/security-authorities.mock';
import {
fakeGroupsApiResponse,
createNewSecurityGroupMock
} from './mock/security-groups.mock';
import {
fakeMarksApiResponse,
createNewSecurityMarkMock
} from './mock/security-marks.mock';
import {
SecurityGroupBody,
SecurityGroupEntry,
SecurityMarkBody,
SecurityMarkEntry
} from '@alfresco/js-api';
describe('SecurityControlsService', () => {
let service: SecurityControlsService;
let securityGroupId;
let securityMarkId;
const securityGroupBody: SecurityGroupBody = {
groupName: 'TestGroup',
groupType: 'HIERARCHICAL'
};
const securityMarkBody: SecurityMarkBody = {
name: 'securityMark1'
};
beforeEach(() => {
TestBed.configureTestingModule({
imports: [CoreTestingModule]
});
service = TestBed.inject(SecurityControlsService);
});
it('should be able to get the list of Security groups', async () => {
const getGroupSpy = spyOn(
service.groupsApi,
'getSecurityGroups'
).and.returnValue(Promise.resolve(fakeGroupsApiResponse));
const groupPromise = service.getSecurityGroup( 0, 5, 'inUse');
const group = await groupPromise;
expect(getGroupSpy).toHaveBeenCalledWith({
skipCount: 0,
maxItems: 5,
include: 'inUse'
});
expect(group.pagination.skipCount).toBe(0);
expect(group.pagination.maxItems).toBe(5);
expect(group.entries[0].id).toBe('classification');
expect(group.entries[0].groupName).toBe('Classification');
expect(group.entries[0].groupType).toBe('HIERARCHICAL');
expect(group.entries[1].id).toBe(
'd2b11d9f-2707-439f-a7c6-e7872f395553'
);
expect(group.entries[1].groupName).toBe('SG1');
expect(group.entries[1].groupType).toBe('USER_REQUIRES_ALL');
expect(group.entries[2].id).toBe(
'1b77a32d-6b8b-4a37-b195-7f2ff2fe4ed3'
);
expect(group.entries[2].groupName).toBe('SG2');
expect(group.entries[2].groupType).toBe('USER_REQUIRES_ALL');
expect(group.entries[3].id).toBe(
'709791f8-22dc-428a-82dd-daf3e1aa8a60'
);
expect(group.entries[3].groupName).toBe('SG3');
expect(group.entries[3].groupType).toBe('USER_REQUIRES_ALL');
});
it('should create new security group', async () => {
spyOn(service.groupsApi, 'createSecurityGroup').and.returnValue(
Promise.resolve(
new SecurityGroupEntry({
entry: {
groupName: 'TestGroup',
groupType: 'HIERARCHICAL',
id: 'eddf6269-ceba-42c6-b979-9ac445d29a94'
}
})
)
);
const response = await service
.createSecurityGroup(createNewSecurityGroupMock)
.toPromise();
securityGroupId = response.entry.id;
expect(response.entry.groupName).toEqual('TestGroup');
expect(response.entry.groupType).toEqual('HIERARCHICAL');
expect(response.entry.id).toEqual(
'eddf6269-ceba-42c6-b979-9ac445d29a94'
);
});
it('should be able to get the list of Security Marks', async () => {
const getMarkSpy = spyOn(
service.marksApi,
'getSecurityMarks'
).and.returnValue(Promise.resolve(fakeMarksApiResponse));
const markPromise = service.getSecurityMark(
securityGroupId,
0,
'inUse'
);
const mark = await markPromise;
expect(getMarkSpy).toHaveBeenCalledWith(securityGroupId, {
skipCount: 0,
include: 'inUse'
});
expect(mark.pagination.skipCount).toBe(0);
expect(mark.pagination.maxItems).toBe(10);
expect(mark.entries[0].groupId).toBe(
'eddf6269-ceba-42c6-b979-9ac445d29a94'
);
expect(mark.entries[0].name).toBe('securityMark1');
expect(mark.entries[0].id).toBe('ffBOeOJJ');
});
it('should create new security mark', async () => {
spyOn(service.marksApi, 'createSecurityMarks').and.returnValue(
Promise.resolve(
new SecurityMarkEntry({
entry: {
groupId: 'eddf6269-ceba-42c6-b979-9ac445d29a94',
name: 'securityMark1',
id: 'ffBOeOJJ'
}
})
)
);
const response = await service.createSecurityMarks(securityGroupId, createNewSecurityMarkMock);
if (response instanceof SecurityMarkEntry) {
securityMarkId = response.entry.id;
expect(response.entry.groupId).toEqual('eddf6269-ceba-42c6-b979-9ac445d29a94');
expect(response.entry.name).toEqual('securityMark1');
expect(response.entry.id).toEqual('ffBOeOJJ');
}
});
it('should edit a security mark', async () => {
spyOn(service.marksApi, 'updateSecurityMark').and.returnValue(
Promise.resolve(
new SecurityMarkEntry({
entry: {
groupId: 'eddf6269-ceba-42c6-b979-9ac445d29a94',
name: 'securityMark1',
id: 'ffBOeOJJ'
}
})
)
);
const response = await service
.updateSecurityMark(
securityGroupId,
securityMarkId,
securityMarkBody
);
securityGroupId = response.entry.groupId;
securityMarkId = response.entry.id;
expect(response.entry.groupId).toEqual(securityGroupId);
expect(response.entry.name).toEqual('securityMark1');
expect(response.entry.id).toEqual(securityMarkId);
});
it('should update a security group', async () => {
spyOn(service.groupsApi, 'updateSecurityGroup').and.returnValue(
Promise.resolve(
new SecurityGroupEntry({
entry: {
groupName: 'TestGroup',
groupType: 'HIERARCHICAL',
id: 'eddf6269-ceba-42c6-b979-9ac445d29a94'
}
})
)
);
const opts = {};
const response = await service.updateSecurityGroup(securityGroupId, securityGroupBody, opts);
expect(response.entry.groupName).toEqual('TestGroup');
expect(response.entry.groupType).toEqual('HIERARCHICAL');
expect(response.entry.id).toEqual(securityGroupId);
});
it('should delete a security mark', async () => {
spyOn(service.marksApi, 'deleteSecurityMark').and.returnValue(
Promise.resolve(
new SecurityMarkEntry({
entry: {
groupId: 'eddf6269-ceba-42c6-b979-9ac445d29a94',
name: 'securityMark1',
id: 'ffBOeOJJ'
}
})
)
);
const response = await service.deleteSecurityMark(securityGroupId, securityMarkId);
securityMarkId = response.entry.id;
securityGroupId = response.entry.groupId;
expect(response.entry.groupId).toEqual('eddf6269-ceba-42c6-b979-9ac445d29a94');
expect(response.entry.name).toEqual('securityMark1');
expect(response.entry.id).toEqual('ffBOeOJJ');
});
it('should delete a security group', async () => {
spyOn(service.groupsApi, 'deleteSecurityGroup').and.returnValue(
Promise.resolve(
new SecurityGroupEntry({
entry: {
groupName: 'TestGroup',
groupType: 'HIERARCHICAL',
id: 'eddf6269-ceba-42c6-b979-9ac445d29a94'
}
})
)
);
const response = await service
.deleteSecurityGroup(securityGroupId)
.toPromise();
expect(response.entry.groupName).toEqual('TestGroup');
expect(response.entry.groupType).toEqual('HIERARCHICAL');
expect(response.entry.id).toEqual('eddf6269-ceba-42c6-b979-9ac445d29a94');
});
it('should be able to get clearances for authority', async () => {
const getClearancesForAuthoritySpy = spyOn(
service.authorityClearanceApi,
'getAuthorityClearanceForAuthority'
).and.returnValue(Promise.resolve(fakeAuthorityClearanceApiResponse));
const clearancePromise = service.getClearancesForAuthority('test-id', 0, 10);
const clearance = await clearancePromise.toPromise();
expect(getClearancesForAuthoritySpy).toHaveBeenCalledWith('test-id', {
skipCount: 0,
maxItems: 10
});
expect(clearance.list.pagination.skipCount).toBe(0);
expect(clearance.list.pagination.maxItems).toBe(10);
expect(clearance.list.entries[0].entry.id).toBe('test-id');
expect(clearance.list.entries[0].entry.displayLabel).toBe('test-displayLabel');
expect(clearance.list.entries[0].entry.systemGroup).toBe(false);
expect(clearance.list.entries[0].entry.type).toBe('test-type');
});
it('should update a clearances for authority', async () => {
spyOn(service.authorityClearanceApi, 'updateAuthorityClearance').and.returnValue(
Promise.resolve(
new SecurityMarkEntry({
entry: {
id: 'test-id',
name: 'test-name',
groupId: 'test-groupId'
}
})
)
);
const response = await service.updateClearancesForAuthority('test-id', [{
groupId: 'test-group-id',
op: 'test-op',
id: 'test-id'
}]).toPromise();
if (response instanceof SecurityMarkEntry) {
expect(response.entry.id).toEqual('test-id');
expect(response.entry.groupId).toEqual('test-groupId');
expect(response.entry.name).toEqual('test-name');
}
});
it('should reload security groups', doneCallback => {
service.reloadSecurityControls$.subscribe(res => {
expect(res).toBeUndefined();
doneCallback();
});
service.reloadSecurityGroups();
});
});

View File

@@ -0,0 +1,367 @@
/*!
* @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 { BehaviorSubject, from, Observable, Subject } from 'rxjs';
import { SecurityControlsGroupResponse } from './models/security-controls-group-response.interface';
import { SecurityControlsMarkResponse } from './models/security-controls-mark-response.interface';
import {
SecurityGroupsApi,
SecurityMarksApi,
SecurityGroupEntry,
SecurityMarkEntry,
SecurityGroupBody,
SecurityMarkPaging,
SecurityMarkBody,
SecurityGroupPaging,
AuthorityClearanceApi,
AuthorityClearanceGroupPaging,
NodeSecurityMarkBody
} from '@alfresco/js-api';
import { AlfrescoApiService, UserPreferencesService } from '@alfresco/adf-core';
import { finalize } from 'rxjs/operators';
const DEFAULT_SKIP_COUNT = 0;
const DEFAULT_INCLUDE = 'inUse';
@Injectable({ providedIn: 'root' })
export class SecurityControlsService {
private groupsPaginatedSource = new Subject<SecurityControlsGroupResponse>();
groupsPaginated$ = this.groupsPaginatedSource.asObservable();
private reloadSecurityControls: Subject<void> = new Subject<void>();
reloadSecurityControls$ = this.reloadSecurityControls.asObservable();
private _reloadAuthorityClearance: Subject<void> = new Subject<void>();
reloadAuthorityClearance$ = this._reloadAuthorityClearance.asObservable();
private marksPaginatedSource = new Subject<SecurityControlsMarkResponse>();
marksPaginated$ = this.marksPaginatedSource.asObservable();
private loadingSource = new BehaviorSubject<boolean>(true);
loading$ = this.loadingSource.asObservable();
private securityGroup: SecurityGroupsApi;
private securityMark: SecurityMarksApi;
private authorityClearance: AuthorityClearanceApi;
constructor(private apiService: AlfrescoApiService, private userPreferencesService: UserPreferencesService) {}
get groupsApi(): SecurityGroupsApi {
return this.securityGroup || (this.securityGroup = new SecurityGroupsApi(this.apiService.getInstance()));
}
get marksApi(): SecurityMarksApi {
return this.securityMark || (this.securityMark = new SecurityMarksApi(this.apiService.getInstance()));
}
get authorityClearanceApi(): AuthorityClearanceApi {
return this.authorityClearance || (this.authorityClearance = new AuthorityClearanceApi(this.apiService.getInstance()));
}
get reloadAuthorityClearance(): Subject<void> {
return this._reloadAuthorityClearance;
}
/**
* Get All security groups
*
* @param include Additional information about the security group
* @param skipCount The number of entities that exist in the collection before those included in this list.
* @param maxItems The maximum number of items to return in the list. Default is specified by UserPreferencesService.
* @return Promise<SecurityControlsGroupResponse>
*/
getSecurityGroup(
skipCount = DEFAULT_SKIP_COUNT,
maxItems = this.userPreferencesService.paginationSize,
include = DEFAULT_INCLUDE
): Promise<SecurityControlsGroupResponse> {
let securityControlsGroupResponse: SecurityControlsGroupResponse;
return new Promise((resolve, reject) => {
this.groupsApi
.getSecurityGroups({
include,
skipCount,
maxItems
})
.then((response: SecurityGroupPaging) => {
this.groupsPaginatedSource.next(
(securityControlsGroupResponse = {
pagination: response.list.pagination,
entries: response.list.entries.map(
(group: SecurityGroupEntry) => group.entry
)
})
);
resolve(securityControlsGroupResponse);
})
.catch((error) => reject(error));
});
}
/**
* Create security group
*
* @param input securityGroupBody.
* @return Observable<SecurityGroupEntry>
*/
createSecurityGroup(
input: SecurityGroupBody
): Observable<SecurityGroupEntry> {
this.loadingSource.next(true);
const payload: SecurityGroupBody = {
...input
};
const opts = {
DEFAULT_INCLUDE
};
const promise = this.groupsApi.createSecurityGroup(payload, opts);
return from(promise).pipe(
finalize(() => this.loadingSource.next(false))
);
}
/**
* Create security marks
*
* @param securityGroupId The key for the security group id.
* @param input securityMarkBody[].
* @return Promise<SecurityMarkPaging | SecurityMarkEntry>
*/
createSecurityMarks(
securityGroupId: string,
input: SecurityMarkBody[]
): Promise<SecurityMarkPaging | SecurityMarkEntry> {
this.loadingSource.next(true);
const promise = this.marksApi.createSecurityMarks(
securityGroupId,
input
)
.then((result) => {
this.loadingSource.next(false);
return result;
})
.catch((error) => {
this.loadingSource.next(false);
return error;
});
return promise;
}
/**
* Get security mark value
* Gets the value for a selected **securityGroupId**.
*
* @param securityGroupId The key for the security group id.
* @param skipCount The number of entities that exist in the collection before those included in this list.
* @param include The key for the security mark is in use or not
* @return Promise<SecurityControlsMarkResponse>
*/
getSecurityMark(
securityGroupId: string,
skipCount = DEFAULT_SKIP_COUNT,
include = DEFAULT_INCLUDE
): Promise<SecurityControlsMarkResponse> {
let securityControlsMarkResponse: SecurityControlsMarkResponse;
return new Promise((resolve, reject) => {
this.marksApi
.getSecurityMarks(securityGroupId, {
include,
skipCount
})
.then((response: SecurityMarkPaging) => {
this.marksPaginatedSource.next(
(securityControlsMarkResponse = {
pagination: response.list.pagination,
entries: response.list.entries.map(
(mark: SecurityMarkEntry) => mark.entry
)
})
);
resolve(securityControlsMarkResponse);
})
.catch((error) => reject(error));
});
}
/**
* Update a security groups information
*
* @param securityGroupId The Key of Security Group id for which info is required
* @param input SecurityGroupBody
* @param opts additional information about the security group
* @return Promise<SecurityGroupEntry>
*/
updateSecurityGroup(
securityGroupId: string,
input: SecurityGroupBody,
opts?: any
): Promise<SecurityGroupEntry> {
this.loadingSource.next(true);
const payload: SecurityGroupBody = {
...input
};
if (!opts) {
opts = {
DEFAULT_INCLUDE
};
}
const promise = this.groupsApi.updateSecurityGroup(
securityGroupId,
payload,
opts
)
.then((result) => {
this.loadingSource.next(false);
return result;
})
.catch((error) => {
this.loadingSource.next(false);
return error;
});
return promise;
}
/**
* Updates Security Mark value
*
* @param securityGroupId The key for the security group id.
* @param securityMarkId The key for the security mark is in use or not.
* @param input securityMarkBody.
* @return Promise<SecurityMarkEntry>
*/
updateSecurityMark(
securityGroupId: string,
securityMarkId: string,
input: SecurityMarkBody
): Promise<SecurityMarkEntry> {
this.loadingSource.next(true);
const payload: SecurityMarkBody = {
...input
};
const promise = this.marksApi.updateSecurityMark(
securityGroupId,
securityMarkId,
payload
)
.then((result) => {
this.loadingSource.next(false);
return result;
})
.catch((error) => {
this.loadingSource.next(false);
return error;
});
return promise;
}
/**
* Delete security group
*
* @param securityGroupId The key for the security group id.
* @return Observable<SecurityGroupEntry>
*/
deleteSecurityGroup(
securityGroupId: string
): Observable<SecurityGroupEntry> {
this.loadingSource.next(true);
const promise = this.groupsApi.deleteSecurityGroup(securityGroupId);
return from(promise).pipe(
finalize(() => this.loadingSource.next(false))
);
}
/**
* Delete security mark
*
* @param securityGroupId The key for the security group id.
* @param securityMarkId The key for the security mark id.
* @return Promise<SecurityMarkEntry>
*/
deleteSecurityMark(
securityGroupId: string,
securityMarkId: string
): Promise<SecurityMarkEntry> {
this.loadingSource.next(true);
const promise = this.marksApi.deleteSecurityMark(
securityGroupId,
securityMarkId
)
.then((result) => {
this.loadingSource.next(false);
return result;
})
.catch((error) => {
this.loadingSource.next(false);
return error;
});
return promise;
}
/**
* Get the authority clearances for a single user/group
*
* @param authorityName The name for the authority for which the clearance is to be fetched. Can be left blank in which case it will fetch it for all users with pagination
* @param skipCount The number of entities that exist in the collection before those included in this list.
* @param maxItems The maximum number of items to return in the list. Default is specified by UserPreferencesService.
* @return Observable<AuthorityClearanceGroupPaging>
*/
getClearancesForAuthority(
authorityName: string,
skipCount = DEFAULT_SKIP_COUNT,
maxItems = this.userPreferencesService.paginationSize
): Observable<AuthorityClearanceGroupPaging> {
this.loadingSource.next(true);
const opts = {
skipCount, maxItems
};
const promise =
this.authorityClearanceApi.getAuthorityClearanceForAuthority(authorityName, opts);
return from(promise).pipe(
finalize(() => this.loadingSource.next(false))
);
}
/**
* Updates the authority clearance.
*
* @param authorityName The name for the authority for which the clearance is to be updated
* @param securityMarksList NodeSecurityMarkBody[]
* @return Observable<SecurityMarkEntry | SecurityMarkPaging>
*/
updateClearancesForAuthority(authorityName: string, securityMarksList: NodeSecurityMarkBody[]): Observable<SecurityMarkEntry | SecurityMarkPaging> {
this.loadingSource.next(true);
const promise = this.authorityClearanceApi.updateAuthorityClearance(authorityName, securityMarksList);
return from(promise).pipe(
finalize(() => {
this.loadingSource.next(false);
this._reloadAuthorityClearance.next();
})
);
}
reloadSecurityGroups() {
this.reloadSecurityControls.next();
}
}

View File

@@ -0,0 +1,24 @@
/*!
* @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 { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
@NgModule({
imports: [CommonModule]
})
export class SecurityControlsServiceModule {}

View File

@@ -45,5 +45,6 @@ export * from './lib/common/index';
export * from './lib/tree/index'; export * from './lib/tree/index';
export * from './lib/category/index'; export * from './lib/category/index';
export * from './lib/viewer/index'; export * from './lib/viewer/index';
export * from './lib/security/index';
export * from './lib/content.module'; export * from './lib/content.module';