summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatiana Ovchinnikova <t.v.ovtchinnikova@gmail.com>2022-11-08 14:40:13 -0600
committerTatiana Ovchinnikova <t.v.ovtchinnikova@gmail.com>2022-11-25 19:02:02 +0000
commit22d629caecceba1f2bdcf3565e04b3f0a2ec06ce (patch)
treea3979b3be53ae80f85a322e81f1a763f95dc20ed
parent2f8aaa03e8ed4c2c8e3628f1f723f304b24b1f82 (diff)
downloadhorizon-22d629caecceba1f2bdcf3565e04b3f0a2ec06ce.tar.gz
Make readonly metadata properties unable to edit
Image metadata properties os_hash_algo and os_hash_value are readonly, and attempts to edit them fail with unclear message. This patch makes these fields readonly in update metadata form. Also, if the existing metadata property is null, Horizon should consider it optional too, in addition to empty field fix: https://review.opendev.org/c/openstack/horizon/+/812009 Change-Id: I892465ca4688fce9f7123682d02f11c92c7d2c5c (cherry picked from commit 892080ec0ff6174d5fd5de221ec4802bd21371a6)
-rw-r--r--horizon/static/framework/widgets/metadata/tree/metadata-tree-item.controller.js8
-rw-r--r--horizon/static/framework/widgets/metadata/tree/tree.service.js2
2 files changed, 10 insertions, 0 deletions
diff --git a/horizon/static/framework/widgets/metadata/tree/metadata-tree-item.controller.js b/horizon/static/framework/widgets/metadata/tree/metadata-tree-item.controller.js
index 1d0720f12..6234699db 100644
--- a/horizon/static/framework/widgets/metadata/tree/metadata-tree-item.controller.js
+++ b/horizon/static/framework/widgets/metadata/tree/metadata-tree-item.controller.js
@@ -16,6 +16,8 @@
(function () {
'use strict';
+ var READONLY_PROPERTIES = ['os_hash_algo', 'os_hash_value'];
+
angular
.module('horizon.framework.widgets.metadata.tree')
.controller('MetadataTreeItemController', MetadataTreeItemController);
@@ -32,6 +34,12 @@
ctrl.formatErrorMessage = formatErrorMessage;
ctrl.opened = false;
+ if ('item' in ctrl && 'leaf' in ctrl.item &&
+ READONLY_PROPERTIES.includes(ctrl.item.leaf.name)) {
+ ctrl.item.leaf.readonly = true;
+ ctrl.item.leaf.required = false;
+ }
+
if ('item' in ctrl && 'leaf' in ctrl.item && ctrl.item.leaf.type === 'array') {
ctrl.values = ctrl.item.leaf.items.enum.filter(filter).sort();
diff --git a/horizon/static/framework/widgets/metadata/tree/tree.service.js b/horizon/static/framework/widgets/metadata/tree/tree.service.js
index 1256985f5..47ba1a844 100644
--- a/horizon/static/framework/widgets/metadata/tree/tree.service.js
+++ b/horizon/static/framework/widgets/metadata/tree/tree.service.js
@@ -71,6 +71,8 @@
Property.prototype.setValue = function (value) {
if (value === null) {
this.value = this.type !== 'array' ? null : [];
+ // if the existing property is null, make the field not required
+ this.required = false;
return;
}