Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable email settings #3119

Merged
merged 5 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def test_digest_email
end

def save_settings
user_settings = ['notify-comment-direct:false']
user_settings = ['notify-comment-direct:false', 'notify-likes-direct:false', 'notify-comment-indirect:false']

user_settings.each do |setting|
if params[setting] && params[setting] == "on"
Expand Down
5 changes: 4 additions & 1 deletion app/models/concerns/comments_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def author
end

def parent_commenter_uids
parent.comments.collect(&:uid)
commenter_ids = parent.comments.collect(&:uid).uniq
commenter_ids.each do |commenter|
commenter_ids.delete(commenter) if UserTag.exists?(commenter, 'notify-comment-indirect:false')
end
end

def parent_liker_uids
Expand Down
2 changes: 1 addition & 1 deletion app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ def self.like(nid, user)
nid: nid).first_or_create
like.liking = true
node = Node.find(nid)
if node.type == 'note'
if node.type == 'note' && !UserTag.exists?(node.uid, 'notify-likes-direct:false')
SubscriptionMailer.notify_note_liked(node, like.user).deliver_now
end
count = 1
Expand Down
26 changes: 26 additions & 0 deletions app/views/users/settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,32 @@
<br />
<br />

<div style="display: inline-flex; justify-content: space-between; width: 90%;">
<span>Do you want to be notified by email for likes on your posts ? </span>
<span>
<label class="switch">
<input type="checkbox" name="notify-likes-direct:false" <% unless UserTag.exists?(current_user.id, 'notify-likes-direct:false') %>checked<% end %>>
<span class="slider round"></span>
</label>
</span>
</div>

<br />
<br />

<div style="display: inline-flex; justify-content: space-between; width: 90%;">
<span>Do you want to be notified by email for comments on all posts you've commented on ? </span>
<span>
<label class="switch">
<input type="checkbox" name="notify-comment-indirect:false" <% unless UserTag.exists?(current_user.id, 'notify-comment-indirect:false') %>checked<% end %>>
<span class="slider round"></span>
</label>
</span>
</div>

<br />
<br />

<div style="display: inline-flex; justify-content: space-between; width: 90%;">
<span>Do you want to receive customized digest weekly ?</span>
<span>
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/comments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,11 @@ spam_comment:
comment: This thing is spam.
timestamp: <%= Time.now.to_i + 14 %>
thread: /01

comment_by_test_user:
uid: 8
nid: 2
status: 1
comment: Note comment for setting
timestamp: <%= Time.now.to_i + 3 %>
thread: /03
12 changes: 11 additions & 1 deletion test/fixtures/user_tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,14 @@ github2:
notify-comment-direct:
id: 14
uid: 10
value: notify-comment-direct:false
value: notify-comment-direct:false

notify-likes-direct:
id: 15
uid: 10
value: notify-likes-direct:false

notify-comment-indirect:
id: 16
uid: 8
value: notify-comment-indirect:false
12 changes: 12 additions & 0 deletions test/functional/comment_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,18 @@ def teardown
assert_not ActionMailer::Base.deliveries.collect(&:to).include?([users(:test_user).email])
end

test 'should not send notification email to another commenter if notify-comment-indirect:false usertag is present' do
UserSession.create(users(:test_user))
post :create, params: {
id: nodes(:about).nid,
body: 'A comment by test user on note of author bob'
}, xhr: true

assert ActionMailer::Base.deliveries.collect(&:subject).include?("New comment on #{nodes(:about).title} (##{nodes(:about).nid}) ")
assert ActionMailer::Base.deliveries.collect(&:to).include?([users(:jeff).email]) # notifying normal commenter
assert_not ActionMailer::Base.deliveries.collect(&:to).include?([users(:lurker).email]) # not notifying commenter with tag as setting turned off
end

private

def current_user
Expand Down
20 changes: 20 additions & 0 deletions test/functional/like_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def teardown; end
assert_equal @response.body, '1'
assert_equal note.likers.length, note.cached_likes
assert_equal cached_likes + 1, note.cached_likes
assert ActionMailer::Base.deliveries.size, 1
assert ActionMailer::Base.deliveries.collect(&:to).include?([note.author.email])
assert ActionMailer::Base.deliveries.collect(&:subject).include?("[PublicLab] #{current_user.username} liked your " + (note.has_power_tag('question') ? 'question' : 'research note'))
end

test 'delete like' do
Expand Down Expand Up @@ -106,4 +109,21 @@ def teardown; end
assert_equal likers_length + 1 , note.likers.count
end

test 'create like without notifying author if notify-likes-direct:false tag present' do
UserSession.create(User.find(1))
current_user = User.find 1
note = nodes(:activity)
cached_likes = note.cached_likes

get :create, params: { id: note.id }
assert_response :success

note = Node.find note.id
assert_equal @response.body, '1'
assert_equal note.likers.length, note.cached_likes
assert_equal cached_likes + 1, note.cached_likes
assert ActionMailer::Base.deliveries.size, 0
assert_not ActionMailer::Base.deliveries.collect(&:to).include?([note.author.email])
assert_not ActionMailer::Base.deliveries.collect(&:subject).include?("[PublicLab] #{current_user.username} liked your " + (note.has_power_tag('question') ? 'question' : 'research note'))
end
end