Skip to content

Commit 4adb719

Browse files
authored
Allow modification of user vm details if user.vm.readonly.details is empty (#10456)
1 parent c8cadcb commit 4adb719

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

api/src/main/java/org/apache/cloudstack/query/QueryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public interface QueryService {
118118

119119
ConfigKey<String> UserVMReadOnlyDetails = new ConfigKey<>(String.class,
120120
"user.vm.readonly.details", "Advanced", "dataDiskController, rootDiskController",
121-
"List of read-only VM settings/details as comma separated string", true, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null);
121+
"List of read-only VM settings/details as comma separated string", true, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null, "");
122122

123123
ConfigKey<Boolean> SortKeyAscending = new ConfigKey<>("Advanced", Boolean.class, "sortkey.algorithm", "true",
124124
"Sort algorithm - ascending or descending - to use. For entities that use sort key(template, disk offering, service offering, " +

framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKey.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,18 @@ public String toString() {
120120

121121
static ConfigDepotImpl s_depot = null;
122122

123-
static public void init(ConfigDepotImpl depot) {
123+
private String _defaultValueIfEmpty = null;
124+
125+
public static void init(ConfigDepotImpl depot) {
124126
s_depot = depot;
125127
}
126128

129+
public ConfigKey(Class<T> type, String name, String category, String defaultValue, String description, boolean isDynamic, Scope scope, T multiplier,
130+
String displayText, String parent, Ternary<String, String, Long> group, Pair<String, Long> subGroup, Kind kind, String options, String defaultValueIfEmpty) {
131+
this(type, name, category, defaultValue, description, isDynamic, scope, multiplier, displayText, parent, group, subGroup, kind, options);
132+
this._defaultValueIfEmpty = defaultValueIfEmpty;
133+
}
134+
127135
public ConfigKey(String category, Class<T> type, String name, String defaultValue, String description, boolean isDynamic, Scope scope) {
128136
this(type, name, category, defaultValue, description, isDynamic, scope, null);
129137
}
@@ -216,7 +224,19 @@ public boolean isSameKeyAs(Object obj) {
216224
public T value() {
217225
if (_value == null || isDynamic()) {
218226
String value = s_depot != null ? s_depot.getConfigStringValue(_name, Scope.Global, null) : null;
219-
_value = valueOf((value == null) ? defaultValue() : value);
227+
228+
String effective;
229+
if (value != null) {
230+
if (value.isEmpty() && _defaultValueIfEmpty != null) {
231+
effective = _defaultValueIfEmpty;
232+
} else {
233+
effective = value;
234+
}
235+
} else {
236+
effective = _defaultValueIfEmpty != null ? _defaultValueIfEmpty : defaultValue();
237+
}
238+
239+
_value = valueOf(effective);
220240
}
221241

222242
return _value;
@@ -231,6 +251,10 @@ protected T valueInScope(Scope scope, Long id) {
231251
if (value == null) {
232252
return value();
233253
}
254+
255+
if (value.isEmpty() && _defaultValueIfEmpty != null) {
256+
return valueOf(_defaultValueIfEmpty);
257+
}
234258
return valueOf(value);
235259
}
236260

0 commit comments

Comments
 (0)