users can now disable email notfications
This commit is contained in:
parent
8de5c5babd
commit
c774685d52
6 changed files with 58 additions and 17 deletions
|
|
@ -23,7 +23,12 @@ class UsersController < ApplicationController
|
|||
params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank?
|
||||
params[:user].delete(:language) if params[:user][:language].blank?
|
||||
|
||||
if params[:user][:password] && params[:user][:password_confirmation]
|
||||
# change email notifications
|
||||
if params[:user][:disable_mail]
|
||||
@user.update_attributes(:disable_mail => params[:user][:disable_mail])
|
||||
flash[:notice] = I18n.t 'users.update.email_notification_changed'
|
||||
# change passowrd
|
||||
elsif params[:user][:password] && params[:user][:password_confirmation]
|
||||
if @user.update_attributes(:password => params[:user][:password], :password_confirmation => params[:user][:password_confirmation])
|
||||
flash[:notice] = I18n.t 'users.update.password_changed'
|
||||
else
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ class User
|
|||
key :visible_person_ids, Array, :typecast => 'ObjectId'
|
||||
|
||||
key :getting_started, Boolean, :default => true
|
||||
key :disable_mail, Boolean, :default => false
|
||||
|
||||
key :language, String
|
||||
|
||||
|
|
@ -60,7 +61,7 @@ class User
|
|||
person.save if person
|
||||
end
|
||||
|
||||
attr_accessible :getting_started, :password, :password_confirmation, :language,
|
||||
attr_accessible :getting_started, :password, :password_confirmation, :language, :disable_mail
|
||||
|
||||
def strip_and_downcase_username
|
||||
if username.present?
|
||||
|
|
@ -281,6 +282,13 @@ class User
|
|||
end
|
||||
end
|
||||
|
||||
######### Mailer #######################
|
||||
def mail(job, *args)
|
||||
unless self.disable_mail
|
||||
Resque.enqueue(job, *args)
|
||||
end
|
||||
end
|
||||
|
||||
######### Posts and Such ###############
|
||||
def retract(post)
|
||||
aspect_ids = aspects_with_post(post.id)
|
||||
|
|
@ -367,24 +375,11 @@ class User
|
|||
self
|
||||
end
|
||||
|
||||
|
||||
def seed_aspects
|
||||
self.aspects.create(:name => I18n.t('aspects.seed.family'))
|
||||
self.aspects.create(:name => I18n.t('aspects.seed.work'))
|
||||
end
|
||||
|
||||
def as_json(opts={})
|
||||
{
|
||||
:user => {
|
||||
:posts => self.raw_visible_posts.each { |post| post.as_json },
|
||||
:contacts => self.contacts.each { |contact| contact.as_json },
|
||||
:aspects => self.aspects.each { |aspect| aspect.as_json },
|
||||
:pending_requests => self.pending_requests.each { |request| request.as_json },
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
def self.generate_key
|
||||
key_size = (Rails.env == 'test' ? 512 : 4096)
|
||||
OpenSSL::PKey::RSA::generate key_size
|
||||
|
|
|
|||
|
|
@ -81,6 +81,22 @@
|
|||
%hr
|
||||
%br
|
||||
|
||||
%h3
|
||||
= t('.email_notifications')
|
||||
= form_for @user do |f|
|
||||
= f.error_messages
|
||||
|
||||
%p.checkbox_select
|
||||
= f.label :disable_mail, t('.receive_email_notifications')
|
||||
= f.check_box :disable_mail, {:checked => !@user.disable_mail}, false, true
|
||||
%br
|
||||
= f.submit t('.change')
|
||||
|
||||
%br
|
||||
%br
|
||||
%hr
|
||||
%br
|
||||
|
||||
|
||||
.span-8.append-2
|
||||
%h3
|
||||
|
|
|
|||
|
|
@ -180,6 +180,9 @@ en:
|
|||
your_handle: "Your diaspora handle"
|
||||
your_email: "Your email"
|
||||
edit_account: "Edit account"
|
||||
email_notifications: "Email notificaions"
|
||||
receive_email_notifications: "Receive email notificaions?"
|
||||
change: "Change"
|
||||
destroy: "Account successfully closed."
|
||||
getting_started:
|
||||
welcome: "Welcome to Diaspora!"
|
||||
|
|
@ -214,6 +217,7 @@ en:
|
|||
password_not_changed: "Password Change Failed"
|
||||
language_changed: "Language Changed"
|
||||
language_not_changed: "Language Change Failed"
|
||||
email_notifications_changed: "Language Change Failed"
|
||||
public:
|
||||
does_not_exist: "User %{username} does not exist!"
|
||||
comments:
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ module Diaspora
|
|||
self.pending_requests << contact_request
|
||||
self.save!
|
||||
Rails.logger.info("event=contact_request status=received_new_request from=#{contact_request.from.diaspora_handle} to=#{self.diaspora_handle}")
|
||||
Resque.enqueue(Jobs::MailRequestReceived, self.id, contact_request.from.id)
|
||||
self.mail(Jobs::MailRequestReceived, self.id, contact_request.from.id)
|
||||
end
|
||||
else
|
||||
Rails.logger.info "event=contact_request status=abort from=#{contact_request.from.diaspora_handle} to=#{self.diaspora_handle} reason=self-love"
|
||||
|
|
@ -83,7 +83,7 @@ module Diaspora
|
|||
pending_requests.delete(sent_request)
|
||||
sent_request.destroy
|
||||
self.save
|
||||
Resque.enqueue(Jobs::MailRequestAcceptance, self.id, received_request.from.id, destination_aspect.id)
|
||||
self.mail(Jobs::MailRequestAcceptance, self.id, received_request.from.id, destination_aspect.id)
|
||||
end
|
||||
|
||||
def disconnect(bad_contact)
|
||||
|
|
|
|||
|
|
@ -381,4 +381,25 @@ describe User do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#mail' do
|
||||
it 'enqueues a mail job' do
|
||||
user.disable_mail = false
|
||||
user.save
|
||||
user.reload
|
||||
|
||||
Resque.should_receive(:enqueue).with(Jobs::MailRequestReceived, user.id, 'contactrequestid').once
|
||||
user.mail(Jobs::MailRequestReceived, user.id, 'contactrequestid')
|
||||
end
|
||||
|
||||
it 'does not enqueue a mail job' do
|
||||
user.disable_mail = true
|
||||
user.save
|
||||
user.reload
|
||||
|
||||
Resque.should_not_receive(:enqueue)
|
||||
user.mail(Jobs::MailRequestReceived, user.id, 'contactrequestid')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue