Adds a Group filter on the admin users list (#7893).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5150 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
3c19cacf97
commit
4f8e8df6e0
|
@ -1,5 +1,5 @@
|
||||||
# Redmine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2010 Jean-Philippe Lang
|
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
|
@ -38,6 +38,9 @@ class UsersController < ApplicationController
|
||||||
@limit = per_page_option
|
@limit = per_page_option
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scope = User
|
||||||
|
scope = scope.in_group(params[:group_id].to_i) if params[:group_id].present?
|
||||||
|
|
||||||
@status = params[:status] ? params[:status].to_i : 1
|
@status = params[:status] ? params[:status].to_i : 1
|
||||||
c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
|
c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
|
||||||
|
|
||||||
|
@ -46,17 +49,20 @@ class UsersController < ApplicationController
|
||||||
c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name]
|
c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name]
|
||||||
end
|
end
|
||||||
|
|
||||||
@user_count = User.count(:conditions => c.conditions)
|
@user_count = scope.count(:conditions => c.conditions)
|
||||||
@user_pages = Paginator.new self, @user_count, @limit, params['page']
|
@user_pages = Paginator.new self, @user_count, @limit, params['page']
|
||||||
@offset ||= @user_pages.current.offset
|
@offset ||= @user_pages.current.offset
|
||||||
@users = User.find :all,
|
@users = scope.find :all,
|
||||||
:order => sort_clause,
|
:order => sort_clause,
|
||||||
:conditions => c.conditions,
|
:conditions => c.conditions,
|
||||||
:limit => @limit,
|
:limit => @limit,
|
||||||
:offset => @offset
|
:offset => @offset
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { render :layout => !request.xhr? }
|
format.html {
|
||||||
|
@groups = Group.all.sort
|
||||||
|
render :layout => !request.xhr?
|
||||||
|
}
|
||||||
format.api
|
format.api
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -74,6 +74,11 @@ class User < Principal
|
||||||
validates_confirmation_of :password, :allow_nil => true
|
validates_confirmation_of :password, :allow_nil => true
|
||||||
validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true
|
validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true
|
||||||
|
|
||||||
|
named_scope :in_group, lambda {|group|
|
||||||
|
group_id = group.is_a?(Group) ? group.id : group.to_i
|
||||||
|
{ :conditions => ["#{User.table_name}.id IN (SELECT gu.user_id FROM #{table_name_prefix}groups_users#{table_name_suffix} gu WHERE gu.group_id = ?)", group_id] }
|
||||||
|
}
|
||||||
|
|
||||||
def before_create
|
def before_create
|
||||||
self.mail_notification = Setting.default_notification_option if self.mail_notification.blank?
|
self.mail_notification = Setting.default_notification_option if self.mail_notification.blank?
|
||||||
true
|
true
|
||||||
|
|
|
@ -8,6 +8,12 @@
|
||||||
<fieldset><legend><%= l(:label_filter_plural) %></legend>
|
<fieldset><legend><%= l(:label_filter_plural) %></legend>
|
||||||
<label><%= l(:field_status) %>:</label>
|
<label><%= l(:field_status) %>:</label>
|
||||||
<%= select_tag 'status', users_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %>
|
<%= select_tag 'status', users_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %>
|
||||||
|
|
||||||
|
<% if @groups.present? %>
|
||||||
|
<label><%= l(:label_group) %>:</label>
|
||||||
|
<%= select_tag 'group_id', '<option></option>' + options_from_collection_for_select(@groups, :id, :name, params[:group_id].to_i), :onchange => "this.form.submit(); return false;" %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<label><%= l(:label_user) %>:</label>
|
<label><%= l(:label_user) %>:</label>
|
||||||
<%= text_field_tag 'name', params[:name], :size => 30 %>
|
<%= text_field_tag 'name', params[:name], :size => 30 %>
|
||||||
<%= submit_tag l(:button_apply), :class => "small", :name => nil %>
|
<%= submit_tag l(:button_apply), :class => "small", :name => nil %>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
|
@ -24,7 +24,7 @@ class UsersController; def rescue_action(e) raise e end; end
|
||||||
class UsersControllerTest < ActionController::TestCase
|
class UsersControllerTest < ActionController::TestCase
|
||||||
include Redmine::I18n
|
include Redmine::I18n
|
||||||
|
|
||||||
fixtures :users, :projects, :members, :member_roles, :roles, :auth_sources, :custom_fields, :custom_values
|
fixtures :users, :projects, :members, :member_roles, :roles, :auth_sources, :custom_fields, :custom_values, :groups_users
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@controller = UsersController.new
|
@controller = UsersController.new
|
||||||
|
@ -59,6 +59,15 @@ class UsersControllerTest < ActionController::TestCase
|
||||||
assert_equal 'John', users.first.firstname
|
assert_equal 'John', users.first.firstname
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_index_with_group_filter
|
||||||
|
get :index, :group_id => '10'
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'index'
|
||||||
|
users = assigns(:users)
|
||||||
|
assert users.any?
|
||||||
|
assert_equal([], (users - Group.find(10).users))
|
||||||
|
end
|
||||||
|
|
||||||
def test_show
|
def test_show
|
||||||
@request.session[:user_id] = nil
|
@request.session[:user_id] = nil
|
||||||
get :show, :id => 2
|
get :show, :id => 2
|
||||||
|
|
Loading…
Reference in New Issue