##// END OF EJS Templates
Preserve status filter and page number when using lock/unlock/activate links on the users list (closes #998)....
Jean-Philippe Lang -
r1319:0249ae5f5000
parent child
Show More
@@ -1,112 +1,113
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 layout 'base'
19 layout 'base'
20 before_filter :require_admin
20 before_filter :require_admin
21
21
22 helper :sort
22 helper :sort
23 include SortHelper
23 include SortHelper
24 helper :custom_fields
24 helper :custom_fields
25 include CustomFieldsHelper
25 include CustomFieldsHelper
26
26
27 def index
27 def index
28 list
28 list
29 render :action => 'list' unless request.xhr?
29 render :action => 'list' unless request.xhr?
30 end
30 end
31
31
32 def list
32 def list
33 sort_init 'login', 'asc'
33 sort_init 'login', 'asc'
34 sort_update
34 sort_update
35
35
36 @status = params[:status] ? params[:status].to_i : 1
36 @status = params[:status] ? params[:status].to_i : 1
37 conditions = "status <> 0"
37 conditions = "status <> 0"
38 conditions = ["status=?", @status] unless @status == 0
38 conditions = ["status=?", @status] unless @status == 0
39
39
40 @user_count = User.count(:conditions => conditions)
40 @user_count = User.count(:conditions => conditions)
41 @user_pages = Paginator.new self, @user_count,
41 @user_pages = Paginator.new self, @user_count,
42 per_page_option,
42 per_page_option,
43 params['page']
43 params['page']
44 @users = User.find :all,:order => sort_clause,
44 @users = User.find :all,:order => sort_clause,
45 :conditions => conditions,
45 :conditions => conditions,
46 :limit => @user_pages.items_per_page,
46 :limit => @user_pages.items_per_page,
47 :offset => @user_pages.current.offset
47 :offset => @user_pages.current.offset
48
48
49 render :action => "list", :layout => false if request.xhr?
49 render :action => "list", :layout => false if request.xhr?
50 end
50 end
51
51
52 def add
52 def add
53 if request.get?
53 if request.get?
54 @user = User.new(:language => Setting.default_language)
54 @user = User.new(:language => Setting.default_language)
55 @custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
55 @custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
56 else
56 else
57 @user = User.new(params[:user])
57 @user = User.new(params[:user])
58 @user.admin = params[:user][:admin] || false
58 @user.admin = params[:user][:admin] || false
59 @user.login = params[:user][:login]
59 @user.login = params[:user][:login]
60 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
60 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
61 @custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
61 @custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
62 @user.custom_values = @custom_values
62 @user.custom_values = @custom_values
63 if @user.save
63 if @user.save
64 Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
64 Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
65 flash[:notice] = l(:notice_successful_create)
65 flash[:notice] = l(:notice_successful_create)
66 redirect_to :action => 'list'
66 redirect_to :action => 'list'
67 end
67 end
68 end
68 end
69 @auth_sources = AuthSource.find(:all)
69 @auth_sources = AuthSource.find(:all)
70 end
70 end
71
71
72 def edit
72 def edit
73 @user = User.find(params[:id])
73 @user = User.find(params[:id])
74 if request.get?
74 if request.get?
75 @custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @user.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
75 @custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @user.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
76 else
76 else
77 @user.admin = params[:user][:admin] if params[:user][:admin]
77 @user.admin = params[:user][:admin] if params[:user][:admin]
78 @user.login = params[:user][:login] if params[:user][:login]
78 @user.login = params[:user][:login] if params[:user][:login]
79 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
79 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
80 if params[:custom_fields]
80 if params[:custom_fields]
81 @custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
81 @custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
82 @user.custom_values = @custom_values
82 @user.custom_values = @custom_values
83 end
83 end
84 if @user.update_attributes(params[:user])
84 if @user.update_attributes(params[:user])
85 flash[:notice] = l(:notice_successful_update)
85 flash[:notice] = l(:notice_successful_update)
86 redirect_to :action => 'list'
86 # Give a string to redirect_to otherwise it would use status param as the response code
87 redirect_to(url_for(:action => 'list', :status => params[:status], :page => params[:page]))
87 end
88 end
88 end
89 end
89 @auth_sources = AuthSource.find(:all)
90 @auth_sources = AuthSource.find(:all)
90 @roles = Role.find_all_givable
91 @roles = Role.find_all_givable
91 @projects = Project.find(:all, :order => 'name', :conditions => "status=#{Project::STATUS_ACTIVE}") - @user.projects
92 @projects = Project.find(:all, :order => 'name', :conditions => "status=#{Project::STATUS_ACTIVE}") - @user.projects
92 @membership ||= Member.new
93 @membership ||= Member.new
93 end
94 end
94
95
95 def edit_membership
96 def edit_membership
96 @user = User.find(params[:id])
97 @user = User.find(params[:id])
97 @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:user => @user)
98 @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:user => @user)
98 @membership.attributes = params[:membership]
99 @membership.attributes = params[:membership]
99 if request.post? and @membership.save
100 if request.post? and @membership.save
100 flash[:notice] = l(:notice_successful_update)
101 flash[:notice] = l(:notice_successful_update)
101 end
102 end
102 redirect_to :action => 'edit', :id => @user and return
103 redirect_to :action => 'edit', :id => @user and return
103 end
104 end
104
105
105 def destroy_membership
106 def destroy_membership
106 @user = User.find(params[:id])
107 @user = User.find(params[:id])
107 if request.post? and Member.find(params[:membership_id]).destroy
108 if request.post? and Member.find(params[:membership_id]).destroy
108 flash[:notice] = l(:notice_successful_update)
109 flash[:notice] = l(:notice_successful_update)
109 end
110 end
110 redirect_to :action => 'edit', :id => @user and return
111 redirect_to :action => 'edit', :id => @user and return
111 end
112 end
112 end
113 end
@@ -1,25 +1,37
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 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 module UsersHelper
18 module UsersHelper
19 def status_options_for_select(selected)
19 def status_options_for_select(selected)
20 options_for_select([[l(:label_all), ''],
20 options_for_select([[l(:label_all), ''],
21 [l(:status_active), 1],
21 [l(:status_active), 1],
22 [l(:status_registered), 2],
22 [l(:status_registered), 2],
23 [l(:status_locked), 3]], selected)
23 [l(:status_locked), 3]], selected)
24 end
24 end
25
26 def change_status_link(user)
27 url = {:action => 'edit', :id => user, :page => params[:page], :status => params[:status]}
28
29 if user.locked?
30 link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock'
31 elsif user.registered?
32 link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :post, :class => 'icon icon-unlock'
33 else
34 link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :post, :class => 'icon icon-lock'
35 end
36 end
25 end
37 end
@@ -1,54 +1,44
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', status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %>
10 <%= select_tag 'status', status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %>
11 </fieldset>
11 </fieldset>
12 <% end %>
12 <% end %>
13 &nbsp;
13 &nbsp;
14
14
15 <table class="list">
15 <table class="list">
16 <thead><tr>
16 <thead><tr>
17 <%= sort_header_tag('login', :caption => l(:field_login)) %>
17 <%= sort_header_tag('login', :caption => l(:field_login)) %>
18 <%= sort_header_tag('firstname', :caption => l(:field_firstname)) %>
18 <%= sort_header_tag('firstname', :caption => l(:field_firstname)) %>
19 <%= sort_header_tag('lastname', :caption => l(:field_lastname)) %>
19 <%= sort_header_tag('lastname', :caption => l(:field_lastname)) %>
20 <%= sort_header_tag('mail', :caption => l(:field_mail)) %>
20 <%= sort_header_tag('mail', :caption => l(:field_mail)) %>
21 <%= sort_header_tag('admin', :caption => l(:field_admin), :default_order => 'desc') %>
21 <%= 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') %>
22 <%= 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') %>
23 <%= sort_header_tag('last_login_on', :caption => l(:field_last_login_on), :default_order => 'desc') %>
24 <th></th>
24 <th></th>
25 </tr></thead>
25 </tr></thead>
26 <tbody>
26 <tbody>
27 <% for user in @users -%>
27 <% for user in @users -%>
28 <tr class="user <%= cycle("odd", "even") %> <%= %w(anon active registered locked)[user.status] %>">
28 <tr class="user <%= cycle("odd", "even") %> <%= %w(anon active registered locked)[user.status] %>">
29 <td class="username"><%= link_to user.login, :action => 'edit', :id => user %></td>
29 <td class="username"><%= link_to user.login, :action => 'edit', :id => user %></td>
30 <td class="firstname"><%= user.firstname %></td>
30 <td class="firstname"><%= user.firstname %></td>
31 <td class="lastname"><%= user.lastname %></td>
31 <td class="lastname"><%= user.lastname %></td>
32 <td class="email"><%= user.mail %></td>
32 <td class="email"><%= user.mail %></td>
33 <td align="center"><%= image_tag('true.png') if user.admin? %></td>
33 <td align="center"><%= image_tag('true.png') if user.admin? %></td>
34 <td class="created_on" align="center"><%= format_time(user.created_on) %></td>
34 <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>
35 <td class="last_login_on" align="center"><%= format_time(user.last_login_on) unless user.last_login_on.nil? %></td>
36 <td>
36 <td><small><%= change_status_link(user) %></small></td>
37 <small>
38 <% if user.locked? -%>
39 <%= link_to l(:button_unlock), {:action => 'edit', :id => user, :user => {:status => User::STATUS_ACTIVE}}, :method => :post, :class => 'icon icon-unlock' %>
40 <% elsif user.registered? -%>
41 <%= link_to l(:button_activate), {:action => 'edit', :id => user, :user => {:status => User::STATUS_ACTIVE}}, :method => :post, :class => 'icon icon-unlock' %>
42 <% else -%>
43 <%= link_to l(:button_lock), {:action => 'edit', :id => user, :user => {:status => User::STATUS_LOCKED}}, :method => :post, :class => 'icon icon-lock' %>
44 <% end -%>
45 </small>
46 </td>
47 </tr>
37 </tr>
48 <% end -%>
38 <% end -%>
49 </tbody>
39 </tbody>
50 </table>
40 </table>
51
41
52 <p class="pagination"><%= pagination_links_full @user_pages, @user_count %></p>
42 <p class="pagination"><%= pagination_links_full @user_pages, @user_count %></p>
53
43
54 <% html_title(l(:label_user_plural)) -%>
44 <% html_title(l(:label_user_plural)) -%>
General Comments 0
You need to be logged in to leave comments. Login now