@@ -1,5 +1,5 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 |
# Copyright (C) 2006-201 |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
@@ -38,6 +38,9 class UsersController < ApplicationController | |||||
38 | @limit = per_page_option |
|
38 | @limit = per_page_option | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
|
41 | scope = User | |||
|
42 | scope = scope.in_group(params[:group_id].to_i) if params[:group_id].present? | |||
|
43 | ||||
41 | @status = params[:status] ? params[:status].to_i : 1 |
|
44 | @status = params[:status] ? params[:status].to_i : 1 | |
42 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) |
|
45 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) | |
43 |
|
46 | |||
@@ -46,17 +49,20 class UsersController < ApplicationController | |||||
46 | c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name] |
|
49 | c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name] | |
47 | end |
|
50 | end | |
48 |
|
51 | |||
49 |
@user_count = |
|
52 | @user_count = scope.count(:conditions => c.conditions) | |
50 | @user_pages = Paginator.new self, @user_count, @limit, params['page'] |
|
53 | @user_pages = Paginator.new self, @user_count, @limit, params['page'] | |
51 | @offset ||= @user_pages.current.offset |
|
54 | @offset ||= @user_pages.current.offset | |
52 |
@users = |
|
55 | @users = scope.find :all, | |
53 | :order => sort_clause, |
|
56 | :order => sort_clause, | |
54 | :conditions => c.conditions, |
|
57 | :conditions => c.conditions, | |
55 | :limit => @limit, |
|
58 | :limit => @limit, | |
56 | :offset => @offset |
|
59 | :offset => @offset | |
57 |
|
60 | |||
58 | respond_to do |format| |
|
61 | respond_to do |format| | |
59 | format.html { render :layout => !request.xhr? } |
|
62 | format.html { | |
|
63 | @groups = Group.all.sort | |||
|
64 | render :layout => !request.xhr? | |||
|
65 | } | |||
60 | format.api |
|
66 | format.api | |
61 | end |
|
67 | end | |
62 | end |
|
68 | end |
@@ -76,6 +76,11 class User < Principal | |||||
76 |
|
76 | |||
77 | before_destroy :remove_references_before_destroy |
|
77 | before_destroy :remove_references_before_destroy | |
78 |
|
78 | |||
|
79 | named_scope :in_group, lambda {|group| | |||
|
80 | group_id = group.is_a?(Group) ? group.id : group.to_i | |||
|
81 | { :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] } | |||
|
82 | } | |||
|
83 | ||||
79 | def before_create |
|
84 | def before_create | |
80 | self.mail_notification = Setting.default_notification_option if self.mail_notification.blank? |
|
85 | self.mail_notification = Setting.default_notification_option if self.mail_notification.blank? | |
81 | true |
|
86 | true |
@@ -8,6 +8,12 | |||||
8 | <fieldset><legend><%= l(:label_filter_plural) %></legend> |
|
8 | <fieldset><legend><%= l(:label_filter_plural) %></legend> | |
9 | <label><%= l(:field_status) %>:</label> |
|
9 | <label><%= l(:field_status) %>:</label> | |
10 | <%= select_tag 'status', users_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %> |
|
10 | <%= select_tag 'status', users_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %> | |
|
11 | ||||
|
12 | <% if @groups.present? %> | |||
|
13 | <label><%= l(:label_group) %>:</label> | |||
|
14 | <%= 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;" %> | |||
|
15 | <% end %> | |||
|
16 | ||||
11 | <label><%= l(:label_user) %>:</label> |
|
17 | <label><%= l(:label_user) %>:</label> | |
12 | <%= text_field_tag 'name', params[:name], :size => 30 %> |
|
18 | <%= text_field_tag 'name', params[:name], :size => 30 %> | |
13 | <%= submit_tag l(:button_apply), :class => "small", :name => nil %> |
|
19 | <%= submit_tag l(:button_apply), :class => "small", :name => nil %> |
@@ -1,5 +1,5 | |||||
1 |
# |
|
1 | # Redmine - project management software | |
2 |
# Copyright (C) 2006-20 |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # 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 | |||||
24 | class UsersControllerTest < ActionController::TestCase |
|
24 | class UsersControllerTest < ActionController::TestCase | |
25 | include Redmine::I18n |
|
25 | include Redmine::I18n | |
26 |
|
26 | |||
27 | fixtures :users, :projects, :members, :member_roles, :roles, :auth_sources, :custom_fields, :custom_values |
|
27 | fixtures :users, :projects, :members, :member_roles, :roles, :auth_sources, :custom_fields, :custom_values, :groups_users | |
28 |
|
28 | |||
29 | def setup |
|
29 | def setup | |
30 | @controller = UsersController.new |
|
30 | @controller = UsersController.new | |
@@ -59,6 +59,15 class UsersControllerTest < ActionController::TestCase | |||||
59 | assert_equal 'John', users.first.firstname |
|
59 | assert_equal 'John', users.first.firstname | |
60 | end |
|
60 | end | |
61 |
|
61 | |||
|
62 | def test_index_with_group_filter | |||
|
63 | get :index, :group_id => '10' | |||
|
64 | assert_response :success | |||
|
65 | assert_template 'index' | |||
|
66 | users = assigns(:users) | |||
|
67 | assert users.any? | |||
|
68 | assert_equal([], (users - Group.find(10).users)) | |||
|
69 | end | |||
|
70 | ||||
62 | def test_show |
|
71 | def test_show | |
63 | @request.session[:user_id] = nil |
|
72 | @request.session[:user_id] = nil | |
64 | get :show, :id => 2 |
|
73 | get :show, :id => 2 |
General Comments 0
You need to be logged in to leave comments.
Login now