Merge "Support setting more visibility options for edit/create image"
This commit is contained in:
commit
a235ebde56
|
@ -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' });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -221,7 +221,7 @@
|
|||
|
||||
<div class="selected-source">
|
||||
<div class="row">
|
||||
<div class="col-xs-6 col-sm-6" ng-show='ctrl.allowPublicizeImage'>
|
||||
<div class="col-xs-6 col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="control-label required">
|
||||
<translate>Visibility</translate>
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
'$scope',
|
||||
'horizon.app.core.images.imageFormats',
|
||||
'horizon.app.core.images.validationRules',
|
||||
'horizon.app.core.openstack-service-api.settings'
|
||||
'horizon.app.core.openstack-service-api.settings',
|
||||
'horizon.app.core.openstack-service-api.policy'
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -38,7 +39,8 @@
|
|||
$scope,
|
||||
imageFormats,
|
||||
validationRules,
|
||||
settings
|
||||
settings,
|
||||
policy
|
||||
) {
|
||||
var ctrl = this;
|
||||
|
||||
|
@ -52,12 +54,11 @@
|
|||
];
|
||||
|
||||
ctrl.imageVisibilityOptions = [
|
||||
{ label: gettext('Public'), value: 'public' },
|
||||
{ label: gettext('Private'), value: 'private' }
|
||||
{ label: gettext('Private'), value: 'private' },
|
||||
{ label: gettext('Shared'), value: 'shared' }
|
||||
];
|
||||
|
||||
ctrl.setFormats = setFormats;
|
||||
ctrl.allowPublicizeImage = { rules: [['image', 'image:publicize_image']] };
|
||||
|
||||
$scope.imagePromise.then(init);
|
||||
|
||||
|
@ -80,13 +81,26 @@
|
|||
ctrl.image.kernel = ctrl.image.properties.kernel_id;
|
||||
ctrl.image.ramdisk = ctrl.image.properties.ramdisk_id;
|
||||
ctrl.image.architecture = ctrl.image.properties.architecture;
|
||||
ctrl.image.visibility = ctrl.image.is_public ? 'public' : 'private';
|
||||
ctrl.image_format = ctrl.image.disk_format;
|
||||
if (ctrl.image.container_format === 'docker') {
|
||||
ctrl.image_format = 'docker';
|
||||
ctrl.image.disk_format = 'raw';
|
||||
}
|
||||
setFormats();
|
||||
getVisibilities();
|
||||
}
|
||||
|
||||
function getVisibilities() {
|
||||
policy.ifAllowed({rules: [['image', 'communitize_image']]}).then(
|
||||
function() {
|
||||
ctrl.imageVisibilityOptions.push({ label: gettext('Community'), value: 'community' });
|
||||
}
|
||||
);
|
||||
policy.ifAllowed({rules: [['image', 'publicize_image']]}).then(
|
||||
function() {
|
||||
ctrl.imageVisibilityOptions.push({ label: gettext('Public'), value: 'public' });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function setFormats() {
|
||||
|
|
|
@ -19,7 +19,15 @@
|
|||
|
||||
describe('horizon.app.core.images edit image controller', function() {
|
||||
|
||||
var controller, $scope, $q, settingsCall, $timeout;
|
||||
function policyIfAllowed() {
|
||||
return {
|
||||
then: function(callback) {
|
||||
callback({allowed: true});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var controller, $scope, $q, settingsCall, $timeout, policy;
|
||||
|
||||
///////////////////////
|
||||
|
||||
|
@ -35,6 +43,9 @@
|
|||
$timeout = _$timeout_;
|
||||
|
||||
controller = $injector.get('$controller');
|
||||
|
||||
policy = $injector.get('horizon.app.core.openstack-service-api.policy');
|
||||
spyOn(policy, 'ifAllowed').and.callFake(policyIfAllowed);
|
||||
}));
|
||||
|
||||
function createController() {
|
||||
|
@ -57,19 +68,12 @@
|
|||
}
|
||||
|
||||
it('should have options for visibility and protected', function() {
|
||||
setImagePromise({id: '1', container_format: 'bare', is_public: false, properties: []});
|
||||
var ctrl = createController();
|
||||
|
||||
expect(ctrl.imageVisibilityOptions.length).toEqual(2);
|
||||
expect(ctrl.imageProtectedOptions.length).toEqual(2);
|
||||
});
|
||||
|
||||
it('should map is_public', function() {
|
||||
setImagePromise({id: '1', container_format: 'bare', is_public: false, properties: []});
|
||||
setImagePromise({id: '1', container_format: 'bare', visibility: 'shared', properties: []});
|
||||
var ctrl = createController();
|
||||
$timeout.flush();
|
||||
|
||||
expect(ctrl.image.visibility).toEqual('private');
|
||||
expect(ctrl.imageVisibilityOptions.length).toEqual(4);
|
||||
expect(ctrl.imageProtectedOptions.length).toEqual(2);
|
||||
});
|
||||
|
||||
it('reads the data format settings', function() {
|
||||
|
@ -87,14 +91,14 @@
|
|||
id: '1',
|
||||
container_format: 'bare',
|
||||
disk_format: 'ova',
|
||||
is_public: true,
|
||||
visibility: 'private',
|
||||
properties: []
|
||||
});
|
||||
var ctrl = createController();
|
||||
$timeout.flush();
|
||||
|
||||
expect(ctrl.image.disk_format).toEqual('ova');
|
||||
expect(ctrl.image.visibility).toEqual('public');
|
||||
expect(ctrl.image.visibility).toEqual('private');
|
||||
});
|
||||
|
||||
it('should set local image_format to docker when container is docker', function() {
|
||||
|
|
|
@ -123,7 +123,7 @@
|
|||
|
||||
<div class="selected-source clearfix">
|
||||
<div class="row">
|
||||
<div class="col-xs-6 col-sm-6" hz-if-policies="ctrl.allowPublicizeImage">
|
||||
<div class="col-xs-6 col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="control-label required" translate>Visibility</label>
|
||||
<div class="form-field">
|
||||
|
|
|
@ -121,7 +121,7 @@
|
|||
* The minimum memory size required to boot the image. Optional.
|
||||
*
|
||||
* @param {boolean} image.visibility
|
||||
* values of 'public', 'private', and 'shared' are valid. Required.
|
||||
* values of 'public', 'private', 'shared' and 'community' are valid. Required.
|
||||
*
|
||||
* @param {boolean} image.protected
|
||||
* True if the image is protected, false otherwise. Required.
|
||||
|
@ -217,7 +217,7 @@
|
|||
* The minimum memory size required to boot the image. Optional.
|
||||
*
|
||||
* @param {boolean} image.visibility
|
||||
* Values of 'public', 'private', and 'shared' are valid. Required.
|
||||
* Values of 'public', 'private', 'shared' and 'community' are valid. Required.
|
||||
*
|
||||
* @param {boolean} image.protected
|
||||
* True if the image is protected, false otherwise. Required.
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
other:
|
||||
- |
|
||||
The default visibility when creating new images has been changed from
|
||||
`private` to `shared` to bring it inline with the default changing in
|
||||
Glance since Image API v2.5.
|
Loading…
Reference in New Issue