diff --git a/app/controllers/dmsf_state_controller.rb b/app/controllers/dmsf_state_controller.rb index 9e7e1502..b515e139 100644 --- a/app/controllers/dmsf_state_controller.rb +++ b/app/controllers/dmsf_state_controller.rb @@ -25,9 +25,9 @@ class DmsfStateController < ApplicationController before_filter :authorize def user_pref_save - @user_pref = DmsfUserPref.for(@project, User.current) - @user_pref.email_notify = params[:email_notify]; - @user_pref.save + member = @project.members.find(:first, :conditions => {:user_id => User.current.id}) + member.dmsf_mail_notification = params[:email_notify]; + member.save! flash[:notice] = l(:notice_your_preferences_were_saved) redirect_to :controller => "projects", :action => 'settings', :tab => 'dmsf', :id => @project end diff --git a/app/models/dmsf_mailer.rb b/app/models/dmsf_mailer.rb index f1263e26..186f6526 100644 --- a/app/models/dmsf_mailer.rb +++ b/app/models/dmsf_mailer.rb @@ -79,8 +79,7 @@ class DmsfMailer < Mailer if notify_user.pref[:no_self_notified] && notify_user == user false else - dmsf_user_prefs = DmsfUserPref.for(project, notify_user) - if dmsf_user_prefs.email_notify.nil? + if notify_member.dmsf_mail_notification.nil? case notify_user.mail_notification when 'all' true @@ -93,7 +92,7 @@ class DmsfMailer < Mailer else false end - else dmsf_user_prefs.email_notify + else notify_member.dmsf_mail_notification end end end diff --git a/app/views/dmsf_state/_user_pref.html.erb b/app/views/dmsf_state/_user_pref.html.erb index 735d1c10..5933f266 100644 --- a/app/views/dmsf_state/_user_pref.html.erb +++ b/app/views/dmsf_state/_user_pref.html.erb @@ -7,7 +7,7 @@ <%= select_tag("email_notify", options_for_select([[l(:select_option_default), nil], [l(:select_option_activated), true], [l(:select_option_deactivated), false]], - :selected => DmsfUserPref.for(@project, User.current).email_notify)) %> + :selected => @project.members.find(:first, :conditions => {:user_id => User.current.id}).dmsf_mail_notification)) %> <%= submit_tag(l(:submit_save), :title => l(:title_save_preferences)) %> <% end %> diff --git a/app/models/dmsf_user_pref.rb b/db/migrate/04_dmsf_0_9_0.rb similarity index 58% rename from app/models/dmsf_user_pref.rb rename to db/migrate/04_dmsf_0_9_0.rb index 1cdfccab..f8dba9af 100644 --- a/app/models/dmsf_user_pref.rb +++ b/db/migrate/04_dmsf_0_9_0.rb @@ -16,22 +16,23 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class DmsfUserPref < ActiveRecord::Base - unloadable - belongs_to :project - belongs_to :user - - validates_presence_of :project, :user - validates_uniqueness_of :user_id, :scope => [:project_id] - - def self.for(project, user) - user_pref = find(:first, :conditions => - ["project_id = :project_id and user_id = :user_id", - {:project_id => project.id, :user_id => user.id}]) - user_pref = DmsfUserPref.new({:project_id => project.id, :user_id => user.id, - :email_notify => nil}) if user_pref.nil? - return user_pref +class Dmsf090 < ActiveRecord::Migration + def self.up + add_column :members, :dmsf_mail_notification, :boolean + drop_table :dmsf_user_prefs end - -end + def self.down + remove_column :members, :dmsf_mail_notification + + create_table :dmsf_user_prefs do |t| + t.references :project, :null => false + t.references :user, :null => false + + t.boolean :email_notify + + t.timestamps + end + end + +end