PermissionHandler.generatedByType constructor

PermissionHandler.generatedByType({
  1. PermissionCheckerCallback? read,
  2. PermissionCheckerCallback? update,
  3. PermissionCheckerCallback? delete,
  4. PermissionCheckerCallback? create,
  5. PermissionCheckerCallback? write,
  6. required bool defaultPermission,
  7. bool beforeNeed = false,
})

Implementation

PermissionHandler.generatedByType(
    {PermissionCheckerCallback? read,
    PermissionCheckerCallback? update,
    PermissionCheckerCallback? delete,
    PermissionCheckerCallback? create,
    PermissionCheckerCallback? write,
    required bool defaultPermission,
    this.beforeNeed = false})
    : assert(write == null ||
          (update == null && delete == null && create == null)) {
  var defaultsMap = {
    if (write != null) ...{
      DbOperationType.create: write,
      DbOperationType.update: write,
      DbOperationType.delete: write,
    },
    if (read != null) DbOperationType.read: read,
    if (update != null) DbOperationType.update: update,
    if (create != null) DbOperationType.create: create,
    if (delete != null) DbOperationType.delete: delete
  };

  checker = (_) {
    return (defaultsMap[_.access.type]?.call(_)) ?? defaultPermission;
  };
  ;
}