@@ -1,144 +1,146 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2009 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 'admin' |
|
19 | layout 'admin' | |
20 |
|
20 | |||
21 | before_filter :require_admin, :except => :show |
|
21 | before_filter :require_admin, :except => :show | |
22 |
|
22 | |||
23 | helper :sort |
|
23 | helper :sort | |
24 | include SortHelper |
|
24 | include SortHelper | |
25 | helper :custom_fields |
|
25 | helper :custom_fields | |
26 | include CustomFieldsHelper |
|
26 | include CustomFieldsHelper | |
27 |
|
27 | |||
28 | def index |
|
28 | def index | |
29 | sort_init 'login', 'asc' |
|
29 | sort_init 'login', 'asc' | |
30 | sort_update %w(login firstname lastname mail admin created_on last_login_on) |
|
30 | sort_update %w(login firstname lastname mail admin created_on last_login_on) | |
31 |
|
31 | |||
32 | @status = params[:status] ? params[:status].to_i : 1 |
|
32 | @status = params[:status] ? params[:status].to_i : 1 | |
33 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) |
|
33 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) | |
34 |
|
34 | |||
35 | unless params[:name].blank? |
|
35 | unless params[:name].blank? | |
36 | name = "%#{params[:name].strip.downcase}%" |
|
36 | name = "%#{params[:name].strip.downcase}%" | |
37 | c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name] |
|
37 | c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name] | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | @user_count = User.count(:conditions => c.conditions) |
|
40 | @user_count = User.count(:conditions => c.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 => c.conditions, |
|
45 | :conditions => c.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 :layout => !request.xhr? |
|
49 | render :layout => !request.xhr? | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def show |
|
52 | def show | |
53 | @user = User.active.find(params[:id]) |
|
53 | @user = User.active.find(params[:id]) | |
54 | @custom_values = @user.custom_values |
|
54 | @custom_values = @user.custom_values | |
55 |
|
55 | |||
56 | # show only public projects and private projects that the logged in user is also a member of |
|
56 | # show only public projects and private projects that the logged in user is also a member of | |
57 | @memberships = @user.memberships.select do |membership| |
|
57 | @memberships = @user.memberships.select do |membership| | |
58 | membership.project.is_public? || (User.current.member_of?(membership.project)) |
|
58 | membership.project.is_public? || (User.current.member_of?(membership.project)) | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) |
|
61 | events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) | |
62 | @events_by_day = events.group_by(&:event_date) |
|
62 | @events_by_day = events.group_by(&:event_date) | |
63 |
|
63 | |||
64 | if @user != User.current && !User.current.admin? && @memberships.empty? && events.empty? |
|
64 | if @user != User.current && !User.current.admin? && @memberships.empty? && events.empty? | |
65 | render_404 |
|
65 | render_404 | |
66 | return |
|
66 | return | |
67 | end |
|
67 | end | |
68 | render :layout => 'base' |
|
68 | render :layout => 'base' | |
69 |
|
69 | |||
70 | rescue ActiveRecord::RecordNotFound |
|
70 | rescue ActiveRecord::RecordNotFound | |
71 | render_404 |
|
71 | render_404 | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def add |
|
74 | def add | |
75 | if request.get? |
|
75 | if request.get? | |
76 | @user = User.new(:language => Setting.default_language) |
|
76 | @user = User.new(:language => Setting.default_language) | |
77 | else |
|
77 | else | |
78 | @user = User.new(params[:user]) |
|
78 | @user = User.new(params[:user]) | |
79 | @user.admin = params[:user][:admin] || false |
|
79 | @user.admin = params[:user][:admin] || false | |
80 | @user.login = params[:user][:login] |
|
80 | @user.login = params[:user][:login] | |
81 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id |
|
81 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id | |
82 | if @user.save |
|
82 | if @user.save | |
83 | Mailer.deliver_account_information(@user, params[:password]) if params[:send_information] |
|
83 | Mailer.deliver_account_information(@user, params[:password]) if params[:send_information] | |
84 | flash[:notice] = l(:notice_successful_create) |
|
84 | flash[:notice] = l(:notice_successful_create) | |
85 |
redirect_to :controller => 'users', :action => ' |
|
85 | redirect_to(params[:continue] ? {:controller => 'users', :action => 'add'} : | |
|
86 | {:controller => 'users', :action => 'edit', :id => @user}) | |||
|
87 | return | |||
86 | end |
|
88 | end | |
87 | end |
|
89 | end | |
88 | @auth_sources = AuthSource.find(:all) |
|
90 | @auth_sources = AuthSource.find(:all) | |
89 | end |
|
91 | end | |
90 |
|
92 | |||
91 | def edit |
|
93 | def edit | |
92 | @user = User.find(params[:id]) |
|
94 | @user = User.find(params[:id]) | |
93 | if request.post? |
|
95 | if request.post? | |
94 | @user.admin = params[:user][:admin] if params[:user][:admin] |
|
96 | @user.admin = params[:user][:admin] if params[:user][:admin] | |
95 | @user.login = params[:user][:login] if params[:user][:login] |
|
97 | @user.login = params[:user][:login] if params[:user][:login] | |
96 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id |
|
98 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id | |
97 | @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids] |
|
99 | @user.group_ids = params[:user][:group_ids] if params[:user][:group_ids] | |
98 | @user.attributes = params[:user] |
|
100 | @user.attributes = params[:user] | |
99 | # Was the account actived ? (do it before User#save clears the change) |
|
101 | # Was the account actived ? (do it before User#save clears the change) | |
100 | was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) |
|
102 | was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) | |
101 | if @user.save |
|
103 | if @user.save | |
102 | if was_activated |
|
104 | if was_activated | |
103 | Mailer.deliver_account_activated(@user) |
|
105 | Mailer.deliver_account_activated(@user) | |
104 | elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil? |
|
106 | elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil? | |
105 | Mailer.deliver_account_information(@user, params[:password]) |
|
107 | Mailer.deliver_account_information(@user, params[:password]) | |
106 | end |
|
108 | end | |
107 | flash[:notice] = l(:notice_successful_update) |
|
109 | flash[:notice] = l(:notice_successful_update) | |
108 | redirect_to :back |
|
110 | redirect_to :back | |
109 | end |
|
111 | end | |
110 | end |
|
112 | end | |
111 | @auth_sources = AuthSource.find(:all) |
|
113 | @auth_sources = AuthSource.find(:all) | |
112 | @membership ||= Member.new |
|
114 | @membership ||= Member.new | |
113 | rescue ::ActionController::RedirectBackError |
|
115 | rescue ::ActionController::RedirectBackError | |
114 | redirect_to :controller => 'users', :action => 'edit', :id => @user |
|
116 | redirect_to :controller => 'users', :action => 'edit', :id => @user | |
115 | end |
|
117 | end | |
116 |
|
118 | |||
117 | def edit_membership |
|
119 | def edit_membership | |
118 | @user = User.find(params[:id]) |
|
120 | @user = User.find(params[:id]) | |
119 | @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:principal => @user) |
|
121 | @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:principal => @user) | |
120 | @membership.attributes = params[:membership] |
|
122 | @membership.attributes = params[:membership] | |
121 | @membership.save if request.post? |
|
123 | @membership.save if request.post? | |
122 | respond_to do |format| |
|
124 | respond_to do |format| | |
123 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } |
|
125 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } | |
124 | format.js { |
|
126 | format.js { | |
125 | render(:update) {|page| |
|
127 | render(:update) {|page| | |
126 | page.replace_html "tab-content-memberships", :partial => 'users/memberships' |
|
128 | page.replace_html "tab-content-memberships", :partial => 'users/memberships' | |
127 | page.visual_effect(:highlight, "member-#{@membership.id}") |
|
129 | page.visual_effect(:highlight, "member-#{@membership.id}") | |
128 | } |
|
130 | } | |
129 | } |
|
131 | } | |
130 | end |
|
132 | end | |
131 | end |
|
133 | end | |
132 |
|
134 | |||
133 | def destroy_membership |
|
135 | def destroy_membership | |
134 | @user = User.find(params[:id]) |
|
136 | @user = User.find(params[:id]) | |
135 | @membership = Member.find(params[:membership_id]) |
|
137 | @membership = Member.find(params[:membership_id]) | |
136 | if request.post? && @membership.deletable? |
|
138 | if request.post? && @membership.deletable? | |
137 | @membership.destroy |
|
139 | @membership.destroy | |
138 | end |
|
140 | end | |
139 | respond_to do |format| |
|
141 | respond_to do |format| | |
140 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } |
|
142 | format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } | |
141 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} } |
|
143 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} } | |
142 | end |
|
144 | end | |
143 | end |
|
145 | end | |
144 | end |
|
146 | end |
@@ -1,7 +1,10 | |||||
1 | <h2><%= link_to l(:label_user_plural), :controller => 'users', :action => 'index' %> » <%=l(:label_user_new)%></h2> |
|
1 | <h2><%= link_to l(:label_user_plural), :controller => 'users', :action => 'index' %> » <%=l(:label_user_new)%></h2> | |
2 |
|
2 | |||
3 | <% labelled_tabular_form_for :user, @user, :url => { :action => "add" }, :html => { :class => nil } do |f| %> |
|
3 | <% labelled_tabular_form_for :user, @user, :url => { :action => "add" }, :html => { :class => nil } do |f| %> | |
4 | <%= render :partial => 'form', :locals => { :f => f } %> |
|
4 | <%= render :partial => 'form', :locals => { :f => f } %> | |
5 | <p><label><%= check_box_tag 'send_information', 1, true %> <%= l(:label_send_information) %></label></p> |
|
5 | <p><label><%= check_box_tag 'send_information', 1, true %> <%= l(:label_send_information) %></label></p> | |
6 | <p><%= submit_tag l(:button_create) %></p> |
|
6 | <p> | |
|
7 | <%= submit_tag l(:button_create) %> | |||
|
8 | <%= submit_tag l(:button_create_and_continue), :name => 'continue' %> | |||
|
9 | </p> | |||
7 | <% end %> |
|
10 | <% end %> |
General Comments 0
You need to be logged in to leave comments.
Login now