Skip to content

Commit

Permalink
Merge pull request #1039 from eclipse-tractusx/feature/#832-enable-po…
Browse files Browse the repository at this point in the history
…licy-management

Feature/#832 enable policy management
  • Loading branch information
ds-mwesener authored Jun 17, 2024
2 parents da2b239 + 9d5ecb1 commit 28d7370
Show file tree
Hide file tree
Showing 55 changed files with 3,115 additions and 240 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ _**For better traceability add the corresponding GitHub issue number in each cha
- #965 Implement proxy functionality of the IRS policy store

### Added
- #832 added policymanagement list view, creator and editor
- #737 Added concept: Contract table -> parts link action
- XXX Added interceptor to EdcRestTemplates to log requests

Expand Down
116 changes: 89 additions & 27 deletions docs/src/docs/user/user-manual.adoc

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 21 additions & 2 deletions frontend/src/app/mocks/services/policy-mock/policy.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,31 @@
********************************************************************************/
import { environment } from '@env';
import { rest } from 'msw';
import { getPolicies } from './policy.model';
import { getPolicies, getPolicyById } from './policy.model';

export const policyHandler = (_ => {
return [
rest.get(`*${ environment.apiUrl }/policies`, (req, res, ctx) => {
return res(ctx.status(200), ctx.json(getPolicies()));
})
}),

rest.post(`*${ environment.apiUrl }/policies`, (req, res, ctx) => {
return res(ctx.status(201), ctx.json('success'));
}),

rest.get(`*${ environment.apiUrl }/policies/:policyId`, (req, res, ctx) => {
const { policyId } = req.params;
const policy = getPolicyById(policyId);
return res(ctx.status(200), ctx.json(policy));
}),

rest.put(`*${ environment.apiUrl }/policies`, (req, res, ctx) => {
return res(ctx.status(200), ctx.json('success'));
}),

rest.delete(`*${ environment.apiUrl }/policies/:policyId`, (req, res, ctx) => {
return res(ctx.status(200), ctx.json('success'));
}),

]
})();
31 changes: 31 additions & 0 deletions frontend/src/app/mocks/services/policy-mock/policy.model.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { getOperatorTypeSign, OperatorType } from '@page/policies/model/policy.model';

describe('getOperatorTypeSign', () => {
it('should return "=" for OperatorType.EQ', () => {
expect(getOperatorTypeSign(OperatorType.EQ)).toBe('=');
});

it('should return "!=" for OperatorType.NEQ', () => {
expect(getOperatorTypeSign(OperatorType.NEQ)).toBe('!=');
});

it('should return "<" for OperatorType.LT', () => {
expect(getOperatorTypeSign(OperatorType.LT)).toBe('<');
});

it('should return ">" for OperatorType.GT', () => {
expect(getOperatorTypeSign(OperatorType.GT)).toBe('>');
});

it('should return "<=" for OperatorType.LTEQ', () => {
expect(getOperatorTypeSign(OperatorType.LTEQ)).toBe('<=');
});

it('should return ">=" for OperatorType.GTEQ', () => {
expect(getOperatorTypeSign(OperatorType.GTEQ)).toBe('>=');
});

it('should return the string representation of the type for unknown types', () => {
expect(getOperatorTypeSign('UNKNOWN' as OperatorType)).toBe('UNKNOWN');
});
});
201 changes: 175 additions & 26 deletions frontend/src/app/mocks/services/policy-mock/policy.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { OperatorType, Policy, PolicyAction, PolicyResponseMap } from '@page/policies/model/policy.model';

/********************************************************************************
* Copyright (c) 2022, 2023, 2024 Contributors to the Eclipse Foundation
*
Expand All @@ -17,36 +19,183 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
// For now Mocks are built by current response (any). This is because Policy Model changes frequently
export const getPolicies = () => [
export const getPolicies = (): Policy[] => {
return mockedPolicyList;
};

export const getPolicyById = (policyId: string | ReadonlyArray<string>): Policy => {
return mockedPolicyList.filter(policy => policy.policyId === policyId)[0];
};


export const mockedPolicyList: Policy[] = [
{
policyId: "Mocked_Policy_Id",
createdOn: 1706690077.834424001,
validUntil: 1727740799.990000000,
permissions: [
'policyId': 'default-policy',
'bpn': 'BPNL00000003CML1,BPNL00000003CNKC',
'createdOn': '2024-05-29T06:18:40Z',
'validUntil': '2029-05-29T06:18:40Z',
'permissions': [
{
action: "USE",
constraints: [
{
'action': PolicyAction.USE,
'constraints': {
'and': null,
'or': [
{
'leftOperand': 'cx-policy:FrameworkAgreement',
'operatorTypeResponse': OperatorType.EQ,
'rightOperand': 'traceability:1.0',
},
{
'leftOperand': 'cx-policy:UsagePurpose',
'operatorTypeResponse': OperatorType.EQ,
'rightOperand': 'cx.core.industrycore:1',
},
],
},
},
],
},
{
'policyId': 'default-policy-2',
'bpn': 'BPNL00000003CML1',
'createdOn': '2024-05-29T06:18:40Z',
'validUntil': '2029-05-29T06:18:40Z',
'permissions': [
{
'action': PolicyAction.USE,
'constraints': {
'and': [
{
'leftOperand': 'cx-policy:FrameworkAgreement',
'operatorTypeResponse': OperatorType.EQ,
'rightOperand': 'traceability:1.0',
},
{
'leftOperand': 'cx-policy:UsagePurpose',
'operatorTypeResponse': OperatorType.EQ,
'rightOperand': 'cx.core.industrycore:1',
},
],
'or': null,
},
},
],
},
];

const mockedPolicies = {
page: 0,
pageCount: 0,
pageSize: 10,
totalItems: 2,

content: [
{
bpnSelection: [ 'BPN10000000OEM0A', 'BPN10000000OEM0B' ],
policyName: 'Mocked_Policy_Name_1',
policyId: 'Mocked_Policy_1',
accessType: PolicyAction.ACCESS,
createdOn: '2024-05-29T06:18:40Z',
validUntil: '2024-05-29T06:18:40Z',
constraints: [ 'Membership = active', 'AND FrameworkAgreement.traceability in [active]', 'AND PURPOSE = ID 3.1 Trace' ],
permissions: [
{
action: PolicyAction.USE,
constraint: {
and: [
{
leftOperand: 'PURPOSE',
operator: {
id: OperatorType.EQ,
},
rightOperand: 'ID 3.0 Trace',
},
],
or: [
{
leftOperand: 'PURPOSE',
operator: {
id: OperatorType.EQ,
},
rightOperand: 'ID 3.0 Trace',
},
],
},
},
],
},
{
bpnSelection: [ 'BPN10000000OEM0A', 'BPN10000000OEM0B' ],
policyName: 'Mocked_Policy_Name_2',
policyId: 'Mocked_Policy_2',
accessType: PolicyAction.USE,
createdOn: '2024-05-29T06:18:40Z',
validUntil: '2024-05-29T06:18:40Z',
constraints: [ 'PURPOSE = ID 3.1 Trace', 'OR PURPOSE = ID 3.0 Trace' ],
permissions: [
{
action: PolicyAction.USE,
constraint: {
and: [
{
leftOperand: "PURPOSE",
operatorTypeResponse: "EQ",
rightOperands: [
"ID 3.0 Trace"
]
leftOperand: 'PURPOSE',
operator: {
id: OperatorType.IN,
},
rightOperand: 'BMW',
},
],
or: [
{
leftOperand: "PURPOSE",
operatorTypeResponse: "EQ",
rightOperands: [
"ID 3.0 Trace"
]
}
leftOperand: 'PURPOSE',
operator: {
id: OperatorType.EQ,
},
rightOperand: 'ID 3.0 Trace',
},
],
or: []
}
]
}
]
}
]
},
},
],
},

],

};

export const MockPolicyResponseMap: PolicyResponseMap = {
'default': [
{
'validUntil': '2024-06-30T11:07:00Z',
'payload': {
'@context': {
'odrl': 'http://www.w3.org/ns/odrl/2/',
},
'@id': 'asdadasdas',
'policy': {
'policyId': 'asdadasdas',
'createdOn': '2024-06-13T09:07:32.229901783Z',
'validUntil': '2024-06-30T11:07:00Z',
'permissions': [
{
'action': PolicyAction.USE,
'constraint': {
'and': null,
'or': [
{
'leftOperand': 'asd',
'operator': {
'@id': OperatorType.EQ,
},
'odrl:rightOperand': 'dsa',
},
],
},
},
],
},
},
},
],
};

3 changes: 3 additions & 0 deletions frontend/src/app/modules/core/user/table-settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { NotificationsReceivedConfigurationModel } from '@shared/components/part
import { NotificationsSentConfigurationModel } from '@shared/components/parts-table/notifications-sent-configuration.model';
import { PartsAsBuiltConfigurationModel } from '@shared/components/parts-table/parts-as-built-configuration.model';
import { PartsAsPlannedConfigurationModel } from '@shared/components/parts-table/parts-as-planned-configuration.model';
import { PoliciesConfigurationModel } from '@shared/components/parts-table/policies-configuration.model';
import { TableViewConfig } from '@shared/components/parts-table/table-view-config.model';
import { ToastService } from '@shared/components/toasts/toast.service';
import { Subject } from 'rxjs';
Expand Down Expand Up @@ -112,6 +113,8 @@ export class TableSettingsService {
return new NotificationsSentConfigurationModel().filterConfiguration();
case TableType.RECEIVED_NOTIFICATION:
return new NotificationsReceivedConfigurationModel().filterConfiguration();
case TableType.POLICIES:
return new PoliciesConfigurationModel().filterConfiguration();
}
}

Expand Down
49 changes: 28 additions & 21 deletions frontend/src/app/modules/page/admin/admin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,36 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {getI18nPageProvider} from '@core/i18n';
import {AdminFacade} from '@page/admin/core/admin.facade';
import {AdminService} from '@page/admin/core/admin.service';
import {ContractDetailComponent} from '@page/admin/presentation/contracts/contract-detail/contract-detail.component';
import {ContractsComponent} from '@page/admin/presentation/contracts/contracts.component';
import {ContractsFacade} from '@page/admin/presentation/contracts/contracts.facade';
import {ContractsState} from '@page/admin/presentation/contracts/contracts.state';
import {ModalModule} from '@shared/modules/modal/modal.module';
import {SharedModule} from '@shared/shared.module';
import {TemplateModule} from '@shared/template.module';
import {AdminRoutingModule} from './admin.routing';
import {AdminComponent} from './presentation/admin.component';
import {BpnConfigurationComponent} from './presentation/bpn-configuration/bpn-configuration.component';
import {SaveBpnConfigModal} from './presentation/bpn-configuration/save-modal/save-modal.component';
import {ImportJsonComponent} from './presentation/import-json/import-json.component';
import {NgxJsonViewerModule} from "ngx-json-viewer";
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { MatLineModule } from '@angular/material/core';
import { getI18nPageProvider } from '@core/i18n';
import { AdminFacade } from '@page/admin/core/admin.facade';
import { AdminService } from '@page/admin/core/admin.service';
import { ContractDetailComponent } from '@page/admin/presentation/contracts/contract-detail/contract-detail.component';
import { ContractsComponent } from '@page/admin/presentation/contracts/contracts.component';
import { ContractsFacade } from '@page/admin/presentation/contracts/contracts.facade';
import { ContractsState } from '@page/admin/presentation/contracts/contracts.state';
import { DeletionDialogComponent } from '@page/admin/presentation/policy-management/deletion-dialog/deletion-dialog.component';
import { PoliciesComponent } from '@page/admin/presentation/policy-management/policies/policies.component';
import { PoliciesFacade } from '@page/admin/presentation/policy-management/policies/policies.facade';
import { PoliciesState } from '@page/admin/presentation/policy-management/policies/policies.state';
import { PolicyEditorComponent } from '@page/admin/presentation/policy-management/policy-editor/policy-editor.component';
import { ModalModule } from '@shared/modules/modal/modal.module';
import { PolicyService } from '@shared/service/policy.service';
import { SharedModule } from '@shared/shared.module';
import { TemplateModule } from '@shared/template.module';
import { NgxJsonViewerModule } from 'ngx-json-viewer';
import { AdminRoutingModule } from './admin.routing';
import { AdminComponent } from './presentation/admin.component';
import { BpnConfigurationComponent } from './presentation/bpn-configuration/bpn-configuration.component';
import { SaveBpnConfigModal } from './presentation/bpn-configuration/save-modal/save-modal.component';
import { ImportJsonComponent } from './presentation/import-json/import-json.component';

@NgModule({
declarations: [ AdminComponent, BpnConfigurationComponent, SaveBpnConfigModal, ImportJsonComponent, ContractsComponent, ContractDetailComponent ],
imports: [CommonModule, TemplateModule, SharedModule, AdminRoutingModule, ModalModule, NgxJsonViewerModule],
providers: [ ...getI18nPageProvider('page.admin'), AdminService, AdminFacade, ContractsFacade, ContractsState ],
declarations: [ AdminComponent, BpnConfigurationComponent, SaveBpnConfigModal, ImportJsonComponent, ContractsComponent, ContractDetailComponent, PoliciesComponent, DeletionDialogComponent, PolicyEditorComponent ],
imports: [ CommonModule, TemplateModule, SharedModule, AdminRoutingModule, ModalModule, NgxJsonViewerModule, MatLineModule ],
providers: [ ...getI18nPageProvider('page.admin'), AdminService, AdminFacade, ContractsFacade, ContractsState, PoliciesFacade, PoliciesState, PolicyService ],
})
export class AdminModule {
}
Loading

0 comments on commit 28d7370

Please sign in to comment.