如何在 运行 时间为所有模型添加 ACL 规则?

How can I Add ACL rules at run time for all model?

我正尝试在 运行 时为所有模型创建 acl 规则。 我有包含 ACL 信息的表格,例如:

id, 
model name,
property,
accesstype,
principalId, (here I am assign roldId from role table).
PrincipalType.

提交表单后,信息将存储在ACL table (DB: mysql)。我的问题是如何获取 mixin 或 boot scritpt 中的数据或任何以及何时从 acl table 获取 acl 数据以及如何在 运行 时间分配给所有模型。

我试过 mixin 和引导脚本,但我不清楚。

在mixin文件中,如何获取acl数据以及如何分配给所有模型..

我真的很困惑,因为我不知道什么时候会在 运行 时间内为所有模型推送 acl 数据(如引导、混合、操作挂钩)。

请给点意见。

我想喜欢,在 mixin 或启动脚本或任何。

从 acl 获取所有数据并分配给所有模型。

In mixin.// I don't know how to get acl data from database in mixin files. 
ACL.find(function(err, data)
{
    var acl = data;
});

// doing some iteration..

 Model.settings.acls.push(data);

默认情况下,ACL(base Class) 在 运行 时收集并连接静态 JSON acl 规则和 ACL Table 数据,因此它将自动运行。

get Static ACL from Model.JSON ex: user.json

ACL.getStaticACLs = function getStaticACLs(model, property) {
var modelClass = loopback.findModel(model);
var staticACLs = [];
if (modelClass && modelClass.settings.acls) {
  modelClass.settings.acls.forEach(function(acl) {
    var prop = acl.property;
    // We support static ACL property with array of string values.
    if (Array.isArray(prop) && prop.indexOf(property) >= 0)
      prop = property;
    if (!prop || prop === ACL.ALL || property === prop) {
      staticACLs.push(new ACL({
        model: model,
        property: prop || ACL.ALL,
        principalType: acl.principalType,
        principalId: acl.principalId, // TODO: Should it be a name?
        accessType: acl.accessType || ACL.ALL,
        permission: acl.permission
      }));
    }
  });
}
var prop = modelClass && (
  // regular property
  modelClass.definition.properties[property] ||
  // relation/scope
  (modelClass._scopeMeta && modelClass._scopeMeta[property]) ||
  // static method
  modelClass[property] ||
  // prototype method
  modelClass.prototype[property]);
if (prop && prop.acls) {
  prop.acls.forEach(function(acl) {
    staticACLs.push(new ACL({
      model: modelClass.modelName,
      property: property,
      principalType: acl.principalType,
      principalId: acl.principalId,
      accessType: acl.accessType,
      permission: acl.permission
    }));
  });
}
return staticACLs;

};

get ACL from ACL table(database)

var self = this;
var roleModel = registry.getModelByType(Role);
this.find({where: {model: model.modelName, property: propertyQuery,
  accessType: accessTypeQuery}}, function(err, acls) {
  if (err) {
    if (callback) callback(err);
    return;
  }
  var inRoleTasks = [];

  acls = acls.concat(staticACLs);