isAllowedEntityTypeField method

bool? isAllowedEntityTypeField(
  1. Type type,
  2. String field, {
  3. EntityAccessRulesContext? context,
})

Implementation

bool? isAllowedEntityTypeField(Type type, String field,
    {EntityAccessRulesContext? context}) {
  if (isInnocuous) return null;

  final entityFields = this.entityFields;

  if (entityType == type) {
    final condition = this.condition;

    if (ruleType == EntityAccessRuleType.allow) {
      if (entityFields.anyIgnoreCase(field)) {
        return (condition == null || condition(context));
      } else {
        return null;
      }
    } else if (ruleType == EntityAccessRuleType.block) {
      if (entityFields.anyIgnoreCase(field)) {
        return !(condition == null || condition(context));
      } else {
        return null;
      }
    }
  }

  final rules = this.rules;
  if (rules == null || rules.isEmpty) return null;

  for (var r in rules.reversed) {
    var allowed = r.isAllowedEntityTypeField(type, field, context: context);
    if (allowed != null) return allowed;
  }

  return null;
}