From 747b9ec5683ff8ae96f96c09ea709376db50b910 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Tue, 28 Sep 2010 22:13:11 +0000 Subject: [PATCH] Refactor: move method to model git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4224 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/my_controller.rb | 8 +------- app/controllers/users_controller.rb | 17 +---------------- app/models/user.rb | 11 +++++++++++ 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index e430cab0e..46747b334 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -66,13 +66,7 @@ class MyController < ApplicationController return end end - @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_options = @user.valid_notification_options @notification_option = @user.mail_notification #? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected') end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index fb7a0e10d..3fb11103d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -77,14 +77,6 @@ class UsersController < ApplicationController @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 } @@ -121,14 +113,7 @@ class UsersController < ApplicationController 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_options = @user.valid_notification_options @notification_option = @user.mail_notification if request.post? diff --git a/app/models/user.rb b/app/models/user.rb index 481c832b4..638e5f7bd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -259,6 +259,17 @@ class User < Principal notified_projects_ids end + # Only users that belong to more than 1 project can select projects for which they are notified + def valid_notification_options + # Note that @user.membership.size would fail since AR ignores + # :include association option when doing a count + if memberships.length < 1 + MAIL_NOTIFICATION_OPTIONS.delete_if {|option| option.first == :selected} + else + MAIL_NOTIFICATION_OPTIONS + end + end + # Find a user account by matching the exact login and then a case-insensitive # version. Exact matches will be given priority. def self.find_by_login(login) -- 2.39.5