Still missing are add/remove for privileges on a role, so any new roles that are added to
the UI will be empty (no associated privileges).
This must be applied on top of the "refactored role/privilege model" patch.
Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
src/app/controllers/admin/roles_controller.rb | 5 +++++
src/app/views/admin/roles/_properties.haml | 18 ++++++++++++++++++
src/features/role.feature | 24 +++++++++++++++---------
src/features/step_definitions/role_steps.rb | 23 ++++++++++++++++++++++-
4 files changed, 60 insertions(+), 10 deletions(-)
diff --git a/src/app/controllers/admin/roles_controller.rb
b/src/app/controllers/admin/roles_controller.rb
index 70f0097..b47d917 100644
--- a/src/app/controllers/admin/roles_controller.rb
+++ b/src/app/controllers/admin/roles_controller.rb
@@ -3,6 +3,7 @@ class Admin::RolesController < ApplicationController
before_filter :load_roles, :only => [:index, :show]
def create
+ require_privilege(Privilege::ACTION_PERM_SET)
@role = Role.new(params[:role])
# TODO: (lmartinc) Fix this and let user select the scope. Consult with sseago.
@@ -17,6 +18,7 @@ class Admin::RolesController < ApplicationController
end
def show
+ require_privilege(Privilege::ACTION_PERM_VIEW)
@role = Role.find(params[:id])
@url_params = params.clone
@@ -34,10 +36,12 @@ class Admin::RolesController < ApplicationController
end
def edit
+ require_privilege(Privilege::ACTION_PERM_SET)
@role = Role.find(params[:id])
end
def update
+ require_privilege(Privilege::ACTION_PERM_SET)
@role = Role.find(params[:id])
if params[:commit] == "Reset"
@@ -53,6 +57,7 @@ class Admin::RolesController < ApplicationController
end
def multi_destroy
+ require_privilege(Privilege::ACTION_PERM_SET)
Role.destroy(params[:role_selected])
redirect_to admin_roles_url
end
diff --git a/src/app/views/admin/roles/_properties.haml
b/src/app/views/admin/roles/_properties.haml
index 8645d33..bcb59f4 100644
--- a/src/app/views/admin/roles/_properties.haml
+++ b/src/app/views/admin/roles/_properties.haml
@@ -2,4 +2,22 @@
%h2 #{(a)role.name}
%strong Scope:
%span #{(a)role.scope}
+ %table
+ %thead
+ %tr
+ %th.show
+ Privileges
+ %th.show
+ %tbody
+ %tr
+ %td
+ %label Action
+ %td
+ %label Target type
+ -(a)role.privileges.each do |privilege|
+ %tr
+ %td
+ = privilege.action
+ %td
+ = privilege.target_type
= link_to t(:edit), edit_admin_role_path(@role), :class => 'button
formbutton'
diff --git a/src/features/role.feature b/src/features/role.feature
index 1975f5a..70c99f0 100644
--- a/src/features/role.feature
+++ b/src/features/role.feature
@@ -6,34 +6,40 @@ Feature: Manage Roles
Background:
Given I am an authorised user
And I am logged in
- And there's no role
- And a role "Captan" exists
+ Given there's a list of roles
+ And a role "Captain" exists
And I am using new UI
Scenario: Change the name
Given I am on the admin roles page
- And there is a role "Captan"
- When I follow "Captan"
+ And there should be a role named "Captain"
+ When I follow "Captain"
And I follow "Edit"
Then I should see "Editing Role:"
When I fill in "role[name]" with "Admiral"
And I press "Save"
Then I should see "Role updated successfully!"
- Scenario: Show role detials
+ Scenario: Show role details
Given a role "Admiral" exists
And I am on the admin roles page
When I follow "Admiral"
Then I should be on Admiral's role page
+ Scenario: Show default role privileges
+ Given I am on the admin roles page
+ And there should be a role named "Administrator"
+ When I follow "Administrator"
+ Then I should be on Administrator's role page
+
Scenario: Delete roles
Given a role "Admiral" exists
And I am on the admin roles page
- And there are 2 roles
+ And there are 2 more roles
When I check "Admiral" role
- And I check "Captan" role
+ And I check "Captain" role
And I press "Destroy"
- Then there should only be 0 roles
+ Then there should be 0 more roles
And I should be on the admin roles page
- And I should not see "Captan"
+ And I should not see "Captain"
And I should not see "Admiral"
diff --git a/src/features/step_definitions/role_steps.rb
b/src/features/step_definitions/role_steps.rb
index 3dac6d0..095216a 100644
--- a/src/features/step_definitions/role_steps.rb
+++ b/src/features/step_definitions/role_steps.rb
@@ -2,11 +2,15 @@ Given /there's no role/ do
Role.destroy_all
end
+Given /there's a list of roles/ do
+ @initial_num_roles = Role.count
+end
+
Given /^a role "([^"]*)" exists$/ do |role_name|
Role.create(:name => role_name, :scope => BasePermissionObject.to_s)
end
-Given /^there is a role "([^"]*)"$/ do |name|
+Given /^there should be a role named "([^\"]*)"$/ do |name|
Role.find_by_name(name).should_not == nil
end
@@ -14,6 +18,15 @@ Given /^there are (\d+) roles$/ do |number|
Role.count.should == number.to_i
end
+Given /^there are (\d+) more roles$/ do |number|
+ Role.count.should == @initial_num_roles + number.to_i
+end
+
+Given /^there are (\d+) fewer roles$/ do |number|
+ Role.count.should == @initial_num_roles - number.to_i
+ (@initial_num_roles + Role.count).should == number.to_i
+end
+
When /^(?:|I )check "([^"]*)" role$/ do |role_name|
role = Role.find_by_name(role_name)
check("role_checkbox_#{role.id}")
@@ -22,3 +35,11 @@ end
Then /^there should only be (\d+) roles$/ do |number|
Role.count.should == number.to_i
end
+
+Then /^there should be (\d+) more roles$/ do |number|
+ Role.count.should == @initial_num_roles + number.to_i
+end
+
+Then /^there should be (\d+) fewer roles$/ do |number|
+ Role.count.should == (@initial_num_roles - number.to_i)
+end
--
1.7.3.4