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

Comment and sent email when co-author added #2259

Merged
merged 10 commits into from
Mar 7, 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
7 changes: 7 additions & 0 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ def create
uid: current_user.uid,
body: "@#{current_user.username} awards a #{barnstar_info_link} to #{node.drupal_user.name} for their awesome contribution!")

elsif tagname.split(':')[0] == "with"
user = User.find_by_username_case_insensitive(tagname.split(':')[1])
CommentMailer.notify_coauthor(user, node)
node.add_comment(subject: 'co-author',
uid: current_user.uid,
body: " @#{current_user.username} has marked #{tagname.split(':')[1]} as a co-author. ")

end

if saved
Expand Down
8 changes: 8 additions & 0 deletions app/mailers/comment_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@ def notify_answer_author(user, comment)
@footer = feature('email-footer')
mail(to: user.email, subject: "New comment on your answer on '" + comment.parent.title + "'")
end

def notify_coauthor(user, note)
@user = user
@note = note
@author = note.author
@footer = feature('email-footer')
mail(to: user.email, subject: 'You were added as a co-author!').deliver
end
end
2 changes: 1 addition & 1 deletion app/views/comment_mailer/notify_answer_author.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Hi! There's been a new comment to your answer on '<a href='https://<%= ActionMai

<p>https://<%= ActionMailer::Base.default_url_options[:host] %><%= @comment.parent.path(:question) %>#answer-<%= @comment.aid %>-comment-<%= @comment.cid %></p>

<p><b><a href="https://<%= ActionMailer::Base.default_url_options[:host] %>/profile/<%= @comment.author.name %>"><%= @comment.author.name %> wrote:</b></p>
<p><b><a href="https://<%= ActionMailer::Base.default_url_options[:host] %>/profile/<%= @comment.author.name %>"><%= @comment.author.name %></a> wrote:</b></p>

<hr />

Expand Down
15 changes: 15 additions & 0 deletions app/views/comment_mailer/notify_coauthor.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'<a href='https://<%= ActionMailer::Base.default_url_options[:host] %>/profile/<%= @author.name %>'><%= @author.name %></a>' has added you as a co-author of '<a href='https://<%= ActionMailer::Base.default_url_options[:host] %><%= @note.path %>'><%= @note.title %></a>'. Do NOT reply to this email; click this link to respond:

<p>https://<%= ActionMailer::Base.default_url_options[:host] %><%= @note.path %></p>

<hr />

<div style="color:#aaa;">

<p>Reply at: https://<%= ActionMailer::Base.default_url_options[:host] %><%= @note.path %>#comments</p>

<p>Report abuse to: moderators@<%= ActionMailer::Base.default_url_options[:host] %></p>

<%= @footer %>

</div>
2 changes: 1 addition & 1 deletion app/views/comment_mailer/notify_note_author.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Do NOT reply to this email; click this link to respond:
<p>https://<%= ActionMailer::Base.default_url_options[:host] %><%= @comment.node.path %>#c<%= @comment.cid %></p>
<% end %>

<p><b><a href="https://<%= ActionMailer::Base.default_url_options[:host] %>/profile/<%= @comment.author.name %>"><%= @comment.author.name %> wrote:</b></p>
<p><b><a href="https://<%= ActionMailer::Base.default_url_options[:host] %>/profile/<%= @comment.author.name %>"><%= @comment.author.name %></a> wrote:</b></p>

<hr />

Expand Down
15 changes: 15 additions & 0 deletions test/functional/tag_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,21 @@ def setup
end
end

test 'adds comment when creating coauthor' do
UserSession.create(users(:jeff))
user = users(:bob)
node = nodes(:one)

assert_difference 'Comment.count' do
tagname = "with:#{user.name}"
post :create,
name: tagname,
nid: node.id

assert_equal " [@#{node.author.name}](/profile/#{node.author.name}) has marked #{tagname.split(':')[1]} as a co-author. ", Comment.last.body
end
end

test 'should take node type as question if tag is a question tag' do
tag = tags(:question)

Expand Down
19 changes: 17 additions & 2 deletions test/unit/comment_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CommentMailerTest < ActionMailer::TestCase
assert_equal "New comment on your answer on '" + comment.parent.title + "'", email.subject
assert email.body.include?("Hi! There's been a new comment to your answer on '<a href='https://#{request_host}#{comment.parent.path(:question)}#a#{comment.answer.id}'>#{comment.parent.title}</a>'")
end

test 'notify barnstar' do
user = users(:bob)
note = nodes(:one)
Expand All @@ -90,4 +90,19 @@ class CommentMailerTest < ActionMailer::TestCase
assert_equal "You were awarded a Barnstar!", email.subject
assert email.body.include?("'<a href='https://#{request_host}/profile/#{user.name}'>#{user.name}</a>' has awarded you a '<a href='https://#{request_host}/wiki/barnstars'>Barnstar</a>' for your work in the research note '<a href='https://#{request_host}#{note.path}'>#{note.title}</a>'")
end
end

test 'notify coauthor' do
user = users(:bob)
note = nodes(:one)
assert_difference 'ActionMailer::Base.deliveries.size', 1 do
CommentMailer.notify_coauthor(user, note)
end
assert !ActionMailer::Base.deliveries.empty?

email = ActionMailer::Base.deliveries.last
assert_equal ["do-not-reply@#{request_host}"], email.from
assert_equal [user.email], email.to
assert_equal "You were added as a co-author!", email.subject
assert email.body.include?("'<a href='https://#{request_host}/profile/#{note.author.name}'>#{note.author.name}</a>' has added you as a co-author of '<a href='https://#{request_host}#{note.path}'>#{note.title}</a>'")
end
end