legacyStoragePolicy function

FilesPolicy legacyStoragePolicy(
  1. Iterable<({String path, bool readOnly})>? paths
)

Implementation

FilesPolicy legacyStoragePolicy(Iterable<({String path, bool readOnly})>? paths) {
  if (paths == null) {
    return FilesPolicy(
      paths: [
        FilePathRule(path: '', recursive: true, actions: [FileAction.list, FileAction.read, FileAction.write, FileAction.delete]),
      ],
    );
  }
  final previous = <String>[];
  final rules = <FilePathRule>[];
  for (final grant in paths) {
    final path = grant.path.replaceAll(RegExp(r'^/+|/+$'), '');
    rules.add(
      FilePathRule(
        path: path,
        recursive: true,
        actions: grant.readOnly
            ? [FileAction.list, FileAction.read]
            : [FileAction.list, FileAction.read, FileAction.write, FileAction.delete],
        excludedPaths: previous,
      ),
    );
    previous.add(path);
  }
  return FilesPolicy(paths: rules);
}