From 81bc3d7267948038bf0723215d4602c67ad8b640 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 16 Dec 2015 16:13:25 +0100 Subject: [PATCH 1/3] add link in emails to manage notification settings (unsubscribe) --- app/views/mailer/comment.html.erb | 4 ++++ app/views/mailer/reply.html.erb | 4 ++++ config/locales/mailers.en.yml | 2 ++ config/locales/mailers.es.yml | 2 ++ spec/features/emails_spec.rb | 4 ++++ 5 files changed, 16 insertions(+) diff --git a/app/views/mailer/comment.html.erb b/app/views/mailer/comment.html.erb index a9834bd0b..bfd576835 100644 --- a/app/views/mailer/comment.html.erb +++ b/app/views/mailer/comment.html.erb @@ -15,4 +15,8 @@

<%= text_with_links @comment.body %>

+ +

+ <%= t("mailers.config.manage_email_subscriptions") %> <%= link_to t("account.show.title"), account_url, style: "color: #2895F1; text-decoration:none;" %> +

diff --git a/app/views/mailer/reply.html.erb b/app/views/mailer/reply.html.erb index 0c1844507..dadb17dfe 100644 --- a/app/views/mailer/reply.html.erb +++ b/app/views/mailer/reply.html.erb @@ -15,4 +15,8 @@

<%= text_with_links @reply.body %>

+ +

+ <%= t("mailers.config.manage_email_subscriptions") %> <%= link_to t("account.show.title"), account_url, style: "color: #2895F1; text-decoration:none;" %> +

diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index e3f791185..2b4a24ff3 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -1,5 +1,7 @@ en: mailers: + config: + manage_email_subscriptions: "To stop receiving these emails change your settings in" comment: subject: "Someone has commented on your %{commentable}" hi: "Hi" diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 350c4c423..6bc4e3309 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -1,5 +1,7 @@ es: mailers: + config: + manage_email_subscriptions: "Puedes dejar de recibir estos emails cambiando tu configuración en" comment: subject: "Alguien ha comentado en tu %{commentable}" hi: "Hola" diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index b5052d582..f21966a92 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -63,6 +63,8 @@ feature '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(I18n.t("mailers.config.manage_email_subscriptions")) + expect(email).to have_body_text(account_path) end scenario 'Do not send email about own debate comments', :js do @@ -91,6 +93,8 @@ feature 'Emails' do expect(email).to have_subject('Someone has responded to your comment') expect(email).to deliver_to(user) expect(email).to have_body_text(debate_path(Comment.first.commentable)) + expect(email).to have_body_text(I18n.t("mailers.config.manage_email_subscriptions")) + expect(email).to have_body_text(account_path) end scenario "Do not send email about own replies to own comments", :js do From e7314ac38048e97c026bb22b0fb06da33b5a2fa0 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 16 Dec 2015 16:14:35 +0100 Subject: [PATCH 2/3] add option to subscribe/unsubscribe to website newsletter --- app/controllers/account_controller.rb | 4 +-- app/views/account/show.html.erb | 7 +++++ config/locales/en.yml | 1 + config/locales/es.yml | 1 + ...24_add_newsletter_subscription_to_users.rb | 5 ++++ db/schema.rb | 27 ++++++++++--------- spec/models/user_spec.rb | 6 +++++ 7 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 db/migrate/20151215165824_add_newsletter_subscription_to_users.rb diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index f2a553c38..2d51c4b18 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -23,9 +23,9 @@ class AccountController < ApplicationController def account_params if @account.organization? - params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, organization_attributes: [:name, :responsible_name]) + params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, :subscription_to_website_newsletter, organization_attributes: [:name, :responsible_name]) else - params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply) + params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply, :subscription_to_website_newsletter) end end diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index 5acf6eb62..452300f1b 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -54,6 +54,13 @@ <% end %> +
+ <%= f.label :email_newsletter_subscribed do %> + <%= f.check_box :subscription_to_website_newsletter, label: false %> + <%= t("account.show.subscription_to_website_newsletter_label") %> + <% end %> +
+ <%= f.submit t("account.show.save_changes_submit"), class: "button radius" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 8f377af1d..7a5f3bd08 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -291,6 +291,7 @@ en: public_activity_label: "Keep my list of activities public" email_on_comment_label: "Notify me by email when someone comments on my proposals or debates" email_on_comment_reply_label: "Notify me by email when someone replies to my comments" + subscription_to_website_newsletter_label: "Receive by email website relevant information" erase_account_link: "Erase my account" personal: "Personal details" username_label: "Username" diff --git a/config/locales/es.yml b/config/locales/es.yml index a1b1952f2..88f21506f 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -291,6 +291,7 @@ es: public_activity_label: "Mostrar públicamente mi lista de actividades" email_on_comment_label: "Recibir un email cuando alguien comenta en mis propuestas o debates" email_on_comment_reply_label: "Recibir un email cuando alguien contesta a mis comentarios" + subscription_to_website_newsletter_label: "Recibir emails con información interesante sobre la web" erase_account_link: "Darme de baja" personal: "Datos personales" username_label: "Nombre de usuario" diff --git a/db/migrate/20151215165824_add_newsletter_subscription_to_users.rb b/db/migrate/20151215165824_add_newsletter_subscription_to_users.rb new file mode 100644 index 000000000..61e3ffff1 --- /dev/null +++ b/db/migrate/20151215165824_add_newsletter_subscription_to_users.rb @@ -0,0 +1,5 @@ +class AddNewsletterSubscriptionToUsers < ActiveRecord::Migration + def change + add_column :users, :subscription_to_website_newsletter, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 448fa1a8e..7a02cd7cb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151111202657) do +ActiveRecord::Schema.define(version: 20151215165824) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -270,30 +270,30 @@ ActiveRecord::Schema.define(version: 20151111202657) do add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree create_table "users", force: :cascade do |t| - t.string "email", default: "" - t.string "encrypted_password", default: "", null: false + t.string "email", default: "" + t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.string "unconfirmed_email" - t.boolean "email_on_comment", default: false - t.boolean "email_on_comment_reply", default: false - t.string "phone_number", limit: 30 + t.boolean "email_on_comment", default: false + t.boolean "email_on_comment_reply", default: false + t.string "phone_number", limit: 30 t.string "official_position" - t.integer "official_level", default: 0 + t.integer "official_level", default: 0 t.datetime "hidden_at" t.string "sms_confirmation_code" - t.string "username", limit: 60 + t.string "username", limit: 60 t.string "document_number" t.string "document_type" t.datetime "residence_verified_at" @@ -304,11 +304,12 @@ ActiveRecord::Schema.define(version: 20151111202657) do t.datetime "letter_requested_at" t.datetime "confirmed_hide_at" t.string "letter_verification_code" - t.integer "failed_census_calls_count", default: 0 + t.integer "failed_census_calls_count", default: 0 t.datetime "level_two_verified_at" t.string "erase_reason" t.datetime "erased_at" - t.boolean "public_activity", default: true + t.boolean "public_activity", default: true + t.boolean "subscription_to_website_newsletter", default: false end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 9b654ddb2..aaf60586b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -77,6 +77,12 @@ describe User do expect(subject.email_on_comment_reply).to eq(false) end end + + describe 'subscription_to_website_newsletter' do + it 'should be false by default' do + expect(subject.subscription_to_website_newsletter).to eq(false) + end + end end describe 'OmniAuth' do From 2049eb0455864180c7231017505b6a7a0bf293b7 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Thu, 24 Dec 2015 12:53:03 +0100 Subject: [PATCH 3/3] rename column name to newsletter --- app/controllers/account_controller.rb | 4 +-- app/views/account/show.html.erb | 2 +- ...24_add_newsletter_subscription_to_users.rb | 2 +- db/schema.rb | 26 +++++++++---------- spec/models/user_spec.rb | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 2d51c4b18..9a0f89bae 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -23,9 +23,9 @@ class AccountController < ApplicationController def account_params if @account.organization? - params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, :subscription_to_website_newsletter, organization_attributes: [:name, :responsible_name]) + params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, :newsletter, organization_attributes: [:name, :responsible_name]) else - params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply, :subscription_to_website_newsletter) + params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply, :newsletter) end end diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index 452300f1b..d10cc78c0 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -56,7 +56,7 @@
<%= f.label :email_newsletter_subscribed do %> - <%= f.check_box :subscription_to_website_newsletter, label: false %> + <%= f.check_box :newsletter, label: false %> <%= t("account.show.subscription_to_website_newsletter_label") %> <% end %>
diff --git a/db/migrate/20151215165824_add_newsletter_subscription_to_users.rb b/db/migrate/20151215165824_add_newsletter_subscription_to_users.rb index 61e3ffff1..61e741c27 100644 --- a/db/migrate/20151215165824_add_newsletter_subscription_to_users.rb +++ b/db/migrate/20151215165824_add_newsletter_subscription_to_users.rb @@ -1,5 +1,5 @@ class AddNewsletterSubscriptionToUsers < ActiveRecord::Migration def change - add_column :users, :subscription_to_website_newsletter, :boolean, default: false + add_column :users, :newsletter, :boolean, default: false end end diff --git a/db/schema.rb b/db/schema.rb index 7a02cd7cb..b854a7446 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -270,30 +270,30 @@ ActiveRecord::Schema.define(version: 20151215165824) do add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree create_table "users", force: :cascade do |t| - t.string "email", default: "" - t.string "encrypted_password", default: "", null: false + t.string "email", default: "" + t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.string "unconfirmed_email" - t.boolean "email_on_comment", default: false - t.boolean "email_on_comment_reply", default: false - t.string "phone_number", limit: 30 + t.boolean "email_on_comment", default: false + t.boolean "email_on_comment_reply", default: false + t.string "phone_number", limit: 30 t.string "official_position" - t.integer "official_level", default: 0 + t.integer "official_level", default: 0 t.datetime "hidden_at" t.string "sms_confirmation_code" - t.string "username", limit: 60 + t.string "username", limit: 60 t.string "document_number" t.string "document_type" t.datetime "residence_verified_at" @@ -304,12 +304,12 @@ ActiveRecord::Schema.define(version: 20151215165824) do t.datetime "letter_requested_at" t.datetime "confirmed_hide_at" t.string "letter_verification_code" - t.integer "failed_census_calls_count", default: 0 + t.integer "failed_census_calls_count", default: 0 t.datetime "level_two_verified_at" t.string "erase_reason" t.datetime "erased_at" - t.boolean "public_activity", default: true - t.boolean "subscription_to_website_newsletter", default: false + t.boolean "public_activity", default: true + t.boolean "newsletter", default: false end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index aaf60586b..a3327c5aa 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -80,7 +80,7 @@ describe User do describe 'subscription_to_website_newsletter' do it 'should be false by default' do - expect(subject.subscription_to_website_newsletter).to eq(false) + expect(subject.newsletter).to eq(false) end end end