diff --git a/Demo Artifacts/iRec.zip b/Demo Artifacts/iRec.zip index e1991d2a88..7c8ec3420a 100644 Binary files a/Demo Artifacts/iRec.zip and b/Demo Artifacts/iRec.zip differ diff --git a/frontend/src/app/components/header/header.component.ts b/frontend/src/app/components/header/header.component.ts index 9f7bd40f04..1e0958d232 100644 --- a/frontend/src/app/components/header/header.component.ts +++ b/frontend/src/app/components/header/header.component.ts @@ -40,7 +40,7 @@ export class HeaderComponent implements OnInit { this.linksConfig[UserRole.USER] = [{ name: "Profile", disabled: false, - link: '/installer-profile' + link: '/user-profile' }, { name: "Policies", disabled: false, diff --git a/ui-service/src/policy-engine/block-tree-generator.ts b/ui-service/src/policy-engine/block-tree-generator.ts index cff4dea0f3..4fa9e0c72a 100644 --- a/ui-service/src/policy-engine/block-tree-generator.ts +++ b/ui-service/src/policy-engine/block-tree-generator.ts @@ -53,13 +53,17 @@ export class BlockTreeGenerator { */ stateChangeCb(uuid: string, state: any, user?: IAuthUser) { this.wss.clients.forEach(async (client: AuthenticatedWebSocket) => { - const policy = await getMongoRepository(Policy).findOne((StateContainer.GetBlockByUUID(uuid) as any).policyId); - const role = policy.registeredUsers[user.did]; - if (!role) { - return - } - if (StateContainer.IfUUIDRegistered(uuid) && StateContainer.IfHasPermission(uuid, role, user)) { - client.send(uuid); + try { + const policy = await getMongoRepository(Policy).findOne((StateContainer.GetBlockByUUID(uuid) as any).policyId); + const role = policy.registeredUsers[user.did]; + if (!role) { + return + } + if (StateContainer.IfUUIDRegistered(uuid) && StateContainer.IfHasPermission(uuid, role, user)) { + client.send(uuid); + } + } catch (e) { + console.error('WS Error', e); } }); @@ -429,7 +433,7 @@ export class BlockTreeGenerator { res.status(err.errorObject.code).send(err.errorObject); return; } - const data = await block.getData(req.user, req.params.uuid); + const data = await block.getData(req.user, req.params.uuid, req.query); res.send(data); } catch (e) { try { diff --git a/ui-service/src/policy-engine/blocks/interface-document-action-block.ts b/ui-service/src/policy-engine/blocks/interface-document-action-block.ts index ffdaf12cd3..d989f0c3ea 100644 --- a/ui-service/src/policy-engine/blocks/interface-document-action-block.ts +++ b/ui-service/src/policy-engine/blocks/interface-document-action-block.ts @@ -10,6 +10,7 @@ import {Users} from '@helpers/users'; import {KeyType, Wallet} from '@helpers/wallet'; import {User} from '@entity/user'; import {PolicyValidationResultsContainer} from '@policy-engine/policy-validation-results-container'; +import {SchemaStatus} from 'interfaces'; /** * Document action clock with UI @@ -139,13 +140,23 @@ export class InterfaceDocumentActionBlock { resultsContainer.addBlockError(ref.uuid, 'Option "targetUrl" does not set'); } - const schemas = await this.guardians.getSchemes({}) || []; + const schemas = await this.guardians.getSchemes() || []; if (!ref.options.schema) { resultsContainer.addBlockError(ref.uuid, 'Option "schema" does not set'); - } else if (typeof ref.options.schema !== 'string') { + break; + } + if (typeof ref.options.schema !== 'string') { resultsContainer.addBlockError(ref.uuid, 'Option "schema" must be a string'); - } else if (!schemas.find(s => s.uuid === ref.options.schema)) { - resultsContainer.addBlockError(ref.uuid, `Schema with id "${ref.options.schema}" does not exist`) + break; + } + const schema = schemas.find(s => s.uuid === ref.options.schema) + if (!schema) { + resultsContainer.addBlockError(ref.uuid, `Schema with id "${ref.options.schema}" does not exist`); + break; + } + if (schema.status != SchemaStatus.PUBLISHED) { + resultsContainer.addBlockError(ref.uuid, `Schema with id "${ref.options.schema}" does not published`); + break; } break; diff --git a/ui-service/src/policy-engine/blocks/request-vc-document-block.ts b/ui-service/src/policy-engine/blocks/request-vc-document-block.ts index 42922ad0b9..36d9e1e42a 100644 --- a/ui-service/src/policy-engine/blocks/request-vc-document-block.ts +++ b/ui-service/src/policy-engine/blocks/request-vc-document-block.ts @@ -8,11 +8,11 @@ import { BlockStateUpdate } from '@policy-engine/helpers/decorators'; import { PolicyBlockHelpers } from '@policy-engine/helpers/policy-block-helpers'; import { PolicyBlockStateData } from '@policy-engine/interfaces'; import { StateContainer } from '@policy-engine/state-container'; -import { Schema } from 'interfaces'; +import { Schema, SchemaStatus } from 'interfaces'; import { HederaHelper, HederaUtils } from 'vc-modules'; import { IAuthUser } from '../../auth/auth.interface'; import { EventBlock } from '../helpers/decorators/event-block'; -import {PolicyValidationResultsContainer} from '@policy-engine/policy-validation-results-container'; +import { PolicyValidationResultsContainer } from '@policy-engine/policy-validation-results-container'; @EventBlock({ blockType: 'requestVcDocument', @@ -47,7 +47,7 @@ export class RequestVcDocumentBlock { async getData(user: IAuthUser): Promise { const options = PolicyBlockHelpers.GetBlockUniqueOptionsObject(this); - if(!this.schema) { + if (!this.schema) { const schemas = await this.guardians.getSchemes({}) || []; this.schema = Schema.mapRef(schemas).find(s => s.uuid === options.schema); } @@ -96,7 +96,7 @@ export class RequestVcDocumentBlock { await this.update(Object.assign(StateContainer.GetBlockState((this as any).uuid, user), { data }), user); - if(ref.options.stopPropagation) { + if (ref.options.stopPropagation) { return {}; } @@ -148,13 +148,23 @@ export class RequestVcDocumentBlock { const ref = PolicyBlockHelpers.GetBlockRef(this); // Test schema options - const schemas = await this.guardians.getSchemes({}) || []; + const schemas = await this.guardians.getSchemes() || []; if (!ref.options.schema) { resultsContainer.addBlockError(ref.uuid, 'Option "schema" does not set'); - } else if (typeof ref.options.schema !== 'string') { + return; + } + if (typeof ref.options.schema !== 'string') { resultsContainer.addBlockError(ref.uuid, 'Option "schema" must be a string'); - } else if (!schemas.find(s => s.uuid === ref.options.schema)) { - resultsContainer.addBlockError(ref.uuid, `Schema with id "${ref.options.schema}" does not exist`) + return; + } + const schema = schemas.find(s => s.uuid === ref.options.schema) + if (!schema) { + resultsContainer.addBlockError(ref.uuid, `Schema with id "${ref.options.schema}" does not exist`); + return; + } + if (schema.status != SchemaStatus.PUBLISHED) { + resultsContainer.addBlockError(ref.uuid, `Schema with id "${ref.options.schema}" does not published`); + return; } } } diff --git a/ui-service/src/policy-engine/import-export.ts b/ui-service/src/policy-engine/import-export.ts index 833a569ab2..308ce239f0 100644 --- a/ui-service/src/policy-engine/import-export.ts +++ b/ui-service/src/policy-engine/import-export.ts @@ -49,13 +49,16 @@ importExportAPI.post('/import', async (req: AuthenticatedRequest, res: Response) const dateNow = '_' + Date.now(); - const existingTokens = await guardians.getTokens({}); - const existingSchemas = await guardians.getSchemes({}); + const existingTokens = await guardians.getTokens(); + const existingSchemas = await guardians.getSchemes(); + + const existingTokensMap = {}; + existingTokens.forEach(token => existingTokensMap[token.tokenId] = true); + tokens = tokens.filter((token:any) => !existingTokensMap[token.tokenId]); for (let token of tokens) { + delete token.id; delete token.selected; } - tokens = tokens.filter(token => existingTokens.includes(token.tokenId)); - tokens = tokens.map(t => existingTokens.find(_t => t.tokenId === _t.tokenId)); for (let schema of schemas) { const oldUUID = schema.uuid; @@ -65,6 +68,7 @@ importExportAPI.post('/import', async (req: AuthenticatedRequest, res: Response) } schema.uuid = newUUID; policy = JSON.parse(JSON.stringify(policy).replace(new RegExp(oldUUID, 'g'), newUUID)); + schema.document = schema.document.replace(new RegExp(oldUUID, 'g'), newUUID); } const policyRepository = getMongoRepository(Policy); diff --git a/ui-service/src/policy-engine/policy-engine.interface.ts b/ui-service/src/policy-engine/policy-engine.interface.ts index 53f427b766..91875ca1fc 100644 --- a/ui-service/src/policy-engine/policy-engine.interface.ts +++ b/ui-service/src/policy-engine/policy-engine.interface.ts @@ -52,5 +52,5 @@ export interface IPolicyInterfaceBlock extends IPolicyBlock { setData(user: IAuthUser | null, data: any): Promise; - getData(user: IAuthUser | null, uuid: string): Promise; + getData(user: IAuthUser | null, uuid: string, queryParams?: any): Promise; }