diff --git a/Changelog.md b/Changelog.md index 3de3e3bd838cbb9aaf7d29142c351b8dd898e98c..262715223d02f1b340119bbb54640c68c7e5b934 100644 --- a/Changelog.md +++ b/Changelog.md @@ -129,6 +129,7 @@ This is disabled by default since it requires the installation of additional pac * Make the source code URL configurable [#5410](https://github.com/diaspora/diaspora/pull/5410) * Prefill publisher on the tag pages [#5442](https://github.com/diaspora/diaspora/pull/5442) * Allows users to export their data in JSON format from their user settings page [#5354](https://github.com/diaspora/diaspora/pull/5354) +* Don't include the content of non-public posts into notification mails [#5494](https://github.com/diaspora/diaspora/pull/5494) # 0.4.1.2 diff --git a/app/helpers/notifier_helper.rb b/app/helpers/notifier_helper.rb index 44de54f1c84fc0fda4043eb20114787ae1c4d9db..e8f28e0eb70414945f6c3f624a74992791cec1eb 100644 --- a/app/helpers/notifier_helper.rb +++ b/app/helpers/notifier_helper.rb @@ -4,7 +4,9 @@ module NotifierHelper # @param opts [Hash] Optional hash. Accepts :length parameters. # @return [String] The truncated and formatted post. def post_message(post, opts={}) - if post.respond_to? :message + if !post.public? + I18n.translate 'notifier.a_private_message' + elsif post.respond_to? :message post.message.plain_text_without_markdown truncate: opts.fetch(:length, 200) else I18n.translate 'notifier.a_post_you_shared' @@ -15,6 +17,10 @@ module NotifierHelper # @param opts [Hash] Optional hash. Accepts :length parameters. # @return [String] The truncated and formatted comment. def comment_message(comment, opts={}) - comment.message.plain_text_without_markdown truncate: opts.fetch(:length, 600) + if comment.post.public? + comment.message.plain_text_without_markdown truncate: opts.fetch(:length, 600) + else + I18n.translate 'notifier.a_limited_post_comment' + end end end diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 9f305891dd373eb3f58ed2197ec82c3c7902f4bb..b046af3245932c74927f5f69e92ece08c268e634 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -731,6 +731,8 @@ en: notifier: a_post_you_shared: "a post." + a_private_message: "There's a new private message in diaspora* for you to check out." + a_limited_post_comment: "There's a new comment on a limited post in diaspora* for you to check out." email_sent_by_diaspora: "This email was sent by %{pod_name}. If you'd like to stop getting emails like this," click_here: "click here" hello: "Hello %{name}!" diff --git a/spec/helpers/notifier_helper_spec.rb b/spec/helpers/notifier_helper_spec.rb index 52697a7c1c8fb4dbecb4f5b248e3425d31219157..1116a18ea2f65a8eb057ff16b2119fe9f150763c 100644 --- a/spec/helpers/notifier_helper_spec.rb +++ b/spec/helpers/notifier_helper_spec.rb @@ -8,12 +8,14 @@ describe NotifierHelper, :type => :helper do describe '#post_message' do before do # post for truncate test - @post = FactoryGirl.create(:status_message, text: "hi dude! "*10) + @post = FactoryGirl.create(:status_message, text: "hi dude! "*10, public: true) @truncated_post = "hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi du..." # post for markdown test @markdown_post = FactoryGirl.create(:status_message, - text: "[link](http://diasporafoundation.org) **bold text** *other text*") + 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 'truncates in the post' do @@ -25,6 +27,10 @@ describe NotifierHelper, :type => :helper do opts = {:length => @markdown_post.text.length} expect(post_message(@markdown_post, opts)).to eq(@striped_markdown_post) end + + it 'hides the private content' do + expect(post_message(@limited_post)).not_to include("secret post") + end end describe '#comment_message' do @@ -32,11 +38,19 @@ describe NotifierHelper, :type => :helper do # comment for truncate test @comment = FactoryGirl.create(:comment) @comment.text = "hi dude! "*10 + @comment.post.public = true @truncated_comment = "hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi d..." + # comment for markdown test @markdown_comment = FactoryGirl.create(:comment) + @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 'truncates in the comment' do @@ -48,5 +62,9 @@ describe NotifierHelper, :type => :helper do opts = {:length => @markdown_comment.text.length} expect(comment_message(@markdown_comment, opts)).to eq(@striped_markdown_comment) end + + it 'hides the private content' do + expect(comment_message(@limited_comment)).not_to include("secret comment") + end end end diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index c5296b5c61be1a3ac1219577cb77ac05e40d74eb..baeb4e2baffff4de341cbeddc04ba2dad971f7f0 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -82,10 +82,10 @@ describe Notifier, :type => :mailer do describe ".mentioned" do before do @user = alice - @sm = FactoryGirl.create(:status_message) - @m = Mention.create(:person => @user.person, :post=> @sm) + @post = FactoryGirl.create(:status_message, public: true) + @mention = Mention.create(:person => @user.person, :post => @post) - @mail = Notifier.mentioned(@user.id, @sm.author.id, @m.id) + @mail = Notifier.mentioned(@user.id, @post.author.id, @mention.id) end it 'TO: goes to the right person' do @@ -93,11 +93,11 @@ describe Notifier, :type => :mailer do end it 'SUBJECT: has the name of person mentioning in the subject' do - expect(@mail.subject).to include(@sm.author.name) + expect(@mail.subject).to include(@post.author.name) end it 'has the post text in the body' do - expect(@mail.body.encoded).to include(@sm.text) + expect(@mail.body.encoded).to include(@post.text) end it 'should not include translation fallback' do @@ -107,8 +107,8 @@ describe Notifier, :type => :mailer do describe ".liked" do before do - @sm = FactoryGirl.create(:status_message, :author => alice.person) - @like = @sm.likes.create!(:author => bob.person) + @post = FactoryGirl.create(:status_message, :author => alice.person, :public => true) + @like = @post.likes.create!(:author => bob.person) @mail = Notifier.liked(alice.id, @like.author.id, @like.id) end @@ -117,7 +117,7 @@ describe Notifier, :type => :mailer do end it 'BODY: contains the truncated original post' do - expect(@mail.body.encoded).to include(@sm.message.plain_text) + expect(@mail.body.encoded).to include(@post.message.plain_text) end it 'BODY: contains the name of person liking' do @@ -137,8 +137,8 @@ describe Notifier, :type => :mailer do describe ".reshared" do before do - @sm = FactoryGirl.create(:status_message, :author => alice.person, :public => true) - @reshare = FactoryGirl.create(:reshare, :root => @sm, :author => bob.person) + @post = FactoryGirl.create(:status_message, :author => alice.person, :public => true) + @reshare = FactoryGirl.create(:reshare, :root => @post, :author => bob.person) @mail = Notifier.reshared(alice.id, @reshare.author.id, @reshare.id) end @@ -147,7 +147,7 @@ describe Notifier, :type => :mailer do end it 'BODY: contains the truncated original post' do - expect(@mail.body.encoded).to include(@sm.message.plain_text) + expect(@mail.body.encoded).to include(@post.message.plain_text) end it 'BODY: contains the name of person liking' do @@ -196,8 +196,8 @@ describe Notifier, :type => :mailer do expect(@mail.subject).to eq("Re: #{@cnv.subject}") end - it 'BODY: contains the message text' do - expect(@mail.body.encoded).to include(@cnv.messages.first.text) + it 'BODY: does not contain the message text' do + expect(@mail.body.encoded).not_to include(@cnv.messages.first.text) end it 'should not include translation fallback' do @@ -206,7 +206,7 @@ describe Notifier, :type => :mailer do end context "comments" do - let(:commented_post) {bob.post(:status_message, :text => "### Headline \r\n It's **really** sunny outside today, and this is a super long status message! #notreally", :to => :all)} + let(:commented_post) {bob.post(:status_message, :text => "### Headline \r\n It's **really** sunny outside today, and this is a super long status message! #notreally", :to => :all, :public => true)} let(:comment) { eve.comment!(commented_post, "Totally is")} describe ".comment_on_post" do @@ -271,7 +271,7 @@ describe Notifier, :type => :mailer do end it "contains the original post's link" do - expect(comment_mail.body.encoded.include?("#{comment.post.id.to_s}")).to be true + expect(comment_mail.body.encoded).to include("#{comment.post.id.to_s}") end it 'should not include translation fallback' do