@rebasepro/common 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -220
- package/dist/index.es.js +11 -11
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +11 -11
- package/dist/index.umd.js.map +1 -1
- package/dist/util/permissions.d.ts +14 -6
- package/package.json +3 -3
- package/src/collections/CollectionRegistry.ts +1 -1
- package/src/util/permissions.ts +25 -21
package/dist/index.umd.js
CHANGED
|
@@ -907,14 +907,14 @@
|
|
|
907
907
|
if (rule.withCheck && !evaluateAST(rule.withCheck, auth, entity)) return false;
|
|
908
908
|
return true;
|
|
909
909
|
}
|
|
910
|
-
function checkOperation(collection,
|
|
910
|
+
function checkOperation(collection, authContext, entity, targetOperation) {
|
|
911
911
|
const securityRules = types.getDataSourceCapabilities(collection.driver).supportsRLS ? collection.securityRules : void 0;
|
|
912
912
|
if (!securityRules || securityRules.length === 0) {
|
|
913
913
|
return true;
|
|
914
914
|
}
|
|
915
915
|
const applicableRules = securityRules.filter((r) => r.operation === targetOperation || r.operation === "all" || r.operations?.includes(targetOperation) || r.operations?.includes("all"));
|
|
916
916
|
if (applicableRules.length === 0) return false;
|
|
917
|
-
const userRoleIds =
|
|
917
|
+
const userRoleIds = authContext.user?.roles ?? [];
|
|
918
918
|
const userRoles = [...userRoleIds, "public"];
|
|
919
919
|
const roleApplicableRules = applicableRules.filter((rule) => {
|
|
920
920
|
if (!rule.roles || rule.roles.length === 0) return true;
|
|
@@ -925,7 +925,7 @@
|
|
|
925
925
|
let deniedByRestrictive = false;
|
|
926
926
|
for (const rule of roleApplicableRules) {
|
|
927
927
|
const mode = rule.mode || "permissive";
|
|
928
|
-
const passed = evaluateRule(rule,
|
|
928
|
+
const passed = evaluateRule(rule, authContext, entity);
|
|
929
929
|
if (mode === "restrictive" && !passed) {
|
|
930
930
|
deniedByRestrictive = true;
|
|
931
931
|
break;
|
|
@@ -942,17 +942,17 @@
|
|
|
942
942
|
return false;
|
|
943
943
|
}
|
|
944
944
|
}
|
|
945
|
-
function canReadCollection(collection,
|
|
946
|
-
return checkOperation(collection,
|
|
945
|
+
function canReadCollection(collection, authContext) {
|
|
946
|
+
return checkOperation(collection, authContext, null, "select");
|
|
947
947
|
}
|
|
948
|
-
function canEditEntity(collection,
|
|
949
|
-
return checkOperation(collection,
|
|
948
|
+
function canEditEntity(collection, authContext, path, entity) {
|
|
949
|
+
return checkOperation(collection, authContext, entity, "update");
|
|
950
950
|
}
|
|
951
|
-
function canCreateEntity(collection,
|
|
952
|
-
return checkOperation(collection,
|
|
951
|
+
function canCreateEntity(collection, authContext, path, entity) {
|
|
952
|
+
return checkOperation(collection, authContext, entity, "insert");
|
|
953
953
|
}
|
|
954
|
-
function canDeleteEntity(collection,
|
|
955
|
-
return checkOperation(collection,
|
|
954
|
+
function canDeleteEntity(collection, authContext, path, entity) {
|
|
955
|
+
return checkOperation(collection, authContext, entity, "delete");
|
|
956
956
|
}
|
|
957
957
|
function getEntityImagePreviewPropertyKey(collection) {
|
|
958
958
|
for (const key in collection.properties) {
|