Skip to content

Commit

Permalink
Make readonly metadata properties unable to edit
Browse files Browse the repository at this point in the history
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 892080e)
  • Loading branch information
xtmprsqzntwlfb authored and darmach committed May 25, 2023
1 parent 38c62b4 commit 2b7a182
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -33,6 +35,12 @@
ctrl.opened = false;

this.$onInit = function init() {
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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 2b7a182

Please sign in to comment.