From 04fe1156bf4860ecf7992ed7a41b6f0f8c444a37 Mon Sep 17 00:00:00 2001 From: Andy Botting Date: Wed, 29 Aug 2018 12:12:07 +1000 Subject: [PATCH] Support setting more visibility options for edit/create image The edit and create image pages could only set public or private visibility for an image. With Glance v2, we have 'shared' and 'community' available to us. This commit adds buttons for those pages selectively when the policy allows it. It also only displays 'public' visibility if policy allows. Closes-Bug: #1792411 Depends-On: https://review.openstack.org/#/c/614688/ Change-Id: I193bc0580e4bf9351ad7f17b148a5062e95313ab --- .../create-image/create-image.controller.js | 18 ++++++----- .../create-image.controller.spec.js | 14 +++++++-- .../steps/create-image/create-image.html | 2 +- .../steps/edit-image/edit-image.controller.js | 26 ++++++++++++---- .../edit-image/edit-image.controller.spec.js | 30 +++++++++++-------- .../images/steps/edit-image/edit-image.html | 2 +- .../openstack-service-api/glance.service.js | 4 +-- ...ult-image-visibility-560c3b6ab2830cdc.yaml | 6 ++++ 8 files changed, 69 insertions(+), 33 deletions(-) create mode 100644 releasenotes/notes/change-default-image-visibility-560c3b6ab2830cdc.yaml diff --git a/openstack_dashboard/static/app/core/images/steps/create-image/create-image.controller.js b/openstack_dashboard/static/app/core/images/steps/create-image/create-image.controller.js index 5d15b307a0..517a1c79d0 100644 --- a/openstack_dashboard/static/app/core/images/steps/create-image/create-image.controller.js +++ b/openstack_dashboard/static/app/core/images/steps/create-image/create-image.controller.js @@ -54,7 +54,6 @@ ctrl.diskFormats = []; ctrl.prepareUpload = prepareUpload; ctrl.apiVersion = 0; - ctrl.allowPublicizeImage = true; $scope.stepModels.imageForm = ctrl.image = { source_type: '', @@ -66,7 +65,7 @@ min_ram: 0, container_format: '', disk_format: '', - visibility: 'public' + visibility: 'shared' }; ctrl.uploadProgress = -1; @@ -84,8 +83,8 @@ ctrl.imageSourceOptions = []; ctrl.imageVisibilityOptions = [ - { label: gettext('Public'), value: 'public'}, - { label: gettext('Private'), value: 'private' } + { label: gettext('Private'), value: 'private' }, + { label: gettext('Shared'), value: 'shared'} ]; ctrl.kernelImages = []; @@ -148,11 +147,14 @@ function init() { glance.getImages({paginate: false}).success(onGetImages); - policyAPI.ifAllowed({rules: [['image', 'publicize_image']]}).then( - angular.noop, + policyAPI.ifAllowed({rules: [['image', 'communitize_image']]}).then( function () { - ctrl.image.visibility = "private"; - ctrl.allowPublicizeImage = false; + ctrl.imageVisibilityOptions.push({ label: gettext('Community'), value: 'community' }); + } + ); + policyAPI.ifAllowed({rules: [['image', 'publicize_image']]}).then( + function () { + ctrl.imageVisibilityOptions.push({ label: gettext('Public'), value: 'public' }); } ); } diff --git a/openstack_dashboard/static/app/core/images/steps/create-image/create-image.controller.spec.js b/openstack_dashboard/static/app/core/images/steps/create-image/create-image.controller.spec.js index d0301d48f3..ffb2c2511f 100644 --- a/openstack_dashboard/static/app/core/images/steps/create-image/create-image.controller.spec.js +++ b/openstack_dashboard/static/app/core/images/steps/create-image/create-image.controller.spec.js @@ -97,7 +97,7 @@ it('should have options for visibility, protected and copying', function() { var ctrl = createController(); - expect(ctrl.imageVisibilityOptions.length).toEqual(2); + expect(ctrl.imageVisibilityOptions.length).toEqual(4); expect(ctrl.imageProtectedOptions.length).toEqual(2); expect(ctrl.imageCopyOptions.length).toEqual(2); }); @@ -124,7 +124,7 @@ expect(ctrl.imageFormats).toBeDefined(); expect(ctrl.validationRules).toBeDefined(); expect(ctrl.diskFormats).toEqual([]); - expect(ctrl.image.visibility).toEqual('public'); + expect(ctrl.image.visibility).toEqual('shared'); expect(ctrl.image.min_disk).toEqual(0); expect(ctrl.image.min_ram).toEqual(0); }); @@ -214,6 +214,16 @@ $timeout.flush(); expect(ctrl.imageSourceOptions).toEqual([fileSourceOption, urlSourceOption]); }); + + it('test image visibility is private if set as default', function() { + var ctrl = createController(); + settingsCall.resolve({ + OPENSTACK_IMAGE_FORMATS: [], + CREATE_IMAGE_DEFAULTS: { image_visibility: 'private' } + }); + $timeout.flush(); + expect(ctrl.image.visibility).toEqual('private'); + }); }); }); diff --git a/openstack_dashboard/static/app/core/images/steps/create-image/create-image.html b/openstack_dashboard/static/app/core/images/steps/create-image/create-image.html index 5ea8afbf3d..4cfe7a60bc 100644 --- a/openstack_dashboard/static/app/core/images/steps/create-image/create-image.html +++ b/openstack_dashboard/static/app/core/images/steps/create-image/create-image.html @@ -221,7 +221,7 @@
-
+