* finished: Issue 82: Move user settings to members relation
git-svn-id: http://redmine-dmsf.googlecode.com/svn/trunk/redmine_dmsf@152 5e329b0b-a2ee-ea63-e329-299493fc886d
This commit is contained in:
parent
8f64bbab2c
commit
b357d6cb1e
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user