DateTime 签入权限 Hyperledger fabric

DateTime check in permissions Hyperledger fabric

我正在尝试检查是否可以在 composer Hyperledger fabric 的 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 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
  }

上面的函数总是returns对吗?

2) 日期检查在这里工作吗? new Date() 真的会给我当前的日期和时间吗?

提前致谢。

此致, 哈里

您即将完成这项工作:-)

从基本示例网络(命名空间 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 !

rule nurseCanViewDocumentsWithinExpiry {
 description: "Allow all participants full access to their assets"
 participant(p): "org.example.basic.SampleParticipant"
 operation: READ
 resource(r): "org.example.basic.MedDocument"
 condition: (testRange(r, p))
 action: ALLOW
}

我将这个函数添加到我的 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 日!)是我可以看到第一个 MedDocument,但看不到第二个。

我正在将资产 (MedDocument) 传递到脚本函数中,同时传递参与者。我不使用参与者,但把它留在那里,因为你可能需要它。)