Skip to content

Commit d0bb952

Browse files
committed
fix: prevent accidental removal of all settings in setAllFromJson by validating non-empty input #11639
1 parent 6c4cd02 commit d0bb952

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,10 +1127,16 @@ public JsonObjectBuilder setAllFromJson(JsonObject settings) {
11271127
// Convert JSON to Setting objects
11281128
Set<Setting> newSettings = convertJsonToSettings(settings);
11291129

1130-
// Execute the update (in one atomic operation using a transaction)
1131-
Map<Setting, Op> operationalDetails = replaceAllSettings(newSettings);
1130+
// Perform atomic update (replace all settings)
1131+
// We don't allow to completely wipe all settings coming from JSON here, so no acciddents happen.
1132+
// (It's completely unrealistic someone would try to remove all settings and leave it at that.)
1133+
if (newSettings != null && !newSettings.isEmpty()) {
1134+
// Execute the update (in one atomic operation using a transaction)
1135+
Map<Setting, Op> operationalDetails = replaceAllSettings(newSettings);
11321136

1133-
return Op.convertToJson(operationalDetails);
1137+
return Op.convertToJson(operationalDetails);
1138+
}
1139+
throw new IllegalArgumentException("Settings cannot be empty - you'd wipe the entire configuration.");
11341140
}
11351141

11361142
/**

0 commit comments

Comments
 (0)