From c2e0feb38b191615f02b7750de9fb022b4b242f2 Mon Sep 17 00:00:00 2001 From: flaburgan Date: Fri, 7 Jul 2017 22:54:13 +0200 Subject: [PATCH 1/3] Include first/last name in invitation emails --- app/views/notifier/invite.markerb | 9 ++++++++- config/locales/diaspora/en.yml | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/views/notifier/invite.markerb b/app/views/notifier/invite.markerb index 1e00c6c0a..ee3942a3b 100644 --- a/app/views/notifier/invite.markerb +++ b/app/views/notifier/invite.markerb @@ -1 +1,8 @@ -<%= t('.message', :invite_url => invite_code_url(@invitation_code), :diasporafoundation_url => 'https://diasporafoundation.org/', :diaspora_id => @inviter.try(:diaspora_handle)) %> +<%= t('.message', + invite_url: invite_code_url(@invitation_code), + diasporafoundation_url: 'https://diasporafoundation.org/', + user: @inviter.try(:diaspora_handle) == @inviter.try(:name) ? + @inviter.try(:diaspora_handle) : + @inviter.try(:name) + " (" + @inviter.try(:diaspora_handle) + ")", + diaspora_id: @inviter.try(:diaspora_handle)) +%> diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 931dfceda..10f82eb23 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -807,7 +807,7 @@ en: message: |- Hello! - You have been invited to join diaspora* by %{diaspora_id}! + You have been invited to join diaspora* by %{user}! Click this link to get started From 9a2798331361954c259657a96d300fbe59ad5590 Mon Sep 17 00:00:00 2001 From: flaburgan Date: Wed, 19 Jul 2017 10:49:47 +0200 Subject: [PATCH 2/3] Refactor name condition to a cleaner code, delegate :full_name from profile to person to user --- app/models/person.rb | 2 +- app/models/user.rb | 2 +- app/views/notifier/invite.markerb | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/models/person.rb b/app/models/person.rb index 13be8ec8b..d76cfcb92 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -22,7 +22,7 @@ class Person < ActiveRecord::Base end has_one :profile, dependent: :destroy - delegate :last_name, :image_url, :tag_string, :bio, :location, + delegate :last_name, :full_name, :image_url, :tag_string, :bio, :location, :gender, :birthday, :formatted_birthday, :tags, :searchable, :public_details?, to: :profile accepts_nested_attributes_for :profile diff --git a/app/models/user.rb b/app/models/user.rb index 940a48f25..2061efc9b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -46,7 +46,7 @@ class User < ActiveRecord::Base delegate :guid, :public_key, :posts, :photos, :owns?, :image_url, :diaspora_handle, :name, :atom_url, :profile_url, :profile, :url, - :first_name, :last_name, :gender, :participations, to: :person + :first_name, :last_name, :full_name, :gender, :participations, to: :person delegate :id, :guid, to: :person, prefix: true has_many :aspects, -> { order('order_id ASC') } diff --git a/app/views/notifier/invite.markerb b/app/views/notifier/invite.markerb index ee3942a3b..8c20a00c0 100644 --- a/app/views/notifier/invite.markerb +++ b/app/views/notifier/invite.markerb @@ -1,8 +1,6 @@ <%= t('.message', invite_url: invite_code_url(@invitation_code), diasporafoundation_url: 'https://diasporafoundation.org/', - user: @inviter.try(:diaspora_handle) == @inviter.try(:name) ? - @inviter.try(:diaspora_handle) : - @inviter.try(:name) + " (" + @inviter.try(:diaspora_handle) + ")", + user: @inviter.try(:full_name).empty? ? @inviter.try(:diaspora_handle) : "#{@inviter.name} (#{@inviter.diaspora_handle})", diaspora_id: @inviter.try(:diaspora_handle)) %> From 1eea034844d69ee35479ea785af70d7fea867457 Mon Sep 17 00:00:00 2001 From: flaburgan Date: Mon, 7 Aug 2017 19:08:15 +0200 Subject: [PATCH 3/3] Add a test --- Changelog.md | 1 + app/mailers/notifier.rb | 6 ++--- features/desktop/invitations.feature | 1 + features/step_definitions/user_steps.rb | 8 +++++-- spec/mailers/notifier_spec.rb | 31 +++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Changelog.md b/Changelog.md index d4ed93ea3..265d9581b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -36,6 +36,7 @@ If so, please delete it since it will prevent the federation from working proper * Render mentions as links in comments [#7327](https://github.com/diaspora/diaspora/pull/7327) * Add support for mentions in comments to the front-end [#7386](https://github.com/diaspora/diaspora/pull/7386) * Support direct links to comments on mobile [#7508](https://github.com/diaspora/diaspora/pull/7508) +* Add inviter first and last name in the invitation e-mail [#7484](https://github.com/diaspora/diaspora/pull/7484) # 0.6.8.0 diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 69fdfe11b..d58a58761 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -44,9 +44,9 @@ class Notifier < ActionMailer::Base @invitation_code = invitation_code I18n.with_locale(locale) do - mail_opts = {:to => email, :from => AppConfig.mail.sender_address, - :subject => I18n.t('notifier.invited_you', :name => @inviter.name), - :host => AppConfig.pod_uri.host} + mail_opts = {to: email, from: "\"#{AppConfig.settings.pod_name}\" <#{AppConfig.mail.sender_address}>", + subject: I18n.t("notifier.invited_you", name: @inviter.name), + host: AppConfig.pod_uri.host} mail(mail_opts) do |format| format.text { render :layout => nil } diff --git a/features/desktop/invitations.feature b/features/desktop/invitations.feature index dd38873cc..eca4ef758 100644 --- a/features/desktop/invitations.feature +++ b/features/desktop/invitations.feature @@ -59,6 +59,7 @@ Feature: Invitations And I press "Send an invitation" Then I should see a flash message indicating success And I should have 1 Devise email delivery + And I should see "You have been invited to join diaspora* by Alice Smith" in the last sent email And I should not see "change your notification settings" in the last sent email Scenario: sends an invitation from the people search page diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index f01025a07..7eb0e2b6e 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -168,10 +168,14 @@ Then /^I should have (\d+) email delivery$/ do |n| ActionMailer::Base.deliveries.length.should == n.to_i end -Then /^I should not see "([^\"]*)" in the last sent email$/ do |text| +Then /^I should( not)? see "([^\"]*)" in the last sent email$/ do |negate, text| email_text = Devise.mailer.deliveries.first.body.to_s email_text = Devise.mailer.deliveries.first.html_part.body.raw_source if email_text.blank? - email_text.should_not match(text) + if negate + expect(email_text).to_not have_content(text) + else + expect(email_text).to have_content(text) + end end When /^"([^\"]+)" has posted a (public )?status message with a photo$/ do |email, public_status| diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 6594f8408..12ee1dd78 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -501,6 +501,37 @@ describe Notifier, type: :mailer do end end + describe ".invite" do + let(:email) { Notifier.invite(alice.email, nil, bob, "1234", "en") } + + it "goes to the right person" do + expect(email.to).to eq([alice.email]) + end + + it "FROM: header should be the pod name + default sender address" do + expect(email["From"].to_s).to eq("#{pod_name} <#{AppConfig.mail.sender_address}>") + end + + it "has the correct subject" do + expect(email.subject).to eq(I18n.translate("notifier.invited_you", name: bob.name)) + end + + it "has the inviter name in the body" do + expect(email.body.encoded).to include("#{bob.name} (#{bob.diaspora_handle})") + end + + it "has the inviter id if the name is nil" do + bob.person.profile.update_attributes(first_name: "", last_name: "") + mail = Notifier.invite(alice.email, nil, bob, "1234", "en") + expect(email.body.encoded).to_not include("#{bob.name} (#{bob.diaspora_handle})") + expect(mail.body.encoded).to include(bob.person.diaspora_handle) + end + + it "has the invitation code in the body" do + expect(email.body.encoded).to include("/i/1234") + end + end + describe ".csrf_token_fail" do let(:email) { Notifier.send_notification("csrf_token_fail", alice.id) }