Merge pull request #5494 from margori/4266-remove-content-from-email-notifications

Remove limited content from email notifications
This commit is contained in:
Jonne Haß 2014-12-29 17:32:34 +01:00
commit 8fa0ae1db2
5 changed files with 46 additions and 19 deletions

View file

@ -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

View file

@ -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

View file

@ -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}!"

View file

@ -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

View file

@ -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