Disable Glance option to publicize image on Update

The Glance policy file contains a property that controls the ability to
publicize a Glance Image. In Horizon we use this policy check to Hide
the checkbox on Project > Images > Create Image. This is working as
expected.

For Updating an Image we attempt to make the Public checkbox read-only
which isn't enough to disable it.

To test try the following:

1) Update the glance_policy.json file in Horizon (located here
horizon/openstack_dashboard/conf/) to reflect this rule:
...
 "publicize_image": "role:admin",
...
 2) Create a non-admin user and try to Create a new Glance Image
 3) Observe that there is no Public check box.
 4) This is expected.
 5) Continue creating the image.
 6) Once the image is created, Click on Edit Image
 7) Notice that Public checkbox is there and you can select it.
 8) This is not expected.

 Expected Behavior:
 For the Edit Image modal, the checkbox should be disabled like this.

 https://github.com/openstack/horizon/blob/master/openstack_dashboard/dashboards/project/images/images/forms.py#L344

         if not policy.check((("image", "publicize_image"),), request):
                         self.fields['public'].widget =
                         forms.CheckboxInput(
                                         attrs={'readonly': 'readonly',
                                         'disabled': disabled})
Closes-Bug: #1553420

Change-Id: I9c441252f7959e169eedbf432d140f9415d1a32b
This commit is contained in:
daniel-a-nguyen 2016-03-04 16:18:19 -08:00
parent a699e5a371
commit a2c1a0a33b

View File

@ -341,7 +341,9 @@ class UpdateImageForm(forms.SelfHandlingForm):
if value]
if not policy.check((("image", "publicize_image"),), request):
self.fields['public'].widget = forms.CheckboxInput(
attrs={'readonly': 'readonly'})
attrs={'readonly': 'readonly', 'disabled': 'disabled'})
self.fields['public'].help_text = _(
'Non admin users are not allowed to make images public.')
def handle(self, request, data):
image_id = data['image_id']