##// END OF EJS Templates
Adds the ability to search for a user on the administration users list....
Jean-Philippe Lang -
r1943:d967507dcb20
parent child
Show More
@@ -1,100 +1,104
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class UsersController < ApplicationController
19 19 before_filter :require_admin
20 20
21 21 helper :sort
22 22 include SortHelper
23 23 helper :custom_fields
24 24 include CustomFieldsHelper
25 25
26 26 def index
27 27 list
28 28 render :action => 'list' unless request.xhr?
29 29 end
30 30
31 31 def list
32 32 sort_init 'login', 'asc'
33 33 sort_update
34 34
35 35 @status = params[:status] ? params[:status].to_i : 1
36 conditions = "status <> 0"
37 conditions = ["status=?", @status] unless @status == 0
36 c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status])
37
38 unless params[:name].blank?
39 name = "%#{params[:name].strip.downcase}%"
40 c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ?", name, name, name]
41 end
38 42
39 @user_count = User.count(:conditions => conditions)
43 @user_count = User.count(:conditions => c.conditions)
40 44 @user_pages = Paginator.new self, @user_count,
41 45 per_page_option,
42 46 params['page']
43 47 @users = User.find :all,:order => sort_clause,
44 :conditions => conditions,
48 :conditions => c.conditions,
45 49 :limit => @user_pages.items_per_page,
46 50 :offset => @user_pages.current.offset
47 51
48 52 render :action => "list", :layout => false if request.xhr?
49 53 end
50 54
51 55 def add
52 56 if request.get?
53 57 @user = User.new(:language => Setting.default_language)
54 58 else
55 59 @user = User.new(params[:user])
56 60 @user.admin = params[:user][:admin] || false
57 61 @user.login = params[:user][:login]
58 62 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
59 63 if @user.save
60 64 Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
61 65 flash[:notice] = l(:notice_successful_create)
62 66 redirect_to :action => 'list'
63 67 end
64 68 end
65 69 @auth_sources = AuthSource.find(:all)
66 70 end
67 71
68 72 def edit
69 73 @user = User.find(params[:id])
70 74 if request.post?
71 75 @user.admin = params[:user][:admin] if params[:user][:admin]
72 76 @user.login = params[:user][:login] if params[:user][:login]
73 77 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
74 78 if @user.update_attributes(params[:user])
75 79 flash[:notice] = l(:notice_successful_update)
76 80 # Give a string to redirect_to otherwise it would use status param as the response code
77 81 redirect_to(url_for(:action => 'list', :status => params[:status], :page => params[:page]))
78 82 end
79 83 end
80 84 @auth_sources = AuthSource.find(:all)
81 85 @roles = Role.find_all_givable
82 86 @projects = Project.find(:all, :order => 'name', :conditions => "status=#{Project::STATUS_ACTIVE}") - @user.projects
83 87 @membership ||= Member.new
84 88 @memberships = @user.memberships
85 89 end
86 90
87 91 def edit_membership
88 92 @user = User.find(params[:id])
89 93 @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:user => @user)
90 94 @membership.attributes = params[:membership]
91 95 @membership.save if request.post?
92 96 redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
93 97 end
94 98
95 99 def destroy_membership
96 100 @user = User.find(params[:id])
97 101 Member.find(params[:membership_id]).destroy if request.post?
98 102 redirect_to :action => 'edit', :id => @user, :tab => 'memberships'
99 103 end
100 104 end
@@ -1,44 +1,47
1 1 <div class="contextual">
2 2 <%= link_to l(:label_user_new), {:action => 'add'}, :class => 'icon icon-add' %>
3 3 </div>
4 4
5 5 <h2><%=l(:label_user_plural)%></h2>
6 6
7 7 <% form_tag({}, :method => :get) do %>
8 8 <fieldset><legend><%= l(:label_filter_plural) %></legend>
9 <label><%= l(:field_status) %> :</label>
9 <label><%= l(:field_status) %>:</label>
10 10 <%= select_tag 'status', users_status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %>
11 <label><%= l(:label_user) %>:</label>
12 <%= text_field_tag 'name', params[:name], :size => 30 %>
13 <%= submit_tag l(:button_apply), :class => "small", :name => nil %>
11 14 </fieldset>
12 15 <% end %>
13 16 &nbsp;
14 17
15 18 <table class="list">
16 19 <thead><tr>
17 20 <%= sort_header_tag('login', :caption => l(:field_login)) %>
18 21 <%= sort_header_tag('firstname', :caption => l(:field_firstname)) %>
19 22 <%= sort_header_tag('lastname', :caption => l(:field_lastname)) %>
20 23 <%= sort_header_tag('mail', :caption => l(:field_mail)) %>
21 24 <%= sort_header_tag('admin', :caption => l(:field_admin), :default_order => 'desc') %>
22 25 <%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %>
23 26 <%= sort_header_tag('last_login_on', :caption => l(:field_last_login_on), :default_order => 'desc') %>
24 27 <th></th>
25 28 </tr></thead>
26 29 <tbody>
27 30 <% for user in @users -%>
28 31 <tr class="user <%= cycle("odd", "even") %> <%= %w(anon active registered locked)[user.status] %>">
29 32 <td class="username"><%= link_to h(user.login), :action => 'edit', :id => user %></td>
30 33 <td class="firstname"><%= h(user.firstname) %></td>
31 34 <td class="lastname"><%= h(user.lastname) %></td>
32 35 <td class="email"><%= mail_to(h(user.mail)) %></td>
33 36 <td align="center"><%= image_tag('true.png') if user.admin? %></td>
34 37 <td class="created_on" align="center"><%= format_time(user.created_on) %></td>
35 38 <td class="last_login_on" align="center"><%= format_time(user.last_login_on) unless user.last_login_on.nil? %></td>
36 39 <td><small><%= change_status_link(user) %></small></td>
37 40 </tr>
38 41 <% end -%>
39 42 </tbody>
40 43 </table>
41 44
42 45 <p class="pagination"><%= pagination_links_full @user_pages, @user_count %></p>
43 46
44 47 <% html_title(l(:label_user_plural)) -%>
General Comments 0
You need to be logged in to leave comments. Login now