updated to listen to disable mail
This commit is contained in:
parent
580f0576c8
commit
d825eeaaa0
2 changed files with 8 additions and 9 deletions
|
|
@ -46,10 +46,13 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
attr_accessible :getting_started, :password, :password_confirmation, :language, :disable_mail
|
attr_accessible :getting_started, :password, :password_confirmation, :language, :disable_mail
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def update_user_preferences(pref_hash)
|
def update_user_preferences(pref_hash)
|
||||||
|
if self.disable_mail
|
||||||
|
mails = ['mentioned', 'request_received', 'comment_on_post', 'request_acceptence', 'also_commented', 'private_message']
|
||||||
|
mails.each{|x| self.user_preferences.find_or_create_by_email_type(x)}
|
||||||
|
self.update_attributes(:disable_mail => false)
|
||||||
|
end
|
||||||
|
|
||||||
pref_hash.keys.each do |key|
|
pref_hash.keys.each do |key|
|
||||||
if pref_hash[key] == 'true'
|
if pref_hash[key] == 'true'
|
||||||
self.user_preferences.find_or_create_by_email_type(key)
|
self.user_preferences.find_or_create_by_email_type(key)
|
||||||
|
|
@ -175,7 +178,8 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
######### Mailer #######################
|
######### Mailer #######################
|
||||||
def mail(job, *args)
|
def mail(job, *args)
|
||||||
unless self.disable_mail
|
pref = job.to_s.gsub('Job::Mail', '').underscore
|
||||||
|
unless self.disable_mail || self.user_preferences.exists?(:email_type => pref)
|
||||||
Resque.enqueue(job, *args)
|
Resque.enqueue(job, *args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe UserPreferences do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
||||||
Loading…
Reference in a new issue