diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 494068476..e9b5b6c99 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -17,7 +17,7 @@ class AccountController < ApplicationController end def account_params - params.require(:account).permit(:first_name, :last_name, :nickname, :use_nickname) + params.require(:account).permit(:first_name, :last_name, :nickname, :use_nickname, :email_on_debate_comment, :email_on_comment_reply) end end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index c5c0fe0c7..bbad3ca3b 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -8,8 +8,8 @@ class CommentsController < ApplicationController @comment.save! @comment.move_to_child_of(@parent) if reply? - Mailer.comment(@comment).deliver_now - Mailer.reply(@comment).deliver_now + Mailer.comment(@comment).deliver_now if email_on_debate_comment? + Mailer.reply(@comment).deliver_now if email_on_comment_reply? respond_with @comment end @@ -36,4 +36,12 @@ class CommentsController < ApplicationController def reply? @parent.class == Comment end + + def email_on_debate_comment? + @comment.debate.author.email_on_debate_comment? + end + + def email_on_comment_reply? + reply? && @parent.author.email_on_comment_reply? + end end \ No newline at end of file diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index da568a9b9..d130121f3 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -15,6 +15,16 @@ <%= f.label :nickname, t("account.show.nickname_label") %> <%= f.text_field :nickname %> +
+ <%= f.check_box :email_on_debate_comment %> + <%= f.label :email_on_debate_comment, t("account.show.email_on_debate_comment_label") %> +
+ +
+ <%= f.check_box :email_on_comment_reply %> + <%= f.label :email_on_comment_reply, t("account.show.email_on_comment_reply_label") %> +
+ <%= f.submit t("account.show.save_changes_submit"), class: "button radius" %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index f32e3010e..5a7fa594e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -62,6 +62,8 @@ en: show: title: "My account" save_changes_submit: "Save changes" + email_on_debate_comment_label: "Receive email when someone comments on my debates" + email_on_comment_reply_label: "Receive email when someone replies to my comments" change_credentials_link: "Change my credentials" first_name_label: "First Name" last_name_label: "Last Name" diff --git a/config/locales/es.yml b/config/locales/es.yml index 14e1c3b59..0576aecd7 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -62,6 +62,8 @@ es: show: title: "Mi cuenta" save_changes_submit: "Guardar cambios" + email_on_debate_comment_label: "Recibir un email cuando alguien commenta en mis debates" + email_on_comment_reply_label: "Recibir un email cuando alguien contesta a mis comentarios" change_credentials_link: "Cambiar mi contraseƱa" first_name_label: "Nombre" last_name_label: "Apellidos" diff --git a/db/migrate/20150806163142_add_preferences_to_users.rb b/db/migrate/20150806163142_add_preferences_to_users.rb new file mode 100644 index 000000000..8c3ae57cc --- /dev/null +++ b/db/migrate/20150806163142_add_preferences_to_users.rb @@ -0,0 +1,6 @@ +class AddPreferencesToUsers < ActiveRecord::Migration + def change + add_column :users, :email_on_debate_comment, :boolean, default: false + add_column :users, :email_on_comment_reply, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index e5f6f9c0a..f6947e462 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: 20150806140048) do +ActiveRecord::Schema.define(version: 20150806163142) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -82,6 +82,8 @@ ActiveRecord::Schema.define(version: 20150806140048) do t.string "unconfirmed_email" t.string "nickname" t.boolean "use_nickname", default: false, null: false + t.boolean "email_on_debate_comment", default: false + t.boolean "email_on_comment_reply", default: false end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree