Skip to content

Commit

Permalink
931: fix validate (#940)
Browse files Browse the repository at this point in the history
Co-authored-by: Stepan Kiryakov <[email protected]>
  • Loading branch information
artembuslaev and Stepan-Kirjakov authored May 30, 2022
1 parent 0c340b8 commit f5bdffb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class AggregateBlock {
for (let i = 0; i < vars.length; i++) {
const varName = vars[i];
if (!variables[varName]) {
resultsContainer.addBlockError(ref.uuid, `Variable ${varName} not defined`);
resultsContainer.addBlockError(ref.uuid, `Variable '${varName}' not defined`);
}
}
}
Expand Down
19 changes: 12 additions & 7 deletions guardian-service/src/policy-engine/blocks/report-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class ReportBlock {
documents: documents
}

const vp = await getMongoRepository(VpDocument).findOne({hash, policyId: ref.policyId});
const vp = await getMongoRepository(VpDocument).findOne({ hash, policyId: ref.policyId });

if (vp) {
const vpDocument: IVPReport = {
Expand Down Expand Up @@ -150,7 +150,7 @@ export class ReportBlock {
variables.documentId = doc.id;
variables.documentSubjectId = doc.credentialSubject[0].id;
} else {
const vc = await getMongoRepository(VcDocument).findOne({hash, policyId: ref.policyId})
const vc = await getMongoRepository(VcDocument).findOne({ hash, policyId: ref.policyId })

if (vc) {
const vcDocument: IVCReport = {
Expand Down Expand Up @@ -214,7 +214,7 @@ export class ReportBlock {

await this.reportUserMap(report);

const schemes = await getMongoRepository(Schema).find({status: SchemaStatus.PUBLISHED});
const schemes = await getMongoRepository(Schema).find({ status: SchemaStatus.PUBLISHED });

return {
hash: hash,
Expand All @@ -228,9 +228,14 @@ export class ReportBlock {
}

async setData(user: IAuthUser, data: any) {
const value = data.filterValue;
const blockState = this.state[user.did] || {};
blockState.lastValue = value;
this.state[user.did] = blockState;
const ref = PolicyComponentsUtils.GetBlockRef<IPolicyReportBlock>(this);
try {
const value = data.filterValue;
const blockState = this.state[user.did] || {};
blockState.lastValue = value;
this.state[user.did] = blockState;
} catch (error) {
throw new BlockActionError(error, ref.blockType, ref.uuid);
}
}
}
14 changes: 11 additions & 3 deletions guardian-service/src/policy-engine/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ export enum DataTypes {

export class PolicyUtils {
public static variables(formula: string): string[] {
return mathjs.parse(formula)
.filter((node: any) => node.isSymbolNode)
.map((node: any) => node.name);
const variables = [];
try {
mathjs.parse(formula).traverse((node: any) => {
if (node.isSymbolNode && !mathjs[node.name]) {
variables.push(node.name);
}
});
return variables;
} catch (error) {
return variables;
}
}

public static evaluate(formula: string, scope: any) {
Expand Down

0 comments on commit f5bdffb

Please sign in to comment.