Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
made global users list show only superusers and site admins,\nadded a…
… link to that page to the global menu
  • Loading branch information
mseppae authored and Sven Fuchs committed Jul 29, 2008
1 parent 36d6fd6 commit bdbb694
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 7 deletions.
13 changes: 12 additions & 1 deletion spec/controllers/admin/users_controller_spec.rb
Expand Up @@ -39,13 +39,24 @@
it_guards_permissions :show, :user # TODO depending on scope superuser or admin is required!
it_assigns :users
it_renders_template :index

if scope.blank?
it "fetches users from User.admins_and_superusers" do
User.should_receive(:admins_and_superusers).and_return @users
act!
end
else
it "fetches users from @site.users_and_superusers" do
@site.should_receive(:users_and_superusers).and_return @users
act!
end
end
end

describe "GET to :show" do
act! { request_to :get, @member_path }
it_assigns :user
it_renders_template :show

end

describe "GET to :new" do
Expand Down
13 changes: 11 additions & 2 deletions spec/models/user_spec.rb
Expand Up @@ -132,12 +132,21 @@

it '.superusers returns all superusers' do
User.should_receive(:find) do |arg, options|
arg == :all &&
(options[:conditions] & ['roles.type = ?', 'Role::Superuser']).size == 2 &&
arg == :all and
options[:conditions] == ['roles.type = ?', 'Role::Superuser'] and
Array(options[:include]).include?(:roles)
end
User.superusers
end

it '.admins_and_superusers returns all site admins and superusers' do
User.should_receive(:find) do |arg, options|
arg == :all and
options[:conditions] == ['roles.type IN (?)', ['Role::Superuser', 'Role::Admin']] and
Array(options[:include]).include?(:roles)
end
User.admins_and_superusers
end

describe '.create_superuser' do
before :each do
Expand Down
2 changes: 2 additions & 0 deletions spec/scenarios/site_with_a_user.rb
Expand Up @@ -3,9 +3,11 @@

@user = stub_user
@users = stub_users
@users.stub!(:paginate).and_return @users

User.stub!(:new).and_return @user
User.stub!(:find).and_return @user
User.stub!(:paginate).and_return @users
User.stub!(:admins_and_superusers).and_return @users
Site.stub!(:paginate_users_and_superusers).and_return @users
end
31 changes: 31 additions & 0 deletions spec/views/widgets_spec.rb
@@ -0,0 +1,31 @@
require File.dirname(__FILE__) + '/../spec_helper'
require 'base_helper'

describe "Widgets:", "the admin/menu_global widget" do
include SpecViewHelper

describe "the link to the global user list" do
before :each do
@user = stub_user
template.stub!(:current_user).and_return @user

template.stub!(:site_select_tag).and_return('site_select_tag')
template.stub!(:admin_plugins_path).and_return('admin_plugins_path')
template.stub!(:admin_site_user_path).and_return('admin_site_user_path')
template.stub!(:admin_user_path).and_return('admin_user_path')
template.stub!(:logout_path).and_return('logout_path')
end

it "should be visible when the user is a superuser" do
@user.should_receive(:has_role?).with(:superuser).and_return true
render 'widgets/admin/_menu_global'
response.should have_tag('a[href=?]', '/admin/users')
end

it "should not be visible when the user is not a superuser" do
@user.should_receive(:has_role?).with(:superuser).and_return false
render 'widgets/admin/_menu_global'
response.should_not have_tag('a[href=?]', '/admin/users')
end
end
end
24 changes: 23 additions & 1 deletion stories/steps/user.rb
Expand Up @@ -28,9 +28,25 @@
@site.users << @other_user
end

Given "a site admin and a site member account" do
@site ||= Site.find(:first) || create_site

@admin = create_user :name => 'admin name', :email => 'admin@email.org', :login => 'admin-login', :password => 'password', :password_confirmation => 'password'
@site.users << @admin
@admin.roles << Role.build(:admin, @site)

@user = create_user :name => 'another user name', :email => 'another_user@email.org', :login => 'another-login', :password => 'password', :password_confirmation => 'password'
@site.users << @user
end

# ADMIN VIEWS

When "the user visits the admin site user list page" do
When "the user visits the global user list in the admin interface" do
get admin_users_path
response.should be_success
end

When "the user visits the site's user list in the admin interface" do
get admin_site_users_path(@site)
response.should be_success
end
Expand Down Expand Up @@ -67,6 +83,12 @@
@other_user.name.should == 'an updated name'
end

Then "the page shows a list of users with $count entries" do |count|
response.should have_tag('ul[class=?]', 'users') do |ul|
ul.should have_tag('li', :count => count.to_i)
end
end

Then "the page has an admin user account creation form" do
action = admin_site_users_path(@site)
response.should have_form_posting_to(action)
Expand Down
18 changes: 16 additions & 2 deletions stories/stories/admin/user.txt
Expand Up @@ -5,7 +5,7 @@ Story: Managing users
Scenario: An admin creates a new user account
Given a site
And the user is logged in as admin
When the user visits the admin site user list page
When the user visits the site's user list in the admin interface
And the user clicks on 'Add user'
Then the page has an admin user account creation form
When the user fills in the admin user account creation form with valid values
Expand All @@ -24,4 +24,18 @@ Story: Managing users
When the user fills in name with 'an updated name'
And the user clicks the 'Save' button
Then the other user's name is 'an updated name'
And the user is redirected to the admin site user show page
And the user is redirected to the admin site user show page

Scenario: A superuser reviews the global users list
Given a site
And the user is logged in as superuser
And a site admin and a site member account
When the user visits the global user list in the admin interface
Then the page shows a list of users with 2 entries

Scenario: A superuser reviews a site's users list
Given a site
And the user is logged in as superuser
And a site admin and a site member account
When the user visits the site's user list in the admin interface
Then the page shows a list of users with 3 entries
Expand Up @@ -5,6 +5,10 @@
<% unless @site.nil? %>
<li><%= link_to 'Plugins', admin_plugins_path(@site) %></li>
<% end %>
<li>Global:</li>
<% if current_user.has_role?(:superuser) %>
<li><%= link_to 'Users', admin_users_path %></li>
<% end %>
<li>Logged in as: <%= link_to current_user.name, (@site ? admin_site_user_path(@site, current_user) : admin_user_path(current_user)) %></li>
<li><%= link_to 'Logout', logout_path, :method => :delete %></li>
</ul>
Expand Up @@ -65,7 +65,7 @@ def set_users
@users = if @site
@site.users_and_superusers.paginate :page => current_page
else
User.paginate :page => current_page
User.admins_and_superusers.paginate :page => current_page
end
end

Expand Down
4 changes: 4 additions & 0 deletions vendor/engines/adva_user/app/models/user.rb
Expand Up @@ -40,6 +40,10 @@ def superusers
find :all, :include => :roles, :conditions => ['roles.type = ?', 'Role::Superuser']
end

def admins_and_superusers
find :all, :include => :roles, :conditions => ['roles.type IN (?)', ['Role::Superuser', 'Role::Admin']]
end

def create_superuser(params)
user = User.new(params)
user.verified_at = Time.zone.now
Expand Down

0 comments on commit bdbb694

Please sign in to comment.