summaryrefslogtreecommitdiffstats
path: root/app/controllers/my_controller.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-10-20 12:47:05 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-10-20 12:47:05 +0000
commit90d33c3e518f9e05d9e2893907ebd157062d33de (patch)
treec07d7071247f566b3049a672207dd29c707f67a0 /app/controllers/my_controller.rb
parenteacd050630b2d2b3047e056a7dab7661fba083ca (diff)
downloadredmine-90d33c3e518f9e05d9e2893907ebd157062d33de.tar.gz
redmine-90d33c3e518f9e05d9e2893907ebd157062d33de.zip
More flexible mail notifications settings at user level. A user has now 3 options:
* notification on any event on all his projects * notification on any event on selected projects only (if the user belongs to more than 1 project) * notification only for things that he watches or he is involded in (eg. issues that he watches or he is author or assignee) git-svn-id: http://redmine.rubyforge.org/svn/trunk@855 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/my_controller.rb')
-rw-r--r--app/controllers/my_controller.rb46
1 files changed, 29 insertions, 17 deletions
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb
index bbb3a6e22..5a1b128f9 100644
--- a/app/controllers/my_controller.rb
+++ b/app/controllers/my_controller.rb
@@ -50,32 +50,44 @@ class MyController < ApplicationController
# Edit user's account
def account
- @user = self.logged_in_user
+ @user = User.current
@pref = @user.pref
- @user.attributes = params[:user]
- @user.pref.attributes = params[:pref]
- if request.post? && @user.save && @user.pref.save
- flash[:notice] = l(:notice_account_updated)
- redirect_to :action => 'account'
+ if request.post?
+ @user.attributes = params[:user]
+ @user.mail_notification = (params[:notification_option] == 'all')
+ @user.pref.attributes = params[:pref]
+ if @user.save
+ @user.pref.save
+ @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : [])
+ set_language_if_valid @user.language
+ flash[:notice] = l(:notice_account_updated)
+ redirect_to :action => 'account'
+ return
+ end
end
+ @notification_options = [[l(:label_user_mail_option_all), 'all'],
+ [l(:label_user_mail_option_none), 'none']]
+ # Only users that belong to more than 1 project can select projects for which they are notified
+ # Note that @user.membership.size would fail since AR ignores :include association option when doing a count
+ @notification_options.insert 1, [l(:label_user_mail_option_selected), 'selected'] if @user.memberships.length > 1
+ @notification_option = @user.mail_notification? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')
end
- # Change user's password
- def change_password
+ # Manage user's password
+ def password
@user = self.logged_in_user
flash[:error] = l(:notice_can_t_change_password) and redirect_to :action => 'account' and return if @user.auth_source_id
- if @user.check_password?(params[:password])
- @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
- if @user.save
- flash[:notice] = l(:notice_account_password_updated)
+ if request.post?
+ if @user.check_password?(params[:password])
+ @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
+ if @user.save
+ flash[:notice] = l(:notice_account_password_updated)
+ redirect_to :action => 'account'
+ end
else
- render :action => 'account'
- return
+ flash[:error] = l(:notice_account_wrong_password)
end
- else
- flash[:error] = l(:notice_account_wrong_password)
end
- redirect_to :action => 'account'
end
# Create a new feeds key