{"size": 1948, "ext": "js", "max_stars_repo_path": "test/boot/create-data-acl.js", "max_stars_repo_name": "EdgeVerve/oe-data-acl", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/boot/create-data-acl.js", "max_issues_repo_name": "EdgeVerve/oe-data-acl", "max_issues_repo_issues_event_min_datetime": "2020-05-04T19:08:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-04T19:08:16.000Z", "max_forks_repo_path": "test/boot/create-data-acl.js", "max_forks_repo_name": "EdgeVerve/oe-data-acl", "max_forks_repo_forks_event_min_datetime": "2022-02-03T09:43:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-03T09:43:20.000Z"}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 24.049382716, "max_line_length": 83, "alphanum_fraction": 0.5313141684}
var loopback = require('loopback');

module.exports = function (app, done) {
  var dataAcl = loopback.findModel('DataACL');
  var modelName = 'DataACLModel';
  var dataacls = [
    {
      model: modelName,
      principalType: 'ROLE',
      principalId: 'ROLEA',
      accessType: 'READ',
      group: 'category',
      filter: { 'category': 'book' }
    },
    {
      model: modelName,
      principalType: 'ROLE',
      principalId: 'ROLEA',
      accessType: 'READ',
      group: 'category',
      filter: { 'category': 'music' }
    },
    {
      model: modelName,
      principalType: 'ROLE',
      principalId: 'ROLEA',
      accessType: 'READ',
      group: 'department',
      filter: { 'department': { 'inq': ['d1', 'd2'] } }
    },
    {
      model: modelName,
      principalType: 'ROLE',
      principalId: 'ROLEB',
      accessType: 'READ',
      filter: { 'category': 'others' }
    },
    {
      model: modelName,
      principalType: 'ROLE',
      principalId: 'ROLEB',
      accessType: 'READ',
      filter: { 'product': { 'inq': ['special1', 'special2'] } }
    },
    {
      model: modelName,
      principalType: 'ROLE',
      principalId: 'ROLEB',
      accessType: 'READ',
      filter: { 'department': 'finance' }
    },
    {
      model: modelName,
      principalType: 'ROLE',
      principalId: 'ROLEB',
      accessType: 'WRITE',
      filter: { 'department': '@ctx.department.deptId' }
    },
    {
      model: modelName,
      principalType: 'ROLE',
      principalId: 'ROLEC',
      accessType: 'READ',
      filter: { 'department': '@CC.dept' }
    },
    {
      model: modelName,
      principalType: 'ROLE',
      principalId: 'ROLEC',
      accessType: 'WRITE',
      filter: { 'department': 'engg' }
    }
  ];
  dataAcl.destroyAll({}, { ignoreAutoScope: true }, function (err) {
    dataAcl.create(dataacls, { ctx: { tenantId: '/default' } }, function (err, r) {
      return done();
    });
  });
};

