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