gpt4 book ai didi

javascript - 日期时间 checkin 权限 Hyperledger Fabric

转载 作者:行者123 更新时间:2023-12-03 01:01:59 25 4
gpt4 key购买 nike

我正在尝试检查是否可以在 Composer Hyperledger 结构的 Permission.acl 文件中包含一些条件(复杂的条件)。

我想知道两件事。以下是该 Assets 的 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
}

上面的函数总是返回true?

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

提前致谢。

问候,哈里

最佳答案

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

从基本示例网络(命名空间org.example.basic)开始,我添加了此 Assets :

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,但看不到第二个。

我将 Assets (MedDocument) 传递到脚本函数中,并传递参与者。我不使用参与者,但将其留在那里,因为您可能需要它。)

关于javascript - 日期时间 checkin 权限 Hyperledger Fabric,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52584222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com