diff --git a/frontend/src/app/modules/policy-engine/dialogs/publish-policy-dialog/publish-policy-dialog.component.html b/frontend/src/app/modules/policy-engine/dialogs/publish-policy-dialog/publish-policy-dialog.component.html
index a0add083a8..b311d57d51 100644
--- a/frontend/src/app/modules/policy-engine/dialogs/publish-policy-dialog/publish-policy-dialog.component.html
+++ b/frontend/src/app/modules/policy-engine/dialogs/publish-policy-dialog/publish-policy-dialog.component.html
@@ -13,7 +13,7 @@
diff --git a/frontend/src/app/modules/policy-engine/dialogs/publish-policy-dialog/publish-policy-dialog.component.scss b/frontend/src/app/modules/policy-engine/dialogs/publish-policy-dialog/publish-policy-dialog.component.scss
index 563a0b8408..61e6728c66 100644
--- a/frontend/src/app/modules/policy-engine/dialogs/publish-policy-dialog/publish-policy-dialog.component.scss
+++ b/frontend/src/app/modules/policy-engine/dialogs/publish-policy-dialog/publish-policy-dialog.component.scss
@@ -4,6 +4,10 @@
}
.dialog-header {
+ .header-text {
+ min-width: 190px;
+ }
+
.header-item {
padding: 6px 12px;
margin: 0px 16px;
@@ -13,6 +17,9 @@
background: var(--guardian-dry-run-background);
user-select: none;
cursor: default;
+ max-width: 275px;
+ overflow: hidden;
+ text-overflow: ellipsis;
}
}
@@ -26,6 +33,10 @@
margin-right: 0px !important;
}
+.guardian-input-container {
+ margin-bottom: 24px;
+}
+
.form-input-container {
display: flex;
flex-direction: column;
diff --git a/frontend/src/app/modules/policy-engine/policies/policies.component.scss b/frontend/src/app/modules/policy-engine/policies/policies.component.scss
index ff79b03526..2917561333 100644
--- a/frontend/src/app/modules/policy-engine/policies/policies.component.scss
+++ b/frontend/src/app/modules/policy-engine/policies/policies.component.scss
@@ -990,7 +990,7 @@
.cell-description {
min-width: 150px;
- max-width: calc(100vw - 970px);
+ max-width: calc(100vw - 1080px);
}
.submenu-arrow {
diff --git a/frontend/src/app/modules/schema-engine/document-view/document-view.component.html b/frontend/src/app/modules/schema-engine/document-view/document-view.component.html
index f4246f7aed..1d658dc539 100644
--- a/frontend/src/app/modules/schema-engine/document-view/document-view.component.html
+++ b/frontend/src/app/modules/schema-engine/document-view/document-view.component.html
@@ -131,6 +131,7 @@
diff --git a/frontend/src/app/modules/schema-engine/document-view/document-view.component.ts b/frontend/src/app/modules/schema-engine/document-view/document-view.component.ts
index e6652fc33c..5b96bdeb4f 100644
--- a/frontend/src/app/modules/schema-engine/document-view/document-view.component.ts
+++ b/frontend/src/app/modules/schema-engine/document-view/document-view.component.ts
@@ -1,4 +1,4 @@
-import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit, } from '@angular/core';
+import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit, SimpleChanges, } from '@angular/core';
import { DocumentValidators, Schema, SchemaRuleValidateResult } from '@guardian/interfaces';
import { forkJoin, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@@ -19,6 +19,7 @@ import { FormulasTree } from '../../formulas/models/formula-tree';
export class DocumentViewComponent implements OnInit {
@Input('getByUser') getByUser: boolean = false;
@Input('document') document: any;
+ @Input('formulas') formulas: FormulasTree | null;
@Input('hide-fields') hideFields!: { [x: string]: boolean };
@Input('type') type!: 'VC' | 'VP';
@Input('schema') schema!: any;
@@ -39,7 +40,6 @@ export class DocumentViewComponent implements OnInit {
public schemaMap: { [x: string]: Schema | null } = {};
public rules: DocumentValidators;
public rulesResults: SchemaRuleValidateResult;
- public formulas: FormulasTree | null;
public formulasResults: any | null;
private destroy$: Subject = new Subject();
@@ -86,9 +86,11 @@ export class DocumentViewComponent implements OnInit {
this.subjects.push(this.document.verifiableCredential);
}
}
- if (this.type === 'VC') {
- this.loadSchema();
- }
+ this.loadData();
+ }
+
+ ngOnChanges(changes: SimpleChanges): void {
+ this.formulasResults = this.formulas?.getFields(this.schemaId);
}
ngOnDestroy() {
@@ -96,85 +98,100 @@ export class DocumentViewComponent implements OnInit {
this.destroy$.unsubscribe();
}
- private loadSchema() {
- for (const credentialSubject of this.subjects) {
- const type: string = credentialSubject.type;
- if (!this.schemaMap[type]) {
- this.schemaMap[type] = null;
- }
- if (!this.schemaId) {
- this.schemaId = `#${type}`;
+ private loadData() {
+ const requests: any = {};
+
+ //Load Schemas
+ if (this.type === 'VC') {
+ const schemas: any[] = [];
+ for (const credentialSubject of this.subjects) {
+ const type: string = credentialSubject.type;
+ if (!this.schemaMap[type]) {
+ this.schemaMap[type] = null;
+ }
+ if (!this.schemaId) {
+ this.schemaId = `#${type}`;
+ }
}
- }
- const requests: any[] = [];
- for (const [type, schema] of Object.entries(this.schemaMap)) {
- if (!schema) {
- if (this.getByUser) {
- requests.push(
- this.schemaService
- .getSchemasByTypeAndUser(type)
- .pipe(takeUntil(this.destroy$))
- )
- } else {
- requests.push(
- this.schemaService
- .getSchemasByType(type)
- .pipe(takeUntil(this.destroy$))
- )
+ for (const [type, schema] of Object.entries(this.schemaMap)) {
+ if (!schema) {
+ if (this.getByUser) {
+ schemas.push(
+ this.schemaService
+ .getSchemasByTypeAndUser(type)
+ .pipe(takeUntil(this.destroy$))
+ )
+ } else {
+ schemas.push(
+ this.schemaService
+ .getSchemasByType(type)
+ .pipe(takeUntil(this.destroy$))
+ )
+ }
}
}
+ for (let i = 0; i < schemas.length; i++) {
+ requests[i] = schemas[i];
+ }
}
- requests.push(
- this.schemaRulesService
+ //Load Rules
+ if (this.type === 'VC') {
+ requests.rules = this.schemaRulesService
.getSchemaRuleData({
policyId: this.policyId,
schemaId: this.schemaId,
documentId: this.documentId
})
- .pipe(takeUntil(this.destroy$))
- )
+ .pipe(takeUntil(this.destroy$));
+ }
- requests.push(
- this.formulasService
+ //Load Formulas
+ if (this.documentId) {
+ requests.formulas = this.formulasService
.getFormulasData({
policyId: this.policyId,
schemaId: this.schemaId,
documentId: this.documentId
})
- .pipe(takeUntil(this.destroy$))
- )
+ .pipe(takeUntil(this.destroy$));
+ }
+
this.loading = true;
- forkJoin(requests).subscribe((results: any[]) => {
- const formulas = results.pop();
- const rules = results.pop();
+ forkJoin(requests).subscribe((results: any) => {
+ //Load Rules
+ if (results.rules) {
+ const rules = results.rules;
+ this.rules = new DocumentValidators(rules);
+ this.rulesResults = this.rules.validateVC(this.schemaId, this.document);
+ delete results.rules;
+ }
- for (const result of results) {
- if (result) {
+ //Load Formulas
+ if (results.formulas) {
+ const formulas = results.formulas;
+ this.formulas = FormulasTree.from(formulas);
+ this.formulas?.setDocuments(this.document);
+ this.formulasResults = this.formulas?.getFields(this.schemaId);
+ delete results.formulas;
+ }
+
+ //Load Schemas
+ for (const schema of Object.values(results)) {
+ if (schema) {
try {
- let type = (result.iri || '');
+ let type = (schema.iri || '');
if (type.startsWith('#')) {
type = type.substr(1);
}
- this.schemaMap[type] = new Schema(result);
+ this.schemaMap[type] = new Schema(schema);
} catch (error) {
console.error(error);
}
}
}
- this.rules = new DocumentValidators(rules);
- this.rulesResults = this.rules.validateVC(this.schemaId, this.document);
-
- if (formulas && !formulas.document) {
- formulas.document = { document: this.document };
- }
-
- this.formulas = FormulasTree.from(formulas);
- this.formulas?.setDocuments(this.document);
- this.formulasResults = this.formulas?.getFields(this.schemaId);
-
setTimeout(() => {
this.loading = false;
this.ref.detectChanges();
@@ -183,6 +200,7 @@ export class DocumentViewComponent implements OnInit {
this.loading = false;
this.ref.detectChanges();
});
+
}
getItemsPage(items: any[]) {
diff --git a/frontend/src/app/modules/schema-engine/vc-dialog/vc-dialog.component.ts b/frontend/src/app/modules/schema-engine/vc-dialog/vc-dialog.component.ts
index c5418ed945..43aedcc31d 100644
--- a/frontend/src/app/modules/schema-engine/vc-dialog/vc-dialog.component.ts
+++ b/frontend/src/app/modules/schema-engine/vc-dialog/vc-dialog.component.ts
@@ -73,7 +73,6 @@ export class VCViewerDialog {
getByUser
} = this.dialogConfig.data;
-
this.policyId = row?.policyId;
this.documentId = row?.id;
this.schemaId = row?.schema;
diff --git a/guardian-service/src/api/helpers/formulas-helpers.ts b/guardian-service/src/api/helpers/formulas-helpers.ts
index b9f561a7f7..10789241eb 100644
--- a/guardian-service/src/api/helpers/formulas-helpers.ts
+++ b/guardian-service/src/api/helpers/formulas-helpers.ts
@@ -1,13 +1,15 @@
-import { DatabaseServer, Formula, FormulaImportExport, FormulaMessage, MessageAction, MessageServer, TopicConfig, VcDocument } from '@guardian/common';
+import { DatabaseServer, Formula, FormulaImportExport, FormulaMessage, MessageAction, MessageServer, TopicConfig, VcDocument, VpDocument } from '@guardian/common';
import { EntityStatus, IOwner, IRootConfig } from '@guardian/interfaces';
import { INotifier } from '../../helpers/notifier.js';
-async function findRelationships(target: VcDocument): Promise {
+type IDocument = VcDocument | VpDocument;
+
+async function findRelationships(target: IDocument): Promise {
if (!target) {
return [];
}
- const prevRelationships = new Map();
+ const prevRelationships = new Map();
prevRelationships.set(target.messageId, target);
await addRelationships(target, prevRelationships);
@@ -15,7 +17,7 @@ async function findRelationships(target: VcDocument): Promise {
return Array.from(prevRelationships.values());
}
-async function addRelationships(doc: VcDocument, relationships: Map) {
+async function addRelationships(doc: IDocument, relationships: Map) {
if (doc && doc.relationships) {
for (const id of doc.relationships) {
await addRelationship(id, relationships);
@@ -23,7 +25,7 @@ async function addRelationships(doc: VcDocument, relationships: Map) {
+async function addRelationship(messageId: string, relationships: Map) {
if (!messageId || relationships.has(messageId)) {
return;
}
@@ -48,18 +50,24 @@ export async function getFormulasData(
const { policyId, documentId, parentId } = option;
const result: {
- document: VcDocument | null,
- relationships: VcDocument[]
+ document: IDocument | null,
+ relationships: IDocument[]
} = {
document: null,
relationships: []
}
if (documentId) {
- const doc = await DatabaseServer.getVCById(documentId);
- if (doc) {
- result.document = doc;
- result.relationships = await findRelationships(doc);
+ const vc = await DatabaseServer.getVCById(documentId);
+ if (vc) {
+ result.document = vc;
+ result.relationships = await findRelationships(vc);
+ } else {
+ const vp = await DatabaseServer.getVPById(documentId);
+ if (vp) {
+ result.document = vp;
+ result.relationships = await findRelationships(vp);
+ }
}
}
diff --git a/guardian-service/src/api/helpers/schema-publish-helper.ts b/guardian-service/src/api/helpers/schema-publish-helper.ts
index 7f74dccb2f..b3a6a257db 100644
--- a/guardian-service/src/api/helpers/schema-publish-helper.ts
+++ b/guardian-service/src/api/helpers/schema-publish-helper.ts
@@ -155,7 +155,8 @@ export async function saveSchemas(
export async function publishDefsSchemas(
defs: any,
user: IOwner,
- root: IRootConfig
+ root: IRootConfig,
+ schemaMap: Map | null
) {
if (!defs) {
return;
@@ -167,7 +168,7 @@ export async function publishDefsSchemas(
});
if (schema && schema.status !== SchemaStatus.PUBLISHED) {
schema = await incrementSchemaVersion(schema.iri, user);
- await findAndPublishSchema(schema.id, schema.version, user, root, emptyNotifier());
+ await findAndPublishSchema(schema.id, schema.version, user, root, emptyNotifier(), schemaMap);
}
}
}
@@ -185,7 +186,8 @@ export async function findAndPublishSchema(
version: string,
user: IOwner,
root: IRootConfig,
- notifier: INotifier
+ notifier: INotifier,
+ schemaMap: Map | null
): Promise {
notifier.start('Load schema');
@@ -201,7 +203,7 @@ export async function findAndPublishSchema(
notifier.completedAndStart('Publishing related schemas');
const oldSchemaIri = item.iri;
- await publishDefsSchemas(item.document?.$defs, user, root);
+ await publishDefsSchemas(item.document?.$defs, user, root, schemaMap);
item = await DatabaseServer.getSchema(id);
notifier.completedAndStart('Resolve topic');
@@ -220,6 +222,12 @@ export async function findAndPublishSchema(
await updateSchemaDocument(item);
await updateSchemaDefs(item.iri, oldSchemaIri);
notifier.completed();
+
+ if (schemaMap) {
+ const newSchemaIri = item.iri;
+ schemaMap.set(oldSchemaIri, newSchemaIri);
+ }
+
return item;
}
diff --git a/guardian-service/src/api/schema.service.ts b/guardian-service/src/api/schema.service.ts
index 0df9c2e401..2ee23b9e89 100644
--- a/guardian-service/src/api/schema.service.ts
+++ b/guardian-service/src/api/schema.service.ts
@@ -550,7 +550,7 @@ export async function schemaAPI(logger: PinoLogger): Promise {
const { id, version, owner } = msg;
const users = new Users();
const root = await users.getHederaAccount(owner.creator);
- const item = await findAndPublishSchema(id, version, owner, root, emptyNotifier());
+ const item = await findAndPublishSchema(id, version, owner, root, emptyNotifier(), null);
return new MessageResponse(item);
} catch (error) {
await logger.error(error, ['GUARDIAN_SERVICE']);
@@ -571,7 +571,7 @@ export async function schemaAPI(logger: PinoLogger): Promise {
notifier.completedAndStart('Resolve Hedera account');
const users = new Users();
const root = await users.getHederaAccount(owner.creator);
- const item = await findAndPublishSchema(id, version, owner, root, notifier);
+ const item = await findAndPublishSchema(id, version, owner, root, notifier, null);
notifier.result(item.id);
}, async (error) => {
await logger.error(error, ['GUARDIAN_SERVICE']);
@@ -1184,7 +1184,7 @@ export async function schemaAPI(logger: PinoLogger): Promise {
const { id, version, owner } = msg;
const users = new Users();
const root = await users.getHederaAccount(owner.creator);
- const item = await findAndPublishSchema(id, version, owner, root, emptyNotifier());
+ const item = await findAndPublishSchema(id, version, owner, root, emptyNotifier(), null);
return new MessageResponse(item);
} catch (error) {
await logger.error(error, ['GUARDIAN_SERVICE']);
diff --git a/guardian-service/src/api/tool.service.ts b/guardian-service/src/api/tool.service.ts
index d6175b0f33..2ccaf0ea3a 100644
--- a/guardian-service/src/api/tool.service.ts
+++ b/guardian-service/src/api/tool.service.ts
@@ -221,6 +221,7 @@ export async function publishSchemas(
const schemaIRIs = schemas.map(s => s.iri);
let num: number = 0;
let skipped: number = 0;
+ const schemaMap = new Map();
for (const schemaIRI of schemaIRIs) {
const schema = await incrementSchemaVersion(schemaIRI, owner);
if (!schema || schema.status === SchemaStatus.PUBLISHED) {
@@ -232,7 +233,8 @@ export async function publishSchemas(
schema.version,
owner,
root,
- emptyNotifier()
+ emptyNotifier(),
+ schemaMap
);
if (Array.isArray(tool.config?.variables)) {
for (const variable of tool.config?.variables) {
@@ -241,14 +243,16 @@ export async function publishSchemas(
}
}
}
- replaceAllEntities(tool.config, SchemaFields, schemaIRI, newSchema.iri);
- replaceAllVariables(tool.config, 'Schema', schemaIRI, newSchema.iri);
-
const name = newSchema.name;
num++;
notifier.info(`Schema ${num} (${name || '-'}) published`);
}
+ for (const [oldId, newId] of schemaMap.entries()) {
+ replaceAllEntities(tool.config, SchemaFields, oldId, newId);
+ replaceAllVariables(tool.config, 'Schema', oldId, newId);
+ }
+
if (skipped) {
notifier.info(`Skip published ${skipped}`);
}
diff --git a/guardian-service/src/policy-engine/policy-engine.ts b/guardian-service/src/policy-engine/policy-engine.ts
index 1a7b5be614..c41811a7f0 100644
--- a/guardian-service/src/policy-engine/policy-engine.ts
+++ b/guardian-service/src/policy-engine/policy-engine.ts
@@ -677,11 +677,9 @@ export class PolicyEngine extends NatsService {
schema.version,
user,
root,
- emptyNotifier()
+ emptyNotifier(),
+ schemaMap
);
-
- schemaMap.set(schemaIRI, newSchema.iri);
-
const name = newSchema.name;
num++;
notifier.info(`Schema ${num} (${name || '-'}) published`);