From: Jan Provaznik <jprovazn(a)redhat.com>
https://www.aeolusproject.org/redmine/issues/2402
---
src/app/models/deployment.rb | 11 +++++++++--
src/spec/models/deployment_spec.rb | 12 +++++++++++-
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index 0fb8e7c..1190334 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -152,7 +152,7 @@ class Deployment < ActiveRecord::Base
begin
task = nil
Instance.transaction do
- hw_profile = HardwareProfile.frontend.find_by_name(assembly.hwp)
+ hw_profile = permissioned_frontend_hwprofile(user, assembly.hwp)
raise "Hardware Profile #{assembly.hwp} not found." unless
hw_profile
instance = Instance.create!(
:deployment => self,
@@ -220,7 +220,7 @@ class Deployment < ActiveRecord::Base
errs = {}
deployable_xml.assemblies.each do |assembly|
begin
- hw_profile = HardwareProfile.frontend.find_by_name(assembly.hwp)
+ hw_profile = permissioned_frontend_hwprofile(user, assembly.hwp)
raise "Hardware Profile #{assembly.hwp} not found." unless hw_profile
instance = Instance.new(
:deployment => self,
@@ -316,4 +316,11 @@ class Deployment < ActiveRecord::Base
return
end
end
+
+ private
+
+ def permissioned_frontend_hwprofile(user, hwp_name)
+ HardwareProfile.list_for_user(user, Privilege::VIEW,
+ :conditions => ['hardware_profiles.name = :name AND provider_id IS
NULL', {:name => hwp_name}]).first
+ end
end
diff --git a/src/spec/models/deployment_spec.rb b/src/spec/models/deployment_spec.rb
index c7bbe17..3251fb6 100644
--- a/src/spec/models/deployment_spec.rb
+++ b/src/spec/models/deployment_spec.rb
@@ -111,7 +111,8 @@ describe Deployment do
provider_name =
Image.find(image_id).latest_build.provider_images.first.provider_name
provider = FactoryGirl.create(:mock_provider, :name => provider_name)
@deployment.pool.pool_family.provider_accounts =
[FactoryGirl.create(:mock_provider_account, :label => 'testaccount', :provider
=> provider)]
- @user_for_launch = FactoryGirl.create(:user)
+ admin_perms = FactoryGirl.create :admin_permission
+ @user_for_launch = admin_perms.user
end
it "should return errors when checking assemblies matches which are not
launchable" do
@@ -129,6 +130,15 @@ describe Deployment do
@deployment.instances.count.should == 2
end
+ it "should not launch instances if user has no access to hardware profile"
do
+ @deployment.save!
+ @deployment.instances.should be_empty
+
+ Taskomatic.stub!(:create_instance).and_return(true)
+ @deployment.launch(@user_for_launch)[:errors].should be_empty
+ @deployment.instances.count.should == 2
+ end
+
end
it "should be able to stop running instances on deletion" do
--
1.7.6