From 9695f7766673f74135bd0dd2fc8d81d38a71ca0a Mon Sep 17 00:00:00 2001 From: Avneesh Hota Date: Fri, 22 Nov 2024 18:39:09 +0530 Subject: [PATCH] allow users to edit akto custom data type --- .../com/akto/action/CustomDataTypeAction.java | 11 +++++------ .../com/akto/listener/InitializerListener.java | 9 ++++++--- .../main/java/com/akto/dto/CustomDataType.java | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/apps/dashboard/src/main/java/com/akto/action/CustomDataTypeAction.java b/apps/dashboard/src/main/java/com/akto/action/CustomDataTypeAction.java index 02b67ceabe..106925864b 100644 --- a/apps/dashboard/src/main/java/com/akto/action/CustomDataTypeAction.java +++ b/apps/dashboard/src/main/java/com/akto/action/CustomDataTypeAction.java @@ -186,12 +186,10 @@ public String execute() { CustomDataTypeDao.instance.insertOne(customDataType); } else { - if (customDataTypeFromDb!=null && customDataTypeFromDb.getCreatorId() == 1638571050 && - checkConditionUpdate(customDataTypeFromDb, customDataType)) { - addActionError("Cannot update data type conditions for akto data types. Please create a new data type."); - return ERROR.toUpperCase(); + if (customDataTypeFromDb!=null && customDataTypeFromDb.getCreatorId() == 1638571050) { + customDataType.setUserModifiedTimestamp(Context.now()); } - + FindOneAndUpdateOptions options = new FindOneAndUpdateOptions(); options.returnDocument(ReturnDocument.AFTER); options.upsert(false); @@ -210,7 +208,8 @@ public String execute() { Updates.set(CustomDataType.SAMPLE_DATA_FIXED,customDataType.isSampleDataFixed()), Updates.set(AktoDataType.CATEGORIES_LIST, customDataType.getCategoriesList()), Updates.set(AktoDataType.DATA_TYPE_PRIORITY, customDataType.getDataTypePriority()), - Updates.set(CustomDataType.ICON_STRING, customDataType.getIconString()) + Updates.set(CustomDataType.ICON_STRING, customDataType.getIconString()), + Updates.set(CustomDataType.USER_MODIFIED_TIMESTAMP, customDataType.getUserModifiedTimestamp()) ), options ); diff --git a/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java b/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java index 7ae4dd6495..f0b64e996e 100644 --- a/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java +++ b/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java @@ -590,11 +590,14 @@ public static void executePIISourceFetch() { CustomDataType existingCDT = customDataTypesMap.getOrDefault(piiKey, null); CustomDataType newCDT = getCustomDataTypeFromPiiType(piiSource, piiType, false); - if (currTypes.containsKey(piiKey) && + boolean hasNotChangedCondition = currTypes.containsKey(piiKey) && (currTypes.get(piiKey).equals(piiType) && dt.getBoolean(PIISource.ACTIVE, true)) && (existingCDT != null && existingCDT.getDataTypePriority() != null) - && (existingCDT.getCategoriesList() != null && !existingCDT.getCategoriesList().isEmpty()) - ) { + && (existingCDT.getCategoriesList() != null && !existingCDT.getCategoriesList().isEmpty()); + + boolean userHasChangedCondition = existingCDT.getUserModifiedTimestamp() > 0; + + if (userHasChangedCondition || hasNotChangedCondition) { continue; } else { Severity dtSeverity = null; diff --git a/libs/dao/src/main/java/com/akto/dto/CustomDataType.java b/libs/dao/src/main/java/com/akto/dto/CustomDataType.java index dfe5f1ac68..36021bb3af 100644 --- a/libs/dao/src/main/java/com/akto/dto/CustomDataType.java +++ b/libs/dao/src/main/java/com/akto/dto/CustomDataType.java @@ -45,6 +45,9 @@ public class CustomDataType { public static final String ICON_STRING = "iconString"; private String iconString; + public static final String USER_MODIFIED_TIMESTAMP = "userModifiedTimestamp"; + private int userModifiedTimestamp; + public CustomDataType() { } public CustomDataType(String name, boolean sensitiveAlways, List sensitivePosition, int creatorId, boolean active, Conditions keyConditions, Conditions valueConditions, Conditions.Operator operator, IgnoreData ignoreData, boolean redacted, boolean sampleDataFixed) { @@ -262,4 +265,16 @@ public String getIconString() { public void setIconString(String iconString) { this.iconString = iconString; } + + public int getUserModifiedTimestamp() { + return userModifiedTimestamp; + } + + public void setUserModifiedTimestamp(int userModifiedTimestamp) { + this.userModifiedTimestamp = userModifiedTimestamp; + } + + + + }