From df0d6a28134c8e4af968ca165240db379ee84ed6 Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Wed, 1 May 2024 11:54:25 -0400 Subject: [PATCH] support new readOnlyUi annotations --- html/index.html | 16 ++++++++-------- html/js/routes/config.js | 4 ++++ html/js/routes/config.test.js | 22 ++++++++++++++++++++++ model/config.go | 1 + server/modules/salt/saltstore.go | 2 ++ server/modules/salt/saltstore_test.go | 2 ++ 6 files changed, 39 insertions(+), 8 deletions(-) diff --git a/html/index.html b/html/index.html index 5b1f97b72..b57031dfe 100644 --- a/html/index.html +++ b/html/index.html @@ -4923,12 +4923,12 @@

{{ i18n.settingsCustomized }} {{ settingsCustomized }} fa-circle-question -
+
fa-ban
- +
@@ -4940,7 +4940,7 @@

{{ i18n.settingsCustomized }} {{ settingsCustomized }}

- +
@@ -4951,7 +4951,7 @@

{{ i18n.settingsCustomized }} {{ settingsCustomized }} -
+
fa-circle-arrow-left @@ -4963,11 +4963,11 @@

{{ i18n.settingsCustomized }} {{ settingsCustomized }}

- +
- +
@@ -4986,11 +4986,11 @@

{{ i18n.settingsCustomized }} {{ settingsCustomized }}

- +
- +
diff --git a/html/js/routes/config.js b/html/js/routes/config.js index 121e92439..38edbafe4 100644 --- a/html/js/routes/config.js +++ b/html/js/routes/config.js @@ -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, @@ -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; + }, } }}); diff --git a/html/js/routes/config.test.js b/html/js/routes/config.test.js index 7a148a92a..141f5e6af 100644 --- a/html/js/routes/config.test.js +++ b/html/js/routes/config.test.js @@ -62,6 +62,7 @@ test('loadData', async () => { "node": undefined, "nodeValues": m1, "readonly": undefined, + "readonlyUi": undefined, "regex": "True|False", "regexFailureMessage": "Wrong!", "sensitive": undefined, @@ -84,6 +85,7 @@ test('loadData', async () => { "node": false, "nodeValues": new Map(), "readonly": undefined, + "readonlyUi": undefined, "regex": undefined, "regexFailureMessage": undefined, "sensitive": undefined, @@ -106,6 +108,7 @@ test('loadData', async () => { "node": false, "nodeValues": new Map(), "readonly": undefined, + "readonlyUi": undefined, "regex": undefined, "regexFailureMessage": undefined, "sensitive": undefined, @@ -135,6 +138,7 @@ test('loadData', async () => { "node": undefined, "nodeValues": m1, "readonly": undefined, + "readonlyUi": undefined, "regex": "True|False", "regexFailureMessage": "Wrong!", "sensitive": undefined, @@ -157,6 +161,7 @@ test('loadData', async () => { "node": false, "nodeValues": new Map(), "readonly": undefined, + "readonlyUi": undefined, "regex": undefined, "regexFailureMessage": undefined, "sensitive": undefined, @@ -187,6 +192,7 @@ test('loadData', async () => { "node": false, "nodeValues": new Map(), "readonly": undefined, + "readonlyUi": undefined, "regex": undefined, "regexFailureMessage": undefined, "sensitive": undefined, @@ -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); }); \ No newline at end of file diff --git a/model/config.go b/model/config.go index 35f70d720..1d92e75fd 100644 --- a/model/config.go +++ b/model/config.go @@ -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"` diff --git a/server/modules/salt/saltstore.go b/server/modules/salt/saltstore.go index 5215e74eb..bbd76bffd 100644 --- a/server/modules/salt/saltstore.go +++ b/server/modules/salt/saltstore.go @@ -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": diff --git a/server/modules/salt/saltstore_test.go b/server/modules/salt/saltstore_test.go index 1763dfcb4..004c72955 100644 --- a/server/modules/salt/saltstore_test.go +++ b/server/modules/salt/saltstore_test.go @@ -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" @@ -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)