diff options
Diffstat (limited to 'app/controllers/users_controller.rb')
-rw-r--r-- | app/controllers/users_controller.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f22427a66..fb7a0e10d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -72,17 +72,40 @@ class UsersController < ApplicationController end def add + @notification_options = User::MAIL_NOTIFICATION_OPTIONS + @notification_option = Setting.default_notification_option + @user = User.new(:language => Setting.default_language) @auth_sources = AuthSource.find(:all) + + # TODO: Similar to My#account + # 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 + if @user.memberships.length < 1 + @notification_options.delete_if {|option| option.first == :selected} + end end verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } def create + @notification_options = User::MAIL_NOTIFICATION_OPTIONS + @notification_option = Setting.default_notification_option + @user = User.new(params[:user]) @user.admin = params[:user][:admin] || false @user.login = params[:user][:login] @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id + + # TODO: Similar to My#account + @user.mail_notification = params[:notification_option] || 'only_my_events' + @user.pref.attributes = params[:pref] + @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') + if @user.save + @user.pref.save + @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) + Mailer.deliver_account_information(@user, params[:password]) if params[:send_information] flash[:notice] = l(:notice_successful_create) redirect_to(params[:continue] ? {:controller => 'users', :action => 'add'} : @@ -90,12 +113,24 @@ class UsersController < ApplicationController return else @auth_sources = AuthSource.find(:all) + @notification_option = @user.mail_notification + render :action => 'add' end end def edit @user = User.find(params[:id]) + # TODO: Similar to My#account + @notification_options = User::MAIL_NOTIFICATION_OPTIONS + # 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 + if @user.memberships.length < 1 + @notification_options.delete_if {|option| option.first == :selected} + end + @notification_option = @user.mail_notification + if request.post? @user.admin = params[:user][:admin] if params[:user][:admin] @user.login = params[:user][:login] if params[:user][:login] @@ -106,7 +141,15 @@ class UsersController < ApplicationController @user.attributes = params[:user] # Was the account actived ? (do it before User#save clears the change) was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) + # TODO: Similar to My#account + @user.mail_notification = params[:notification_option] || 'only_my_events' + @user.pref.attributes = params[:pref] + @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') + if @user.save + @user.pref.save + @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : []) + if was_activated Mailer.deliver_account_activated(@user) elsif @user.active? && params[:send_information] && !params[:password].blank? && @user.auth_source_id.nil? |