PermissionHandlerService.create constructor

PermissionHandlerService.create({
  1. bool defaultPermission = true,
  2. Map<DbOperationType, bool>? defaultRules,
  3. List<DbCollection>? collections,
})

Implementation

PermissionHandlerService.create(
    {bool defaultPermission = true,
    Map<DbOperationType, bool>? defaultRules,
    List<DbCollection>? collections})
    : _defaultRules = defaultRules ??
          DbOperationType.values
              .asMap()
              .map((key, value) => MapEntry(value, defaultPermission)),
      _collections = HashMap.from(collections
              ?.where((element) => element.permissionHandler != null)
              .toList()
              .asMap()
              .map((key, value) =>
                  MapEntry(value.collectionName, value.permissionHandler)) ??
          {}) {
  for (var r in DbOperationType.values) {
    _defaultRules[r] ??= defaultPermission;
  }
}