adds preference to receive proposal notifications
This commit is contained in:
@@ -25,7 +25,7 @@ class AccountController < ApplicationController
|
|||||||
if @account.organization?
|
if @account.organization?
|
||||||
params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, :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
|
else
|
||||||
params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply, :newsletter)
|
params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply, :email_on_proposal_notification, :newsletter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ class ProposalNotificationsController < ApplicationController
|
|||||||
@proposal = Proposal.find(notification_params[:proposal_id])
|
@proposal = Proposal.find(notification_params[:proposal_id])
|
||||||
if @notification.save
|
if @notification.save
|
||||||
@proposal.voters.each do |voter|
|
@proposal.voters.each do |voter|
|
||||||
Mailer.proposal_notification(@notification, voter).deliver_later
|
if voter.email_on_proposal_notification?
|
||||||
|
Mailer.proposal_notification(@notification, voter).deliver_later
|
||||||
|
end
|
||||||
end
|
end
|
||||||
redirect_to @notification, notice: I18n.t("flash.actions.create.proposal_notification")
|
redirect_to @notification, notice: I18n.t("flash.actions.create.proposal_notification")
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -34,7 +34,9 @@
|
|||||||
<div>
|
<div>
|
||||||
<%= f.label :public_activity do %>
|
<%= f.label :public_activity do %>
|
||||||
<%= f.check_box :public_activity, title: t('account.show.public_activity_label'), label: false %>
|
<%= f.check_box :public_activity, title: t('account.show.public_activity_label'), label: false %>
|
||||||
<span class="checkbox"><%= t("account.show.public_activity_label") %></span>
|
<span class="checkbox">
|
||||||
|
<%= t("account.show.public_activity_label") %>
|
||||||
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -43,21 +45,36 @@
|
|||||||
<div>
|
<div>
|
||||||
<%= f.label :email_on_comment do %>
|
<%= f.label :email_on_comment do %>
|
||||||
<%= f.check_box :email_on_comment, title: t('account.show.email_on_comment_label'), label: false %>
|
<%= f.check_box :email_on_comment, title: t('account.show.email_on_comment_label'), label: false %>
|
||||||
<span class="checkbox"><%= t("account.show.email_on_comment_label") %></span>
|
<span class="checkbox">
|
||||||
|
<%= t("account.show.email_on_comment_label") %>
|
||||||
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<%= f.label :email_on_comment_reply do %>
|
<%= f.label :email_on_comment_reply do %>
|
||||||
<%= f.check_box :email_on_comment_reply, title: t('account.show.email_on_comment_reply_label'), label: false %>
|
<%= f.check_box :email_on_comment_reply, title: t('account.show.email_on_comment_reply_label'), label: false %>
|
||||||
<span class="checkbox"><%= t("account.show.email_on_comment_reply_label") %></span>
|
<span class="checkbox">
|
||||||
|
<%= t("account.show.email_on_comment_reply_label") %>
|
||||||
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<%= f.label :email_newsletter_subscribed do %>
|
<%= f.label :email_newsletter_subscribed do %>
|
||||||
<%= f.check_box :newsletter, title: t('account.show.subscription_to_website_newsletter_label'), label: false %>
|
<%= f.check_box :newsletter, title: t('account.show.subscription_to_website_newsletter_label'), label: false %>
|
||||||
<span class="checkbox"><%= t("account.show.subscription_to_website_newsletter_label") %></span>
|
<span class="checkbox">
|
||||||
|
<%= t("account.show.subscription_to_website_newsletter_label") %>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= f.label :email_on_proposal_notification do %>
|
||||||
|
<%= f.check_box :email_on_proposal_notification, title: t('account.show.email_on_proposal_notification_label'), label: false %>
|
||||||
|
<span class="checkbox">
|
||||||
|
<%= t("account.show.email_on_proposal_notification_label") %>
|
||||||
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ en:
|
|||||||
public_activity_label: Keep my list of activities public
|
public_activity_label: Keep my list of activities public
|
||||||
save_changes_submit: Save changes
|
save_changes_submit: Save changes
|
||||||
subscription_to_website_newsletter_label: Receive by email website relevant information
|
subscription_to_website_newsletter_label: Receive by email website relevant information
|
||||||
|
email_on_proposal_notification_label: Receive by email notifications about proposals
|
||||||
title: My account
|
title: My account
|
||||||
user_permission_debates: Participate on debates
|
user_permission_debates: Participate on debates
|
||||||
user_permission_info: With your account you can...
|
user_permission_info: With your account you can...
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ es:
|
|||||||
public_activity_label: Mostrar públicamente mi lista de actividades
|
public_activity_label: Mostrar públicamente mi lista de actividades
|
||||||
save_changes_submit: Guardar cambios
|
save_changes_submit: Guardar cambios
|
||||||
subscription_to_website_newsletter_label: Recibir emails con información interesante sobre la web
|
subscription_to_website_newsletter_label: Recibir emails con información interesante sobre la web
|
||||||
|
email_on_proposal_notification_label: Recibir emails con notificaciones sobre propuestas
|
||||||
title: Mi cuenta
|
title: Mi cuenta
|
||||||
user_permission_debates: Participar en debates
|
user_permission_debates: Participar en debates
|
||||||
user_permission_info: Con tu cuenta ya puedes...
|
user_permission_info: Con tu cuenta ya puedes...
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddEmailOnProposalNotificationToUsers < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :users, :email_on_proposal_notification, :boolean, default: true
|
||||||
|
end
|
||||||
|
end
|
||||||
35
db/schema.rb
35
db/schema.rb
@@ -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: 20160601103338) do
|
ActiveRecord::Schema.define(version: 20160606102427) 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"
|
||||||
@@ -402,30 +402,30 @@ ActiveRecord::Schema.define(version: 20160601103338) do
|
|||||||
add_index "tolk_translations", ["phrase_id", "locale_id"], name: "index_tolk_translations_on_phrase_id_and_locale_id", unique: true, using: :btree
|
add_index "tolk_translations", ["phrase_id", "locale_id"], name: "index_tolk_translations_on_phrase_id_and_locale_id", unique: true, using: :btree
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "email", default: ""
|
t.string "email", default: ""
|
||||||
t.string "encrypted_password", default: "", null: false
|
t.string "encrypted_password", default: "", null: false
|
||||||
t.string "reset_password_token"
|
t.string "reset_password_token"
|
||||||
t.datetime "reset_password_sent_at"
|
t.datetime "reset_password_sent_at"
|
||||||
t.datetime "remember_created_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 "current_sign_in_at"
|
||||||
t.datetime "last_sign_in_at"
|
t.datetime "last_sign_in_at"
|
||||||
t.string "current_sign_in_ip"
|
t.string "current_sign_in_ip"
|
||||||
t.string "last_sign_in_ip"
|
t.string "last_sign_in_ip"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.string "confirmation_token"
|
t.string "confirmation_token"
|
||||||
t.datetime "confirmed_at"
|
t.datetime "confirmed_at"
|
||||||
t.datetime "confirmation_sent_at"
|
t.datetime "confirmation_sent_at"
|
||||||
t.string "unconfirmed_email"
|
t.string "unconfirmed_email"
|
||||||
t.boolean "email_on_comment", default: false
|
t.boolean "email_on_comment", default: false
|
||||||
t.boolean "email_on_comment_reply", default: false
|
t.boolean "email_on_comment_reply", default: false
|
||||||
t.string "phone_number", limit: 30
|
t.string "phone_number", limit: 30
|
||||||
t.string "official_position"
|
t.string "official_position"
|
||||||
t.integer "official_level", default: 0
|
t.integer "official_level", default: 0
|
||||||
t.datetime "hidden_at"
|
t.datetime "hidden_at"
|
||||||
t.string "sms_confirmation_code"
|
t.string "sms_confirmation_code"
|
||||||
t.string "username", limit: 60
|
t.string "username", limit: 60
|
||||||
t.string "document_number"
|
t.string "document_number"
|
||||||
t.string "document_type"
|
t.string "document_type"
|
||||||
t.datetime "residence_verified_at"
|
t.datetime "residence_verified_at"
|
||||||
@@ -436,20 +436,21 @@ ActiveRecord::Schema.define(version: 20160601103338) do
|
|||||||
t.datetime "letter_requested_at"
|
t.datetime "letter_requested_at"
|
||||||
t.datetime "confirmed_hide_at"
|
t.datetime "confirmed_hide_at"
|
||||||
t.string "letter_verification_code"
|
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.datetime "level_two_verified_at"
|
||||||
t.string "erase_reason"
|
t.string "erase_reason"
|
||||||
t.datetime "erased_at"
|
t.datetime "erased_at"
|
||||||
t.boolean "public_activity", default: true
|
t.boolean "public_activity", default: true
|
||||||
t.boolean "newsletter", default: true
|
t.boolean "newsletter", default: true
|
||||||
t.integer "notifications_count", default: 0
|
t.integer "notifications_count", default: 0
|
||||||
t.boolean "registering_with_oauth", default: false
|
t.boolean "registering_with_oauth", default: false
|
||||||
t.string "locale"
|
t.string "locale"
|
||||||
t.string "oauth_email"
|
t.string "oauth_email"
|
||||||
t.integer "geozone_id"
|
t.integer "geozone_id"
|
||||||
t.string "redeemable_code"
|
t.string "redeemable_code"
|
||||||
t.string "gender", limit: 10
|
t.string "gender", limit: 10
|
||||||
t.datetime "date_of_birth"
|
t.datetime "date_of_birth"
|
||||||
|
t.boolean "email_on_proposal_notification", default: true
|
||||||
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
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ feature 'Account' do
|
|||||||
fill_in 'account_username', with: 'Larry Bird'
|
fill_in 'account_username', with: 'Larry Bird'
|
||||||
check 'account_email_on_comment'
|
check 'account_email_on_comment'
|
||||||
check 'account_email_on_comment_reply'
|
check 'account_email_on_comment_reply'
|
||||||
|
uncheck 'account_email_on_proposal_notification'
|
||||||
click_button 'Save changes'
|
click_button 'Save changes'
|
||||||
|
|
||||||
expect(page).to have_content "Changes saved"
|
expect(page).to have_content "Changes saved"
|
||||||
@@ -42,8 +43,9 @@ feature 'Account' do
|
|||||||
visit account_path
|
visit account_path
|
||||||
|
|
||||||
expect(page).to have_selector("input[value='Larry Bird']")
|
expect(page).to have_selector("input[value='Larry Bird']")
|
||||||
expect(page).to have_selector("input[id='account_email_on_comment'][value='1']")
|
expect(find("#account_email_on_comment")).to be_checked
|
||||||
expect(page).to have_selector("input[id='account_email_on_comment_reply'][value='1']")
|
expect(find("#account_email_on_comment_reply")).to be_checked
|
||||||
|
expect(find("#account_email_on_proposal_notification")).to_not be_checked
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Edit Organization' do
|
scenario 'Edit Organization' do
|
||||||
@@ -53,6 +55,7 @@ feature 'Account' do
|
|||||||
fill_in 'account_organization_attributes_name', with: 'Google'
|
fill_in 'account_organization_attributes_name', with: 'Google'
|
||||||
check 'account_email_on_comment'
|
check 'account_email_on_comment'
|
||||||
check 'account_email_on_comment_reply'
|
check 'account_email_on_comment_reply'
|
||||||
|
|
||||||
click_button 'Save changes'
|
click_button 'Save changes'
|
||||||
|
|
||||||
expect(page).to have_content "Changes saved"
|
expect(page).to have_content "Changes saved"
|
||||||
@@ -60,8 +63,8 @@ feature 'Account' do
|
|||||||
visit account_path
|
visit account_path
|
||||||
|
|
||||||
expect(page).to have_selector("input[value='Google']")
|
expect(page).to have_selector("input[value='Google']")
|
||||||
expect(page).to have_selector("input[id='account_email_on_comment'][value='1']")
|
expect(find("#account_email_on_comment")).to be_checked
|
||||||
expect(page).to have_selector("input[id='account_email_on_comment_reply'][value='1']")
|
expect(find("#account_email_on_comment_reply")).to be_checked
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Errors on edit" do
|
scenario "Errors on edit" do
|
||||||
|
|||||||
@@ -148,40 +148,60 @@ feature 'Emails' do
|
|||||||
expect(email).to have_body_text(spending_proposal.feasible_explanation)
|
expect(email).to have_body_text(spending_proposal.feasible_explanation)
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Proposal notification" do
|
context "Proposal notifications" do
|
||||||
author = create(:user)
|
|
||||||
|
|
||||||
noelia = create(:user)
|
scenario "Proposal notification" do
|
||||||
vega = create(:user)
|
author = create(:user)
|
||||||
cristina = create(:user)
|
|
||||||
|
|
||||||
proposal = create(:proposal, author: author)
|
noelia = create(:user)
|
||||||
|
vega = create(:user)
|
||||||
|
cristina = create(:user)
|
||||||
|
|
||||||
create(:vote, voter: noelia, votable: proposal, vote_flag: true)
|
proposal = create(:proposal, author: author)
|
||||||
create(:vote, voter: vega, votable: proposal, vote_flag: true)
|
|
||||||
|
|
||||||
reset_mailer
|
create(:vote, voter: noelia, votable: proposal, vote_flag: true)
|
||||||
|
create(:vote, voter: vega, votable: proposal, vote_flag: true)
|
||||||
|
|
||||||
login_as(author)
|
reset_mailer
|
||||||
visit root_path
|
|
||||||
|
|
||||||
visit new_proposal_notification_path(proposal_id: proposal.id)
|
login_as(author)
|
||||||
|
visit root_path
|
||||||
|
|
||||||
fill_in 'proposal_notification_title', with: "Thank you for supporting my proposal"
|
visit new_proposal_notification_path(proposal_id: proposal.id)
|
||||||
fill_in 'proposal_notification_body', with: "Please share it with others so we can make it happen!"
|
|
||||||
click_button "Send"
|
|
||||||
|
|
||||||
expect(page).to have_content "Your message has been sent correctly."
|
fill_in 'proposal_notification_title', with: "Thank you for supporting my proposal"
|
||||||
|
fill_in 'proposal_notification_body', with: "Please share it with others so we can make it happen!"
|
||||||
|
click_button "Send message"
|
||||||
|
|
||||||
expect(unread_emails_for(noelia.email).size).to eql parse_email_count(1)
|
expect(page).to have_content "Your message has been sent correctly."
|
||||||
expect(unread_emails_for(vega.email).size).to eql parse_email_count(1)
|
|
||||||
expect(unread_emails_for(cristina.email).size).to eql parse_email_count(0)
|
|
||||||
expect(unread_emails_for(author.email).size).to eql parse_email_count(0)
|
|
||||||
|
|
||||||
email = open_last_email
|
expect(unread_emails_for(noelia.email).size).to eql parse_email_count(1)
|
||||||
expect(email).to have_subject("Thank you for supporting my proposal")
|
expect(unread_emails_for(vega.email).size).to eql parse_email_count(1)
|
||||||
expect(email).to have_body_text("Please share it with others so we can make it happen!")
|
expect(unread_emails_for(cristina.email).size).to eql parse_email_count(0)
|
||||||
expect(email).to have_body_text(proposal.title)
|
expect(unread_emails_for(author.email).size).to eql parse_email_count(0)
|
||||||
|
|
||||||
|
email = open_last_email
|
||||||
|
expect(email).to have_subject("Thank you for supporting my proposal")
|
||||||
|
expect(email).to have_body_text("Please share it with others so we can make it happen!")
|
||||||
|
expect(email).to have_body_text(proposal.title)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Do not send email about proposal notifications unless set in preferences", :js do
|
||||||
|
author = create(:user)
|
||||||
|
voter = create(:user, email_on_proposal_notification: false)
|
||||||
|
|
||||||
|
proposal = create(:proposal)
|
||||||
|
create(:vote, voter: voter, votable: proposal, vote_flag: true)
|
||||||
|
|
||||||
|
login_as(author)
|
||||||
|
visit new_proposal_notification_path(proposal_id: proposal.id)
|
||||||
|
|
||||||
|
fill_in 'proposal_notification_title', with: "Thank you for supporting my proposal"
|
||||||
|
fill_in 'proposal_notification_body', with: "Please share it with others so we can make it happen!"
|
||||||
|
click_button "Send message"
|
||||||
|
|
||||||
|
expect { open_last_email }.to raise_error "No email has been sent!"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -83,6 +83,12 @@ describe User do
|
|||||||
expect(subject.newsletter).to eq(true)
|
expect(subject.newsletter).to eq(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'email_on_proposal_notification' do
|
||||||
|
it 'should be true by default' do
|
||||||
|
expect(subject.email_on_proposal_notification).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "administrator?" do
|
describe "administrator?" do
|
||||||
|
|||||||
Reference in New Issue
Block a user