From: Ladislav Martincik <lmart...@redhat.com> Fixes for new Admin/Roles UI base on Tomas's patch. --- src/app/controllers/admin/roles_controller.rb | 69 ++++++++++++++++++++++++- src/app/views/admin/roles/_form.haml | 8 +++ src/app/views/admin/roles/_list.haml | 16 ++++++ src/app/views/admin/roles/_properties.haml | 5 ++ src/app/views/admin/roles/edit.haml | 4 ++ src/app/views/admin/roles/index.haml | 3 +- src/app/views/admin/roles/new.haml | 3 + src/config/routes.rb | 3 +- src/features/role.feature | 39 ++++++++++++++ src/features/step_definitions/role_steps.rb | 24 +++++++++ src/features/step_definitions/user_steps.rb | 4 +- src/features/support/paths.rb | 3 + 12 files changed, 176 insertions(+), 5 deletions(-) create mode 100644 src/app/views/admin/roles/_form.haml create mode 100644 src/app/views/admin/roles/_list.haml create mode 100644 src/app/views/admin/roles/_properties.haml create mode 100644 src/app/views/admin/roles/edit.haml create mode 100644 src/app/views/admin/roles/new.haml create mode 100644 src/features/role.feature create mode 100644 src/features/step_definitions/role_steps.rb
diff --git a/src/app/controllers/admin/roles_controller.rb b/src/app/controllers/admin/roles_controller.rb index 95868d4..70f0097 100644 --- a/src/app/controllers/admin/roles_controller.rb +++ b/src/app/controllers/admin/roles_controller.rb @@ -1,6 +1,73 @@ class Admin::RolesController < ApplicationController before_filter :require_user + before_filter :load_roles, :only => [:index, :show] - def index + def create + @role = Role.new(params[:role]) + + # TODO: (lmartinc) Fix this and let user select the scope. Consult with sseago. + @role.scope = BasePermissionObject.to_s if @role.scope.nil? + + if @role.save + flash[:notice] = 'Role successfully saved!' + redirect_to admin_roles_path and return + end + + render :action => 'new' + end + + def show + @role = Role.find(params[:id]) + + @url_params = params.clone + @tab_captions = ['Properties'] + @details_tab = params[:details_tab].blank? ? 'properties' : params[:details_tab] + respond_to do |format| + format.js do + if @url_params.delete :details_pane + render :partial => 'layouts/details_pane' and return + end + render :partial => @details_tab + end + format.html { render :partial => @details_tab } + end + end + + def edit + @role = Role.find(params[:id]) end + + def update + @role = Role.find(params[:id]) + + if params[:commit] == "Reset" + redirect_to edit_admin_role_url(@role) and return + end + + if @role.update_attributes(params[:role]) + flash[:notice] = 'Role updated successfully!' + redirect_to admin_roles_url and return + end + + render :action => 'edit' + end + + def multi_destroy + Role.destroy(params[:role_selected]) + redirect_to admin_roles_url + end + + protected + + def load_roles + @header = [ + { :name => "Role name", :sort_attr => :name } + ] + @roles = Role.paginate(:all, + :page => params[:page] || 1, + :order => (params[:order_field] || 'name') +' '+ (params[:order_dir] || 'asc') + ) + @url_params = params.clone + end + end diff --git a/src/app/views/admin/roles/_form.haml b/src/app/views/admin/roles/_form.haml new file mode 100644 index 0000000..fc10dd2 --- /dev/null +++ b/src/app/views/admin/roles/_form.haml @@ -0,0 +1,8 @@ += form.error_messages +%fieldset.clear + = form.label :name, 'Name', :class => "grid_3 alpha" + = form.text_field :name, :class => "grid_5" +%fieldset.clearfix + = form.submit "Save", :class => "submit formbutton" + = form.submit "Reset", :class => "submit formbutton" + = link_to t(:cancel), admin_roles_path, :class => 'button formbutton' diff --git a/src/app/views/admin/roles/_list.haml b/src/app/views/admin/roles/_list.haml new file mode 100644 index 0000000..1c86a8c --- /dev/null +++ b/src/app/views/admin/roles/_list.haml @@ -0,0 +1,16 @@ +- form_tag do + = restful_submit_tag "New Role", "new", new_admin_role_path, 'GET' + = restful_submit_tag "Destroy", "destroy", multi_destroy_admin_roles_path, 'DELETE' + %p + Select: + = link_to "All", @url_params.merge(:select => 'all') + %span> , + = link_to "None", @url_params.merge(:select => 'none') + %table + = sortable_table_header @header + - @roles.each do |role| + %tr + %td + - selected = @url_params[:select] == 'all' + %input{:name => "role_selected[]", :type => "checkbox", :value => role.id, :id => "role_checkbox_#{role.id}", :checked => selected } + = link_to role.name, admin_role_path(role) diff --git a/src/app/views/admin/roles/_properties.haml b/src/app/views/admin/roles/_properties.haml new file mode 100644 index 0000000..8645d33 --- /dev/null +++ b/src/app/views/admin/roles/_properties.haml @@ -0,0 +1,5 @@ +.grid_13 + %h2 #...@role.name} + %strong Scope: + %span #...@role.scope} + = link_to t(:edit), edit_admin_role_path(@role), :class => 'button formbutton' diff --git a/src/app/views/admin/roles/edit.haml b/src/app/views/admin/roles/edit.haml new file mode 100644 index 0000000..7aa428e --- /dev/null +++ b/src/app/views/admin/roles/edit.haml @@ -0,0 +1,4 @@ +%h2 Editing Role: #...@role.name} + +- form_for @role, :url => admin_role_path(@role), :html => { :method => :put } do |f| + = render :partial => "form", :locals => { :form => f } diff --git a/src/app/views/admin/roles/index.haml b/src/app/views/admin/roles/index.haml index d063630..62ccbc6 100644 --- a/src/app/views/admin/roles/index.haml +++ b/src/app/views/admin/roles/index.haml @@ -1 +1,2 @@ -admin/roles/index.haml +- content_for :list do + = render :partial => 'list' diff --git a/src/app/views/admin/roles/new.haml b/src/app/views/admin/roles/new.haml new file mode 100644 index 0000000..7fe46ba --- /dev/null +++ b/src/app/views/admin/roles/new.haml @@ -0,0 +1,3 @@ +%h2 New Role +- form_for Role.new, :url => admin_roles_path do |f| + = render :partial => "form", :locals => { :form => f } diff --git a/src/config/routes.rb b/src/config/routes.rb index 5dd6560..052eba5 100644 --- a/src/config/routes.rb +++ b/src/config/routes.rb @@ -43,8 +43,9 @@ ActionController::Routing::Routes.draw do |map| map.connect '/set_layout', :controller => 'application', :action => 'set_layout' map.namespace 'admin' do |r| - r.resources :hardware_profiles, :pool_families, :providers, :provider_accounts, :realms, :roles, :settings + r.resources :hardware_profiles, :pool_families, :providers, :provider_accounts, :realms, :settings r.resources :users, :collection => { :multi_destroy => :delete } + r.resources :roles, :collection => { :multi_destroy => :delete } end map.resources :pools diff --git a/src/features/role.feature b/src/features/role.feature new file mode 100644 index 0000000..1975f5a --- /dev/null +++ b/src/features/role.feature @@ -0,0 +1,39 @@ +Feature: Manage Roles + In order to manage roles + As an admin + I want to add/edit/remove roles + + Background: + Given I am an authorised user + And I am logged in + And there's no role + And a role "Captan" 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 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 + 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: Delete roles + Given a role "Admiral" exists + And I am on the admin roles page + And there are 2 roles + When I check "Admiral" role + And I check "Captan" role + And I press "Destroy" + Then there should only be 0 roles + And I should be on the admin roles page + And I should not see "Captan" + And I should not see "Admiral" diff --git a/src/features/step_definitions/role_steps.rb b/src/features/step_definitions/role_steps.rb new file mode 100644 index 0000000..3dac6d0 --- /dev/null +++ b/src/features/step_definitions/role_steps.rb @@ -0,0 +1,24 @@ +Given /there's no role/ do + Role.destroy_all +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| + Role.find_by_name(name).should_not == nil +end + +Given /^there are (\d+) roles$/ do |number| + 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}") +end + +Then /^there should only be (\d+) roles$/ do |number| + Role.count.should == number.to_i +end diff --git a/src/features/step_definitions/user_steps.rb b/src/features/step_definitions/user_steps.rb index c6467e8..ed474e3 100644 --- a/src/features/step_definitions/user_steps.rb +++ b/src/features/step_definitions/user_steps.rb @@ -3,9 +3,9 @@ Given /^there is a user "([^"]*)"$/ do |name| end Given /^there are (\d+) users$/ do |number| - User.all.size.should == number.to_i + User.count.should == number.to_i end Then /^there should only be (\d+) users$/ do |number| - User.all.size.should == number.to_i + User.count.should == number.to_i end diff --git a/src/features/support/paths.rb b/src/features/support/paths.rb index c60b940..12eb062 100644 --- a/src/features/support/paths.rb +++ b/src/features/support/paths.rb @@ -20,6 +20,9 @@ module NavigationHelpers when /^(.*)'s user page$/i admin_user_path(User.find_by_login($1)) + when /^(.*)'s role page$/i + admin_role_path(Role.find_by_name($1)) + when /the account page/ account_path -- 1.7.3.2 _______________________________________________ deltacloud-devel mailing list deltacloud-devel@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/deltacloud-devel