[PATCH aggregator] New UI for Admin/Roles
by lmartinc@redhat.com
From: Ladislav Martincik <lmartinc(a)redhat.com>
---
src/app/controllers/admin/roles_controller.rb | 69 ++++++++++++++++++++++++-
src/app/views/admin/roles/_form.haml | 8 +++
src/app/views/admin/roles/_list.haml | 30 +++++++++++
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, 190 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..d825e2f
--- /dev/null
+++ b/src/app/views/admin/roles/_list.haml
@@ -0,0 +1,30 @@
+- form_tag do
+ = link_to "New Role", new_admin_role_path, :class => 'button'
+ = restful_submit_tag "Destroy", "destroy", multi_destroy_admin_roles_path, 'DELETE', :id => 'delete_button'
+ %p
+ Select:
+ = link_to "All", @url_params.merge(:select => 'all')
+ %span> ,
+ = link_to "None", @url_params.merge(:select => 'none')
+ %table#roles_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)
+
+:javascript
+ $(document).ready(function () {
+ $('#delete_button').click(function(e) {
+ if ($("#roles_table input[@type=radio]:checked").length == 0) {
+ alert('Please select any user to be deleted before clicking Delete button.');
+ e.preventDefault();
+ } else {
+ if (!confirm("Are you sure you want to delete this user?")) {
+ e.preventDefault();
+ }
+ }
+ });
+ });
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 #{(a)role.name}
+ %strong Scope:
+ %span #{(a)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: #{(a)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 17d72d1..fa48dfd 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -44,10 +44,11 @@ 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, :provider_accounts, :realms, :roles, :settings
+ r.resources :hardware_profiles, :pool_families, :provider_accounts, :realms, :settings
r.resources :providers, :collection => { :multi_destroy => :delete }
r.resources :users, :collection => { :multi_destroy => :delete }
r.resources :provider_accounts, :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 c3309fe..54486af 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
13 years, 5 months
[PATCH aggregator] Fix for new UI for Users base on Tomas's template
by lmartinc@redhat.com
From: Ladislav Martincik <lmartinc(a)redhat.com>
---
src/app/controllers/admin/users_controller.rb | 13 +++
src/app/views/admin/users/_list.haml | 2 -
src/app/views/admin/users/_properties.haml | 98 ++++++++++++++++++++++++
src/app/views/admin/users/show.haml | 99 -------------------------
src/config/environment.rb | 2 +-
src/features/user.feature | 3 +-
6 files changed, 114 insertions(+), 103 deletions(-)
create mode 100644 src/app/views/admin/users/_properties.haml
delete mode 100644 src/app/views/admin/users/show.haml
diff --git a/src/app/controllers/admin/users_controller.rb b/src/app/controllers/admin/users_controller.rb
index 65b1ce6..0e854a9 100644
--- a/src/app/controllers/admin/users_controller.rb
+++ b/src/app/controllers/admin/users_controller.rb
@@ -35,6 +35,19 @@ class Admin::UsersController < ApplicationController
def show
@user = User.find_by_id(params[:id]) || current_user
@quota_resources = @user.quota.quota_resources
+
+ @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
diff --git a/src/app/views/admin/users/_list.haml b/src/app/views/admin/users/_list.haml
index ff62782..6a544ed 100644
--- a/src/app/views/admin/users/_list.haml
+++ b/src/app/views/admin/users/_list.haml
@@ -14,7 +14,6 @@
=link_to "Quota", admin_users_url(:sort_by => "quota")
%span (Instances)
%th= link_to "e-mail", admin_users_url(:sort_by => "email")
- %th
-(a)users.each do |user|
%tr
%td
@@ -25,7 +24,6 @@
%td= sprintf("%.2f", user.quota.percentage_used)
%td= Quota.no_limit(user.quota.maximum_running_instances) ? "Unlimited" : user.quota.maximum_running_instances
%td= user.email
- %td= link_to "edit", edit_admin_user_path(user)
:javascript
$(document).ready(function () {
diff --git a/src/app/views/admin/users/_properties.haml b/src/app/views/admin/users/_properties.haml
new file mode 100644
index 0000000..fc8af9c
--- /dev/null
+++ b/src/app/views/admin/users/_properties.haml
@@ -0,0 +1,98 @@
+.grid_13
+ %h2 #{(a)user.first_name} #{(a)user.last_name} (#{(a)user.login})
+
+ = link_to 'Edit', edit_admin_user_path(@user), :class => 'button'
+
+ %table
+ %thead
+ %tr
+ %th.show
+ Personal Details
+ %th.show
+ %tbody
+ %tr
+ %td
+ %label Username
+ %td
+ = @user.login
+ %tr
+ %td
+ %label First Name
+ %td
+ = @user.first_name
+ %tr
+ %td
+ %label Last Name
+ %td
+ = @user.last_name
+ %tr
+ %td
+ %label e-mail
+ %td
+ = @user.email
+
+ %table
+ %thead
+ %tr
+ %th.show
+ Quota Status
+ %th.show
+ %tbody
+ %tr
+ %td
+ %label Maximum
+ %td
+ = @quota_resources["running_instances"].max
+ %tr
+ %td
+ %label Used
+ %td
+ = @quota_resources["running_instances"].used
+ %tr
+ %td
+ %label Availabe
+ %td
+ = @quota_resources["running_instances"].available
+
+ %table
+ %thead
+ %tr
+ %th.show
+ Login Information
+ %th.show
+ %tbody
+ %tr
+ %td
+ %label Current Login IP
+ %td
+ = @user.current_login_ip
+ %tr
+ %td
+ %label Current Login at
+ %td
+ = @user.current_login_at
+ %tr
+ %td
+ %label Last Login IP
+ %td
+ = @user.last_login_ip
+ %tr
+ %td
+ %label Last Login at
+ %td
+ = @user.last_login_at
+ %tr
+ %td
+ %label Login Count
+ %td
+ = @user.login_count
+ %tr
+ %td
+ %label Failed Login Count
+ %td
+ = @user.login_count
+ %tr
+ %td
+ %label Last Request at
+ %td
+ = @user.last_request_at
diff --git a/src/app/views/admin/users/show.haml b/src/app/views/admin/users/show.haml
deleted file mode 100644
index c5cca96..0000000
--- a/src/app/views/admin/users/show.haml
+++ /dev/null
@@ -1,99 +0,0 @@
--content_for :list do
- = render :partial => 'list'
--content_for :details do
- .grid_13
- %h2 #{(a)user.first_name} #{(a)user.last_name} (#{(a)user.login})
-
- %table
- %thead
- %tr
- %th.show
- Personal Details
- %th.show
- %tbody
- %tr
- %td
- %label Username
- %td
- = @user.login
- %tr
- %td
- %label First Name
- %td
- = @user.first_name
- %tr
- %td
- %label Last Name
- %td
- = @user.last_name
- %tr
- %td
- %label e-mail
- %td
- = @user.email
-
- %table
- %thead
- %tr
- %th.show
- Quota Status
- %th.show
- %tbody
- %tr
- %td
- %label Maximum
- %td
- = @quota_resources["running_instances"].max
- %tr
- %td
- %label Used
- %td
- = @quota_resources["running_instances"].used
- %tr
- %td
- %label Availabe
- %td
- = @quota_resources["running_instances"].available
-
- %table
- %thead
- %tr
- %th.show
- Login Information
- %th.show
- %tbody
- %tr
- %td
- %label Current Login IP
- %td
- = @user.current_login_ip
- %tr
- %td
- %label Current Login at
- %td
- = @user.current_login_at
- %tr
- %td
- %label Last Login IP
- %td
- = @user.last_login_ip
- %tr
- %td
- %label Last Login at
- %td
- = @user.last_login_at
- %tr
- %td
- %label Login Count
- %td
- = @user.login_count
- %tr
- %td
- %label Failed Login Count
- %td
- = @user.login_count
- %tr
- %td
- %label Last Request at
- %td
- = @user.last_request_at
diff --git a/src/config/environment.rb b/src/config/environment.rb
index 09ec85b..6b21c42 100644
--- a/src/config/environment.rb
+++ b/src/config/environment.rb
@@ -51,7 +51,7 @@ Rails::Initializer.run do |config|
config.gem "compass-960-plugin", :lib => "ninesixty"
config.gem "simple-navigation"
config.gem "typhoeus"
- config.gem "rb-inotify"
+ #config.gem "rb-inotify"
config.gem 'rack-restful_submit', :version => '1.1.2'
config.middleware.swap Rack::MethodOverride, 'Rack::RestfulSubmit'
diff --git a/src/features/user.feature b/src/features/user.feature
index 2160ed1..89dd7d5 100644
--- a/src/features/user.feature
+++ b/src/features/user.feature
@@ -12,7 +12,8 @@ Feature: Manage Users
Scenario: Change the password
Given I am on the admin users page
And there is a user "testuser"
- When I follow "edit"
+ When I follow "testuser"
+ And I follow "Edit"
Then I should see "Editing User:"
When I fill in "user[password]" with "new password"
And I fill in "user[password_confirmation]" with ""
--
1.7.3.2
13 years, 5 months