Image panel: check instance create policy for 'Launch' button

Closes-Bug: #1771851
Change-Id: If77746cbbe73540218b90c516e5f8802c002854f
This commit is contained in:
andrewbogott 2018-05-16 23:08:41 -05:00 committed by Ivan Kolodyazhny
parent e5fbf73411
commit e98d7e6890
2 changed files with 18 additions and 1 deletions

View File

@ -23,6 +23,7 @@
launchInstanceService.$inject = [ launchInstanceService.$inject = [
'$q', '$q',
'horizon.app.core.images.non_bootable_image_types', 'horizon.app.core.images.non_bootable_image_types',
'horizon.app.core.openstack-service-api.policy',
'horizon.dashboard.project.workflow.launch-instance.modal.service', 'horizon.dashboard.project.workflow.launch-instance.modal.service',
'horizon.framework.util.q.extensions' 'horizon.framework.util.q.extensions'
]; ];
@ -44,6 +45,7 @@
function launchInstanceService( function launchInstanceService(
$q, $q,
nonBootableImageTypes, nonBootableImageTypes,
policy,
launchInstanceModal, launchInstanceModal,
$qExtensions $qExtensions
) { ) {
@ -66,7 +68,11 @@
} }
function allowed(image) { function allowed(image) {
return $q.all([isBootable(image), isActive(image)]); return $q.all([
isBootable(image),
isActive(image),
policy.ifAllowed({ rules: [['compute', 'compute:create']] })
]);
} }
function isActive(image) { function isActive(image) {

View File

@ -22,6 +22,16 @@
open: function () {} open: function () {}
}; };
var policyAPI = {
ifAllowed: function() {
return {
success: function(callback) {
callback({allowed: true});
}
};
}
};
var service, $scope; var service, $scope;
/////////////////////// ///////////////////////
@ -31,6 +41,7 @@
$provide.value( $provide.value(
'horizon.dashboard.project.workflow.launch-instance.modal.service', launchInstanceModalMock 'horizon.dashboard.project.workflow.launch-instance.modal.service', launchInstanceModalMock
); );
$provide.value('horizon.app.core.openstack-service-api.policy', policyAPI);
})); }));
beforeEach(inject(function($injector, _$rootScope_) { beforeEach(inject(function($injector, _$rootScope_) {