From 630ea22ecefec05a0da8271d6f1ad750338a01da Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 18 Dec 2020 09:34:36 +0100 Subject: [PATCH 01/12] Add new 'subscriptions_token' column to the users' table Giving any user a direct link to edit another user's account settings doesn't seem like a great idea. Instead we'll generate a random secure hash string to help keep things more secure. We'll store these hashes on each user so that we have a way to find them during this public query. To do this we need to add a column to the user table. --- .../20201218082830_add_subscriptions_token_to_users.rb | 5 +++++ db/schema.rb | 1 + 2 files changed, 6 insertions(+) create mode 100644 db/migrate/20201218082830_add_subscriptions_token_to_users.rb diff --git a/db/migrate/20201218082830_add_subscriptions_token_to_users.rb b/db/migrate/20201218082830_add_subscriptions_token_to_users.rb new file mode 100644 index 000000000..5d447d019 --- /dev/null +++ b/db/migrate/20201218082830_add_subscriptions_token_to_users.rb @@ -0,0 +1,5 @@ +class AddSubscriptionsTokenToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :subscriptions_token, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 9758897cc..050cb482f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1625,6 +1625,7 @@ ActiveRecord::Schema.define(version: 2021_11_03_112944) do t.boolean "public_interests", default: false t.boolean "recommended_debates", default: true t.boolean "recommended_proposals", default: true + t.string "subscriptions_token" t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["date_of_birth"], name: "index_users_on_date_of_birth" t.index ["email"], name: "index_users_on_email", unique: true From 2bef215fc6831dd40ce1a1dbd4a905c41a3540ce Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 18 Dec 2020 09:39:02 +0100 Subject: [PATCH 02/12] Add method to generate subscriptions_token Note that we only update a user with a new token if the user has not yet been assigned one. --- app/models/user.rb | 4 ++++ spec/models/user_spec.rb | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index 0c6e03bfe..0dde87ca7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -415,6 +415,10 @@ class User < ApplicationRecord devise_mailer.send(notification, self, *args).deliver_later end + def add_subscriptions_token + update!(subscriptions_token: SecureRandom.base58(32)) if subscriptions_token.blank? + end + private def clean_document_number diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 9c326f846..72acf4f50 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -823,4 +823,22 @@ describe User do expect(other_user_legislation_proposal.reload).to be_hidden end end + + describe "#add_subscriptions_token" do + let(:user) { build(:user, subscriptions_token: nil) } + + it "generates a subscriptions token when the user doesn't have one" do + user.add_subscriptions_token + + expect(user.subscriptions_token).to be_present + end + + it "keeps the existing subscriptions token when the user already has one" do + user.update!(subscriptions_token: "already_set") + + user.add_subscriptions_token + + expect(user.subscriptions_token).to eq "already_set" + end + end end From 6d9e4a9330c930172112030bc2b7125ccaf26e6b Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 29 Dec 2020 12:08:57 +0100 Subject: [PATCH 03/12] Allow users to manage their notifications The user can access this page without being logged in. We identify the user through the "subscriptions_token" parameter and show a list of the notifications that can be enable/disable. We will return a 404 error in case someone accesses the page with a non-existent token. We also control the case that some anonymous user tries to access the page without any token, by returning the CanCan::AccessDenied exception. --- app/assets/stylesheets/application.scss | 1 + app/assets/stylesheets/layout.scss | 3 ++- app/assets/stylesheets/subscriptions.scss | 5 +++++ .../subscriptions/edit_component.html.erb | 13 +++++++++++++ .../subscriptions/edit_component.rb | 7 +++++++ app/controllers/subscriptions_controller.rb | 17 +++++++++++++++++ app/views/subscriptions/edit.html.erb | 1 + config/routes/account.rb | 2 ++ .../subscriptions/edit_component_spec.rb | 19 +++++++++++++++++++ .../subscriptions_controller_spec.rb | 16 ++++++++++++++++ 10 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/subscriptions.scss create mode 100644 app/components/subscriptions/edit_component.html.erb create mode 100644 app/components/subscriptions/edit_component.rb create mode 100644 app/controllers/subscriptions_controller.rb create mode 100644 app/views/subscriptions/edit.html.erb create mode 100644 spec/components/subscriptions/edit_component_spec.rb create mode 100644 spec/controllers/subscriptions_controller_spec.rb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 08bb60faa..0aa0834a7 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -47,6 +47,7 @@ @import "sdg/**/*"; @import "sdg_management/*"; @import "sdg_management/**/*"; +@import "subscriptions"; @import "widgets/**/*"; @import "custom"; diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 4c38b27d7..d3c5ca090 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -74,7 +74,8 @@ main { &.sdg-goals-index, &.sdg-goal-show, &.topic-edit, - &.topic-new { + &.topic-new, + &.subscriptions-edit { @include grid-column-gutter; } } diff --git a/app/assets/stylesheets/subscriptions.scss b/app/assets/stylesheets/subscriptions.scss new file mode 100644 index 000000000..6affddaaf --- /dev/null +++ b/app/assets/stylesheets/subscriptions.scss @@ -0,0 +1,5 @@ +.subscriptions-edit { + form { + max-width: $global-width * 7 / 12; + } +} diff --git a/app/components/subscriptions/edit_component.html.erb b/app/components/subscriptions/edit_component.html.erb new file mode 100644 index 000000000..09e65926b --- /dev/null +++ b/app/components/subscriptions/edit_component.html.erb @@ -0,0 +1,13 @@ +
+ <%= form_for user, url: subscriptions_path(token: user.subscriptions_token) do |f| %> +

<%= t("account.show.notifications") %>

+ +
<%= f.check_box :email_on_comment %>
+
<%= f.check_box :email_on_comment_reply %>
+
<%= f.check_box :newsletter %>
+
<%= f.check_box :email_digest %>
+
<%= f.check_box :email_on_direct_message %>
+ + <%= f.submit t("account.show.save_changes_submit"), class: "button margin-top" %> + <% end %> +
diff --git a/app/components/subscriptions/edit_component.rb b/app/components/subscriptions/edit_component.rb new file mode 100644 index 000000000..bd5771102 --- /dev/null +++ b/app/components/subscriptions/edit_component.rb @@ -0,0 +1,7 @@ +class Subscriptions::EditComponent < ApplicationComponent + attr_reader :user + + def initialize(user) + @user = user + end +end diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb new file mode 100644 index 000000000..e5c4fa34a --- /dev/null +++ b/app/controllers/subscriptions_controller.rb @@ -0,0 +1,17 @@ +class SubscriptionsController < ApplicationController + before_action :set_user + skip_authorization_check + + def edit + end + + private + + def set_user + @user = if params[:token].present? + User.find_by!(subscriptions_token: params[:token]) + else + current_user || raise(CanCan::AccessDenied) + end + end +end diff --git a/app/views/subscriptions/edit.html.erb b/app/views/subscriptions/edit.html.erb new file mode 100644 index 000000000..cc3b8a685 --- /dev/null +++ b/app/views/subscriptions/edit.html.erb @@ -0,0 +1 @@ +<%= render Subscriptions::EditComponent.new(@user) %> diff --git a/config/routes/account.rb b/config/routes/account.rb index 2b377bc36..128107207 100644 --- a/config/routes/account.rb +++ b/config/routes/account.rb @@ -1,3 +1,5 @@ resource :account, controller: "account", only: [:show, :update, :delete] do get :erase, on: :collection end + +resource :subscriptions, only: [:edit] diff --git a/spec/components/subscriptions/edit_component_spec.rb b/spec/components/subscriptions/edit_component_spec.rb new file mode 100644 index 000000000..060407d16 --- /dev/null +++ b/spec/components/subscriptions/edit_component_spec.rb @@ -0,0 +1,19 @@ +require "rails_helper" + +describe Subscriptions::EditComponent do + let(:user) { create(:user, subscriptions_token: SecureRandom.base58(32)) } + let(:component) { Subscriptions::EditComponent.new(user) } + + it "renders checkboxes to change the subscriptions preferences" do + render_inline component + + expect(page).to have_content "Notifications" + expect(page).to have_field "Notify me by email when someone comments on my proposals or debates", + type: :checkbox + expect(page).to have_field "Notify me by email when someone replies to my comments", type: :checkbox + expect(page).to have_field "Receive by email website relevant information", type: :checkbox + expect(page).to have_field "Receive a summary of proposal notifications", type: :checkbox + expect(page).to have_field "Receive emails about direct messages", type: :checkbox + expect(page).to have_button "Save changes" + end +end diff --git a/spec/controllers/subscriptions_controller_spec.rb b/spec/controllers/subscriptions_controller_spec.rb new file mode 100644 index 000000000..ef1309c46 --- /dev/null +++ b/spec/controllers/subscriptions_controller_spec.rb @@ -0,0 +1,16 @@ +require "rails_helper" + +describe SubscriptionsController do + describe "GET edit" do + it "returns a 404 code with a wrong token" do + expect { get :edit, params: { token: "non_existent" } }.to raise_error ActiveRecord::RecordNotFound + end + + it "doesn't allow access to anonymous users without a token" do + get :edit, params: { token: "" } + + expect(response).to redirect_to "/" + expect(flash[:alert]).to eq "You do not have permission to access this page." + end + end +end From 2bfdc421aecd0f4d27bf8ed27633682ac2b54ef3 Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 29 Dec 2020 12:14:42 +0100 Subject: [PATCH 04/12] Allow updating the status of notifications You can update the same "notifications" section that we allow you to update in "my account". This "subscriptions" section differs from the "my account" section because we do not need to be logged in to update the status of the notifications. --- app/controllers/subscriptions_controller.rb | 14 ++++++++++ config/routes/account.rb | 2 +- spec/system/subscriptions_spec.rb | 30 +++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 spec/system/subscriptions_spec.rb diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index e5c4fa34a..4ec340cff 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -5,6 +5,12 @@ class SubscriptionsController < ApplicationController def edit end + def update + @user.update!(subscriptions_params) + redirect_to edit_subscriptions_path(token: @user.subscriptions_token), + notice: t("flash.actions.save_changes.notice") + end + private def set_user @@ -14,4 +20,12 @@ class SubscriptionsController < ApplicationController current_user || raise(CanCan::AccessDenied) end end + + def subscriptions_params + params.require(:user).permit(allowed_params) + end + + def allowed_params + [:email_on_comment, :email_on_comment_reply, :email_on_direct_message, :email_digest, :newsletter] + end end diff --git a/config/routes/account.rb b/config/routes/account.rb index 128107207..e4baa306e 100644 --- a/config/routes/account.rb +++ b/config/routes/account.rb @@ -2,4 +2,4 @@ resource :account, controller: "account", only: [:show, :update, :delete] do get :erase, on: :collection end -resource :subscriptions, only: [:edit] +resource :subscriptions, only: [:edit, :update] diff --git a/spec/system/subscriptions_spec.rb b/spec/system/subscriptions_spec.rb new file mode 100644 index 000000000..d480f8a38 --- /dev/null +++ b/spec/system/subscriptions_spec.rb @@ -0,0 +1,30 @@ +require "rails_helper" + +describe "Subscriptions" do + let(:user) { create(:user, subscriptions_token: SecureRandom.base58(32)) } + + context "Update" do + scenario "Allow updating the status notification" do + user.update!(email_on_comment: false, + email_on_comment_reply: true, + newsletter: true, + email_digest: false, + email_on_direct_message: true) + visit edit_subscriptions_path(token: user.subscriptions_token) + + check "Notify me by email when someone comments on my proposals or debates" + uncheck "Notify me by email when someone replies to my comments" + uncheck "Receive by email website relevant information" + check "Receive a summary of proposal notifications" + uncheck "Receive emails about direct messages" + click_button "Save changes" + + expect(page).to have_content "Changes saved" + expect(page).to have_field "Notify me by email when someone comments on my contents", checked: true + expect(page).to have_field "Notify me by email when someone replies to my comments", checked: false + expect(page).to have_field "Receive by email website relevant information", checked: false + expect(page).to have_field "Receive a summary of proposal notifications", checked: true + expect(page).to have_field "Receive emails about direct messages", checked: false + end + end +end From 0af765a3bdc28e405a8027d98f79ec1f8ce3349f Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 29 Dec 2020 12:26:55 +0100 Subject: [PATCH 05/12] Update "comment" notification email to add unsubscribe link We modified the link that previously redirected us to the "My content" page to redirect us to the new page for managing subscriptions. We also adapted the existing generic text by adding a description of the related notification. --- app/mailers/mailer.rb | 6 +++++ app/views/mailer/comment.html.erb | 9 +++++++- config/locales/en/mailers.yml | 2 ++ config/locales/es/mailers.yml | 2 ++ spec/mailers/mailer_spec.rb | 22 ++++++++++++++++++ spec/system/admin/system_emails_spec.rb | 3 +++ spec/system/emails_spec.rb | 30 ++++++++++++++++--------- 7 files changed, 63 insertions(+), 11 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 9fbb8ec88..17440bec2 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -9,6 +9,7 @@ class Mailer < ApplicationMailer @comment = comment @commentable = comment.commentable @email_to = @commentable.author.email + manage_subscriptions_token(@commentable.author) with_user(@commentable.author) do subject = t("mailers.comment.subject", commentable: t("activerecord.models.#{@commentable.class.name.underscore}", count: 1).downcase) @@ -150,4 +151,9 @@ class Mailer < ApplicationMailer mail.perform_deliveries = false end end + + def manage_subscriptions_token(user) + user.add_subscriptions_token + @token = user.subscriptions_token + end end diff --git a/app/views/mailer/comment.html.erb b/app/views/mailer/comment.html.erb index c4e7d1354..d831b60bc 100644 --- a/app/views/mailer/comment.html.erb +++ b/app/views/mailer/comment.html.erb @@ -18,6 +18,13 @@

- <%= t("mailers.config.manage_email_subscriptions") %> <%= link_to t("account.show.title"), account_url, style: "color: #2895F1; text-decoration:none;" %> + <%= sanitize(t("mailers.config.unsubscribe_text", + notifications: link_to( + t("mailers.config.notifications_link"), + edit_subscriptions_url(token: @token), + style: "color: #2895F1; text-decoration: none;" + ), + notification: User.human_attribute_name(:email_on_comment) + )) %>

diff --git a/config/locales/en/mailers.yml b/config/locales/en/mailers.yml index 552aa9831..d8d5f05fd 100644 --- a/config/locales/en/mailers.yml +++ b/config/locales/en/mailers.yml @@ -9,6 +9,8 @@ en: title: New comment config: manage_email_subscriptions: To stop receiving these emails change your settings in + notifications_link: Notifications + unsubscribe_text: 'To unsubscribe from these emails, visit %{notifications} and uncheck "%{notification}".' email_verification: click_here_to_verify: this link instructions_2: This email will verify your account with %{document_type} %{document_number}. If these don't belong to you, please don't click on the previous link and ignore this email. diff --git a/config/locales/es/mailers.yml b/config/locales/es/mailers.yml index ec4974a4d..d45c500c7 100644 --- a/config/locales/es/mailers.yml +++ b/config/locales/es/mailers.yml @@ -9,6 +9,8 @@ es: title: Nuevo comentario config: manage_email_subscriptions: Puedes dejar de recibir estos emails cambiando tu configuración en + notifications_link: Notificaciones + unsubscribe_text: 'Para darse de baja de estos emails, puedes entrar en %{notifications} y desmarcar la opción "%{notification}".' email_verification: click_here_to_verify: en este enlace instructions_2: Este email es para verificar tu cuenta con %{document_type} %{document_number}. Si esos no son tus datos, por favor no pulses el enlace anterior e ignora este email. diff --git a/spec/mailers/mailer_spec.rb b/spec/mailers/mailer_spec.rb index d69d9cc01..21231ca4d 100644 --- a/spec/mailers/mailer_spec.rb +++ b/spec/mailers/mailer_spec.rb @@ -29,4 +29,26 @@ describe Mailer do expect(email.subject).to include("commented on your proposal") end end + + describe "#manage_subscriptions_token" do + let(:user) { create(:user) } + let(:proposal) { create(:proposal, author: user) } + let(:comment) { create(:comment, commentable: proposal) } + + it "generates a subscriptions token when the receiver doesn't have one" do + user.update!(subscriptions_token: nil) + + Mailer.comment(comment).deliver_now + + expect(user.reload.subscriptions_token).to be_present + end + + it "uses the existing subscriptions token when the receivesr already has one" do + user.update!(subscriptions_token: "subscriptions_token_value") + + Mailer.comment(comment).deliver_now + + expect(user.subscriptions_token).to eq "subscriptions_token_value" + end + end end diff --git a/spec/system/admin/system_emails_spec.rb b/spec/system/admin/system_emails_spec.rb index e464998f2..7786631f7 100644 --- a/spec/system/admin/system_emails_spec.rb +++ b/spec/system/admin/system_emails_spec.rb @@ -155,6 +155,9 @@ describe "System Emails" do expect(page).to have_content comment.body expect(page).to have_link "Let's do...", href: debate_url(debate, host: app_host) + expect(page).to have_link("Notifications", + href: edit_subscriptions_url(token: user.subscriptions_token, + host: app_host)) end scenario "#reply" do diff --git a/spec/system/emails_spec.rb b/spec/system/emails_spec.rb index 9f9cb9398..87ccada2a 100644 --- a/spec/system/emails_spec.rb +++ b/spec/system/emails_spec.rb @@ -50,8 +50,10 @@ describe "Emails" do expect(email).to have_subject("Someone has commented on your citizen proposal") expect(email).to deliver_to(proposal.author) expect(email).to have_body_text(proposal_path(proposal)) - expect(email).to have_body_text("To stop receiving these emails change your settings in") - expect(email).to have_body_text(account_path) + expect(email).to have_body_text("To unsubscribe from these emails, visit") + expect(email).to have_body_text(edit_subscriptions_path(token: proposal.author.subscriptions_token)) + expect(email).to have_body_text( + 'and uncheck "Notify me by email when someone comments on my proposals or debates"') end scenario "Do not send email about own proposal comments" do @@ -77,8 +79,10 @@ describe "Emails" do expect(email).to have_subject("Someone has commented on your debate") expect(email).to deliver_to(debate.author) expect(email).to have_body_text(debate_path(debate)) - expect(email).to have_body_text("To stop receiving these emails change your settings in") - expect(email).to have_body_text(account_path) + expect(email).to have_body_text("To unsubscribe from these emails, visit") + expect(email).to have_body_text(edit_subscriptions_path(token: debate.author.subscriptions_token)) + expect(email).to have_body_text( + 'and uncheck "Notify me by email when someone comments on my proposals or debates"') end scenario "Do not send email about own debate comments" do @@ -104,8 +108,10 @@ describe "Emails" do expect(email).to have_subject("Someone has commented on your investment") expect(email).to deliver_to(investment.author) expect(email).to have_body_text(budget_investment_path(investment, budget_id: investment.budget_id)) - expect(email).to have_body_text("To stop receiving these emails change your settings in") - expect(email).to have_body_text(account_path) + expect(email).to have_body_text("To unsubscribe from these emails, visit") + expect(email).to have_body_text(edit_subscriptions_path(token: investment.author.subscriptions_token)) + expect(email).to have_body_text( + 'and uncheck "Notify me by email when someone comments on my proposals or debates"') end scenario "Do not send email about own budget investments comments" do @@ -132,8 +138,10 @@ describe "Emails" do expect(email).to have_subject("Someone has commented on your topic") expect(email).to deliver_to(topic.author) expect(email).to have_body_text(community_topic_path(topic, community_id: topic.community_id)) - expect(email).to have_body_text("To stop receiving these emails change your settings in") - expect(email).to have_body_text(account_path) + expect(email).to have_body_text("To unsubscribe from these emails, visit") + expect(email).to have_body_text(edit_subscriptions_path(token: topic.author.subscriptions_token)) + expect(email).to have_body_text( + 'and uncheck "Notify me by email when someone comments on my proposals or debates"') end scenario "Do not send email about own topic comments" do @@ -159,8 +167,10 @@ describe "Emails" do expect(email).to have_subject("Someone has commented on your poll") expect(email).to deliver_to(poll.author) expect(email).to have_body_text(poll_path(poll)) - expect(email).to have_body_text("To stop receiving these emails change your settings in") - expect(email).to have_body_text(account_path) + expect(email).to have_body_text("To unsubscribe from these emails, visit") + expect(email).to have_body_text(edit_subscriptions_path(token: poll.author.subscriptions_token)) + expect(email).to have_body_text( + 'and uncheck "Notify me by email when someone comments on my proposals or debates"') end scenario "Do not send email about own poll comments" do From a36f3feb87af41efcbd0bbdc671caef7a6be121c Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 29 Dec 2020 12:23:55 +0100 Subject: [PATCH 06/12] Update "direct message" notification email to add unsubscribe link We modified the link that previously redirected us to the "My content" page to redirect us to the new page for managing subscriptions. --- app/mailers/mailer.rb | 1 + app/views/mailer/direct_message_for_receiver.html.erb | 7 ++++--- config/locales/en/mailers.yml | 3 +-- config/locales/es/mailers.yml | 3 +-- spec/system/admin/system_emails_spec.rb | 3 +++ spec/system/emails_spec.rb | 1 + 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 17440bec2..73e8fa903 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -42,6 +42,7 @@ class Mailer < ApplicationMailer @direct_message = direct_message @receiver = @direct_message.receiver @email_to = @receiver.email + manage_subscriptions_token(@receiver) with_user(@receiver) do mail(to: @email_to, subject: t("mailers.direct_message_for_receiver.subject")) diff --git a/app/views/mailer/direct_message_for_receiver.html.erb b/app/views/mailer/direct_message_for_receiver.html.erb index b563ce621..ae9637d3e 100644 --- a/app/views/mailer/direct_message_for_receiver.html.erb +++ b/app/views/mailer/direct_message_for_receiver.html.erb @@ -26,9 +26,10 @@

- <%= sanitize(t("mailers.direct_message_for_receiver.unsubscribe", - account: link_to(t("mailers.direct_message_for_receiver.unsubscribe_account"), - account_url, style: "color: #2895F1; text-decoration: none;"))) %> + <%= sanitize(t("mailers.direct_message_for_receiver.unsubscribe_text", + notifications: link_to(t("mailers.config.notifications_link"), + edit_subscriptions_url(token: @token), + style: "color: #2895F1; text-decoration: none;"))) %>

diff --git a/config/locales/en/mailers.yml b/config/locales/en/mailers.yml index d8d5f05fd..1960ca558 100644 --- a/config/locales/en/mailers.yml +++ b/config/locales/en/mailers.yml @@ -34,8 +34,7 @@ en: direct_message_for_receiver: subject: "You have received a new private message" reply: Reply to %{sender} - unsubscribe: "If you don't want to receive direct messages, visit %{account} and uncheck 'Receive emails about direct messages'." - unsubscribe_account: My account + unsubscribe_text: "If you don't want to receive direct messages, visit %{notifications} and uncheck 'Receive emails about direct messages'." direct_message_for_sender: subject: "You have sent a new private message" title: "You have sent a new private message to %{receiver} with the content:" diff --git a/config/locales/es/mailers.yml b/config/locales/es/mailers.yml index d45c500c7..961c88b96 100644 --- a/config/locales/es/mailers.yml +++ b/config/locales/es/mailers.yml @@ -34,8 +34,7 @@ es: direct_message_for_receiver: subject: "Has recibido un nuevo mensaje privado" reply: Responder a %{sender} - unsubscribe: "Si no quieres recibir mensajes privados, puedes entrar en %{account} y desmarcar la opción 'Recibir emails con mensajes privados'." - unsubscribe_account: Mi cuenta + unsubscribe_text: "Si no quieres recibir mensajes privados, puedes entrar en %{notifications} y desmarcar la opción 'Recibir emails con mensajes privados'." direct_message_for_sender: subject: "Has enviado un nuevo mensaje privado" title: "Has enviado un nuevo mensaje privado a %{receiver} con el siguiente contenido:" diff --git a/spec/system/admin/system_emails_spec.rb b/spec/system/admin/system_emails_spec.rb index 7786631f7..1d8d8fca9 100644 --- a/spec/system/admin/system_emails_spec.rb +++ b/spec/system/admin/system_emails_spec.rb @@ -185,6 +185,9 @@ describe "System Emails" do expect(page).to have_content "This is a sample of message's content." expect(page).to have_link "Reply to #{admin.user.name}", href: user_url(admin.user, host: app_host) + expect(page).to have_link("Notifications", + href: edit_subscriptions_url(token: admin.user.subscriptions_token, + host: app_host)) end scenario "#direct_message_for_sender" do diff --git a/spec/system/emails_spec.rb b/spec/system/emails_spec.rb index 87ccada2a..a77863432 100644 --- a/spec/system/emails_spec.rb +++ b/spec/system/emails_spec.rb @@ -243,6 +243,7 @@ describe "Emails" do expect(email).to have_body_text(direct_message.body) expect(email).to have_body_text(direct_message.sender.name) expect(email).to have_body_text(/#{user_path(direct_message.sender_id)}/) + expect(email).to have_body_text(edit_subscriptions_path(token: receiver.subscriptions_token)) end scenario "Sender email" do From 478ac3a952d8df2b454330654e2f4b9bbf216a32 Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 29 Dec 2020 12:25:29 +0100 Subject: [PATCH 07/12] Update "proposal" notification email to add unsubscribe link We modified the link that previously redirected us to the "My content" page to redirect us to the new page for managing subscriptions. --- app/mailers/mailer.rb | 1 + app/views/mailer/proposal_notification_digest.html.erb | 7 ++++--- config/locales/en/mailers.yml | 3 +-- config/locales/es/mailers.yml | 3 +-- spec/system/admin/system_emails_spec.rb | 1 + spec/system/emails_spec.rb | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 73e8fa903..a32cd82dd 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -62,6 +62,7 @@ class Mailer < ApplicationMailer def proposal_notification_digest(user, notifications) @notifications = notifications @email_to = user.email + manage_subscriptions_token(user) with_user(user) do mail(to: @email_to, subject: t("mailers.proposal_notification_digest.title", org_name: Setting["org_name"])) diff --git a/app/views/mailer/proposal_notification_digest.html.erb b/app/views/mailer/proposal_notification_digest.html.erb index 576b592cd..7b3d0f58b 100644 --- a/app/views/mailer/proposal_notification_digest.html.erb +++ b/app/views/mailer/proposal_notification_digest.html.erb @@ -70,9 +70,10 @@

- <%= sanitize(t("mailers.proposal_notification_digest.unsubscribe", - account: link_to(t("mailers.proposal_notification_digest.unsubscribe_account"), - account_url, style: "color: #2895F1; text-decoration: none;"))) %> + <%= sanitize(t("mailers.proposal_notification_digest.unsubscribe_text", + notifications: link_to(t("mailers.config.notifications_link"), + edit_subscriptions_url(token: @token), + style: "color: #2895F1; text-decoration: none;"))) %>

diff --git a/config/locales/en/mailers.yml b/config/locales/en/mailers.yml index 1960ca558..36482beaa 100644 --- a/config/locales/en/mailers.yml +++ b/config/locales/en/mailers.yml @@ -28,8 +28,7 @@ en: title: "Proposal notifications in %{org_name}" share: Share proposal comment: Comment proposal - unsubscribe: "If you don't want to receive any proposal notifications, visit %{account} and uncheck 'Receive a summary of proposal notifications'." - unsubscribe_account: My account + unsubscribe_text: "If you don't want to receive any proposal notifications, visit %{notifications} and uncheck 'Receive a summary of proposal notifications'." unfollow: "Visit this proposal and unfollow it to stop receiving notifications." direct_message_for_receiver: subject: "You have received a new private message" diff --git a/config/locales/es/mailers.yml b/config/locales/es/mailers.yml index 961c88b96..fa08d810a 100644 --- a/config/locales/es/mailers.yml +++ b/config/locales/es/mailers.yml @@ -28,8 +28,7 @@ es: title: "Notificaciones de propuestas en %{org_name}" share: Compartir propuesta comment: Comentar propuesta - unsubscribe: "Si no quieres recibir notificaciones de propuestas, puedes entrar en %{account} y desmarcar la opción 'Recibir resumen de notificaciones sobre propuestas'." - unsubscribe_account: Mi cuenta + unsubscribe_text: "Si no quieres recibir notificaciones de propuestas, puedes entrar en %{notifications} y desmarcar la opción 'Recibir resumen de notificaciones sobre propuestas'." unfollow: "Si no quieres recibir más notificaciones, visita esta propuesta y deja de seguirla." direct_message_for_receiver: subject: "Has recibido un nuevo mensaje privado" diff --git a/spec/system/admin/system_emails_spec.rb b/spec/system/admin/system_emails_spec.rb index 1d8d8fca9..cfcd3cf70 100644 --- a/spec/system/admin/system_emails_spec.rb +++ b/spec/system/admin/system_emails_spec.rb @@ -92,6 +92,7 @@ describe "System Emails" do href: proposal_url(proposal_b, anchor: "tab-notifications", host: app_host)) expect(page).to have_content("Proposal A Notification Body") expect(page).to have_content("Proposal B Notification Body") + expect(page).to have_link "Notifications" end scenario "#budget_investment_created" do diff --git a/spec/system/emails_spec.rb b/spec/system/emails_spec.rb index a77863432..46e859104 100644 --- a/spec/system/emails_spec.rb +++ b/spec/system/emails_spec.rb @@ -303,7 +303,7 @@ describe "Emails" do expect(email).to have_body_text(proposal2.author.name) expect(email).not_to have_body_text(proposal3.title) - expect(email).to have_body_text(/#{account_path}/) + expect(email).to have_body_text(edit_subscriptions_path(token: user.subscriptions_token)) expect(email).to have_body_text("Visit this proposal and unfollow it to stop receiving notifications.") notification1.reload From 3a2564a92d657f8ab0760bd6d5612b7796352086 Mon Sep 17 00:00:00 2001 From: taitus Date: Mon, 25 Jan 2021 11:40:52 +0100 Subject: [PATCH 08/12] Remove "slashes" from specs I think the "slashes" can be removed. The specs work fine without the "slashes". --- spec/system/emails_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/system/emails_spec.rb b/spec/system/emails_spec.rb index 46e859104..922bdb8e8 100644 --- a/spec/system/emails_spec.rb +++ b/spec/system/emails_spec.rb @@ -242,7 +242,7 @@ describe "Emails" do expect(email).to have_body_text(direct_message.title) expect(email).to have_body_text(direct_message.body) expect(email).to have_body_text(direct_message.sender.name) - expect(email).to have_body_text(/#{user_path(direct_message.sender_id)}/) + expect(email).to have_body_text(user_path(direct_message.sender_id)) expect(email).to have_body_text(edit_subscriptions_path(token: receiver.subscriptions_token)) end @@ -290,16 +290,16 @@ describe "Emails" do expect(email).to have_body_text(notification1.notifiable.body) expect(email).to have_body_text(proposal1.author.name) - expect(email).to have_body_text(/#{proposal_path(proposal1, anchor: "tab-notifications")}/) - expect(email).to have_body_text(/#{proposal_path(proposal1, anchor: "comments")}/) - expect(email).to have_body_text(/#{proposal_path(proposal1, anchor: "social-share")}/) + expect(email).to have_body_text(proposal_path(proposal1, anchor: "tab-notifications")) + expect(email).to have_body_text(proposal_path(proposal1, anchor: "comments")) + expect(email).to have_body_text(proposal_path(proposal1, anchor: "social-share")) expect(email).to have_body_text(proposal2.title) expect(email).to have_body_text(notification2.notifiable.title) expect(email).to have_body_text(notification2.notifiable.body) - expect(email).to have_body_text(/#{proposal_path(proposal2, anchor: "tab-notifications")}/) - expect(email).to have_body_text(/#{proposal_path(proposal2, anchor: "comments")}/) - expect(email).to have_body_text(/#{proposal_path(proposal2, anchor: "social-share")}/) + expect(email).to have_body_text(proposal_path(proposal2, anchor: "tab-notifications")) + expect(email).to have_body_text(proposal_path(proposal2, anchor: "comments")) + expect(email).to have_body_text(proposal_path(proposal2, anchor: "social-share")) expect(email).to have_body_text(proposal2.author.name) expect(email).not_to have_body_text(proposal3.title) @@ -347,7 +347,7 @@ describe "Emails" do email = open_last_email expect(email).to have_subject("Invitation to CONSUL") - expect(email).to have_body_text(/#{new_user_registration_path}/) + expect(email).to have_body_text(new_user_registration_path) end end From 1fcbd49448b072303f9b83ce6375d557709058ae Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 29 Dec 2020 12:27:35 +0100 Subject: [PATCH 09/12] Update "reply" notification email to add unsubscribe link We modified the link that previously redirected us to the "My content" page to redirect us to the new page for managing subscriptions. We also adapted the existing generic text by adding a description of the related notification. --- app/mailers/mailer.rb | 1 + app/views/mailer/reply.html.erb | 9 ++++++++- spec/system/admin/system_emails_spec.rb | 3 +++ spec/system/emails_spec.rb | 10 ++++++---- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index a32cd82dd..d69c8016d 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -20,6 +20,7 @@ class Mailer < ApplicationMailer def reply(reply) @email = ReplyEmail.new(reply) @email_to = @email.to + manage_subscriptions_token(@email.recipient) with_user(@email.recipient) do mail(to: @email_to, subject: @email.subject) if @email.can_be_sent? diff --git a/app/views/mailer/reply.html.erb b/app/views/mailer/reply.html.erb index 38419aacf..ac1b7ee55 100644 --- a/app/views/mailer/reply.html.erb +++ b/app/views/mailer/reply.html.erb @@ -18,6 +18,13 @@

- <%= t("mailers.config.manage_email_subscriptions") %> <%= link_to t("account.show.title"), account_url, style: "color: #2895F1; text-decoration:none;" %> + <%= sanitize(t("mailers.config.unsubscribe_text", + notifications: link_to( + t("mailers.config.notifications_link"), + edit_subscriptions_url(token: @token), + style: "color: #2895F1; text-decoration: none;" + ), + notification: User.human_attribute_name(:email_on_comment_reply) + )) %>

diff --git a/spec/system/admin/system_emails_spec.rb b/spec/system/admin/system_emails_spec.rb index cfcd3cf70..b0717c98a 100644 --- a/spec/system/admin/system_emails_spec.rb +++ b/spec/system/admin/system_emails_spec.rb @@ -176,6 +176,9 @@ describe "System Emails" do expect(page).to have_content reply.body expect(page).to have_link "Let's do...", href: comment_url(reply, host: app_host) + expect(page).to have_link("Notifications", + href: edit_subscriptions_url(token: user.subscriptions_token, + host: app_host)) end scenario "#direct_message_for_receiver" do diff --git a/spec/system/emails_spec.rb b/spec/system/emails_spec.rb index 922bdb8e8..a1e525991 100644 --- a/spec/system/emails_spec.rb +++ b/spec/system/emails_spec.rb @@ -198,8 +198,9 @@ describe "Emails" do expect(email).to deliver_to(user) expect(email).not_to have_body_text(debate_path(debate)) expect(email).to have_body_text(comment_path(Comment.last)) - expect(email).to have_body_text("To stop receiving these emails change your settings in") - expect(email).to have_body_text(account_path) + expect(email).to have_body_text("To unsubscribe from these emails, visit") + expect(email).to have_body_text(edit_subscriptions_path(token: user.subscriptions_token)) + expect(email).to have_body_text('and uncheck "Notify me by email when someone replies to my comments"') end scenario "Do not send email about own replies to own comments" do @@ -469,8 +470,9 @@ describe "Emails" do expect(email).to deliver_to(user1) expect(email).not_to have_body_text(poll_path(poll)) expect(email).to have_body_text(comment_path(Comment.last)) - expect(email).to have_body_text("To stop receiving these emails change your settings in") - expect(email).to have_body_text(account_path) + expect(email).to have_body_text("To unsubscribe from these emails, visit") + expect(email).to have_body_text(edit_subscriptions_path(token: user1.subscriptions_token)) + expect(email).to have_body_text('and uncheck "Notify me by email when someone replies to my comments"') end end From 13965901f8aab2c557d2d1745421995955921da9 Mon Sep 17 00:00:00 2001 From: taitus Date: Mon, 1 Feb 2021 18:21:16 +0100 Subject: [PATCH 10/12] Update "newsletter" notification email to add unsubscribe link --- app/mailers/mailer.rb | 1 + app/views/mailer/newsletter.html.erb | 11 +++++++++++ config/locales/en/mailers.yml | 1 - config/locales/es/mailers.yml | 1 - spec/system/emails_spec.rb | 4 ++++ 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index d69c8016d..b0c0d3541 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -120,6 +120,7 @@ class Mailer < ApplicationMailer def newsletter(newsletter, recipient_email) @newsletter = newsletter @email_to = recipient_email + manage_subscriptions_token(User.find_by(email: @email_to)) mail(to: @email_to, from: @newsletter.from, subject: @newsletter.subject) end diff --git a/app/views/mailer/newsletter.html.erb b/app/views/mailer/newsletter.html.erb index 3b45f6105..e28be0eea 100644 --- a/app/views/mailer/newsletter.html.erb +++ b/app/views/mailer/newsletter.html.erb @@ -2,4 +2,15 @@

<%= auto_link_already_sanitized_html wysiwyg(@newsletter.body) %>

+ +

+ <%= sanitize(t("mailers.config.unsubscribe_text", + notifications: link_to( + t("mailers.config.notifications_link"), + edit_subscriptions_url(token: @token), + style: "color: #2895F1; text-decoration: none;" + ), + notification: User.human_attribute_name(:newsletter) + )) %> +

diff --git a/config/locales/en/mailers.yml b/config/locales/en/mailers.yml index 36482beaa..f70669073 100644 --- a/config/locales/en/mailers.yml +++ b/config/locales/en/mailers.yml @@ -8,7 +8,6 @@ en: subject: Someone has commented on your %{commentable} title: New comment config: - manage_email_subscriptions: To stop receiving these emails change your settings in notifications_link: Notifications unsubscribe_text: 'To unsubscribe from these emails, visit %{notifications} and uncheck "%{notification}".' email_verification: diff --git a/config/locales/es/mailers.yml b/config/locales/es/mailers.yml index fa08d810a..0cc21c5b5 100644 --- a/config/locales/es/mailers.yml +++ b/config/locales/es/mailers.yml @@ -8,7 +8,6 @@ es: subject: Alguien ha comentado en tu %{commentable} title: Nuevo comentario config: - manage_email_subscriptions: Puedes dejar de recibir estos emails cambiando tu configuración en notifications_link: Notificaciones unsubscribe_text: 'Para darse de baja de estos emails, puedes entrar en %{notifications} y desmarcar la opción "%{notification}".' email_verification: diff --git a/spec/system/emails_spec.rb b/spec/system/emails_spec.rb index a1e525991..a8de896d0 100644 --- a/spec/system/emails_spec.rb +++ b/spec/system/emails_spec.rb @@ -502,6 +502,10 @@ describe "Emails" do expect(email).to have_subject("This is a different subject") expect(email).to deliver_from("no-reply@consul.dev") expect(email.body.encoded).to include("This is a different body") + expect(email).to have_body_text("To unsubscribe from these emails, visit") + expect(email).to have_body_text( + edit_subscriptions_path(token: user_with_newsletter_in_segment_2.subscriptions_token)) + expect(email).to have_body_text('and uncheck "Receive by email website relevant information"') end end From 8b9f478e816cb7007754ac9e82a2a831a3d957e3 Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 22 Dec 2021 09:51:08 +0100 Subject: [PATCH 11/12] Render the page in the user's preferred locale We add new method set_user_locale to render the page with the user's preferred locale. Note that we add a condition 'if params[:locale].blank?' to recover the user's preferred locale. This is necessary because it may be the case that the user does not have an associated locale, and when execute '@user.locale' when this value is 'nil', by default returns the default locale. As we do not want this to happen and we want the locale we receive as parameter to prevail in this case. --- app/controllers/subscriptions_controller.rb | 9 +++++++- .../subscriptions_controller_spec.rb | 7 ++++++ spec/system/subscriptions_spec.rb | 22 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index 4ec340cff..580bd0e34 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -1,5 +1,5 @@ class SubscriptionsController < ApplicationController - before_action :set_user + before_action :set_user, :set_user_locale skip_authorization_check def edit @@ -28,4 +28,11 @@ class SubscriptionsController < ApplicationController def allowed_params [:email_on_comment, :email_on_comment_reply, :email_on_direct_message, :email_digest, :newsletter] end + + def set_user_locale + if params[:locale].blank? + I18n.locale = I18n.available_locales.find { |locale| locale == @user.locale&.to_sym } + session[:locale] = I18n.locale + end + end end diff --git a/spec/controllers/subscriptions_controller_spec.rb b/spec/controllers/subscriptions_controller_spec.rb index ef1309c46..3c1d39414 100644 --- a/spec/controllers/subscriptions_controller_spec.rb +++ b/spec/controllers/subscriptions_controller_spec.rb @@ -12,5 +12,12 @@ describe SubscriptionsController do expect(response).to redirect_to "/" expect(flash[:alert]).to eq "You do not have permission to access this page." end + + it "shows the 'not allowed' message in the current locale" do + get :edit, params: { token: "", locale: :es } + + expect(response).to redirect_to "/" + expect(flash[:alert]).to eq "No tienes permiso para acceder a esta página." + end end end diff --git a/spec/system/subscriptions_spec.rb b/spec/system/subscriptions_spec.rb index d480f8a38..39cda642a 100644 --- a/spec/system/subscriptions_spec.rb +++ b/spec/system/subscriptions_spec.rb @@ -3,6 +3,28 @@ require "rails_helper" describe "Subscriptions" do let(:user) { create(:user, subscriptions_token: SecureRandom.base58(32)) } + context "Edit page" do + scenario "Render content in the user's preferred locale" do + user.update!(locale: "es") + visit edit_subscriptions_path(token: user.subscriptions_token) + + expect(page).to have_content "Notificaciones" + expect(page).to have_field "Recibir un email cuando alguien comenta en mis propuestas o debates", + type: :checkbox + expect(page).to have_field "Recibir un email cuando alguien contesta a mis comentarios", type: :checkbox + expect(page).to have_field "Recibir emails con información interesante sobre la web", type: :checkbox + expect(page).to have_field "Recibir resumen de notificaciones sobre propuestas", type: :checkbox + expect(page).to have_field "Recibir emails con mensajes privados", type: :checkbox + expect(page).to have_button "Guardar cambios" + end + + scenario "Use the locale in the parameters when accessing anonymously" do + visit edit_subscriptions_path(token: user.subscriptions_token, locale: :es) + + expect(page).to have_content "Notificaciones" + end + end + context "Update" do scenario "Allow updating the status notification" do user.update!(email_on_comment: false, From 7bd1f15f37c2fd235f19ecf08cc8bb0eeeddcb45 Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 19 Jan 2022 15:02:41 +0100 Subject: [PATCH 12/12] Improve translation for the notification of comments Currently the translation: "Notify me by email when someone comments on my proposals or debates" It only refers to proposals and debates, but actually it also refers to budget investments, topics and polls. --- config/locales/en/activerecord.yml | 2 +- config/locales/es/activerecord.yml | 2 +- .../subscriptions/edit_component_spec.rb | 3 +-- spec/system/emails_spec.rb | 15 +++++---------- spec/system/subscriptions_spec.rb | 5 ++--- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index ce7e4f199..973455a05 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -272,7 +272,7 @@ en: password: "Password" current_password: "Current password" email_digest: "Receive a summary of proposal notifications" - email_on_comment: "Notify me by email when someone comments on my proposals or debates" + email_on_comment: "Notify me by email when someone comments on my contents" email_on_comment_reply: "Notify me by email when someone replies to my comments" email_on_direct_message: "Receive emails about direct messages" newsletter: "Receive by email website relevant information" diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 74d03742a..82c682edf 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -272,7 +272,7 @@ es: password: "Contraseña" current_password: "Contraseña actual" email_digest: "Recibir resumen de notificaciones sobre propuestas" - email_on_comment: "Recibir un email cuando alguien comenta en mis propuestas o debates" + email_on_comment: "Recibir un email cuando alguien comenta en mis contenidos" email_on_comment_reply: "Recibir un email cuando alguien contesta a mis comentarios" email_on_direct_message: "Recibir emails con mensajes privados" newsletter: "Recibir emails con información interesante sobre la web" diff --git a/spec/components/subscriptions/edit_component_spec.rb b/spec/components/subscriptions/edit_component_spec.rb index 060407d16..4e8fa6323 100644 --- a/spec/components/subscriptions/edit_component_spec.rb +++ b/spec/components/subscriptions/edit_component_spec.rb @@ -8,8 +8,7 @@ describe Subscriptions::EditComponent do render_inline component expect(page).to have_content "Notifications" - expect(page).to have_field "Notify me by email when someone comments on my proposals or debates", - type: :checkbox + expect(page).to have_field "Notify me by email when someone comments on my contents", type: :checkbox expect(page).to have_field "Notify me by email when someone replies to my comments", type: :checkbox expect(page).to have_field "Receive by email website relevant information", type: :checkbox expect(page).to have_field "Receive a summary of proposal notifications", type: :checkbox diff --git a/spec/system/emails_spec.rb b/spec/system/emails_spec.rb index a8de896d0..57db5c376 100644 --- a/spec/system/emails_spec.rb +++ b/spec/system/emails_spec.rb @@ -52,8 +52,7 @@ describe "Emails" do expect(email).to have_body_text(proposal_path(proposal)) expect(email).to have_body_text("To unsubscribe from these emails, visit") expect(email).to have_body_text(edit_subscriptions_path(token: proposal.author.subscriptions_token)) - expect(email).to have_body_text( - 'and uncheck "Notify me by email when someone comments on my proposals or debates"') + expect(email).to have_body_text('and uncheck "Notify me by email when someone comments on my contents"') end scenario "Do not send email about own proposal comments" do @@ -81,8 +80,7 @@ describe "Emails" do expect(email).to have_body_text(debate_path(debate)) expect(email).to have_body_text("To unsubscribe from these emails, visit") expect(email).to have_body_text(edit_subscriptions_path(token: debate.author.subscriptions_token)) - expect(email).to have_body_text( - 'and uncheck "Notify me by email when someone comments on my proposals or debates"') + expect(email).to have_body_text('and uncheck "Notify me by email when someone comments on my contents"') end scenario "Do not send email about own debate comments" do @@ -110,8 +108,7 @@ describe "Emails" do expect(email).to have_body_text(budget_investment_path(investment, budget_id: investment.budget_id)) expect(email).to have_body_text("To unsubscribe from these emails, visit") expect(email).to have_body_text(edit_subscriptions_path(token: investment.author.subscriptions_token)) - expect(email).to have_body_text( - 'and uncheck "Notify me by email when someone comments on my proposals or debates"') + expect(email).to have_body_text('and uncheck "Notify me by email when someone comments on my contents"') end scenario "Do not send email about own budget investments comments" do @@ -140,8 +137,7 @@ describe "Emails" do expect(email).to have_body_text(community_topic_path(topic, community_id: topic.community_id)) expect(email).to have_body_text("To unsubscribe from these emails, visit") expect(email).to have_body_text(edit_subscriptions_path(token: topic.author.subscriptions_token)) - expect(email).to have_body_text( - 'and uncheck "Notify me by email when someone comments on my proposals or debates"') + expect(email).to have_body_text('and uncheck "Notify me by email when someone comments on my contents"') end scenario "Do not send email about own topic comments" do @@ -169,8 +165,7 @@ describe "Emails" do expect(email).to have_body_text(poll_path(poll)) expect(email).to have_body_text("To unsubscribe from these emails, visit") expect(email).to have_body_text(edit_subscriptions_path(token: poll.author.subscriptions_token)) - expect(email).to have_body_text( - 'and uncheck "Notify me by email when someone comments on my proposals or debates"') + expect(email).to have_body_text('and uncheck "Notify me by email when someone comments on my contents"') end scenario "Do not send email about own poll comments" do diff --git a/spec/system/subscriptions_spec.rb b/spec/system/subscriptions_spec.rb index 39cda642a..8cc6b7244 100644 --- a/spec/system/subscriptions_spec.rb +++ b/spec/system/subscriptions_spec.rb @@ -9,8 +9,7 @@ describe "Subscriptions" do visit edit_subscriptions_path(token: user.subscriptions_token) expect(page).to have_content "Notificaciones" - expect(page).to have_field "Recibir un email cuando alguien comenta en mis propuestas o debates", - type: :checkbox + expect(page).to have_field "Recibir un email cuando alguien comenta en mis contenidos", type: :checkbox expect(page).to have_field "Recibir un email cuando alguien contesta a mis comentarios", type: :checkbox expect(page).to have_field "Recibir emails con información interesante sobre la web", type: :checkbox expect(page).to have_field "Recibir resumen de notificaciones sobre propuestas", type: :checkbox @@ -34,7 +33,7 @@ describe "Subscriptions" do email_on_direct_message: true) visit edit_subscriptions_path(token: user.subscriptions_token) - check "Notify me by email when someone comments on my proposals or debates" + check "Notify me by email when someone comments on my contents" uncheck "Notify me by email when someone replies to my comments" uncheck "Receive by email website relevant information" check "Receive a summary of proposal notifications"