How can I write a condition in a rule of the ACL file, if I'm working with arrays?

524 views Asked by At

I have this rule:

rule Viewer {
  description: "Allow the viewer read access to his assigned assets"
  participant(v): "org.biz.app.Viewer"
  operation: READ
  resource(d): "org.biz.app.Activo"
  condition: (v.getIdentifier() === d.viewers.getIdentifier())
  action: ALLOW
}

and in the model file:

asset Activo identified by acitvoId {
  o String activoId
  o String activoName
  o Integer version
  o DateTime startDate
  o DateTime endDate
  --> Author owner
  --> Viewer[] viewers optional
}

What I want the rule to be is that the viewer only gets read access to the assets that he is assigned to. The:

v.getIdentifier();

returns the viewer id, and I want to compare it with the array of viewers in the asset:

--> Viewer[] viewers optional

if the viewerid is in the array, the viewer has read access. How can I write that rule?

1

There are 1 answers

0
Dan Selman On BEST ANSWER

The pii-network includes ACL rules that reference arrays. E.g. the call to indexOf here:

https://github.com/hyperledger/composer-sample-networks/blob/master/packages/pii-network/permissions.acl#L38