expandAllowedPaths method

List<String> expandAllowedPaths(
  1. List<PermissionRule> rules
)

Expand allowed paths from a set of rules that have file scope.

Extracts resource patterns from file-scope rules with allow levels and adds them to the allowed paths list.

Implementation

List<String> expandAllowedPaths(List<PermissionRule> rules) {
  final expanded = <String>[];
  for (final rule in rules) {
    if (rule.scope == PermissionScope.file &&
        rule.isActive &&
        rule.level.isAllowed &&
        rule.resourcePattern != null) {
      final pattern = rule.resourcePattern!;
      // Only expand literal paths, not globs or regex.
      if (!pattern.contains('*') &&
          !pattern.contains('?') &&
          !pattern.startsWith('regex:')) {
        expanded.add(pattern);
        if (!_allowedPaths.contains(pattern)) {
          _allowedPaths.add(pattern);
        }
      }
    }
  }
  return expanded;
}