adds email sending preferences [#23]

This commit is contained in:
rgarcia
2015-08-07 20:56:27 +02:00
parent 3752054aab
commit beb1a796f5
7 changed files with 34 additions and 4 deletions

View File

@@ -17,7 +17,7 @@ class AccountController < ApplicationController
end end
def account_params 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
end end

View File

@@ -8,8 +8,8 @@ class CommentsController < ApplicationController
@comment.save! @comment.save!
@comment.move_to_child_of(@parent) if reply? @comment.move_to_child_of(@parent) if reply?
Mailer.comment(@comment).deliver_now Mailer.comment(@comment).deliver_now if email_on_debate_comment?
Mailer.reply(@comment).deliver_now Mailer.reply(@comment).deliver_now if email_on_comment_reply?
respond_with @comment respond_with @comment
end end
@@ -36,4 +36,12 @@ class CommentsController < ApplicationController
def reply? def reply?
@parent.class == Comment @parent.class == Comment
end 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 end

View File

@@ -15,6 +15,16 @@
<%= f.label :nickname, t("account.show.nickname_label") %> <%= f.label :nickname, t("account.show.nickname_label") %>
<%= f.text_field :nickname %> <%= f.text_field :nickname %>
<div>
<%= f.check_box :email_on_debate_comment %>
<%= f.label :email_on_debate_comment, t("account.show.email_on_debate_comment_label") %>
</div>
<div>
<%= f.check_box :email_on_comment_reply %>
<%= f.label :email_on_comment_reply, t("account.show.email_on_comment_reply_label") %>
</div>
<%= f.submit t("account.show.save_changes_submit"), class: "button radius" %> <%= f.submit t("account.show.save_changes_submit"), class: "button radius" %>
<% end %> <% end %>

View File

@@ -62,6 +62,8 @@ en:
show: show:
title: "My account" title: "My account"
save_changes_submit: "Save changes" 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" change_credentials_link: "Change my credentials"
first_name_label: "First Name" first_name_label: "First Name"
last_name_label: "Last Name" last_name_label: "Last Name"

View File

@@ -62,6 +62,8 @@ es:
show: show:
title: "Mi cuenta" title: "Mi cuenta"
save_changes_submit: "Guardar cambios" 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" change_credentials_link: "Cambiar mi contraseña"
first_name_label: "Nombre" first_name_label: "Nombre"
last_name_label: "Apellidos" last_name_label: "Apellidos"

View File

@@ -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

View File

@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -82,6 +82,8 @@ ActiveRecord::Schema.define(version: 20150806140048) do
t.string "unconfirmed_email" t.string "unconfirmed_email"
t.string "nickname" t.string "nickname"
t.boolean "use_nickname", default: false, null: false 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 end
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree