Javascript 日期时间签入权限Hyperledger结构
我正在尝试检查是否可以在composer Hyperledger结构的permission.acl文件中包含一些复杂的条件 我想知道两件事。以下是资产的cto组成部分:Javascript 日期时间签入权限Hyperledger结构,javascript,function,hyperledger-fabric,hyperledger-composer,Javascript,Function,Hyperledger Fabric,Hyperledger Composer,我正在尝试检查是否可以在composer Hyperledger结构的permission.acl文件中包含一些复杂的条件 我想知道两件事。以下是资产的cto组成部分: asset Document identified by documentId { o String documentId o String value o DocumentType type o String owner o String reviewer optional o String statu
asset Document identified by documentId {
o String documentId
o String value
o DocumentType type
o String owner
o String reviewer optional
o String status
o String mediatype
o DateTime validFrom
o DateTime validTo
}
rule nurseCanViewDocumentsWithinExpiry {
description: "Allow all participants full access to their assets"
participant(p): "org.apatics.net.Participants"
operation: READ
resource(r): "org.apatics.net.Document"
condition: ##HOW TO GIVE THE FUNCTION HERE##
action: ALLOW
}
1我可以包括一些复杂的条件吗?通过函数?我尝试了如下函数:
function (r){
var currentDate = new Date();
if (new Date() > r.validTo && r.reviewer == p.participantId && p.type == "test")
return true
else
return false
}
上面的函数总是返回true
日期检查在这里行吗?新的日期真的会给我当前的日期和时间吗
提前谢谢
问候,,
Hari您即将实现这一目标:- 从基本示例网络名称空间org.example.Basic开始,我添加了以下资产:
asset MedDocument identified by documentId {
o String documentId
o String value
o String type
o String owner
o Boolean reviewer optional
o String status
o String mediatype
o DateTime validFrom
o DateTime validTo
}
我创建了以下测试数据:
{
"$class": "org.example.basic.MedDocument",
"documentId": "01",
"value": "Treatment Plan",
"type": "TP",
"owner": "Dr02",
"reviewer": true,
"status": "live",
"mediatype": "paper",
"validFrom": "2018-10-01T09:03:22.171Z",
"validTo": "2018-10-10T09:03:22.171Z",
}
{
"$class": "org.example.basic.MedDocument",
"documentId": "02",
"value": "Treatment Plan",
"type": "TP",
"owner": "Dr02",
"reviewer": true,
"status": "live",
"mediatype": "paper",
"validFrom": "2018-10-11T09:03:22.171Z",
"validTo": "2018-10-20T09:03:22.171Z",
}
我添加了这个ACL规则-并删除了规则EverybodyCanReadEverything
我将此函数添加到我的JS逻辑中:
/**
* Test that the specified asset (medical doc) is within range.
* @param {Resource} asset The asset.
* @param {Resource} participant The participant.
* @return {boolean} True if yes, false if no.
*/
function testRange(asset, participant) {
var current=new Date();
return ((current > asset.validFrom) && (current < asset.validTo));
}
我创建了一个新的SampleParticipant并发布了一个新ID。结果在10月2日运行!我能看到第一份医疗文件,但看不到第二份
我将资产文档传递到脚本函数中,同时也传递参与者。我不使用参与者,但将其留在那里,因为您可能需要它
/**
* Test that the specified asset (medical doc) is within range.
* @param {Resource} asset The asset.
* @param {Resource} participant The participant.
* @return {boolean} True if yes, false if no.
*/
function testRange(asset, participant) {
var current=new Date();
return ((current > asset.validFrom) && (current < asset.validTo));
}