Skip to content
Extraits de code Groupes Projets
Valider 8fa0ae1d rédigé par Jonne Haß's avatar Jonne Haß
Parcourir les fichiers

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

Remove limited content from email notifications
parents 731adffa fe605286
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -129,6 +129,7 @@ This is disabled by default since it requires the installation of additional pac ...@@ -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) * 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) * 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) * 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 # 0.4.1.2
......
...@@ -4,7 +4,9 @@ module NotifierHelper ...@@ -4,7 +4,9 @@ module NotifierHelper
# @param opts [Hash] Optional hash. Accepts :length parameters. # @param opts [Hash] Optional hash. Accepts :length parameters.
# @return [String] The truncated and formatted post. # @return [String] The truncated and formatted post.
def post_message(post, opts={}) 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) post.message.plain_text_without_markdown truncate: opts.fetch(:length, 200)
else else
I18n.translate 'notifier.a_post_you_shared' I18n.translate 'notifier.a_post_you_shared'
...@@ -15,6 +17,10 @@ module NotifierHelper ...@@ -15,6 +17,10 @@ module NotifierHelper
# @param opts [Hash] Optional hash. Accepts :length parameters. # @param opts [Hash] Optional hash. Accepts :length parameters.
# @return [String] The truncated and formatted comment. # @return [String] The truncated and formatted comment.
def comment_message(comment, opts={}) 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
end end
...@@ -731,6 +731,8 @@ en: ...@@ -731,6 +731,8 @@ en:
notifier: notifier:
a_post_you_shared: "a post." 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," 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" click_here: "click here"
hello: "Hello %{name}!" hello: "Hello %{name}!"
......
...@@ -8,12 +8,14 @@ describe NotifierHelper, :type => :helper do ...@@ -8,12 +8,14 @@ describe NotifierHelper, :type => :helper do
describe '#post_message' do describe '#post_message' do
before do before do
# post for truncate test # 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..." @truncated_post = "hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi du..."
# post for markdown test # post for markdown test
@markdown_post = FactoryGirl.create(:status_message, @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" @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 end
it 'truncates in the post' do it 'truncates in the post' do
...@@ -25,6 +27,10 @@ describe NotifierHelper, :type => :helper do ...@@ -25,6 +27,10 @@ describe NotifierHelper, :type => :helper do
opts = {:length => @markdown_post.text.length} opts = {:length => @markdown_post.text.length}
expect(post_message(@markdown_post, opts)).to eq(@striped_markdown_post) expect(post_message(@markdown_post, opts)).to eq(@striped_markdown_post)
end end
it 'hides the private content' do
expect(post_message(@limited_post)).not_to include("secret post")
end
end end
describe '#comment_message' do describe '#comment_message' do
...@@ -32,11 +38,19 @@ describe NotifierHelper, :type => :helper do ...@@ -32,11 +38,19 @@ describe NotifierHelper, :type => :helper do
# comment for truncate test # comment for truncate test
@comment = FactoryGirl.create(:comment) @comment = FactoryGirl.create(:comment)
@comment.text = "hi dude! "*10 @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..." @truncated_comment = "hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi dude! hi d..."
# comment for markdown test # comment for markdown test
@markdown_comment = FactoryGirl.create(:comment) @markdown_comment = FactoryGirl.create(:comment)
@markdown_comment.post.public = true
@markdown_comment.text = "[link](http://diasporafoundation.org) **bold text** *other text*" @markdown_comment.text = "[link](http://diasporafoundation.org) **bold text** *other text*"
@striped_markdown_comment = "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 end
it 'truncates in the comment' do it 'truncates in the comment' do
...@@ -48,5 +62,9 @@ describe NotifierHelper, :type => :helper do ...@@ -48,5 +62,9 @@ describe NotifierHelper, :type => :helper do
opts = {:length => @markdown_comment.text.length} opts = {:length => @markdown_comment.text.length}
expect(comment_message(@markdown_comment, opts)).to eq(@striped_markdown_comment) expect(comment_message(@markdown_comment, opts)).to eq(@striped_markdown_comment)
end end
it 'hides the private content' do
expect(comment_message(@limited_comment)).not_to include("secret comment")
end
end end
end end
...@@ -82,10 +82,10 @@ describe Notifier, :type => :mailer do ...@@ -82,10 +82,10 @@ describe Notifier, :type => :mailer do
describe ".mentioned" do describe ".mentioned" do
before do before do
@user = alice @user = alice
@sm = FactoryGirl.create(:status_message) @post = FactoryGirl.create(:status_message, public: true)
@m = Mention.create(:person => @user.person, :post=> @sm) @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 end
it 'TO: goes to the right person' do it 'TO: goes to the right person' do
...@@ -93,11 +93,11 @@ describe Notifier, :type => :mailer do ...@@ -93,11 +93,11 @@ describe Notifier, :type => :mailer do
end end
it 'SUBJECT: has the name of person mentioning in the subject' do 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 end
it 'has the post text in the body' do 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 end
it 'should not include translation fallback' do it 'should not include translation fallback' do
...@@ -107,8 +107,8 @@ describe Notifier, :type => :mailer do ...@@ -107,8 +107,8 @@ describe Notifier, :type => :mailer do
describe ".liked" do describe ".liked" do
before do before do
@sm = FactoryGirl.create(:status_message, :author => alice.person) @post = FactoryGirl.create(:status_message, :author => alice.person, :public => true)
@like = @sm.likes.create!(:author => bob.person) @like = @post.likes.create!(:author => bob.person)
@mail = Notifier.liked(alice.id, @like.author.id, @like.id) @mail = Notifier.liked(alice.id, @like.author.id, @like.id)
end end
...@@ -117,7 +117,7 @@ describe Notifier, :type => :mailer do ...@@ -117,7 +117,7 @@ describe Notifier, :type => :mailer do
end end
it 'BODY: contains the truncated original post' do 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 end
it 'BODY: contains the name of person liking' do it 'BODY: contains the name of person liking' do
...@@ -137,8 +137,8 @@ describe Notifier, :type => :mailer do ...@@ -137,8 +137,8 @@ describe Notifier, :type => :mailer do
describe ".reshared" do describe ".reshared" do
before do before do
@sm = FactoryGirl.create(:status_message, :author => alice.person, :public => true) @post = FactoryGirl.create(:status_message, :author => alice.person, :public => true)
@reshare = FactoryGirl.create(:reshare, :root => @sm, :author => bob.person) @reshare = FactoryGirl.create(:reshare, :root => @post, :author => bob.person)
@mail = Notifier.reshared(alice.id, @reshare.author.id, @reshare.id) @mail = Notifier.reshared(alice.id, @reshare.author.id, @reshare.id)
end end
...@@ -147,7 +147,7 @@ describe Notifier, :type => :mailer do ...@@ -147,7 +147,7 @@ describe Notifier, :type => :mailer do
end end
it 'BODY: contains the truncated original post' do 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 end
it 'BODY: contains the name of person liking' do it 'BODY: contains the name of person liking' do
...@@ -196,8 +196,8 @@ describe Notifier, :type => :mailer do ...@@ -196,8 +196,8 @@ describe Notifier, :type => :mailer do
expect(@mail.subject).to eq("Re: #{@cnv.subject}") expect(@mail.subject).to eq("Re: #{@cnv.subject}")
end end
it 'BODY: contains the message text' do it 'BODY: does not contain the message text' do
expect(@mail.body.encoded).to include(@cnv.messages.first.text) expect(@mail.body.encoded).not_to include(@cnv.messages.first.text)
end end
it 'should not include translation fallback' do it 'should not include translation fallback' do
...@@ -206,7 +206,7 @@ describe Notifier, :type => :mailer do ...@@ -206,7 +206,7 @@ describe Notifier, :type => :mailer do
end end
context "comments" do 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")} let(:comment) { eve.comment!(commented_post, "Totally is")}
describe ".comment_on_post" do describe ".comment_on_post" do
...@@ -271,7 +271,7 @@ describe Notifier, :type => :mailer do ...@@ -271,7 +271,7 @@ describe Notifier, :type => :mailer do
end end
it "contains the original post's link" do 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 end
it 'should not include translation fallback' do it 'should not include translation fallback' do
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter