Skip to content

Commit

Permalink
Merge pull request #1764 from akto-api-security/feature/edit_custom_d…
Browse files Browse the repository at this point in the history
…atatype

allow users to edit akto custom data type
  • Loading branch information
Ark2307 authored Nov 22, 2024
2 parents ad667d0 + 9695f77 commit b77bdf2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions libs/dao/src/main/java/com/akto/dto/CustomDataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<SingleTypeInfo.Position> sensitivePosition, int creatorId, boolean active, Conditions keyConditions, Conditions valueConditions, Conditions.Operator operator, IgnoreData ignoreData, boolean redacted, boolean sampleDataFixed) {
Expand Down Expand Up @@ -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;
}




}

0 comments on commit b77bdf2

Please sign in to comment.