Странное поведение в Composer Playground, разрешения - PullRequest
0 голосов
/ 22 мая 2019

Я создал простую сеть в Composer Playground (0.20.8) с производителями. продукты, колли и поддоны. Сделал скрипт (FillDemo), который создаст 2 производителя, 6 поддонов (по 3 каждый), 18 колли (3 колли на паллету) и 54 продукта (3 на колли). После создания 2 идентификаторов для 1_manufacturer и 2_manufacturer все выглядит нормально для 1_manufacturer, но при выборе 2_manufacturing 010_colli и 028_product не отображаются.

При попытке 2 производителей, 2 поддона на производителя, 2 колли на поддон, 2 продукта на колли. Все в порядке. С 5 поддонами и т. Д. Также отсутствует некоторая информация.

Также с другой версией Playground (0.20.5) и разными версиями Fabric (1.2.1, 1.4.1) одинаковое поведение ...

model.cto

namespace org.test.org

asset Product identified by productId {
  o String  productId
  --> Colli productColli
}

participant Colli identified by colliId {
  o String colliId
  --> Pallet  colliPallet
}

participant Pallet identified by palletId {
  o String palletId
  --> Manufacturer owner
}

participant Manufacturer identified by manufacturerId {
  o String manufacturerId
}

transaction FillDemo {}

transaction RemoveAll {}

script.js

const namespace = 'org.test.org';

/**
 * Fill the demo
 * @param {org.test.org.FillDemo} FillDemo
 * @transaction
 */

async function FillDemo (FillDemo) {
  const factory = getFactory();
  const productRegistry = await getAssetRegistry(namespace + '.Product');
  const colliRegistry = await getParticipantRegistry(namespace + '.Colli');
  const palletRegistry = await getParticipantRegistry(namespace + '.Pallet');
  const manufacturerRegistry = await getParticipantRegistry(namespace + '.Manufacturer');


  const manufacturerResource = [];
  let aantal = 2;

  for (let i = 0; i < aantal; i++) {
    const manufacturer = factory.newResource(namespace,'Manufacturer',(i+1) + '_manufacturer');
    manufacturerResource.push(manufacturer);
  }
  await manufacturerRegistry.addAll(manufacturerResource);

  const palletResource = [];
  let palletfactor = 3;
  for (let i = 0; i < aantal*palletfactor; i++) {
    var prefix = '000' + (i+1);    
    const pallet = factory.newResource(namespace,'Pallet', prefix.substr(prefix.length-3) + '_pallet');
    let manufacturernumber = Math.floor((i+palletfactor)/palletfactor);    
    pallet.owner = factory.newRelationship(namespace, 'Manufacturer', manufacturernumber + '_manufacturer');    
    palletResource.push(pallet);
  }
  await palletRegistry.addAll(palletResource);

  let collifactor = 3;
  const colliResource = [];
  for (let i = 0; i < aantal*collifactor*palletfactor; i++) {
    var prefix = '000' + (i+1);    
    const colli = factory.newResource(namespace,'Colli', prefix.substr(prefix.length-3) + '_colli');    
    let palletnumber = Math.floor((i+collifactor)/collifactor);     
    var prefix_1 = '000' + palletnumber;
    colli.colliPallet = factory.newRelationship(namespace,'Pallet', prefix_1.substr(prefix_1.length-3) + '_pallet');
    colliResource.push(colli);
  }
  await colliRegistry.addAll(colliResource);

  let productfactor = 3;
  const productResource = [];
  for (let i = 0; i < aantal*palletfactor*collifactor*productfactor; i++) {
    var prefix = '000' + (i+1);
    const product = factory.newResource(namespace,'Product',  prefix.substr(prefix.length-3) + '_product');
    let number = Math.floor((i+productfactor)/productfactor);    
    var prefix_1 = '000' + number;
    product.productColli = factory.newRelationship(namespace,'Colli', prefix_1.substr(prefix_1.length-3) + '_colli');
    productResource.push(product);
  }

  await productRegistry.addAll(productResource) 
}


/**
 * Script RemoveAll
 * @param {org.test.org.RemoveAll} RemoveAll
 * @transaction
 */
async function RemoveAll(RemoveAll) {

    const factory = getFactory();
    const productRegistry = await getAssetRegistry(namespace+ '.Product');
    let a = await productRegistry.getAll();
    await productRegistry.removeAll(a);
    const colliRegistry = await getParticipantRegistry(namespace+ '.Colli');
    let b = await colliRegistry.getAll();
    await colliRegistry.removeAll(b);
    const palletRegistry = await getParticipantRegistry(namespace+ '.Pallet');
    let c = await palletRegistry.getAll();
    await palletRegistry.removeAll(c);
    const manufacturerRegistry = await getParticipantRegistry(namespace+ '.Manufacturer');
    let d = await manufacturerRegistry.getAll();
    await manufacturerRegistry.removeAll(d);    
}

permissions.acl

rule ManufacturerProduct {
    description: "Grant Manufacturer Product"
    participant (p): "org.test.org.Manufacturer"
    operation: ALL
    resource (r): "org.test.org.Product"
    condition: (r.productColli.colliPallet.owner.getIdentifier() == p.getIdentifier())
    action: ALLOW
}

rule ManufacturerColli {
    description: "Grant manufacturer Colli"
    participant (p): "org.test.org.Manufacturer"
    operation: ALL
    resource (r): "org.test.org.Colli"
    condition: (r.colliPallet.owner.getIdentifier() == p.getIdentifier())
    action: ALLOW
}

rule ManufacturerPallet {
    description: "Grant manufacturer Pallets"
    participant (p): "org.test.org.Manufacturer"
    operation: ALL
    resource (r): "org.test.org.Pallet"
    condition: (r.owner.getIdentifier() == p.getIdentifier())
    action: ALLOW
}


rule NetworkAdminUser {
    description: "Grant business network administrators full access to user resources"
    participant: "org.hyperledger.composer.system.NetworkAdmin"
    operation: ALL
    resource: "**"
    action: ALLOW
}

rule NetworkAdminSystem {
    description: "Grant business network administrators full access to system resources"
    participant: "org.hyperledger.composer.system.NetworkAdmin"
    operation: ALL
    resource: "org.hyperledger.composer.system.**"
    action: ALLOW
}

rule ParticipantsSeeSelves {
    description: "Let Participants see themselves"
    participant(p): "org.hyperledger.composer.system.Participant"
    operation: ALL
    resource(r): "org.hyperledger.composer.system.Participant"
    condition: (r.getIdentifier() == p.getIdentifier())
    action: ALLOW
}

rule SystemACL {
    description: "System ACL to permit all access"
    participant: "org.hyperledger.composer.system.Participant"
    operation: ALL
    resource: "org.hyperledger.composer.system.**"
    action: ALLOW
}
...