diff --git a/Changelog.md b/Changelog.md index 3bfec23fb..ff183dbdf 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ * Return 406 when requesting a JSON representation of people/:guid/contacts [#5849](https://github.com/diaspora/diaspora/pull/5849) * Destroy Participation when removing interactions with a post [#5852](https://github.com/diaspora/diaspora/pull/5852) * Hide manage services link in the publisher on certain pages [#5854](https://github.com/diaspora/diaspora/pull/5854) +* Fix notification mails for limited posts [#5877](https://github.com/diaspora/diaspora/pull/5877) ## Features * Hide post title of limited post in comment notification email [#5843](https://github.com/diaspora/diaspora/pull/5843) diff --git a/app/helpers/notifier_helper.rb b/app/helpers/notifier_helper.rb index ee62c5a44..df3526271 100644 --- a/app/helpers/notifier_helper.rb +++ b/app/helpers/notifier_helper.rb @@ -4,9 +4,7 @@ module NotifierHelper # @param opts [Hash] Optional hash. Accepts :length parameters. # @return [String] The formatted post. def post_message(post, opts={}) - if !post.public? - I18n.translate 'notifier.a_private_message' - elsif post.respond_to? :message + if post.respond_to? :message post.message.plain_text_without_markdown else I18n.translate 'notifier.a_post_you_shared' diff --git a/app/views/notifier/liked.markerb b/app/views/notifier/liked.markerb index cec7b37d6..8ed88a979 100644 --- a/app/views/notifier/liked.markerb +++ b/app/views/notifier/liked.markerb @@ -1,6 +1,10 @@ +<% if @notification.like_target.public? %> <%= "#{t('.liked', :name => "#{@notification.sender_name}")}:" %> <%= post_message(@notification.like_target, :process_newlines => true) %> +<% else %> +<%= "#{t('notifier.liked.limited_post', :name => "#{@notification.sender_name}")}." %> +<% end %> [<%= t('.view_post') %>][1] diff --git a/app/views/notifier/mentioned.markerb b/app/views/notifier/mentioned.markerb index 43264d365..a2469a0e5 100644 --- a/app/views/notifier/mentioned.markerb +++ b/app/views/notifier/mentioned.markerb @@ -1,4 +1,8 @@ +<% if @notification.post.public? %> <%= post_message(@notification.post, :process_newlines => true) %> +<% else %> +<%= t('notifier.mentioned.limited_post') %> +<% end %> [<%= t('notifier.comment_on_post.reply', :name => @notification.post_author_name) %>][1] diff --git a/app/views/notifier/private_message.markerb b/app/views/notifier/private_message.markerb index b9b6cbd81..e41a38cb4 100644 --- a/app/views/notifier/private_message.markerb +++ b/app/views/notifier/private_message.markerb @@ -1,4 +1,4 @@ -<%= post_message(@notification.message, :process_newlines => true) %> +<%= t('notifier.a_private_message') %> [<%= t('.reply_to_or_view') %>][1] diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 4e26a12c6..831cb5054 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -759,10 +759,12 @@ en: mentioned: subject: "%{name} has mentioned you on diaspora*" mentioned: "mentioned you in a post:" + limited_post: "You were mentioned in a limited post." private_message: reply_to_or_view: "Reply to or view this conversation >" liked: liked: "%{name} liked your post" + limited_post: "%{name} liked your limited post" view_post: "View post >" reshared: reshared: "%{name} reshared your post" diff --git a/spec/helpers/notifier_helper_spec.rb b/spec/helpers/notifier_helper_spec.rb index a5e1dc98b..0ff872da2 100644 --- a/spec/helpers/notifier_helper_spec.rb +++ b/spec/helpers/notifier_helper_spec.rb @@ -11,16 +11,10 @@ describe NotifierHelper, :type => :helper do @markdown_post = FactoryGirl.create(:status_message, text: "[link](http://diasporafoundation.org) **bold text** *other text*", public: true) @striped_markdown_post = "link (http://diasporafoundation.org) bold text other text" - - @limited_post = FactoryGirl.create(:status_message, text: "This is top secret post. Shhhhhhhh!!!", public: false) - end - - it 'strip markdown in the post' do - expect(post_message(@markdown_post)).to eq(@striped_markdown_post) end - it 'hides the private content' do - expect(post_message(@limited_post)).not_to include("secret post") + it 'strip markdown in the post' do + expect(post_message(@markdown_post)).to eq(@striped_markdown_post) end end @@ -31,17 +25,17 @@ describe NotifierHelper, :type => :helper do @markdown_comment.post.public = true @markdown_comment.text = "[link](http://diasporafoundation.org) **bold text** *other text*" @striped_markdown_comment = "link (http://diasporafoundation.org) bold text other text" - + # comment for limited post @limited_comment = FactoryGirl.create(:comment) @limited_comment.post.public = false @limited_comment.text = "This is top secret comment. Shhhhhhhh!!!" end - + it 'strip markdown in the comment' do expect(comment_message(@markdown_comment)).to eq(@striped_markdown_comment) end - + it 'hides the private content' do expect(comment_message(@limited_comment)).not_to include("secret comment") end diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index c9a0ad9d5..2b37d1a95 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -105,6 +105,32 @@ describe Notifier, :type => :mailer do end end + describe ".mentioned limited" do + before do + @user = alice + @post = FactoryGirl.create(:status_message, public: false) + @mention = Mention.create(person: @user.person, post: @post) + + @mail = Notifier.mentioned(@user.id, @post.author.id, @mention.id) + end + + it "TO: goes to the right person" do + expect(@mail.to).to eq([@user.email]) + end + + it "SUBJECT: has the name of person mentioning in the subject" do + expect(@mail.subject).to include(@post.author.name) + end + + it "has the post text not in the body" do + expect(@mail.body.encoded).not_to include(@post.text) + end + + it "should not include translation fallback" do + expect(@mail.body.encoded).not_to include(I18n.translate "notifier.a_post_you_shared") + end + end + describe ".liked" do before do @post = FactoryGirl.create(:status_message, :author => alice.person, :public => true) @@ -131,7 +157,31 @@ describe Notifier, :type => :mailer do it 'can handle a reshare' do reshare = FactoryGirl.create(:reshare) like = reshare.likes.create!(:author => bob.person) - mail = Notifier.liked(alice.id, like.author.id, like.id) + Notifier.liked(alice.id, like.author.id, like.id) + end + end + + describe ".liked limited" do + before do + @post = FactoryGirl.create(:status_message, author: alice.person, public: false) + @like = @post.likes.create!(author: bob.person) + @mail = Notifier.liked(alice.id, @like.author.id, @like.id) + end + + it "TO: goes to the right person" do + expect(@mail.to).to eq([alice.email]) + end + + it "BODY: not contains the original post" do + expect(@mail.body.encoded).not_to include(@post.message.plain_text) + end + + it "BODY: contains the name of person liking" do + expect(@mail.body.encoded).to include(@like.author.name) + end + + it "should not include translation fallback" do + expect(@mail.body.encoded).not_to include(I18n.translate "notifier.a_post_you_shared") end end