From 45633dc79764a73a1730b6cb50871d243e9513b3 Mon Sep 17 00:00:00 2001 From: Artem Buslaev Date: Wed, 24 May 2023 18:29:51 +0400 Subject: [PATCH 1/8] fix relationship and produced schemas Signed-off-by: Artem Buslaev --- .../src/api/helpers/policy-wizard-helper.ts | 81 ++++++++----------- guardian-service/src/api/wizard.service.ts | 16 +++- 2 files changed, 49 insertions(+), 48 deletions(-) diff --git a/guardian-service/src/api/helpers/policy-wizard-helper.ts b/guardian-service/src/api/helpers/policy-wizard-helper.ts index ea9831b4c5..008c50a42f 100644 --- a/guardian-service/src/api/helpers/policy-wizard-helper.ts +++ b/guardian-service/src/api/helpers/policy-wizard-helper.ts @@ -1,4 +1,12 @@ -import { BlockType, GenerateUUIDv4, IGridConfig, ISchemaRoleConfig, IWizardConfig, IWizardSchemaConfig, IWizardTrustChainConfig } from '@guardian/interfaces'; +import { + BlockType, + GenerateUUIDv4, + IGridConfig, + ISchemaRoleConfig, + IWizardConfig, + IWizardSchemaConfig, + IWizardTrustChainConfig, +} from '@guardian/interfaces'; /** * Policy wizard helper @@ -224,6 +232,9 @@ export class PolicyWizardHelper { const dependencySchema = schemaConfigs.find( (schema) => schema.iri === schemaConfig.dependencySchemaIri ); + const relationshipSchema = schemaConfigs.find( + (schema) => schema.iri === schemaConfig.relationshipsSchemaIri + ); const gridBlock = this.getDocumentsGrid( roleConfig.role, roleConfig.gridColumns @@ -359,57 +370,34 @@ export class PolicyWizardHelper { } if (roleConfig.isCreator) { - if (schemaConfig.isApproveEnable) { - const requestDocumentBlock = this.getDialogRequestDocumentBlock( - roleConfig.role, - schemaConfig.iri + const requestDocumentBlock = this.getDialogRequestDocumentBlock( + roleConfig.role, + schemaConfig.iri + ); + container.children?.push(requestDocumentBlock); + if (relationshipSchema) { + container.children?.push( + this.getSetRelationshipsBlock( + roleConfig.role, + relationshipSchema.iri, + relationshipSchema.isApproveEnable + ) ); - container.children?.push(requestDocumentBlock); - if ( - schemaConfig.relationshipsSchemaIri && - !schemaConfig.dependencySchemaIri - ) { - container.children?.push( - this.getSetRelationshipsBlock( - roleConfig.role, - schemaConfig.relationshipsSchemaIri, - schemaConfig.isApproveEnable - ) - ); - } + } + if (schemaConfig.isApproveEnable) { container.children?.push( this.getDocumentSendBlock(roleConfig.role, true, true) ); } else { - const requestDocumentBlock = this.getDialogRequestDocumentBlock( - roleConfig.role, - schemaConfig.iri - ); - container.children?.push(requestDocumentBlock); - if ( - schemaConfig.relationshipsSchemaIri && - !schemaConfig.dependencySchemaIri - ) { - container.children?.push( - this.getSetRelationshipsBlock( - roleConfig.role, - schemaConfig.relationshipsSchemaIri, - schemaConfig.isApproveEnable - ) - ); - } container.children?.push( this.getDocumentSendBlock( roleConfig.role, !schemaConfig.isMintSchema, - true + false ) ); - if ( - !schemaConfig.isApproveEnable && - schemaConfig.isMintSchema - ) { + if (schemaConfig.isMintSchema) { container.children?.push( this.getMintBlock( roleConfig.role, @@ -420,13 +408,14 @@ export class PolicyWizardHelper { } } if (dependencySchema && createDependencySchemaAddonTag) { - const requestDocumentBlock = this.getDialogRequestDocumentBlock( - roleConfig.role, - dependencySchema.iri, - true - ); + const requestDependencySchemaDocumentBlock = + this.getDialogRequestDocumentBlock( + roleConfig.role, + dependencySchema.iri, + true + ); container.children?.push( - requestDocumentBlock, + requestDependencySchemaDocumentBlock, this.getDocumentSendBlock( roleConfig.role, !dependencySchema.isMintSchema, diff --git a/guardian-service/src/api/wizard.service.ts b/guardian-service/src/api/wizard.service.ts index ed8b516226..ffb289625b 100644 --- a/guardian-service/src/api/wizard.service.ts +++ b/guardian-service/src/api/wizard.service.ts @@ -6,7 +6,7 @@ import { DatabaseServer, Logger, } from '@guardian/common'; -import { MessageAPI } from '@guardian/interfaces'; +import { IWizardConfig, MessageAPI } from '@guardian/interfaces'; import { emptyNotifier, initNotifier } from '@helpers/notifier'; import { PolicyEngine } from '@policy-engine/policy-engine'; import { @@ -21,7 +21,7 @@ import { PolicyWizardHelper } from './helpers/policy-wizard-helper'; * @param owner Owner */ async function createExistingPolicySchemas( - config: any, + config: IWizardConfig, owner: string, policyTopicId?: string ) { @@ -51,6 +51,18 @@ async function createExistingPolicySchemas( ); schema.iri = schemaMap.newIRI; } + if (schemaToCreateIris.includes(schema.dependencySchemaIri)) { + const schemaMap = schemasMap.find( + (item) => item.oldIRI === schema.dependencySchemaIri + ); + schema.dependencySchemaIri = schemaMap.newIRI; + } + if (schemaToCreateIris.includes(schema.relationshipsSchemaIri)) { + const schemaMap = schemasMap.find( + (item) => item.oldIRI === schema.relationshipsSchemaIri + ); + schema.relationshipsSchemaIri = schemaMap.newIRI; + } } for (const trustChainConfig of config.trustChain) { if (schemaToCreateIris.includes(trustChainConfig.mintSchemaIri)) { From 973fd5d3c576c3232b7169ed16bb156e3aa32089 Mon Sep 17 00:00:00 2001 From: Artem Buslaev Date: Wed, 24 May 2023 20:41:19 +0400 Subject: [PATCH 2/8] fix link button Signed-off-by: Artem Buslaev --- .../src/api/helpers/policy-wizard-helper.ts | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/guardian-service/src/api/helpers/policy-wizard-helper.ts b/guardian-service/src/api/helpers/policy-wizard-helper.ts index 008c50a42f..831cc4479c 100644 --- a/guardian-service/src/api/helpers/policy-wizard-helper.ts +++ b/guardian-service/src/api/helpers/policy-wizard-helper.ts @@ -370,9 +370,11 @@ export class PolicyWizardHelper { } if (roleConfig.isCreator) { - const requestDocumentBlock = this.getDialogRequestDocumentBlock( + let requestDocumentBlock = this.getDialogRequestDocumentBlock( roleConfig.role, - schemaConfig.iri + schemaConfig.iri, + false, + schemaConfig.name ); container.children?.push(requestDocumentBlock); if (relationshipSchema) { @@ -408,14 +410,14 @@ export class PolicyWizardHelper { } } if (dependencySchema && createDependencySchemaAddonTag) { - const requestDependencySchemaDocumentBlock = - this.getDialogRequestDocumentBlock( - roleConfig.role, - dependencySchema.iri, - true - ); + requestDocumentBlock = this.getDialogRequestDocumentBlock( + roleConfig.role, + dependencySchema.iri, + true, + dependencySchema.name + ); container.children?.push( - requestDependencySchemaDocumentBlock, + requestDocumentBlock, this.getDocumentSendBlock( roleConfig.role, !dependencySchema.isMintSchema, From dd7c4f8dfd3ed5b71479aa9358d1b0f82f8b251f Mon Sep 17 00:00:00 2001 From: Artem Buslaev Date: Wed, 24 May 2023 22:14:51 +0400 Subject: [PATCH 3/8] added rejected source addon to wizard Signed-off-by: Artem Buslaev --- .../src/api/helpers/policy-wizard-helper.ts | 108 ++++++++---------- 1 file changed, 45 insertions(+), 63 deletions(-) diff --git a/guardian-service/src/api/helpers/policy-wizard-helper.ts b/guardian-service/src/api/helpers/policy-wizard-helper.ts index 831cc4479c..76ac032fb5 100644 --- a/guardian-service/src/api/helpers/policy-wizard-helper.ts +++ b/guardian-service/src/api/helpers/policy-wizard-helper.ts @@ -239,40 +239,54 @@ export class PolicyWizardHelper { roleConfig.role, roleConfig.gridColumns ); + container.children?.push(gridBlock); let createDependencySchemaAddonTag; if (schemaConfig.isApproveEnable) { - if (roleConfig.isApprover) { - const toApproveOrRejectAddon = this.getDocumentsSourceAddon( - roleConfig.role, - schemaConfig.iri, - false, - [ - { - value: 'Waiting for approval', - field: 'option.status', - type: 'equal', - }, - ] - ); - const approvedAddon = this.getDocumentsSourceAddon( - roleConfig.role, - schemaConfig.iri, - false, - [ - { - value: 'approved_entity', - field: 'type', - type: 'equal', - }, - ] - ); - createDependencySchemaAddonTag = approvedAddon.tag; - gridBlock?.children?.push( - toApproveOrRejectAddon, - approvedAddon - ); + const toApproveOrRejectAddon = this.getDocumentsSourceAddon( + roleConfig.role, + schemaConfig.iri, + !roleConfig.isApprover, + [ + { + value: 'Waiting for approval', + field: 'option.status', + type: 'equal', + }, + ] + ); + const approvedAddon = this.getDocumentsSourceAddon( + roleConfig.role, + schemaConfig.iri, + !roleConfig.isApprover, + [ + { + value: 'approved_entity', + field: 'type', + type: 'equal', + }, + ] + ); + const rejectedAddon = this.getDocumentsSourceAddon( + roleConfig.role, + schemaConfig.iri, + !roleConfig.isApprover, + [ + { + value: 'rejected_entity', + field: 'type', + type: 'equal', + }, + ] + ); + createDependencySchemaAddonTag = approvedAddon.tag; + gridBlock?.children?.push( + toApproveOrRejectAddon, + approvedAddon, + rejectedAddon + ); + if (roleConfig.isApprover) { const saveDocumentApprove = this.getChangeDocumentStatusSendBlock( roleConfig.role, @@ -295,7 +309,7 @@ export class PolicyWizardHelper { ); gridBlock.uiMetaData.fields.push(approveRejectField); - container.children?.push(gridBlock, buttonsBlock); + container.children?.push(buttonsBlock); if (!approveBtnTag && !rejectBtnTag) { container.children?.push( saveDocumentApprove, @@ -327,37 +341,6 @@ export class PolicyWizardHelper { ) ); } - } else { - const toApproveOrRejectAddon = this.getDocumentsSourceAddon( - roleConfig.role, - schemaConfig.iri, - true, - [ - { - value: 'Waiting for approval', - field: 'option.status', - type: 'equal', - }, - ] - ); - const approvedAddon = this.getDocumentsSourceAddon( - roleConfig.role, - schemaConfig.iri, - true, - [ - { - value: 'approved_entity', - field: 'type', - type: 'equal', - }, - ] - ); - createDependencySchemaAddonTag = approvedAddon.tag; - gridBlock?.children?.push( - toApproveOrRejectAddon, - approvedAddon - ); - container.children?.push(gridBlock); } } else { const documentsSourceAddon = this.getDocumentsSourceAddon( @@ -366,7 +349,6 @@ export class PolicyWizardHelper { ); createDependencySchemaAddonTag = documentsSourceAddon.tag; gridBlock?.children?.push(documentsSourceAddon); - container.children?.push(gridBlock); } if (roleConfig.isCreator) { From 68165ba63e8ac3a64957b69dc5b0dbdb25f4ba06 Mon Sep 17 00:00:00 2001 From: artembuslaev Date: Thu, 25 May 2023 18:19:15 +0400 Subject: [PATCH 4/8] fixed choose wizard state Signed-off-by: artembuslaev --- .../policies/policies.component.ts | 9 +- .../policy-configuration.component.ts | 106 +++++++++--------- 2 files changed, 55 insertions(+), 60 deletions(-) diff --git a/frontend/src/app/modules/policy-engine/policies/policies.component.ts b/frontend/src/app/modules/policy-engine/policies/policies.component.ts index f39c7bed4b..990196b65d 100644 --- a/frontend/src/app/modules/policy-engine/policies/policies.component.ts +++ b/frontend/src/app/modules/policy-engine/policies/policies.component.ts @@ -626,10 +626,11 @@ export class PoliciesComponent implements OnInit, OnDestroy { forkJoin([ this.tokenService.getTokens(), this.schemaService.getSchemas(), + this.policyEngineService.all(), ]).subscribe((result) => { - const schemas = result[1].map((schema) => new Schema(schema)); const tokens = result[0].map((token) => new Token(token)); - this.loading = false; + const schemas = result[1].map((schema) => new Schema(schema)); + const policies = result[2]; this.wizardService.openPolicyWizardDialog( WizardMode.CREATE, (value) => { @@ -651,8 +652,8 @@ export class PoliciesComponent implements OnInit, OnDestroy { }, tokens, schemas, - this.policies as any[] + policies ); - }); + }, () => undefined, () => this.loading = false); } } diff --git a/frontend/src/app/modules/policy-engine/policy-configuration/policy-configuration/policy-configuration.component.ts b/frontend/src/app/modules/policy-engine/policy-configuration/policy-configuration/policy-configuration.component.ts index 63f629ab3d..bc53b11756 100644 --- a/frontend/src/app/modules/policy-engine/policy-configuration/policy-configuration/policy-configuration.component.ts +++ b/frontend/src/app/modules/policy-engine/policy-configuration/policy-configuration/policy-configuration.component.ts @@ -54,8 +54,6 @@ export class PolicyConfigurationComponent implements OnInit { public currentBlock!: PolicyBlockModel | undefined; public schemas!: Schema[]; - public allSchemas!: Schema[]; - public allPolicies!: any[]; public tokens!: Token[]; public errors: any[] = []; public errorsCount: number = -1; @@ -212,13 +210,6 @@ export class PolicyConfigurationComponent implements OnInit { }, (error) => { console.error(error); }); - - this.schemaService.getSchemas().subscribe(value => { - this.allSchemas = value.map((schema) => new Schema(schema)); - }); - this.policyEngineService.all().subscribe(value => { - this.allPolicies = value; - }) } public select(name: string) { @@ -1186,55 +1177,58 @@ export class PolicyConfigurationComponent implements OnInit { } public openPolicyWizardDialog() { - this.wizardService.openPolicyWizardDialog( - WizardMode.EDIT, - (value) => { - if (value.create) { - this.loading = true; - this.wizardService - .getPolicyConfig(this.policyId, value.config) - .subscribe((result) => { - this.loading = false; - this.policyModel.setPolicyInfo( - value.config.policy - ); - const roles = value.config.roles; - const policy = this.policyModel.getJSON(); - policy.policyRoles = roles.filter( - (role: string) => role !== 'OWNER' - ); - policy.config = result.policyConfig; - this.updatePolicyModel(policy); - if (value.saveState) { - this.wizardService.setWizardPreset( - this.policyId, - { - data: result?.wizardConfig, - currentNode: value?.currentNode, - } + this.loading = true; + forkJoin([ + this.tokenService.getTokens(), + this.schemaService.getSchemas(), + this.policyEngineService.all(), + ]).subscribe((result) => { + const tokens = result[0].map((token) => new Token(token)); + const schemas = result[1].map((schema) => new Schema(schema)); + const policies = result[2]; + this.wizardService.openPolicyWizardDialog( + WizardMode.EDIT, + (value) => { + if (value.create) { + this.loading = true; + this.wizardService + .getPolicyConfig(this.policyId, value.config) + .subscribe((result) => { + this.loading = false; + this.policyModel.setPolicyInfo( + value.config.policy ); - } - this.schemaService - .getSchemas() - .subscribe((value) => { - this.allSchemas = value.map( - (schema) => new Schema(schema) + const roles = value.config.roles; + const policy = this.policyModel.getJSON(); + policy.policyRoles = roles.filter( + (role: string) => role !== 'OWNER' + ); + policy.config = result.policyConfig; + this.updatePolicyModel(policy); + if (value.saveState) { + this.wizardService.setWizardPreset( + this.policyId, + { + data: result?.wizardConfig, + currentNode: value?.currentNode, + } ); - }); + } + }); + } else if (value.saveState) { + this.wizardService.setWizardPreset(this.policyId, { + data: value.config, + currentNode: value.currentNode, }); - } else if (value.saveState) { - this.wizardService.setWizardPreset(this.policyId, { - data: value.config, - currentNode: value.currentNode, - }); - } else { - this.wizardService.removeWizardPreset(this.policyId); - } - }, - this.tokens, - this.allSchemas, - this.allPolicies, - this.policyModel - ); + } else { + this.wizardService.removeWizardPreset(this.policyId); + } + }, + tokens, + schemas, + policies, + this.policyModel + ); + }, () => undefined, () => this.loading = false); } } From 2b96a1636172ac47021cc06522166bcc5aa94c2b Mon Sep 17 00:00:00 2001 From: artembuslaev Date: Thu, 25 May 2023 18:19:29 +0400 Subject: [PATCH 5/8] fixed wizard trustchain Signed-off-by: artembuslaev --- guardian-service/src/api/helpers/policy-wizard-helper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guardian-service/src/api/helpers/policy-wizard-helper.ts b/guardian-service/src/api/helpers/policy-wizard-helper.ts index 76ac032fb5..9096ca3ac9 100644 --- a/guardian-service/src/api/helpers/policy-wizard-helper.ts +++ b/guardian-service/src/api/helpers/policy-wizard-helper.ts @@ -446,7 +446,7 @@ export class PolicyWizardHelper { const vpGrid = this.getVpGrid( trustChainConfig.role, trustChainTag, - !trustChainConfig.viewOnlyOwnDocuments + trustChainConfig.viewOnlyOwnDocuments ); container.children.push(vpGrid); return container; From 8dc119cb846bb908d0931501b98da0fc1f849239 Mon Sep 17 00:00:00 2001 From: Artem Buslaev Date: Fri, 26 May 2023 01:31:27 +0400 Subject: [PATCH 6/8] change approving for initial steps Signed-off-by: Artem Buslaev --- .../policy-wizard-dialog.component.html | 28 +-- .../policy-wizard-dialog.component.ts | 1 - .../src/api/helpers/policy-wizard-helper.ts | 185 ++++++++---------- .../src/interface/wizard-config.interface.ts | 8 +- 4 files changed, 92 insertions(+), 130 deletions(-) diff --git a/frontend/src/app/modules/policy-engine/helpers/policy-wizard-dialog/policy-wizard-dialog.component.html b/frontend/src/app/modules/policy-engine/helpers/policy-wizard-dialog/policy-wizard-dialog.component.html index 1801868187..e5e1240c4b 100644 --- a/frontend/src/app/modules/policy-engine/helpers/policy-wizard-dialog/policy-wizard-dialog.component.html +++ b/frontend/src/app/modules/policy-engine/helpers/policy-wizard-dialog/policy-wizard-dialog.component.html @@ -52,7 +52,6 @@ delete -
* NAME: @@ -87,7 +86,6 @@ {{role}} -
Produced schema: @@ -103,7 +101,6 @@
- Relationship schema: @@ -111,7 +108,6 @@ {{schema.name}} -
Initial for roles: @@ -126,14 +122,12 @@
- - Minting tokens @@ -166,24 +160,14 @@ title: 'Is approver?', visible: approveEnable}"> - - - Approver for initial step of roles: - - - {{role}} - - - - - Is creator? - - + + -

Grid Columns

diff --git a/frontend/src/app/modules/policy-engine/helpers/policy-wizard-dialog/policy-wizard-dialog.component.ts b/frontend/src/app/modules/policy-engine/helpers/policy-wizard-dialog/policy-wizard-dialog.component.ts index 1ef3eeeb56..4719d585c6 100644 --- a/frontend/src/app/modules/policy-engine/helpers/policy-wizard-dialog/policy-wizard-dialog.component.ts +++ b/frontend/src/app/modules/policy-engine/helpers/policy-wizard-dialog/policy-wizard-dialog.component.ts @@ -405,7 +405,6 @@ export class PolicyWizardDialogComponent implements OnInit { role: [role], isApprover: [false], isCreator: [false], - approverRoleFor: [], gridColumns: [[]], }); schemaRoleConfigControl.push(schemaRoleConfigForm); diff --git a/guardian-service/src/api/helpers/policy-wizard-helper.ts b/guardian-service/src/api/helpers/policy-wizard-helper.ts index 9096ca3ac9..9cf3f73602 100644 --- a/guardian-service/src/api/helpers/policy-wizard-helper.ts +++ b/guardian-service/src/api/helpers/policy-wizard-helper.ts @@ -42,34 +42,40 @@ export class PolicyWizardHelper { root.children = [this.getChooseRoleBlock(roles)]; const children = root.children; const roleContainers: any = {}; + const roleTabContainers: any = {}; roles.forEach((role) => { roleContainers[role] = this.getRoleContainer(role); + roleTabContainers[role] = roleContainers[role]; }); - const initialApproveButtonTags: any = {}; - const roleTabContainers: any = {}; - + const approveRejectInitialSteps: { + [key: string]: { + // tslint:disable-next-line:completed-docs + approveBlockTags: string[]; + // tslint:disable-next-line:completed-docs + rejectBlockTags: string[]; + }; + } = {}; for (const schema of schemas) { + const approveBlockTags = []; + const rejectBlockTags = []; + approveRejectInitialSteps[schema.iri] = { + approveBlockTags, + rejectBlockTags, + }; for (const roleInitialSchemaFor of schema.initialRolesFor) { - const tabsContainer = roleContainers[roleInitialSchemaFor]; const stepContainer = this.getRoleStep(roleInitialSchemaFor); roleContainers[roleInitialSchemaFor] = stepContainer; - stepContainer.children.push(tabsContainer); - - const [_, approveBtnTag, rejectBtnTag] = - this.createInitialSchemaSteps( - roleInitialSchemaFor, - stepContainer, - schema - ); - - roleTabContainers[roleInitialSchemaFor] = tabsContainer; - - initialApproveButtonTags[schema.iri] ||= {}; - initialApproveButtonTags[schema.iri][roleInitialSchemaFor] = { - approveBtnTag, - rejectBtnTag, - }; + const [_, rejectInfoBlockTag] = this.createInitialSchemaSteps( + roleInitialSchemaFor, + stepContainer, + roleTabContainers[roleInitialSchemaFor], + schema + ); + approveBlockTags.push( + roleTabContainers[roleInitialSchemaFor].tag + ); + rejectBlockTags.push(rejectInfoBlockTag); } } @@ -81,14 +87,8 @@ export class PolicyWizardHelper { schema, schemas, this.getTabContainer(roleConfig.role, schema.name), - initialApproveButtonTags[schema.iri] && - initialApproveButtonTags[schema.iri][ - roleConfig.approverRoleFor - ]?.approveBtnTag, - initialApproveButtonTags[schema.iri] && - initialApproveButtonTags[schema.iri][ - roleConfig.approverRoleFor - ]?.rejectBtnTag + approveRejectInitialSteps[schema.iri]?.approveBlockTags, + approveRejectInitialSteps[schema.iri]?.rejectBlockTags ); if (roleTabContainers[roleConfig.role]) { @@ -145,6 +145,7 @@ export class PolicyWizardHelper { private createInitialSchemaSteps( role: string, container: any, + roleTabContainer: any, schemaConfig: IWizardSchemaConfig ) { const requestDocument = this.getRequestDocumentBlock( @@ -156,59 +157,31 @@ export class PolicyWizardHelper { false, schemaConfig.isApproveEnable ); + container.children?.push(requestDocument, sendBlock); - let approveBtnTag; if (schemaConfig.isApproveEnable) { const infoBlock = this.getInfoBlock( role, 'Submitted to approve', 'The page will be automatically refreshed' ); - const sendApproveBlock = this.getChangeDocumentStatusSendBlock( - role, - 'Approved' - ); - const reassignBlock = this.getReassignBlock(role, true); - const sendApproveReassignBlock = this.getDocumentSendBlock( - role, - false, - false, - 'approved_entity' - ); - approveBtnTag = sendApproveBlock.tag; - container.children?.unshift( - infoBlock, - sendApproveBlock, - reassignBlock, - sendApproveReassignBlock - ); + container.children?.push(infoBlock); } - container.children?.unshift(requestDocument, sendBlock); + container?.children.push(roleTabContainer); - let rejectBtnTag; + let rejectInfoBlockTag; if (schemaConfig.isApproveEnable) { - const rejectApproveBlock = this.getChangeDocumentStatusSendBlock( + const rejectInfoBlock = this.getInfoBlock( role, - 'Reject' - ); - container.children?.push(rejectApproveBlock); - const reassignBlock = this.getReassignBlock(role, true); - container.children?.push(reassignBlock); - const sendRejectReassignBlock = this.getDocumentSendBlock( - role, - false, - false, - 'rejected_entity' - ); - rejectBtnTag = rejectApproveBlock.tag; - container.children?.push(sendRejectReassignBlock); - container.children?.push( - this.getInfoBlock(role, 'Rejected', 'Document was rejected') + 'Rejected', + 'Document was rejected' ); + rejectInfoBlockTag = rejectInfoBlock.tag; + container.children?.push(rejectInfoBlock); } - return [container, approveBtnTag, rejectBtnTag]; + return [container, rejectInfoBlockTag]; } /** @@ -226,8 +199,8 @@ export class PolicyWizardHelper { schemaConfig: IWizardSchemaConfig, schemaConfigs: IWizardSchemaConfig[], container: any, - approveBtnTag?: string, - rejectBtnTag?: string + approvedBlockTags: string[] = [], + rejectedBlockTags: string[] = [] ) { const dependencySchema = schemaConfigs.find( (schema) => schema.iri === schemaConfig.dependencySchemaIri @@ -297,50 +270,48 @@ export class PolicyWizardHelper { roleConfig.role, 'Rejected' ); - const buttonsBlock = this.getApproveRejectButtonsBlock( roleConfig.role, - approveBtnTag || saveDocumentApprove.tag, - rejectBtnTag || saveDocumentReject.tag + saveDocumentApprove.tag, + saveDocumentReject.tag ); const approveRejectField = this.getApproveRejectField( buttonsBlock.tag, toApproveOrRejectAddon.tag ); - gridBlock.uiMetaData.fields.push(approveRejectField); - container.children?.push(buttonsBlock); - if (!approveBtnTag && !rejectBtnTag) { - container.children?.push( - saveDocumentApprove, - this.getReassignBlock(roleConfig.role), - this.getDocumentSendBlock( - roleConfig.role, - !schemaConfig.isMintSchema, - false, - 'approved_entity' - ) - ); - if (schemaConfig.isMintSchema) { - container.children?.push( - this.getMintBlock( - roleConfig.role, - schemaConfig.mintOptions.tokenId, - schemaConfig.mintOptions.rule - ) - ); - } + container.children?.push( + buttonsBlock, + saveDocumentApprove, + this.getReassignBlock(roleConfig.role), + this.getDocumentSendBlock( + roleConfig.role, + !schemaConfig.isMintSchema, + false, + 'approved_entity', + approvedBlockTags + ) + ); + if (schemaConfig.isMintSchema) { container.children?.push( - saveDocumentReject, - this.getReassignBlock(roleConfig.role), - this.getDocumentSendBlock( + this.getMintBlock( roleConfig.role, - true, - false, - 'rejected_entity' + schemaConfig.mintOptions.tokenId, + schemaConfig.mintOptions.rule ) ); } + container.children?.push( + saveDocumentReject, + this.getReassignBlock(roleConfig.role), + this.getDocumentSendBlock( + roleConfig.role, + true, + false, + 'rejected_entity', + rejectedBlockTags + ) + ); } } else { const documentsSourceAddon = this.getDocumentsSourceAddon( @@ -750,8 +721,10 @@ export class PolicyWizardHelper { role: string, stopPropagation: boolean = false, needApprove: boolean = false, - entityType?: string + entityType?: string, + blockTagsToTriggerRunEvent?: string[] ) { + const tag = this.generateBlockTag(); return { id: GenerateUUIDv4(), blockType: BlockType.SendToGuardian, @@ -769,9 +742,19 @@ export class PolicyWizardHelper { : [], dataSource: 'auto', documentType: 'vc', - tag: this.generateBlockTag(), + tag, stopPropagation, entityType, + events: Array.isArray(blockTagsToTriggerRunEvent) + ? blockTagsToTriggerRunEvent.map((target) => ({ + target, + source: tag, + input: 'RunEvent', + output: 'RunEvent', + actor: 'owner', + disabled: false, + })) + : [], }; } diff --git a/interfaces/src/interface/wizard-config.interface.ts b/interfaces/src/interface/wizard-config.interface.ts index f31735a450..4f09361ed4 100644 --- a/interfaces/src/interface/wizard-config.interface.ts +++ b/interfaces/src/interface/wizard-config.interface.ts @@ -24,10 +24,6 @@ export interface ISchemaRoleConfig { * Is approver */ isApprover: boolean; - /** - * Approver role for - */ - approverRoleFor?: string; /** * Is creator */ @@ -136,7 +132,7 @@ export interface IWizardConfig { /** * Policy */ - policy: IPolicyForm + policy: IPolicyForm; /** * Roles */ @@ -149,4 +145,4 @@ export interface IWizardConfig { * Trust chain */ trustChain: IWizardTrustChainConfig[]; -} \ No newline at end of file +} From f7be89cfee675aaeb11bfe8830c08e8f11e50419 Mon Sep 17 00:00:00 2001 From: Artem Buslaev Date: Fri, 26 May 2023 13:07:34 +0400 Subject: [PATCH 7/8] changed wizard config in swagger Signed-off-by: Artem Buslaev --- api-docs/api/swagger/swagger.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/api-docs/api/swagger/swagger.yaml b/api-docs/api/swagger/swagger.yaml index 985be518ac..4b186f0930 100644 --- a/api-docs/api/swagger/swagger.yaml +++ b/api-docs/api/swagger/swagger.yaml @@ -910,8 +910,6 @@ components: type: boolean isCreator: type: boolean - approverRoleFor: - type: string gridColumns: type: array items: From a12f3df68d17ffe1ac24cc16eba4edf1a7b6999e Mon Sep 17 00:00:00 2001 From: Artem Buslaev Date: Fri, 26 May 2023 18:01:43 +0400 Subject: [PATCH 8/8] added ability to create schemas with draft topics Signed-off-by: Artem Buslaev --- api-gateway/src/api/service/schema.ts | 8 ++------ .../policy-wizard-dialog.component.ts | 17 ++++++++++++----- .../schema-configuration.component.html | 7 ++++--- .../schema-configuration.component.ts | 8 ++++---- .../app/views/schemas/schemas.component.html | 8 +++++++- .../src/api/helpers/schema-helper.ts | 6 ++---- .../api/helpers/schema-import-export-helper.ts | 2 +- guardian-service/src/api/schema.service.ts | 6 +++++- guardian-service/src/api/wizard.service.ts | 2 +- .../src/policy-engine/policy-engine.ts | 4 ++-- 10 files changed, 40 insertions(+), 28 deletions(-) diff --git a/api-gateway/src/api/service/schema.ts b/api-gateway/src/api/service/schema.ts index 55e90c6248..21be05a79c 100644 --- a/api-gateway/src/api/service/schema.ts +++ b/api-gateway/src/api/service/schema.ts @@ -157,9 +157,7 @@ schemaAPI.post('/:topicId', permissionHelper(UserRole.STANDARD_REGISTRY), async const schemas = await createSchema( newSchema, user.did, - topicId && ['null', 'undefined', ''].includes(topicId) - ? undefined - : topicId + topicId, ); return res.status(201).json(SchemaUtils.toOld(schemas)); } catch (error) { @@ -180,9 +178,7 @@ schemaAPI.post('/push/:topicId', permissionHelper(UserRole.STANDARD_REGISTRY), a await createSchemaAsync( newSchema, user.did, - topicId && ['null', 'undefined', ''].includes(topicId) - ? undefined - : topicId, + topicId, taskId ); }, async (error) => { diff --git a/frontend/src/app/modules/policy-engine/helpers/policy-wizard-dialog/policy-wizard-dialog.component.ts b/frontend/src/app/modules/policy-engine/helpers/policy-wizard-dialog/policy-wizard-dialog.component.ts index 4719d585c6..1a79ccc02b 100644 --- a/frontend/src/app/modules/policy-engine/helpers/policy-wizard-dialog/policy-wizard-dialog.component.ts +++ b/frontend/src/app/modules/policy-engine/helpers/policy-wizard-dialog/policy-wizard-dialog.component.ts @@ -123,21 +123,28 @@ export class PolicyWizardDialogComponent implements OnInit { schemas: groupedSchemasByTopic[policy?.topicId], }, { - name: 'Ungrouped schemas', - schemas: groupedSchemasByTopic[''], + name: 'Draft schemas', + schemas: groupedSchemasByTopic['draft'], }, ] : [ { - name: 'Ungrouped schemas', - schemas: groupedSchemasByTopic[''], + name: 'Draft schemas', + schemas: groupedSchemasByTopic['draft'], }, ]; for (const group of Object.entries(groupedSchemasByTopic)) { - if (group[0] && group[0] !== policy?.topicId) { + if ( + group[0] && + group[0] !== 'draft' && + group[0] !== policy?.topicId + ) { const policy = policies.find( (policy) => policy.topicId === group[0] ); + if (!policy) { + continue; + } mappedSchemas.push({ name: policy.name + diff --git a/frontend/src/app/modules/schema-engine/schema-configuration/schema-configuration.component.html b/frontend/src/app/modules/schema-engine/schema-configuration/schema-configuration.component.html index 2a8419a2a1..2daf2e30ad 100644 --- a/frontend/src/app/modules/schema-engine/schema-configuration/schema-configuration.component.html +++ b/frontend/src/app/modules/schema-engine/schema-configuration/schema-configuration.component.html @@ -7,10 +7,11 @@
- - Policy + + * Policy - Empty + Draft {{policy.name}} diff --git a/frontend/src/app/modules/schema-engine/schema-configuration/schema-configuration.component.ts b/frontend/src/app/modules/schema-engine/schema-configuration/schema-configuration.component.ts index 7de3cb2c30..f93147b5e8 100644 --- a/frontend/src/app/modules/schema-engine/schema-configuration/schema-configuration.component.ts +++ b/frontend/src/app/modules/schema-engine/schema-configuration/schema-configuration.component.ts @@ -248,7 +248,7 @@ export class SchemaConfigurationComponent implements OnInit { props = { name: ['', Validators.required], description: [''], - topicId: [this.topicId], + topicId: [this.topicId, Validators.required], entity: new FormControl(SchemaEntity.VC, Validators.required), fields: this.fieldsForm, conditions: this.conditionsForm @@ -271,10 +271,10 @@ export class SchemaConfigurationComponent implements OnInit { this.updateSubSchemas(topicId); } - updateSubSchemas(topicId: any) { + updateSubSchemas(topicId: string | null) { this.schemaTypes = []; - if (this.schemasMap) { - this.schemas = this.schemasMap[topicId || ''] + if (this.schemasMap && topicId) { + this.schemas = this.schemasMap[topicId] ?.filter(s => { if (this.value?.document?.$id) { const isInDefs = Object.keys(s.document?.$defs || {}) diff --git a/frontend/src/app/views/schemas/schemas.component.html b/frontend/src/app/views/schemas/schemas.component.html index c68af1a763..604b0f817e 100644 --- a/frontend/src/app/views/schemas/schemas.component.html +++ b/frontend/src/app/views/schemas/schemas.component.html @@ -14,6 +14,7 @@ Policy All policies + Draft {{policy.name}} ({{policy.topicId}}) @@ -67,7 +68,12 @@ Topic - {{element.topicId}} + + Draft + + + {{element.topicId}} + diff --git a/guardian-service/src/api/helpers/schema-helper.ts b/guardian-service/src/api/helpers/schema-helper.ts index d1d51fa8f1..b689ff1215 100644 --- a/guardian-service/src/api/helpers/schema-helper.ts +++ b/guardian-service/src/api/helpers/schema-helper.ts @@ -5,7 +5,6 @@ import { SchemaHelper, Schema, TopicType, - SchemaCategory, IRootConfig } from '@guardian/interfaces'; import path from 'path'; @@ -328,7 +327,6 @@ export async function createSchema( if (checkForCircularDependency(newSchema)) { throw new Error(`There is circular dependency in schema: ${newSchema.iri}`); } - newSchema.topicId ||= undefined; delete newSchema.id; delete newSchema._id; const users = new Users(); @@ -345,7 +343,7 @@ export async function createSchema( topic = await TopicConfig.fromObject(await DatabaseServer.getTopicById(newSchema.topicId), true); } - if (!topic && newSchema.category !== SchemaCategory.POLICY) { + if (!topic && newSchema.topicId !== 'draft') { const topicHelper = new TopicHelper(root.hederaAccountId, root.hederaAccountKey); topic = await topicHelper.create({ type: TopicType.SchemaTopic, @@ -362,7 +360,7 @@ export async function createSchema( SchemaHelper.updateIRI(schemaObject); schemaObject.status = SchemaStatus.DRAFT; - schemaObject.topicId = topic?.topicId; + schemaObject.topicId = topic?.topicId || 'draft'; schemaObject.iri = schemaObject.iri || `${schemaObject.uuid}`; schemaObject.codeVersion = SchemaConverterUtils.VERSION; const errorsCount = await DatabaseServer.getSchemasCount({ diff --git a/guardian-service/src/api/helpers/schema-import-export-helper.ts b/guardian-service/src/api/helpers/schema-import-export-helper.ts index 32fd35e914..e7607d5ccd 100644 --- a/guardian-service/src/api/helpers/schema-import-export-helper.ts +++ b/guardian-service/src/api/helpers/schema-import-export-helper.ts @@ -161,7 +161,7 @@ export async function importSchemaByFiles( file.messageId = null; file.creator = owner; file.owner = owner; - file.topicId = topicId; + file.topicId = topicId || 'draft'; file.status = SchemaStatus.DRAFT; } diff --git a/guardian-service/src/api/schema.service.ts b/guardian-service/src/api/schema.service.ts index 692e766d25..f5a10e9e0c 100644 --- a/guardian-service/src/api/schema.service.ts +++ b/guardian-service/src/api/schema.service.ts @@ -100,7 +100,11 @@ export async function schemaAPI(): Promise { item.description = msg.description; item.entity = msg.entity; item.document = msg.document; - if (!item.topicId && msg.topicId) { + if ( + (item.topicId === 'draft') && + msg.topicId && + msg.topicId !== 'draft' + ) { item.topicId = msg.topicId; const topic = await TopicConfig.fromObject( await DatabaseServer.getTopicById(msg.topicId), diff --git a/guardian-service/src/api/wizard.service.ts b/guardian-service/src/api/wizard.service.ts index ffb289625b..26f9e1d42d 100644 --- a/guardian-service/src/api/wizard.service.ts +++ b/guardian-service/src/api/wizard.service.ts @@ -30,7 +30,7 @@ async function createExistingPolicySchemas( const schemasToCreate = schemas.filter( (schema) => schemaIris.includes(schema.iri) && - (schema.topicId && + (schema.topicId !== 'draft' && schema.topicId !== policyTopicId) ); const schemaToCreateIris = schemasToCreate.map((schema) => schema.iri); diff --git a/guardian-service/src/policy-engine/policy-engine.ts b/guardian-service/src/policy-engine/policy-engine.ts index 8a96f19286..21ae39468c 100644 --- a/guardian-service/src/policy-engine/policy-engine.ts +++ b/guardian-service/src/policy-engine/policy-engine.ts @@ -162,7 +162,7 @@ export class PolicyEngine extends NatsService { } const schemas = await DatabaseServer.getSchemas({ iri: { $in: schemaIris }, - topicId: { $eq: null }, + topicId: { $eq: 'draft' }, owner }); const users = new Users(); @@ -181,7 +181,7 @@ export class PolicyEngine extends NatsService { ); const dependencySchemas = await DatabaseServer.getSchemas({ iri: { $in: schema.defs }, - topicId: { $eq: null } + topicId: { $eq: 'draft' } }); dependencySchemas.forEach(dependencySchema => { dependencySchema.topicId = policyTopicId;