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