Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support new readOnlyUi annotations #456

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4923,12 +4923,12 @@ <h4 v-if="!$root.loading">{{ i18n.settingsCustomized }} {{ settingsCustomized }}
<v-icon color="info" class="mb-2">fa-circle-question</v-icon>
</a>
</div>
<div v-if="selected.readonly" :title="i18n.settingReadOnlyHelp" data-aid="config_item_readonly_warning">
<div v-if="isReadOnly(selected)" :title="i18n.settingReadOnlyHelp" data-aid="config_item_readonly_warning">
<v-icon class="ma-2" color="warning">fa-ban</v-icon>
<v-subtitle v-text="i18n.settingReadOnly" />
</div>
<v-container fluid>
<v-row v-if="selected.duplicates && !selected.readonly">
<v-row v-if="selected.duplicates && !isReadOnly(selected)">
<v-col>
<v-btn id="config-toggle-duplicate-button" @click="toggleDuplicate(selected)" v-text="i18n.settingDuplicate" data-aid="config_item_show_duplicate"/>
<div v-if="showDuplicate" class="mt-2 mb-8 pl-8">
Expand All @@ -4940,7 +4940,7 @@ <h4 v-if="!$root.loading">{{ i18n.settingsCustomized }} {{ settingsCustomized }}
</div>
</v-col>
</v-row>
<v-row v-if="!selected.readonly && selected.defaultAvailable">
<v-row v-if="!isReadOnly(selected) && selected.defaultAvailable">
<v-col>
<v-btn id="config-toggle-default-button" @click="showDefault = !showDefault" v-text="showDefault ? i18n.settingHideDefault : i18n.settingShowDefault" data-aid="config_item_show_default"/>
<div v-if="showDefault" class="mt-8">
Expand All @@ -4951,7 +4951,7 @@ <h4 v-if="!$root.loading">{{ i18n.settingsCustomized }} {{ settingsCustomized }}
</v-row>
<v-row v-if="selected.global || !selected.node">
<v-col>
<div v-if="!selected.readonly" class="mb-n1 text-right">
<div v-if="!isReadOnly(selected)" class="mb-n1 text-right">
<v-btn id="setting-global-reset" icon @click="remove(selected)" :title="i18n.settingResetHelp" :disabled="!isSettingModified(selected) || isPendingSave(selected)" data-aid="config_item_reset" >
<v-icon color="primary">fa-circle-arrow-left</v-icon>
</v-btn>
Expand All @@ -4963,11 +4963,11 @@ <h4 v-if="!$root.loading">{{ i18n.settingsCustomized }} {{ settingsCustomized }}
</v-btn>
</div>
<div v-if="isMultiline(selected)">
<v-textarea v-if="form.key != selected.id" id="value-output" outlined :label="i18n.settingGlobal" @focus="edit(selected)" :value="selected.value" readonly :disabled="selected.readonly" class="config-editor" data-aid="config_item_customize_multiline_display" />
<v-textarea v-if="form.key != selected.id" id="value-output" outlined :label="i18n.settingGlobal" @focus="edit(selected)" :value="selected.value" readonly :disabled="isReadOnly(selected)" class="config-editor" data-aid="config_item_customize_multiline_display" />
<v-textarea v-else id="value-input" outlined :label="i18n.settingGlobal" v-model="form.value" class="editing config-editor" data-aid="config_item_customize_multiline_input" />
</div>
<div v-else>
<v-text-field v-if="form.key != selected.id" id="value-output" outlined :label="i18n.settingGlobal" @focus="edit(selected)" :value="selected.value" readonly :disabled="selected.readonly" :type="selected.sensitive ? 'password' : 'text'" data-aid="config_item_customize_singleline_display" />
<v-text-field v-if="form.key != selected.id" id="value-output" outlined :label="i18n.settingGlobal" @focus="edit(selected)" :value="selected.value" readonly :disabled="isReadOnly(selected)" :type="selected.sensitive ? 'password' : 'text'" data-aid="config_item_customize_singleline_display" />
<v-text-field v-else id="value-input" outlined :label="i18n.settingGlobal" v-model="form.value" class="editing" @keydown.enter.prevent="save(selected)" data-aid="config_item_singleline_input" />
</div>
</v-col>
Expand All @@ -4986,11 +4986,11 @@ <h4 v-if="!$root.loading">{{ i18n.settingsCustomized }} {{ settingsCustomized }}
</v-btn>
</div>
<div v-if="isMultiline(selected)">
<v-textarea v-if="form.key != item[0]" :id="'node-value-output-' + item[0]" outlined :label="item[0]" @focus="edit(selected, item[0])" :value="item[1]" readonly :disabled="selected.readonly" class="config-editor" data-aid="config_item_customize_node_multiline_display" />
<v-textarea v-if="form.key != item[0]" :id="'node-value-output-' + item[0]" outlined :label="item[0]" @focus="edit(selected, item[0])" :value="item[1]" readonly :disabled="isReadOnly(selected)" class="config-editor" data-aid="config_item_customize_node_multiline_display" />
<v-textarea v-else outlined :id="'node-value-input-' + item[0]" :label="item[0]" v-model="form.value" class="editing config-editor" data-aid="config_item_customize_node_multiline_input" />
</div>
<div v-else>
<v-text-field v-if="form.key != item[0]" :id="'node-value-output-' + item[0]" outlined :label="item[0]" @focus="edit(selected, item[0])" :value="item[1]" readonly :disabled="selected.readonly" :type="selected.sensitive ? 'password' : 'text'" data-aid="config_item_customize_node_singleline_display" />
<v-text-field v-if="form.key != item[0]" :id="'node-value-output-' + item[0]" outlined :label="item[0]" @focus="edit(selected, item[0])" :value="item[1]" readonly :disabled="isReadOnly(selected)" :type="selected.sensitive ? 'password' : 'text'" data-aid="config_item_customize_node_singleline_display" />
<v-text-field v-else outlined :label="item[0]" :id="'node-value-input-' + item[0]" v-model="form.value" class="editing" @keydown.enter.prevent="save(selected, item[0])" data-aid="config_item_customize_node_singleline_display" />
</div>
</v-col>
Expand Down
4 changes: 4 additions & 0 deletions html/js/routes/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ routes.push({ path: '/config', name: 'config', component: {
default: null,
defaultAvailable: false,
readonly: setting.readonly,
readonlyUi: setting.readonlyUi,
sensitive: setting.sensitive,
regex: setting.regex,
regexFailureMessage: setting.regexFailureMessage,
Expand Down Expand Up @@ -508,5 +509,8 @@ routes.push({ path: '/config', name: 'config', component: {
this.active = [new_id]
this.showDuplicate = false;
},
isReadOnly(item) {
return item.readonly || item.readonlyUi;
},
}
}});
22 changes: 22 additions & 0 deletions html/js/routes/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ test('loadData', async () => {
"node": undefined,
"nodeValues": m1,
"readonly": undefined,
"readonlyUi": undefined,
"regex": "True|False",
"regexFailureMessage": "Wrong!",
"sensitive": undefined,
Expand All @@ -84,6 +85,7 @@ test('loadData', async () => {
"node": false,
"nodeValues": new Map(),
"readonly": undefined,
"readonlyUi": undefined,
"regex": undefined,
"regexFailureMessage": undefined,
"sensitive": undefined,
Expand All @@ -106,6 +108,7 @@ test('loadData', async () => {
"node": false,
"nodeValues": new Map(),
"readonly": undefined,
"readonlyUi": undefined,
"regex": undefined,
"regexFailureMessage": undefined,
"sensitive": undefined,
Expand Down Expand Up @@ -135,6 +138,7 @@ test('loadData', async () => {
"node": undefined,
"nodeValues": m1,
"readonly": undefined,
"readonlyUi": undefined,
"regex": "True|False",
"regexFailureMessage": "Wrong!",
"sensitive": undefined,
Expand All @@ -157,6 +161,7 @@ test('loadData', async () => {
"node": false,
"nodeValues": new Map(),
"readonly": undefined,
"readonlyUi": undefined,
"regex": undefined,
"regexFailureMessage": undefined,
"sensitive": undefined,
Expand Down Expand Up @@ -187,6 +192,7 @@ test('loadData', async () => {
"node": false,
"nodeValues": new Map(),
"readonly": undefined,
"readonlyUi": undefined,
"regex": undefined,
"regexFailureMessage": undefined,
"sensitive": undefined,
Expand Down Expand Up @@ -557,4 +563,20 @@ test('duplicate', () => {
expect(comp.settings.length).toBe(2);
expect(comp.settings[1].id).toBe("a.b.foo");
expect(comp.settings[1].name).toBe("foo");
});

test('isReadOnly', () => {
const setting = {
id: "a1",
readonly: false,
readonlyUi: false,
};
expect(comp.isReadOnly(setting)).toBe(false);
setting.readonly = true;
expect(comp.isReadOnly(setting)).toBe(true);
setting.readonly = false;
setting.readonlyUi = true;
expect(comp.isReadOnly(setting)).toBe(true);
setting.readonly = true;
expect(comp.isReadOnly(setting)).toBe(true);
});
1 change: 1 addition & 0 deletions model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Setting struct {
Value string `json:"value"`
Multiline bool `json:"multiline"`
Readonly bool `json:"readonly"`
ReadonlyUi bool `json:"readonlyUi"`
Sensitive bool `json:"sensitive"`
Regex string `json:"regex"`
RegexFailureMessage string `json:"regexFailureMessage"`
Expand Down
2 changes: 2 additions & 0 deletions server/modules/salt/saltstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ func (store *Saltstore) updateSettingWithAnnotation(setting *model.Setting, anno
setting.Description = fmt.Sprintf("%v", value)
case "readonly":
setting.Readonly = value.(bool)
case "readonlyUi":
setting.ReadonlyUi = value.(bool)
case "global":
setting.Global = value.(bool)
case "multiline":
Expand Down
2 changes: 2 additions & 0 deletions server/modules/salt/saltstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ func TestUpdateSettingWithAnnotation(tester *testing.T) {
annotations["file"] = true
annotations["advanced"] = true
annotations["readonly"] = true
annotations["readonlyUi"] = true
annotations["description"] = "My Desc"
annotations["title"] = "My Title"
annotations["regex"] = "My Regex"
Expand All @@ -1070,6 +1071,7 @@ func TestUpdateSettingWithAnnotation(tester *testing.T) {
assert.True(tester, setting.File)
assert.True(tester, setting.Advanced)
assert.True(tester, setting.Readonly)
assert.True(tester, setting.ReadonlyUi)
assert.Equal(tester, "My Desc", setting.Description)
assert.Equal(tester, "My Title", setting.Title)
assert.Equal(tester, "My Regex", setting.Regex)
Expand Down
Loading