From 5a56b5d9b45ed19675a4c907a8e7d9e430fbb4d3 Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Fri, 17 May 2024 16:17:37 -0500 Subject: [PATCH] Treat made-up primary keys as nulls... also, don't start them at -1 (which, idk, is maybe somewhat likely in some world? but instead of half of integer-min-value...) --- .../ValidateRecordSecurityLockHelper.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/tables/helpers/ValidateRecordSecurityLockHelper.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/tables/helpers/ValidateRecordSecurityLockHelper.java index c8de0e4f..93713fff 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/tables/helpers/ValidateRecordSecurityLockHelper.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/tables/helpers/ValidateRecordSecurityLockHelper.java @@ -101,7 +101,7 @@ public class ValidateRecordSecurityLockHelper // actually check lock values // //////////////////////////////// Map errorRecords = new HashMap<>(); - evaluateRecordLocks(table, records, action, locksToCheck, errorRecords, new ArrayList<>()); + evaluateRecordLocks(table, records, action, locksToCheck, errorRecords, new ArrayList<>(), madeUpPrimaryKeys); ///////////////////////////////// // propagate errors to records // @@ -141,7 +141,7 @@ public class ValidateRecordSecurityLockHelper ** BUT - WRITE locks - in their case, we read the record no matter what, and in ** here we need to verify we have a key that allows us to WRITE the record. *******************************************************************************/ - private static void evaluateRecordLocks(QTableMetaData table, List records, Action action, RecordSecurityLock recordSecurityLock, Map errorRecords, List treePosition) throws QException + private static void evaluateRecordLocks(QTableMetaData table, List records, Action action, RecordSecurityLock recordSecurityLock, Map errorRecords, List treePosition, Map madeUpPrimaryKeys) throws QException { if(recordSecurityLock instanceof MultiRecordSecurityLock multiRecordSecurityLock) { @@ -152,7 +152,7 @@ public class ValidateRecordSecurityLockHelper for(RecordSecurityLock childLock : CollectionUtils.nonNullList(multiRecordSecurityLock.getLocks())) { treePosition.add(i); - evaluateRecordLocks(table, records, action, childLock, errorRecords, treePosition); + evaluateRecordLocks(table, records, action, childLock, errorRecords, treePosition, madeUpPrimaryKeys); treePosition.remove(treePosition.size() - 1); i++; } @@ -192,7 +192,7 @@ public class ValidateRecordSecurityLockHelper } Serializable recordSecurityValue = record.getValue(field.getName()); - List recordErrors = validateRecordSecurityValue(table, recordSecurityLock, recordSecurityValue, field.getType(), action); + List recordErrors = validateRecordSecurityValue(table, recordSecurityLock, recordSecurityValue, field.getType(), action, madeUpPrimaryKeys); if(CollectionUtils.nullSafeHasContents(recordErrors)) { errorRecords.computeIfAbsent(record.getValue(primaryKeyField), (k) -> new RecordWithErrors(record)).addAll(recordErrors, treePosition); @@ -337,7 +337,7 @@ public class ValidateRecordSecurityLockHelper for(QRecord inputRecord : inputRecords) { - List recordErrors = validateRecordSecurityValue(table, recordSecurityLock, recordSecurityValue, field.getType(), action); + List recordErrors = validateRecordSecurityValue(table, recordSecurityLock, recordSecurityValue, field.getType(), action, madeUpPrimaryKeys); if(CollectionUtils.nullSafeHasContents(recordErrors)) { errorRecords.computeIfAbsent(inputRecord.getValue(primaryKeyField), (k) -> new RecordWithErrors(inputRecord)).addAll(recordErrors, treePosition); @@ -370,14 +370,14 @@ public class ValidateRecordSecurityLockHelper { String primaryKeyField = table.getPrimaryKeyField(); Map madeUpPrimaryKeys = new HashMap<>(); - Integer madeUpPrimaryKey = -1; + Integer madeUpPrimaryKey = Integer.MIN_VALUE / 2; for(QRecord record : records) { if(record.getValue(primaryKeyField) == null) { madeUpPrimaryKeys.put(madeUpPrimaryKey, record); record.setValue(primaryKeyField, madeUpPrimaryKey); - madeUpPrimaryKey--; + madeUpPrimaryKey++; } } return madeUpPrimaryKeys; @@ -445,9 +445,9 @@ public class ValidateRecordSecurityLockHelper /******************************************************************************* ** *******************************************************************************/ - public static List validateRecordSecurityValue(QTableMetaData table, RecordSecurityLock recordSecurityLock, Serializable recordSecurityValue, QFieldType fieldType, Action action) + public static List validateRecordSecurityValue(QTableMetaData table, RecordSecurityLock recordSecurityLock, Serializable recordSecurityValue, QFieldType fieldType, Action action, Map madeUpPrimaryKeys) { - if(recordSecurityValue == null) + if(recordSecurityValue == null || (madeUpPrimaryKeys != null && madeUpPrimaryKeys.containsKey(recordSecurityValue))) { ///////////////////////////////////////////////////////////////// // handle null values - error if the NullValueBehavior is DENY //