* 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
|
before_filter :authorize
|
||||||
|
|
||||||
def user_pref_save
|
def user_pref_save
|
||||||
@user_pref = DmsfUserPref.for(@project, User.current)
|
member = @project.members.find(:first, :conditions => {:user_id => User.current.id})
|
||||||
@user_pref.email_notify = params[:email_notify];
|
member.dmsf_mail_notification = params[:email_notify];
|
||||||
@user_pref.save
|
member.save!
|
||||||
flash[:notice] = l(:notice_your_preferences_were_saved)
|
flash[:notice] = l(:notice_your_preferences_were_saved)
|
||||||
redirect_to :controller => "projects", :action => 'settings', :tab => 'dmsf', :id => @project
|
redirect_to :controller => "projects", :action => 'settings', :tab => 'dmsf', :id => @project
|
||||||
end
|
end
|
||||||
|
|||||||
@ -79,8 +79,7 @@ class DmsfMailer < Mailer
|
|||||||
if notify_user.pref[:no_self_notified] && notify_user == user
|
if notify_user.pref[:no_self_notified] && notify_user == user
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
dmsf_user_prefs = DmsfUserPref.for(project, notify_user)
|
if notify_member.dmsf_mail_notification.nil?
|
||||||
if dmsf_user_prefs.email_notify.nil?
|
|
||||||
case notify_user.mail_notification
|
case notify_user.mail_notification
|
||||||
when 'all'
|
when 'all'
|
||||||
true
|
true
|
||||||
@ -93,7 +92,7 @@ class DmsfMailer < Mailer
|
|||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
else
dmsf_user_prefs.email_notify
|
else
notify_member.dmsf_mail_notification
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
<%= select_tag("email_notify",
|
<%= select_tag("email_notify",
|
||||||
options_for_select([[l(:select_option_default), nil],
|
options_for_select([[l(:select_option_default), nil],
|
||||||
[l(:select_option_activated), true], [l(:select_option_deactivated), false]],
|
[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)) %>
|
<%= submit_tag(l(:submit_save), :title => l(:title_save_preferences)) %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@ -16,22 +16,23 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class DmsfUserPref < ActiveRecord::Base
|
class Dmsf090 < ActiveRecord::Migration
|
||||||
unloadable
|
def self.up
|
||||||
belongs_to :project
|
add_column :members, :dmsf_mail_notification, :boolean
|
||||||
belongs_to :user
|
drop_table :dmsf_user_prefs
|
||||||
|
|
||||||
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
|
|
||||||
end
|
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