Refactor rls backend simplify add tests (#17357)
## Context Removing full CRUD to RLS since we are actually using an upsert only over the role resolver, this removes a lot of unused code (could be re-added later but unlikely). Simplified the folder arch at the same time Add simple integration tests to RLS
This commit is contained in:
+48
@@ -26,9 +26,11 @@ export class FlatRowLevelPermissionPredicateGroupValidatorService {
|
||||
flatRowLevelPermissionPredicateGroupMaps:
|
||||
optimisticFlatPredicateGroupMaps,
|
||||
flatRoleMaps,
|
||||
flatObjectMetadataMaps,
|
||||
} = optimisticFlatEntityMapsAndRelatedFlatEntityMaps as Partial<{
|
||||
flatRowLevelPermissionPredicateGroupMaps: typeof optimisticFlatEntityMapsAndRelatedFlatEntityMaps.flatRowLevelPermissionPredicateGroupMaps;
|
||||
flatRoleMaps: typeof optimisticFlatEntityMapsAndRelatedFlatEntityMaps.flatRoleMaps;
|
||||
flatObjectMetadataMaps: typeof optimisticFlatEntityMapsAndRelatedFlatEntityMaps.flatObjectMetadataMaps;
|
||||
}>;
|
||||
const validationResult = getEmptyFlatEntityValidationError({
|
||||
flatEntityMinimalInformation: {
|
||||
@@ -86,6 +88,21 @@ export class FlatRowLevelPermissionPredicateGroupValidatorService {
|
||||
});
|
||||
}
|
||||
|
||||
const objectMetadata = flatObjectMetadataMaps
|
||||
? findFlatEntityByIdInFlatEntityMaps({
|
||||
flatEntityId: flatPredicateGroupToValidate.objectMetadataId,
|
||||
flatEntityMaps: flatObjectMetadataMaps,
|
||||
})
|
||||
: undefined;
|
||||
|
||||
if (!isDefined(objectMetadata)) {
|
||||
validationResult.errors.push({
|
||||
code: RowLevelPermissionPredicateGroupExceptionCode.OBJECT_METADATA_NOT_FOUND,
|
||||
message: t`Object metadata not found`,
|
||||
userFriendlyMessage: msg`Object metadata not found`,
|
||||
});
|
||||
}
|
||||
|
||||
return validationResult;
|
||||
}
|
||||
|
||||
@@ -135,9 +152,11 @@ export class FlatRowLevelPermissionPredicateGroupValidatorService {
|
||||
flatRowLevelPermissionPredicateGroupMaps:
|
||||
optimisticFlatPredicateGroupMaps,
|
||||
flatRoleMaps,
|
||||
flatObjectMetadataMaps,
|
||||
} = optimisticFlatEntityMapsAndRelatedFlatEntityMaps as Partial<{
|
||||
flatRowLevelPermissionPredicateGroupMaps: typeof optimisticFlatEntityMapsAndRelatedFlatEntityMaps.flatRowLevelPermissionPredicateGroupMaps;
|
||||
flatRoleMaps: typeof optimisticFlatEntityMapsAndRelatedFlatEntityMaps.flatRoleMaps;
|
||||
flatObjectMetadataMaps: typeof optimisticFlatEntityMapsAndRelatedFlatEntityMaps.flatObjectMetadataMaps;
|
||||
}>;
|
||||
|
||||
const existingPredicateGroup =
|
||||
@@ -180,6 +199,20 @@ export class FlatRowLevelPermissionPredicateGroupValidatorService {
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
updatedPredicateGroup.objectMetadataId !==
|
||||
existingPredicateGroup.objectMetadataId
|
||||
) {
|
||||
const existingObjectMetadataId = existingPredicateGroup.objectMetadataId;
|
||||
const updatedObjectMetadataId = updatedPredicateGroup.objectMetadataId;
|
||||
|
||||
validationResult.errors.push({
|
||||
code: RowLevelPermissionPredicateGroupExceptionCode.UNAUTHORIZED_OBJECT_MODIFICATION,
|
||||
message: t`Cannot modify predicate group to change its object from ${existingObjectMetadataId} to ${updatedObjectMetadataId}`,
|
||||
userFriendlyMessage: msg`Cannot modify predicate group to change its object`,
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
isDefined(
|
||||
updatedPredicateGroup.parentRowLevelPermissionPredicateGroupId,
|
||||
@@ -216,6 +249,21 @@ export class FlatRowLevelPermissionPredicateGroupValidatorService {
|
||||
});
|
||||
}
|
||||
|
||||
const objectMetadata = flatObjectMetadataMaps
|
||||
? findFlatEntityByIdInFlatEntityMaps({
|
||||
flatEntityId: updatedPredicateGroup.objectMetadataId,
|
||||
flatEntityMaps: flatObjectMetadataMaps,
|
||||
})
|
||||
: undefined;
|
||||
|
||||
if (!isDefined(objectMetadata)) {
|
||||
validationResult.errors.push({
|
||||
code: RowLevelPermissionPredicateGroupExceptionCode.OBJECT_METADATA_NOT_FOUND,
|
||||
message: t`Object metadata not found`,
|
||||
userFriendlyMessage: msg`Object metadata not found`,
|
||||
});
|
||||
}
|
||||
|
||||
return validationResult;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user