comparison app/controllers/users_controller.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children bb32da3bea34 622f24f53b42 261b3d9a4903
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 2 # Copyright (C) 2006-2012 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.
36 @offset, @limit = api_offset_and_limit 36 @offset, @limit = api_offset_and_limit
37 else 37 else
38 @limit = per_page_option 38 @limit = per_page_option
39 end 39 end
40 40
41 scope = User 41 @status = params[:status] || 1
42 scope = scope.in_group(params[:group_id].to_i) if params[:group_id].present? 42
43 43 scope = User.logged.status(@status)
44 @status = params[:status] ? params[:status].to_i : 1 44 scope = scope.like(params[:name]) if params[:name].present?
45 c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) 45 scope = scope.in_group(params[:group_id]) if params[:group_id].present?
46 46
47 unless params[:name].blank? 47 @user_count = scope.count
48 name = "%#{params[:name].strip.downcase}%"
49 c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?", name, name, name, name]
50 end
51
52 @user_count = scope.count(:conditions => c.conditions)
53 @user_pages = Paginator.new self, @user_count, @limit, params['page'] 48 @user_pages = Paginator.new self, @user_count, @limit, params['page']
54 @offset ||= @user_pages.current.offset 49 @offset ||= @user_pages.current.offset
55 @users = scope.find :all, 50 @users = scope.find :all,
56 :order => sort_clause, 51 :order => sort_clause,
57 :conditions => c.conditions,
58 :limit => @limit, 52 :limit => @limit,
59 :offset => @offset 53 :offset => @offset
60 54
61 respond_to do |format| 55 respond_to do |format|
62 format.html { 56 format.html {
90 def new 84 def new
91 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) 85 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
92 @auth_sources = AuthSource.find(:all) 86 @auth_sources = AuthSource.find(:all)
93 end 87 end
94 88
95 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
96 def create 89 def create
97 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) 90 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
98 @user.safe_attributes = params[:user] 91 @user.safe_attributes = params[:user]
99 @user.admin = params[:user][:admin] || false 92 @user.admin = params[:user][:admin] || false
100 @user.login = params[:user][:login] 93 @user.login = params[:user][:login]
101 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id 94 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id
102 95
103 # TODO: Similar to My#account
104 @user.pref.attributes = params[:pref]
105 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
106
107 if @user.save 96 if @user.save
97 @user.pref.attributes = params[:pref]
98 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
108 @user.pref.save 99 @user.pref.save
109 @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) 100 @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
110 101
111 Mailer.deliver_account_information(@user, params[:user][:password]) if params[:send_information] 102 Mailer.account_information(@user, params[:user][:password]).deliver if params[:send_information]
112 103
113 respond_to do |format| 104 respond_to do |format|
114 format.html { 105 format.html {
115 flash[:notice] = l(:notice_successful_create) 106 flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user)))
116 redirect_to(params[:continue] ? 107 redirect_to(params[:continue] ?
117 {:controller => 'users', :action => 'new'} : 108 {:controller => 'users', :action => 'new'} :
118 {:controller => 'users', :action => 'edit', :id => @user} 109 {:controller => 'users', :action => 'edit', :id => @user}
119 ) 110 )
120 } 111 }
135 def edit 126 def edit
136 @auth_sources = AuthSource.find(:all) 127 @auth_sources = AuthSource.find(:all)
137 @membership ||= Member.new 128 @membership ||= Member.new
138 end 129 end
139 130
140 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
141 def update 131 def update
142 @user.admin = params[:user][:admin] if params[:user][:admin] 132 @user.admin = params[:user][:admin] if params[:user][:admin]
143 @user.login = params[:user][:login] if params[:user][:login] 133 @user.login = params[:user][:login] if params[:user][:login]
144 if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?) 134 if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
145 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] 135 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation]
154 if @user.save 144 if @user.save
155 @user.pref.save 145 @user.pref.save
156 @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) 146 @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
157 147
158 if was_activated 148 if was_activated
159 Mailer.deliver_account_activated(@user) 149 Mailer.account_activated(@user).deliver
160 elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil? 150 elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil?
161 Mailer.deliver_account_information(@user, params[:user][:password]) 151 Mailer.account_information(@user, params[:user][:password]).deliver
162 end 152 end
163 153
164 respond_to do |format| 154 respond_to do |format|
165 format.html { 155 format.html {
166 flash[:notice] = l(:notice_successful_update) 156 flash[:notice] = l(:notice_successful_update)
167 redirect_to :back 157 redirect_to_referer_or edit_user_path(@user)
168 } 158 }
169 format.api { head :ok } 159 format.api { render_api_ok }
170 end 160 end
171 else 161 else
172 @auth_sources = AuthSource.find(:all) 162 @auth_sources = AuthSource.find(:all)
173 @membership ||= Member.new 163 @membership ||= Member.new
174 # Clear password input 164 # Clear password input
177 respond_to do |format| 167 respond_to do |format|
178 format.html { render :action => :edit } 168 format.html { render :action => :edit }
179 format.api { render_validation_errors(@user) } 169 format.api { render_validation_errors(@user) }
180 end 170 end
181 end 171 end
182 rescue ::ActionController::RedirectBackError 172 end
183 redirect_to :controller => 'users', :action => 'edit', :id => @user 173
184 end
185
186 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
187 def destroy 174 def destroy
188 @user.destroy 175 @user.destroy
189 respond_to do |format| 176 respond_to do |format|
190 format.html { redirect_to(users_url) } 177 format.html { redirect_back_or_default(users_url) }
191 format.api { head :ok } 178 format.api { render_api_ok }
192 end 179 end
193 end 180 end
194 181
195 def edit_membership 182 def edit_membership
196 @membership = Member.edit_membership(params[:membership_id], params[:membership], @user) 183 @membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
197 @membership.save if request.post? 184 @membership.save
198 respond_to do |format| 185 respond_to do |format|
199 if @membership.valid? 186 format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
200 format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } 187 format.js
201 format.js {
202 render(:update) {|page|
203 page.replace_html "tab-content-memberships", :partial => 'users/memberships'
204 page.visual_effect(:highlight, "member-#{@membership.id}")
205 }
206 }
207 else
208 format.js {
209 render(:update) {|page|
210 page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')))
211 }
212 }
213 end
214 end 188 end
215 end 189 end
216 190
217 def destroy_membership 191 def destroy_membership
218 @membership = Member.find(params[:membership_id]) 192 @membership = Member.find(params[:membership_id])
219 if request.post? && @membership.deletable? 193 if @membership.deletable?
220 @membership.destroy 194 @membership.destroy
221 end 195 end
222 respond_to do |format| 196 respond_to do |format|
223 format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } 197 format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' }
224 format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'users/memberships'} } 198 format.js
225 end 199 end
226 end 200 end
227 201
228 private 202 private
229 203