From: Jan Provaznik <jprovazn(a)redhat.com>
BZ 739912
https://www.aeolusproject.org/redmine/issues/2386
---
.../controllers/hardware_profiles_controller.rb | 12 ++++----
.../hardware_profiles_controller_spec.rb | 28 +++++++++++++------
2 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/src/app/controllers/hardware_profiles_controller.rb
b/src/app/controllers/hardware_profiles_controller.rb
index 2463697..0e7249d 100644
--- a/src/app/controllers/hardware_profiles_controller.rb
+++ b/src/app/controllers/hardware_profiles_controller.rb
@@ -33,7 +33,7 @@ class HardwareProfilesController < ApplicationController
save_breadcrumb(hardware_profiles_path)
@params = params
respond_to do |format|
- format.html { load_hardware_profiles }
+ format.html
format.js do
build_hardware_profile(params[:hardware_profile])
matching_provider_hardware_profiles
@@ -213,13 +213,13 @@ class HardwareProfilesController < ApplicationController
end
def load_hardware_profiles
- sort_field = params[:order_field].nil? ? "name" : params[:order_field]
- sort_order = params[:order_dir] == "asc" || params[:order_dir].nil? ?
"" : "desc"
+ sort_field = params[:order_field].blank? ? "name" : params[:order_field]
+ sort_order = params[:order_dir].to_s == "desc" ? "desc" :
"asc"
if sort_field == "name"
- @hardware_profiles = HardwareProfile.all(:order => sort_field + " " +
sort_order, :conditions => 'provider_id IS NULL')
+ @hardware_profiles = HardwareProfile.list_for_user(current_user, Privilege::VIEW,
:order => "hardware_profiles.name #{sort_order}", :conditions =>
['provider_id IS NULL', {}])
else
- @hardware_profiles = HardwareProfile.all(:conditions => 'provider_id IS
NULL')
- if sort_order == ""
+ @hardware_profiles = HardwareProfile.list_for_user(current_user, Privilege::VIEW,
:conditions => ['provider_id IS NULL', {}])
+ if sort_order == "asc"
@hardware_profiles.sort! {|x,y| x.get_property_map[sort_field].sort_value(true)
<=> y.get_property_map[sort_field].sort_value(true)}
else
@hardware_profiles.sort! {|x,y| y.get_property_map[sort_field].sort_value(false)
<=> x.get_property_map[sort_field].sort_value(false)}
diff --git a/src/spec/controllers/hardware_profiles_controller_spec.rb
b/src/spec/controllers/hardware_profiles_controller_spec.rb
index ef2db46..cd5cb6d 100644
--- a/src/spec/controllers/hardware_profiles_controller_spec.rb
+++ b/src/spec/controllers/hardware_profiles_controller_spec.rb
@@ -26,18 +26,18 @@ describe HardwareProfilesController do
@admin = @admin_permission.user
end
- it "should provide ui to view all hardware profiles" do
- mock_warden(@admin)
- @request.accept = "text/html"
- get :index
- response.should be_success
- assigns[:hardware_profiles].size.should == HardwareProfile.count
- response.should render_template("index")
- end
-
describe "Authorization" do
context "Admin" do
+ it "should provide ui to view all hardware profiles" do
+ mock_warden(@admin)
+ @request.accept = "text/html"
+ get :index
+ response.should be_success
+ assigns[:hardware_profiles].size.should == HardwareProfile.count
+ response.should render_template("index")
+ end
+
it "should be able to create hardware profiles" do
mock_warden(@admin)
lambda do
@@ -86,6 +86,16 @@ describe HardwareProfilesController do
@user = @user_permission.user
end
+ it "should not list hw profiles which I'm not allowed to see" do
+ hardware_profile = Factory.create :hardware_profile
+ mock_warden(@user)
+ @request.accept = "text/html"
+ get :index
+ response.should be_success
+ assigns[:hardware_profiles].find {|p| p.name == hardware_profile.name}.should
be_nil
+ response.should render_template("index")
+ end
+
it "should not be able to create hardware profiles" do
mock_warden(@user)
lambda do
--
1.7.6