From f5375e813d16d2dbabac6bfbc6dd0760c0891169 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 1 Jun 2016 13:30:44 +0200 Subject: [PATCH 01/58] stores a proposal notification --- .../proposal_notifications_controller.rb | 29 +++++++++++++++++ app/models/proposal_notification.rb | 8 +++++ app/views/proposal_notifications/new.html.erb | 13 ++++++++ .../proposal_notifications/show.html.erb | 2 ++ config/locales/en.yml | 6 ++++ config/locales/es.yml | 6 ++++ config/locales/responders.en.yml | 2 ++ config/locales/responders.es.yml | 1 + config/routes.rb | 2 ++ ...601103338_create_proposal_notifications.rb | 12 +++++++ db/schema.rb | 11 ++++++- spec/factories.rb | 11 +++++-- spec/features/proposal_notifications_spec.rb | 31 +++++++++++++++++++ spec/models/proposal_notification_spec.rb | 25 +++++++++++++++ 14 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 app/controllers/proposal_notifications_controller.rb create mode 100644 app/models/proposal_notification.rb create mode 100644 app/views/proposal_notifications/new.html.erb create mode 100644 app/views/proposal_notifications/show.html.erb create mode 100644 db/migrate/20160601103338_create_proposal_notifications.rb create mode 100644 spec/features/proposal_notifications_spec.rb create mode 100644 spec/models/proposal_notification_spec.rb diff --git a/app/controllers/proposal_notifications_controller.rb b/app/controllers/proposal_notifications_controller.rb new file mode 100644 index 000000000..bd83c941c --- /dev/null +++ b/app/controllers/proposal_notifications_controller.rb @@ -0,0 +1,29 @@ +class ProposalNotificationsController < ApplicationController + skip_authorization_check + + def new + @notification = ProposalNotification.new + @proposal = Proposal.find(params[:proposal_id]) + end + + def create + @notification = ProposalNotification.new(notification_params) + @proposal = Proposal.find(notification_params[:proposal_id]) + if @notification.save + redirect_to @notification, notice: I18n.t("flash.actions.create.proposal_notification") + else + render :new + end + end + + def show + @notification = ProposalNotification.find(params[:id]) + end + + private + + def notification_params + params.require(:proposal_notification).permit(:title, :body, :proposal_id) + end + +end \ No newline at end of file diff --git a/app/models/proposal_notification.rb b/app/models/proposal_notification.rb new file mode 100644 index 000000000..d31b2e1a5 --- /dev/null +++ b/app/models/proposal_notification.rb @@ -0,0 +1,8 @@ +class ProposalNotification < ActiveRecord::Base + belongs_to :author, class_name: 'User', foreign_key: 'author_id' + belongs_to :proposal + + validates :title, presence: true + validates :body, presence: true + validates :proposal, presence: true +end \ No newline at end of file diff --git a/app/views/proposal_notifications/new.html.erb b/app/views/proposal_notifications/new.html.erb new file mode 100644 index 000000000..728b022a1 --- /dev/null +++ b/app/views/proposal_notifications/new.html.erb @@ -0,0 +1,13 @@ +<%= form_for @notification do |f| %> + <%= render "shared/errors", resource: @notification %> + + <%= f.label :title, t("proposal_notifications.new.title_label") %> + <%= f.text_field :title, label: false %> + + <%= f.label :body, t("proposal_notifications.new.body_label") %> + <%= f.text_area :body, label: false %> + + <%= f.hidden_field :proposal_id, value: @proposal.id %> + + <%= f.submit t("proposal_notifications.new.submit_button") %> +<% end %> \ No newline at end of file diff --git a/app/views/proposal_notifications/show.html.erb b/app/views/proposal_notifications/show.html.erb new file mode 100644 index 000000000..e3c50e8cc --- /dev/null +++ b/app/views/proposal_notifications/show.html.erb @@ -0,0 +1,2 @@ +
<%= @notification.title %>
+
<%= @notification.body %>
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 62fc521c5..725e8d08b 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -146,6 +146,7 @@ en: not_saved: 'prevented this %{resource} from being saved:' policy: Privacy Policy proposal: Proposal + proposal_notification: "Notification" spending_proposal: Spending proposal user: Account verification/sms: phone @@ -360,6 +361,11 @@ en: update: form: submit_button: Save changes + proposal_notifications: + new: + title_label: "Title" + body_label: "Message" + submit_button: "Send" shared: advanced_search: author_type: 'By author category' diff --git a/config/locales/es.yml b/config/locales/es.yml index 05e53fc2b..840dcf705 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -146,6 +146,7 @@ es: not_saved: 'impidieron guardar %{resource}:' policy: Política de privacidad proposal: la propuesta + proposal_notification: "la notificación" spending_proposal: la propuesta de gasto user: la cuenta verification/sms: el teléfono @@ -360,6 +361,11 @@ es: update: form: submit_button: Guardar cambios + proposal_notifications: + new: + title_label: "Título" + body_label: "Mensaje" + submit_button: "Enviar" shared: advanced_search: author_type: 'Por categoría de autor' diff --git a/config/locales/responders.en.yml b/config/locales/responders.en.yml index 3f83f746a..1155ff34a 100755 --- a/config/locales/responders.en.yml +++ b/config/locales/responders.en.yml @@ -6,7 +6,9 @@ en: notice: "%{resource_name} created successfully." debate: "Debate created successfully." proposal: "Proposal created successfully." + proposal_notification: "Your message has been sent correctly." spending_proposal: "Spending proposal created successfully. You can access it from %{activity}" + save_changes: notice: Changes saved update: diff --git a/config/locales/responders.es.yml b/config/locales/responders.es.yml index e57dacd31..948b6650f 100644 --- a/config/locales/responders.es.yml +++ b/config/locales/responders.es.yml @@ -6,6 +6,7 @@ es: notice: "%{resource_name} creado correctamente." debate: "Debate creado correctamente." proposal: "Propuesta creada correctamente." + proposal_notification: "Tu message ha sido enviado correctamente." spending_proposal: "Propuesta de inversión creada correctamente. Puedes acceder a ella desde %{activity}" save_changes: notice: Cambios guardados diff --git a/config/routes.rb b/config/routes.rb index 7d0a3a996..6cba48e42 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -93,6 +93,8 @@ Rails.application.routes.draw do put :mark_all_as_read, on: :collection end + resources :proposal_notifications, only: [:new, :create, :show] + resource :verification, controller: "verification", only: [:show] scope module: :verification do diff --git a/db/migrate/20160601103338_create_proposal_notifications.rb b/db/migrate/20160601103338_create_proposal_notifications.rb new file mode 100644 index 000000000..97760da6b --- /dev/null +++ b/db/migrate/20160601103338_create_proposal_notifications.rb @@ -0,0 +1,12 @@ +class CreateProposalNotifications < ActiveRecord::Migration + def change + create_table :proposal_notifications do |t| + t.string :title + t.text :body + t.integer :author_id + t.integer :proposal_id + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 10f10c7a8..91628725a 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: 20160518141543) do +ActiveRecord::Schema.define(version: 20160601103338) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -260,6 +260,15 @@ ActiveRecord::Schema.define(version: 20160518141543) do add_index "organizations", ["user_id"], name: "index_organizations_on_user_id", using: :btree + create_table "proposal_notifications", force: :cascade do |t| + t.string "title" + t.text "body" + t.integer "author_id" + t.integer "proposal_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "proposals", force: :cascade do |t| t.string "title", limit: 80 t.text "description" diff --git a/spec/factories.rb b/spec/factories.rb index 62bea738f..0a9645dcb 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,5 +1,4 @@ FactoryGirl.define do - sequence(:document_number) { |n| "#{n.to_s.rjust(8, '0')}X" } factory :user do @@ -323,7 +322,13 @@ FactoryGirl.define do style {["banner-style-one", "banner-style-two", "banner-style-three"].sample} image {["banner.banner-img-one", "banner.banner-img-two", "banner.banner-img-three"].sample} target_url {["/proposals", "/debates" ].sample} - post_started_at Time.now - 7.days - post_ended_at Time.now + 7.days + post_started_at Time.now - 7.days + post_ended_at Time.now + 7.days + end + + factory :proposal_notification do + title "Thank you for supporting my proposal" + body "Please let others know so we can make it happen" + proposal end end diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb new file mode 100644 index 000000000..756fc3fdd --- /dev/null +++ b/spec/features/proposal_notifications_spec.rb @@ -0,0 +1,31 @@ +require 'rails_helper' + +feature 'Proposal Notifications' do + + scenario "Send a notification" do + noelia = create(:user) + vega = create(:user) + + proposal = create(:proposal) + #use correct path from my activity + 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" + + expect(page).to have_content "Your message has been sent correctly." + expect(page).to have_content "Thank you for supporting my proposal" + expect(page).to have_content "Please share it with others so we can make it happen!" + end + + scenario "Error messages" do + proposal = create(:proposal) + + visit new_proposal_notification_path(proposal_id: proposal.id) + click_button "Send" + + expect(page).to have_content error_message + end + +end \ No newline at end of file diff --git a/spec/models/proposal_notification_spec.rb b/spec/models/proposal_notification_spec.rb new file mode 100644 index 000000000..5a7575219 --- /dev/null +++ b/spec/models/proposal_notification_spec.rb @@ -0,0 +1,25 @@ +require 'rails_helper' + +describe ProposalNotification do + let(:notification) { build(:proposal_notification) } + + it "should be valid" do + expect(notification).to be_valid + end + + it "should not be valid without a title" do + notification.title = nil + expect(notification).to_not be_valid + end + + it "should not be valid without a body" do + notification.body = nil + expect(notification).to_not be_valid + end + + it "should not be valid without an associated proposal" do + notification.proposal = nil + expect(notification).to_not be_valid + end + +end From 6e4ed0b8951e50a9d05f360a846f922a35c5c48a Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 1 Jun 2016 21:01:24 +0200 Subject: [PATCH 02/58] adds link to send message from my activity --- app/controllers/users_controller.rb | 7 +++- app/views/users/_proposals.html.erb | 11 ++++-- config/locales/en.yml | 6 ++-- config/locales/es.yml | 6 ++-- spec/features/proposal_notifications_spec.rb | 38 ++++++++++++++++++-- 5 files changed, 58 insertions(+), 10 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index af4005e06..fbd77f184 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3,6 +3,7 @@ class UsersController < ApplicationController load_and_authorize_resource helper_method :authorized_for_filter? + helper_method :author? helper_method :author_or_admin? def show @@ -65,8 +66,12 @@ class UsersController < ApplicationController @user.public_activity || authorized_current_user? end + def author? + @author ||= current_user && (current_user == @user) + end + def author_or_admin? - @author_or_admin ||= current_user && (current_user == @user || current_user.administrator?) + @author_or_admin ||= current_user && (author? || current_user.administrator?) end def authorized_current_user? diff --git a/app/views/users/_proposals.html.erb b/app/views/users/_proposals.html.erb index e0b54dcc4..d23e865ca 100644 --- a/app/views/users/_proposals.html.erb +++ b/app/views/users/_proposals.html.erb @@ -7,17 +7,24 @@ <%= proposal.summary %> + <% if author? %> + + <%= link_to t("users.proposals.send_message"), new_proposal_notification_path(proposal_id: proposal.id) %> + + <% end %> + <% if author_or_admin? %> <% if proposal.retired? %> - <%= t('users.show.retired') %> + <%= t('users.proposals.retired') %> <% else %> - <%= link_to t('users.show.retire'), + <%= link_to t('users.proposals.retire'), retire_form_proposal_path(proposal), class: 'delete' %> <% end %> <% end %> + <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 725e8d08b..40407f3fc 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -510,8 +510,10 @@ en: other: "%{count} Spending proposals" no_activity: User has no public activity private_activity: This user decided to keep the activity list private - retire: Retire - retired: Retired + proposals: + send_message: "Send message" + retire: "Retire" + retired: "Retired" votes: agree: I agree anonymous: Too many anonymous votes to admit vote %{verify_account}. diff --git a/config/locales/es.yml b/config/locales/es.yml index 840dcf705..4c26d7561 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -510,8 +510,10 @@ es: other: "%{count} Propuestas de inversión" no_activity: Usuario sin actividad pública private_activity: Este usuario ha decidido mantener en privado su lista de actividades - retire: Retirar - retired: Retirada + proposals: + send_message: "Enviar mensaje" + retire: "Retirar" + retired: "Retirada" votes: agree: Estoy de acuerdo anonymous: Demasiados votos anónimos, para poder votar %{verify_account}. diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb index 756fc3fdd..d10beb6f4 100644 --- a/spec/features/proposal_notifications_spec.rb +++ b/spec/features/proposal_notifications_spec.rb @@ -6,9 +6,17 @@ feature 'Proposal Notifications' do noelia = create(:user) vega = create(:user) - proposal = create(:proposal) - #use correct path from my activity - visit new_proposal_notification_path(proposal_id: proposal.id) + author = create(:user) + proposal = create(:proposal, author: author) + + login_as(author) + visit root_path + + click_link "My activity" + + within("#proposal_#{proposal.id}") do + click_link "Send message" + end 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!" @@ -19,6 +27,30 @@ feature 'Proposal Notifications' do expect(page).to have_content "Please share it with others so we can make it happen!" end + context "Permissions" do + + scenario "Link to send the message" do + user = create(:user) + author = create(:user) + proposal = create(:proposal, author: author) + + login_as(author) + visit user_path(author) + + within("#proposal_#{proposal.id}") do + expect(page).to have_link "Send message" + end + + login_as(user) + visit user_path(author) + + within("#proposal_#{proposal.id}") do + expect(page).to_not have_link "Send message" + end + end + + end + scenario "Error messages" do proposal = create(:proposal) From ca26b3423b01a1889cee75ad66a676e0054f1c13 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 1 Jun 2016 21:40:23 +0200 Subject: [PATCH 03/58] sends notification email to each voter --- .../proposal_notifications_controller.rb | 3 ++ app/mailers/mailer.rb | 8 +++++ app/models/proposal.rb | 4 +++ .../mailer/proposal_notification.html.erb | 2 ++ spec/features/emails_spec.rb | 36 +++++++++++++++++++ spec/features/proposal_notifications_spec.rb | 3 -- 6 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 app/views/mailer/proposal_notification.html.erb diff --git a/app/controllers/proposal_notifications_controller.rb b/app/controllers/proposal_notifications_controller.rb index bd83c941c..fe6add7e2 100644 --- a/app/controllers/proposal_notifications_controller.rb +++ b/app/controllers/proposal_notifications_controller.rb @@ -10,6 +10,9 @@ class ProposalNotificationsController < ApplicationController @notification = ProposalNotification.new(notification_params) @proposal = Proposal.find(notification_params[:proposal_id]) if @notification.save + @proposal.voters.each do |voter| + Mailer.proposal_notification(@notification, voter).deliver_later + end redirect_to @notification, notice: I18n.t("flash.actions.create.proposal_notification") else render :new diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 82abbb205..b8ca433ce 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -42,6 +42,14 @@ class Mailer < ApplicationMailer end end + def proposal_notification(notification, voter) + @notification = notification + + with_user(voter) do + mail(to: voter.email, subject: @notification.title) + end + end + private def with_user(user, &block) diff --git a/app/models/proposal.rb b/app/models/proposal.rb index d2b97f1c5..f9ef60303 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -97,6 +97,10 @@ class Proposal < ActiveRecord::Base cached_votes_up + physical_votes end + def voters + votes_for.voters + end + def editable? total_votes <= Setting["max_votes_for_proposal_edit"].to_i end diff --git a/app/views/mailer/proposal_notification.html.erb b/app/views/mailer/proposal_notification.html.erb new file mode 100644 index 000000000..30e8d8bc6 --- /dev/null +++ b/app/views/mailer/proposal_notification.html.erb @@ -0,0 +1,2 @@ +
<%= @notification.proposal.title %>
+
<%= @notification.body %>
diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index c6f0d3708..81e6560ff 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -148,4 +148,40 @@ feature 'Emails' do expect(email).to have_body_text(spending_proposal.feasible_explanation) end + scenario "Proposal notification" do + author = create(:user) + + noelia = create(:user) + vega = create(:user) + cristina = create(:user) + + proposal = create(:proposal, author: author) + + create(:vote, voter: noelia, votable: proposal, vote_flag: true) + create(:vote, voter: vega, votable: proposal, vote_flag: true) + + reset_mailer + + login_as(author) + visit root_path + + 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" + + expect(page).to have_content "Your message has been sent correctly." + + expect(unread_emails_for(noelia.email).size).to eql parse_email_count(1) + 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(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 + end diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb index d10beb6f4..b014aa162 100644 --- a/spec/features/proposal_notifications_spec.rb +++ b/spec/features/proposal_notifications_spec.rb @@ -3,9 +3,6 @@ require 'rails_helper' feature 'Proposal Notifications' do scenario "Send a notification" do - noelia = create(:user) - vega = create(:user) - author = create(:user) proposal = create(:proposal, author: author) From 0ef316de911252aa9c6df2c5b07cd3f205071601 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Thu, 2 Jun 2016 13:36:41 +0200 Subject: [PATCH 04/58] Improves styles for proposal notifications --- .../mailer/proposal_notification.html.erb | 11 ++++++-- app/views/proposal_notifications/new.html.erb | 28 +++++++++++++------ .../proposal_notifications/show.html.erb | 13 +++++++-- config/locales/en.yml | 5 +++- config/locales/es.yml | 5 +++- 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/app/views/mailer/proposal_notification.html.erb b/app/views/mailer/proposal_notification.html.erb index 30e8d8bc6..59489840c 100644 --- a/app/views/mailer/proposal_notification.html.erb +++ b/app/views/mailer/proposal_notification.html.erb @@ -1,2 +1,9 @@ -
<%= @notification.proposal.title %>
-
<%= @notification.body %>
+ +

+ <%= @notification.proposal.title %> +

+ +

+ <%= @notification.body %> +

+ diff --git a/app/views/proposal_notifications/new.html.erb b/app/views/proposal_notifications/new.html.erb index 728b022a1..60f7e64e4 100644 --- a/app/views/proposal_notifications/new.html.erb +++ b/app/views/proposal_notifications/new.html.erb @@ -1,13 +1,23 @@ -<%= form_for @notification do |f| %> - <%= render "shared/errors", resource: @notification %> +
+
+ <%= render 'shared/back_link' %> - <%= f.label :title, t("proposal_notifications.new.title_label") %> - <%= f.text_field :title, label: false %> +

<%= t("proposal_notifications.new.title") %>

- <%= f.label :body, t("proposal_notifications.new.body_label") %> - <%= f.text_area :body, label: false %> + <%= form_for @notification do |f| %> + <%= render "shared/errors", resource: @notification %> - <%= f.hidden_field :proposal_id, value: @proposal.id %> + <%= f.label :title, t("proposal_notifications.new.title_label") %> + <%= f.text_field :title, label: false %> - <%= f.submit t("proposal_notifications.new.submit_button") %> -<% end %> \ No newline at end of file + <%= f.label :body, t("proposal_notifications.new.body_label") %> + <%= f.text_area :body, label: false, rows: "3" %> + + <%= f.hidden_field :proposal_id, value: @proposal.id %> + +
+ <%= f.submit t("proposal_notifications.new.submit_button"), class: "button expanded" %> +
+ <% end %> +
+
diff --git a/app/views/proposal_notifications/show.html.erb b/app/views/proposal_notifications/show.html.erb index e3c50e8cc..379b361fb 100644 --- a/app/views/proposal_notifications/show.html.erb +++ b/app/views/proposal_notifications/show.html.erb @@ -1,2 +1,11 @@ -
<%= @notification.title %>
-
<%= @notification.body %>
\ No newline at end of file +
+
+ <%= link_to user_path(current_user), class: "back" do %> + + <%= t("proposal_notifications.show.back") %> + <% end %> + +

<%= @notification.title %>

+

<%= @notification.body %>

+
+
diff --git a/config/locales/en.yml b/config/locales/en.yml index 40407f3fc..40b32f712 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -363,9 +363,12 @@ en: submit_button: Save changes proposal_notifications: new: + title: "Send message" title_label: "Title" body_label: "Message" - submit_button: "Send" + submit_button: "Send message" + show: + back: "Go back to my activity" shared: advanced_search: author_type: 'By author category' diff --git a/config/locales/es.yml b/config/locales/es.yml index 4c26d7561..5dc388853 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -363,9 +363,12 @@ es: submit_button: Guardar cambios proposal_notifications: new: + title: "Enviar mensaje" title_label: "Título" body_label: "Mensaje" - submit_button: "Enviar" + submit_button: "Enviar mensaje" + show: + back: "Volver a mi actividad" shared: advanced_search: author_type: 'Por categoría de autor' From fc6cc090f8ab9dbb0d18484f06a818f4e31e6dab Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 6 Jun 2016 12:21:48 +0200 Subject: [PATCH 05/58] displays notifications in proposal view --- app/controllers/proposals_controller.rb | 2 +- app/models/proposal.rb | 5 +++++ app/views/proposals/_notifications.html.erb | 6 ++++++ app/views/proposals/show.html.erb | 1 + spec/features/proposal_notifications_spec.rb | 14 ++++++++++++++ 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 app/views/proposals/_notifications.html.erb diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 0b350f687..578395ab3 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -2,7 +2,6 @@ class ProposalsController < ApplicationController include CommentableActions include FlagActions - before_action :parse_search_terms, only: [:index, :suggest] before_action :parse_advanced_search_terms, only: :index before_action :parse_tag_filter, only: :index @@ -22,6 +21,7 @@ class ProposalsController < ApplicationController def show super + @notifications = @proposal.notifications redirect_to proposal_path(@proposal), status: :moved_permanently if request.path != proposal_path(@proposal) end diff --git a/app/models/proposal.rb b/app/models/proposal.rb index f9ef60303..7d2bddb30 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -16,6 +16,7 @@ class Proposal < ActiveRecord::Base belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :geozone has_many :comments, as: :commentable + has_many :proposal_notifications validates :title, presence: true validates :question, presence: true @@ -154,6 +155,10 @@ class Proposal < ActiveRecord::Base Setting['votes_for_proposal_success'].to_i end + def notifications + proposal_notifications + end + protected def set_responsible_name diff --git a/app/views/proposals/_notifications.html.erb b/app/views/proposals/_notifications.html.erb new file mode 100644 index 000000000..576ed8cc6 --- /dev/null +++ b/app/views/proposals/_notifications.html.erb @@ -0,0 +1,6 @@ +
+ <% @notifications.each do |notification| %> +
<%= notification.title %>
+
<%= notification.body %>
+ <% end %> +
\ No newline at end of file diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index cb2773c65..9d8c3b739 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -118,4 +118,5 @@ <% end %> +<%= render "proposals/notifications" %> <%= render "proposals/comments" %> diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb index b014aa162..1662475b1 100644 --- a/spec/features/proposal_notifications_spec.rb +++ b/spec/features/proposal_notifications_spec.rb @@ -24,6 +24,20 @@ feature 'Proposal Notifications' do expect(page).to have_content "Please share it with others so we can make it happen!" end + scenario "Show notifications" do + proposal = create(:proposal) + notification1 = create(:proposal_notification, proposal: proposal, title: "Hey guys", body: "Just wanted to let you know that...") + notification2 = create(:proposal_notification, proposal: proposal, title: "Another update", body: "We are almost there please share with your peoples!") + + visit proposal_path(proposal) + + expect(page).to have_content "Hey guys" + expect(page).to have_content "Just wanted to let you know that..." + + expect(page).to have_content "Another update" + expect(page).to have_content "We are almost there please share with your peoples!" + end + context "Permissions" do scenario "Link to send the message" do From ad697cd2c190b2079b77f769783ac7c1bb75cb8d Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 6 Jun 2016 12:55:33 +0200 Subject: [PATCH 06/58] adds preference to receive proposal notifications --- app/controllers/account_controller.rb | 2 +- .../proposal_notifications_controller.rb | 4 +- app/views/account/show.html.erb | 25 +++++-- config/locales/en.yml | 1 + config/locales/es.yml | 1 + ...email_on_proposal_notification_to_users.rb | 5 ++ db/schema.rb | 35 +++++----- spec/features/account_spec.rb | 11 +-- spec/features/emails_spec.rb | 68 ++++++++++++------- spec/models/user_spec.rb | 6 ++ 10 files changed, 107 insertions(+), 51 deletions(-) create mode 100644 db/migrate/20160606102427_add_email_on_proposal_notification_to_users.rb diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 9a0f89bae..d1ac9c9c4 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -25,7 +25,7 @@ class AccountController < ApplicationController if @account.organization? 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, :newsletter) + params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply, :email_on_proposal_notification, :newsletter) end end diff --git a/app/controllers/proposal_notifications_controller.rb b/app/controllers/proposal_notifications_controller.rb index fe6add7e2..f1249c707 100644 --- a/app/controllers/proposal_notifications_controller.rb +++ b/app/controllers/proposal_notifications_controller.rb @@ -11,7 +11,9 @@ class ProposalNotificationsController < ApplicationController @proposal = Proposal.find(notification_params[:proposal_id]) if @notification.save @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 redirect_to @notification, notice: I18n.t("flash.actions.create.proposal_notification") else diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index f0d2b6abc..b3a84dede 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -34,7 +34,9 @@
<%= f.label :public_activity do %> <%= f.check_box :public_activity, title: t('account.show.public_activity_label'), label: false %> - <%= t("account.show.public_activity_label") %> + + <%= t("account.show.public_activity_label") %> + <% end %>
@@ -43,21 +45,36 @@
<%= f.label :email_on_comment do %> <%= f.check_box :email_on_comment, title: t('account.show.email_on_comment_label'), label: false %> - <%= t("account.show.email_on_comment_label") %> + + <%= t("account.show.email_on_comment_label") %> + <% end %>
<%= 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 %> - <%= t("account.show.email_on_comment_reply_label") %> + + <%= t("account.show.email_on_comment_reply_label") %> + <% end %>
<%= f.label :email_newsletter_subscribed do %> <%= f.check_box :newsletter, title: t('account.show.subscription_to_website_newsletter_label'), label: false %> - <%= t("account.show.subscription_to_website_newsletter_label") %> + + <%= t("account.show.subscription_to_website_newsletter_label") %> + + <% end %> +
+ +
+ <%= 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 %> + + <%= t("account.show.email_on_proposal_notification_label") %> + <% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 40b32f712..5a0dec0c6 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -15,6 +15,7 @@ en: public_activity_label: Keep my list of activities public save_changes_submit: Save changes 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 user_permission_debates: Participate on debates user_permission_info: With your account you can... diff --git a/config/locales/es.yml b/config/locales/es.yml index 5dc388853..909e20bbc 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -15,6 +15,7 @@ es: public_activity_label: Mostrar públicamente mi lista de actividades save_changes_submit: Guardar cambios 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 user_permission_debates: Participar en debates user_permission_info: Con tu cuenta ya puedes... diff --git a/db/migrate/20160606102427_add_email_on_proposal_notification_to_users.rb b/db/migrate/20160606102427_add_email_on_proposal_notification_to_users.rb new file mode 100644 index 000000000..84753eb50 --- /dev/null +++ b/db/migrate/20160606102427_add_email_on_proposal_notification_to_users.rb @@ -0,0 +1,5 @@ +class AddEmailOnProposalNotificationToUsers < ActiveRecord::Migration + def change + add_column :users, :email_on_proposal_notification, :boolean, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 91628725a..a8e09434e 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: 20160601103338) do +ActiveRecord::Schema.define(version: 20160606102427) do # These are extensions that must be enabled in order to support this database 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 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" @@ -436,20 +436,21 @@ ActiveRecord::Schema.define(version: 20160601103338) 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 "newsletter", default: true - t.integer "notifications_count", default: 0 - t.boolean "registering_with_oauth", default: false + t.boolean "public_activity", default: true + t.boolean "newsletter", default: true + t.integer "notifications_count", default: 0 + t.boolean "registering_with_oauth", default: false t.string "locale" t.string "oauth_email" t.integer "geozone_id" t.string "redeemable_code" - t.string "gender", limit: 10 + t.string "gender", limit: 10 t.datetime "date_of_birth" + t.boolean "email_on_proposal_notification", default: true end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree diff --git a/spec/features/account_spec.rb b/spec/features/account_spec.rb index bc9c38dae..f5ba747fb 100644 --- a/spec/features/account_spec.rb +++ b/spec/features/account_spec.rb @@ -35,6 +35,7 @@ feature 'Account' do fill_in 'account_username', with: 'Larry Bird' check 'account_email_on_comment' check 'account_email_on_comment_reply' + uncheck 'account_email_on_proposal_notification' click_button 'Save changes' expect(page).to have_content "Changes saved" @@ -42,8 +43,9 @@ feature 'Account' do visit account_path expect(page).to have_selector("input[value='Larry Bird']") - expect(page).to have_selector("input[id='account_email_on_comment'][value='1']") - expect(page).to have_selector("input[id='account_email_on_comment_reply'][value='1']") + expect(find("#account_email_on_comment")).to be_checked + expect(find("#account_email_on_comment_reply")).to be_checked + expect(find("#account_email_on_proposal_notification")).to_not be_checked end scenario 'Edit Organization' do @@ -53,6 +55,7 @@ feature 'Account' do fill_in 'account_organization_attributes_name', with: 'Google' check 'account_email_on_comment' check 'account_email_on_comment_reply' + click_button 'Save changes' expect(page).to have_content "Changes saved" @@ -60,8 +63,8 @@ feature 'Account' do visit account_path expect(page).to have_selector("input[value='Google']") - expect(page).to have_selector("input[id='account_email_on_comment'][value='1']") - expect(page).to have_selector("input[id='account_email_on_comment_reply'][value='1']") + expect(find("#account_email_on_comment")).to be_checked + expect(find("#account_email_on_comment_reply")).to be_checked end scenario "Errors on edit" do diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index 81e6560ff..e61403635 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -148,40 +148,60 @@ feature 'Emails' do expect(email).to have_body_text(spending_proposal.feasible_explanation) end - scenario "Proposal notification" do - author = create(:user) + context "Proposal notifications" do - noelia = create(:user) - vega = create(:user) - cristina = create(:user) + scenario "Proposal notification" do + author = 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) - create(:vote, voter: vega, votable: proposal, vote_flag: true) + proposal = create(:proposal, author: author) - reset_mailer + create(:vote, voter: noelia, votable: proposal, vote_flag: true) + create(:vote, voter: vega, votable: proposal, vote_flag: true) - login_as(author) - visit root_path + reset_mailer - 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" - fill_in 'proposal_notification_body', with: "Please share it with others so we can make it happen!" - click_button "Send" + visit new_proposal_notification_path(proposal_id: proposal.id) - 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(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) + expect(page).to have_content "Your message has been sent correctly." - 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) + expect(unread_emails_for(noelia.email).size).to eql parse_email_count(1) + 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(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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 054e043f9..ca46ff68f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -83,6 +83,12 @@ describe User do expect(subject.newsletter).to eq(true) 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 describe "administrator?" do From 86f0cae7bbdd78141f0cd8d3bb7f34b60c9d7c41 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 6 Jun 2016 13:52:40 +0200 Subject: [PATCH 07/58] fixes specs --- app/views/proposals/_notifications.html.erb | 14 ++++++++------ spec/features/proposal_notifications_spec.rb | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/views/proposals/_notifications.html.erb b/app/views/proposals/_notifications.html.erb index 576ed8cc6..9e3af3e9e 100644 --- a/app/views/proposals/_notifications.html.erb +++ b/app/views/proposals/_notifications.html.erb @@ -1,6 +1,8 @@ -
- <% @notifications.each do |notification| %> -
<%= notification.title %>
-
<%= notification.body %>
- <% end %> -
\ No newline at end of file +<% if @notifications.present? %> +
+ <% @notifications.each do |notification| %> +
<%= notification.title %>
+
<%= notification.body %>
+ <% end %> +
+<% end %> \ No newline at end of file diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb index 1662475b1..3046c6ab5 100644 --- a/spec/features/proposal_notifications_spec.rb +++ b/spec/features/proposal_notifications_spec.rb @@ -17,7 +17,7 @@ feature 'Proposal Notifications' do 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" + click_button "Send message" expect(page).to have_content "Your message has been sent correctly." expect(page).to have_content "Thank you for supporting my proposal" @@ -66,7 +66,7 @@ feature 'Proposal Notifications' do proposal = create(:proposal) visit new_proposal_notification_path(proposal_id: proposal.id) - click_button "Send" + click_button "Send message" expect(page).to have_content error_message end From a2c9756c1873fe09ac02e09f58f62a140dcd890a Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 6 Jun 2016 16:50:00 +0200 Subject: [PATCH 08/58] displays message about receivers --- app/views/proposal_notifications/new.html.erb | 8 ++++++++ config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ spec/features/proposal_notifications_spec.rb | 13 +++++++++++++ 4 files changed, 25 insertions(+) diff --git a/app/views/proposal_notifications/new.html.erb b/app/views/proposal_notifications/new.html.erb index 60f7e64e4..f8be10c2e 100644 --- a/app/views/proposal_notifications/new.html.erb +++ b/app/views/proposal_notifications/new.html.erb @@ -4,6 +4,14 @@

<%= t("proposal_notifications.new.title") %>

+

+ <%= t("proposal_notifications.new.info_about_receivers", + count: @proposal.voters.count) %> + + <%= link_to t("proposal_notifications.new.proposal_page"), + proposal_path(@proposal) %> +

+ <%= form_for @notification do |f| %> <%= render "shared/errors", resource: @notification %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 5a0dec0c6..a830de2d8 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -368,6 +368,8 @@ en: title_label: "Title" body_label: "Message" submit_button: "Send message" + info_about_receivers: "This message will be send to %{count} people and it will be visible in " + proposal_page: "the proposal's page" show: back: "Go back to my activity" shared: diff --git a/config/locales/es.yml b/config/locales/es.yml index 909e20bbc..670aaa2d6 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -368,6 +368,8 @@ es: title_label: "Título" body_label: "Mensaje" submit_button: "Enviar mensaje" + info_about_receivers: "Este mensaje se enviará a %{count} usuarios y se publicará en " + proposal_page: "la página de la propuesta" show: back: "Volver a mi actividad" shared: diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb index 3046c6ab5..f40e0b81e 100644 --- a/spec/features/proposal_notifications_spec.rb +++ b/spec/features/proposal_notifications_spec.rb @@ -38,6 +38,19 @@ feature 'Proposal Notifications' do expect(page).to have_content "We are almost there please share with your peoples!" end + scenario "Message about receivers" do + author = create(:user) + proposal = create(:proposal, author: author) + + 7.times { create(:vote, votable: proposal, vote_flag: true) } + + login_as(author) + visit new_proposal_notification_path(proposal_id: proposal.id) + + expect(page).to have_content "This message will be send to 7 people and it will be visible in the proposal's page" + expect(page).to have_link("the proposal's page", href: proposal_path(proposal)) + end + context "Permissions" do scenario "Link to send the message" do From 84f9dcaa7650855b0dafb1ccc82a6548515646a6 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 6 Jun 2016 17:26:48 +0200 Subject: [PATCH 09/58] Adds tabs for notifications on proposal show --- app/assets/stylesheets/_settings.scss | 136 ++++++++++---------- app/assets/stylesheets/layout.scss | 32 ++++- app/assets/stylesheets/participation.scss | 10 ++ app/views/proposals/_comments.html.erb | 12 +- app/views/proposals/_filter_subnav.html.erb | 22 ++++ app/views/proposals/_notifications.html.erb | 17 ++- app/views/proposals/show.html.erb | 13 +- app/views/users/_proposals.html.erb | 5 +- config/locales/en.yml | 2 + config/locales/es.yml | 2 + 10 files changed, 166 insertions(+), 85 deletions(-) create mode 100644 app/views/proposals/_filter_subnav.html.erb diff --git a/app/assets/stylesheets/_settings.scss b/app/assets/stylesheets/_settings.scss index 22e7ac8de..1e181e1c1 100644 --- a/app/assets/stylesheets/_settings.scss +++ b/app/assets/stylesheets/_settings.scss @@ -3,6 +3,7 @@ // // Table of Contents: // +// 0. Custom variables // 1. Global // 2. Breakpoints // 3. The Grid @@ -43,6 +44,70 @@ @import 'util/util'; +// 0. Custom variables +// -------------------- + +$base-font-size: rem-calc(17); +$base-line-height: rem-calc(26); +$small-font-size: rem-calc(14); +$line-height: rem-calc(24); + +$brand: #004A83; +$body: #E9E9E9; +$background: #EDEFF0; +$border: #DEE0E3; +$dark: darken($brand, 10%); + +$text: #222222; +$text-medium: #999999; +$text-light: #CCCCCC; + +$link: #2895F1; +$link-hover: #2178BF; + +$debates: #008CCF; +$votes-bg: #26AEEE; +$votes-border: #1F94CB; + +$votes-like: #7BD2A8; +$votes-like-act: #5D9E7F; +$votes-unlike: #EF8585; +$votes-unlike-act: #BD6A6A; + +$delete: #F04124; +$check: #46DB91; + +$proposals: #FFA42D; +$proposals-border: #CC8425; + +$budget: #454372; +$budget-hover: #7571BF; + +$highlight: #E7F2FC; +$featured: #FED900; + +$footer-bg: #DEE0E2; +$footer-color: #171819; +$footer-link: #454A4C; +$footer-border: #BFC1C3; + +$success-bg: #DFF0D8; +$success-border: #D6E9C6; +$color-success: #3C763D; + +$info-bg: #D9EDF7; +$info-border: #BCE8F1; +$color-info: #31708F; + +$warning-bg: #FCF8E3; +$warning-border: #FAEBCC; +$color-warning: #8A6D3B; + +$alert-bg: #F2DEDE; +$alert-border: #EBCCD1; +$color-alert: #A94442; + + // 1. Global // --------- @@ -510,13 +575,13 @@ $show-header-for-stacked: false; $tab-margin: 0; $tab-background: $white; -$tab-background-active: $light-gray; -$tab-item-font-size: rem-calc(12); +$tab-background-active: $white; +$tab-item-font-size: $base-font-size; $tab-item-background-hover: $white; -$tab-item-padding: 1.25rem 1.5rem; +$tab-item-padding: $line-height/2 0; $tab-expand-max: 6; $tab-content-background: $white; -$tab-content-border: $light-gray; +$tab-content-border: $border; $tab-content-color: foreground($tab-background, $primary-color); $tab-content-padding: 1rem; @@ -563,66 +628,3 @@ $topbar-submenu-background: $topbar-background; $topbar-title-spacing: 1rem; $topbar-input-width: 200px; $topbar-unstack-breakpoint: medium; - -// 37. Custom variables -// -------------------- - -$base-font-size: rem-calc(17); -$base-line-height: rem-calc(26); -$small-font-size: rem-calc(14); -$line-height: rem-calc(24); - -$brand: #004A83; -$body: #E9E9E9; -$background: #EDEFF0; -$border: #DEE0E3; -$dark: darken($brand, 10%); - -$text: #222222; -$text-medium: #999999; -$text-light: #CCCCCC; - -$link: #2895F1; -$link-hover: #2178BF; - -$debates: #008CCF; -$votes-bg: #26AEEE; -$votes-border: #1F94CB; - -$votes-like: #7BD2A8; -$votes-like-act: #5D9E7F; -$votes-unlike: #EF8585; -$votes-unlike-act: #BD6A6A; - -$delete: #F04124; -$check: #46DB91; - -$proposals: #FFA42D; -$proposals-border: #CC8425; - -$budget: #454372; -$budget-hover: #7571BF; - -$highlight: #E7F2FC; -$featured: #FED900; - -$footer-bg: #DEE0E2; -$footer-color: #171819; -$footer-link: #454A4C; -$footer-border: #BFC1C3; - -$success-bg: #DFF0D8; -$success-border: #D6E9C6; -$color-success: #3C763D; - -$info-bg: #D9EDF7; -$info-border: #BCE8F1; -$color-info: #31708F; - -$warning-bg: #FCF8E3; -$warning-border: #FAEBCC; -$color-warning: #8A6D3B; - -$alert-bg: #F2DEDE; -$alert-border: #EBCCD1; -$color-alert: #A94442; diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 42f6f177d..ea426cf45 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -219,6 +219,35 @@ a { float: left; } +.tabs-content { + border: 0; +} + +.tabs { + border: { + left: 0; + right: 0; + top: 0; + }; + + .tabs-title > a { + color: $text-medium; + margin-bottom: rem-calc(-1); + margin-right: $line-height; + + &[aria-selected='true'], + &.is-active { + color: $brand; + border-bottom: 2px solid $brand; + font-weight: bold; + } + } + + h2 { + font-size: $base-font-size; + } +} + // 02. Header // ---------- @@ -1460,7 +1489,6 @@ table { .comments { background: $white; background-repeat: repeat-x; - padding-top: $line-height; padding-bottom: $line-height*4; h2 { @@ -1647,7 +1675,7 @@ table { &:first-child { padding-left: $line-height*1.5; - width: 80%; + width: 75%; } &:before { diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 502fe62aa..6e5b4273a 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -715,6 +715,16 @@ } } +.more-info { + clear: both; + color: $text-medium; + font-size: $small-font-size; + + a { + color: $text-medium; + } +} + .debate { .votes { diff --git a/app/views/proposals/_comments.html.erb b/app/views/proposals/_comments.html.erb index 31f1cb8ba..094814cf1 100644 --- a/app/views/proposals/_comments.html.erb +++ b/app/views/proposals/_comments.html.erb @@ -1,11 +1,13 @@ <% cache [locale_and_user_status, @current_order, commentable_cache_key(@proposal), @comment_tree.comments, @comment_tree.comment_authors, @proposal.comments_count, @comment_flags] do %> -
+
-

- <%= t("proposals.show.comments_title") %> - (<%= @proposal.comments_count %>) -

+ <% if @notifications.blank? %> +

+ <%= t("proposals.show.comments_title") %> + (<%= @proposal.comments_count %>) +

+ <% end %> <%= render 'shared/wide_order_selector', i18n_namespace: "comments" %> diff --git a/app/views/proposals/_filter_subnav.html.erb b/app/views/proposals/_filter_subnav.html.erb new file mode 100644 index 000000000..b7bc85dd6 --- /dev/null +++ b/app/views/proposals/_filter_subnav.html.erb @@ -0,0 +1,22 @@ +
+
+
    +
  • + <%= link_to "#tab-comments" do %> +

    + <%= t("proposals.show.comments_tab") %> + (<%= @proposal.comments_count %>) +

    + <% end %> +
  • +
  • + <%= link_to "#tab-notifications" do %> +

    + <%= t("proposals.show.notifications_tab") %> + (<%= @notifications.count %>) +

    + <% end %> +
  • +
+
+
diff --git a/app/views/proposals/_notifications.html.erb b/app/views/proposals/_notifications.html.erb index 9e3af3e9e..44bb9f4a2 100644 --- a/app/views/proposals/_notifications.html.erb +++ b/app/views/proposals/_notifications.html.erb @@ -1,8 +1,11 @@ -<% if @notifications.present? %> -
- <% @notifications.each do |notification| %> -
<%= notification.title %>
-
<%= notification.body %>
- <% end %> +
+
+
+ <% @notifications.each do |notification| %> +

<%= notification.title %>

+

<%= notification.created_at.to_date %>

+

<%= notification.body %>

+ <% end %> +
-<% end %> \ No newline at end of file +
diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 9d8c3b739..2a6ae7185 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -118,5 +118,14 @@
<% end %> -<%= render "proposals/notifications" %> -<%= render "proposals/comments" %> + +
+ <% if @notifications.present? %> + <%= render "proposals/filter_subnav" %> + <%= render "proposals/notifications" %> + <% end %> + +
+ <%= render "proposals/comments" %> +
+
diff --git a/app/views/users/_proposals.html.erb b/app/views/users/_proposals.html.erb index d23e865ca..a56b096f6 100644 --- a/app/views/users/_proposals.html.erb +++ b/app/views/users/_proposals.html.erb @@ -9,7 +9,8 @@ <% if author? %> - <%= link_to t("users.proposals.send_message"), new_proposal_notification_path(proposal_id: proposal.id) %> + <%= link_to t("users.proposals.send_message"), new_proposal_notification_path(proposal_id: proposal.id), + class: 'button hollow' %> <% end %> @@ -20,7 +21,7 @@ <% else %> <%= link_to t('users.proposals.retire'), retire_form_proposal_path(proposal), - class: 'delete' %> + class: 'button hollow alert' %> <% end %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 5a0dec0c6..4d5816f4c 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -351,10 +351,12 @@ en: one: 1 comment other: "%{count} comments" zero: No comments + comments_tab: Comments comments_title: Comments edit_proposal_link: Edit flag: This proposal has been flagged as inappropriate by several users. login_to_comment: You must %{signin} or %{signup} to leave a comment. + notifications_tab: Notifications retired_warning: "The author considers this proposal should not receive more supports." retired_warning_link_to_explanation: Read the explanation before voting for it. retired: Proposal retired by the author diff --git a/config/locales/es.yml b/config/locales/es.yml index 909e20bbc..36b318cc7 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -351,10 +351,12 @@ es: one: 1 Comentario other: "%{count} Comentarios" zero: Sin comentarios + comments_tab: Comentarios comments_title: Comentarios edit_proposal_link: Editar propuesta flag: Esta propuesta ha sido marcada como inapropiada por varios usuarios. login_to_comment: Necesitas %{signin} o %{signup} para comentar. + notifications_tab: Notificaciones retired_warning: "El autor de esta propuesta considera que ya no debe seguir recogiendo apoyos." retired_warning_link_to_explanation: Revisa su explicación antes de apoyarla. retired: Propuesta retirada por el autor From 14f17983f4363efb2b0976d88f1da7ac57863018 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 6 Jun 2016 17:30:31 +0200 Subject: [PATCH 10/58] Improves styles for about receivers message --- app/views/proposal_notifications/new.html.erb | 14 ++++++++------ config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/views/proposal_notifications/new.html.erb b/app/views/proposal_notifications/new.html.erb index f8be10c2e..a5f829ecc 100644 --- a/app/views/proposal_notifications/new.html.erb +++ b/app/views/proposal_notifications/new.html.erb @@ -4,13 +4,15 @@

<%= t("proposal_notifications.new.title") %>

-

- <%= t("proposal_notifications.new.info_about_receivers", - count: @proposal.voters.count) %> +

+

+ <%= t("proposal_notifications.new.info_about_receivers_html", + count: @proposal.voters.count) %> - <%= link_to t("proposal_notifications.new.proposal_page"), - proposal_path(@proposal) %> -

+ <%= link_to t("proposal_notifications.new.proposal_page"), + proposal_path(@proposal) %> +

+
<%= form_for @notification do |f| %> <%= render "shared/errors", resource: @notification %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 059cf5cd6..8905e0f00 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -370,7 +370,7 @@ en: title_label: "Title" body_label: "Message" submit_button: "Send message" - info_about_receivers: "This message will be send to %{count} people and it will be visible in " + info_about_receivers_html: "This message will be send to %{count} people and it will be visible in " proposal_page: "the proposal's page" show: back: "Go back to my activity" diff --git a/config/locales/es.yml b/config/locales/es.yml index 150c42583..24da77968 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -370,7 +370,7 @@ es: title_label: "Título" body_label: "Mensaje" submit_button: "Enviar mensaje" - info_about_receivers: "Este mensaje se enviará a %{count} usuarios y se publicará en " + info_about_receivers_html: "Este mensaje se enviará a %{count} usuarios y se publicará en " proposal_page: "la página de la propuesta" show: back: "Volver a mi actividad" From 224c9d42c49418401cfc92ea5b4a9eb7de0b36c3 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 6 Jun 2016 17:47:17 +0200 Subject: [PATCH 11/58] Fixes layout for order comments --- app/assets/stylesheets/layout.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index ea426cf45..fdf7ff6c1 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -229,6 +229,7 @@ a { right: 0; top: 0; }; + margin-bottom: $line-height; .tabs-title > a { color: $text-medium; From bfc9c6c0dff9507ad686bc52ee94485350039db6 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 6 Jun 2016 17:51:16 +0200 Subject: [PATCH 12/58] Improves styles for proposal show --- app/assets/stylesheets/layout.scss | 2 +- app/views/proposals/show.html.erb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index fdf7ff6c1..209bcc3c6 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -1513,7 +1513,7 @@ table { .comment-votes { color: $text-medium; - font-size: $small-font-size; + font-size: rem-calc(14); line-height: $line-height; a { diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 2a6ae7185..8a391a031 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -13,8 +13,7 @@ <%= render "shared/back_link" %> <% if current_user && @proposal.editable_by?(current_user) %> - <%= link_to edit_proposal_path(@proposal), class: 'edit-proposal button success small float-right' do %> - + <%= link_to edit_proposal_path(@proposal), class: 'edit-proposal button hollow float-right' do %> <%= t("proposals.show.edit_proposal_link") %> <% end %> <% end %> From 8e12fbdd557eaf1c1aa43943a13f61aa1fe9ad2f Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 7 Jun 2016 13:48:09 +0200 Subject: [PATCH 13/58] adds time limit between notifications --- app/models/proposal_notification.rb | 9 ++++++ config/locales/activerecord.en.yml | 3 ++ config/locales/activerecord.es.yml | 3 ++ db/seeds.rb | 3 ++ spec/features/proposal_notifications_spec.rb | 10 ++++++ spec/models/proposal_notification_spec.rb | 34 ++++++++++++++++++++ 6 files changed, 62 insertions(+) diff --git a/app/models/proposal_notification.rb b/app/models/proposal_notification.rb index d31b2e1a5..11bfea8ae 100644 --- a/app/models/proposal_notification.rb +++ b/app/models/proposal_notification.rb @@ -5,4 +5,13 @@ class ProposalNotification < ActiveRecord::Base validates :title, presence: true validates :body, presence: true validates :proposal, presence: true + validate :minimum_interval + + def minimum_interval + return true if proposal.notifications.blank? + if proposal.notifications.last.created_at > (Time.now - Setting[:proposal_notification_minimum_interval_in_days].to_i.days).to_datetime + errors.add(:minimum_interval, I18n.t('activerecord.errors.models.proposal_notification.minimum_interval', interval: Setting[:proposal_notification_minimum_interval])) + end + end + end \ No newline at end of file diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 91c035dfb..1d46596c2 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -84,3 +84,6 @@ en: attributes: tag_list: less_than_or_equal_to: "tags must be less than or equal to %{count}" + proposal_notification: + attributes: + minimum_interval: "You have to wait a minium of %{interval} days between notifications" \ No newline at end of file diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index a7644f02e..001be7228 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -84,3 +84,6 @@ es: attributes: tag_list: less_than_or_equal_to: "los temas deben ser menor o igual que %{count}" + proposal_notification: + attributes: + minimum_interval: "Debes esperar un mínimo de %{interval} días entre notificaciones" \ No newline at end of file diff --git a/db/seeds.rb b/db/seeds.rb index 7555f6999..5a6db1574 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -74,3 +74,6 @@ Setting['banner-style.banner-style-three'] = "Banner style 3" Setting['banner-img.banner-img-one'] = "Banner image 1" Setting['banner-img.banner-img-two'] = "Banner image 2" Setting['banner-img.banner-img-three'] = "Banner image 3" + +# Proposal notifications +Setting['proposal_notification_minimum_interval_in_days '] = 3 diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb index f40e0b81e..87a717ba2 100644 --- a/spec/features/proposal_notifications_spec.rb +++ b/spec/features/proposal_notifications_spec.rb @@ -84,4 +84,14 @@ feature 'Proposal Notifications' do expect(page).to have_content error_message end + context "Limits" do + + pending "Cannot send more than one notification within established interval" do + end + + pending "use timecop to make sure notifications can be sent after time interval" do + end + + end + end \ No newline at end of file diff --git a/spec/models/proposal_notification_spec.rb b/spec/models/proposal_notification_spec.rb index 5a7575219..f66b254b6 100644 --- a/spec/models/proposal_notification_spec.rb +++ b/spec/models/proposal_notification_spec.rb @@ -22,4 +22,38 @@ describe ProposalNotification do expect(notification).to_not be_valid end + describe "minimum interval between notifications" do + + before(:each) do + Setting[:proposal_notification_minimum_interval_in_days] = 3 + end + + it "should not be valid if below minium interval" do + proposal = create(:proposal) + + notification1 = create(:proposal_notification, proposal: proposal) + notification2 = build(:proposal_notification, proposal: proposal) + + proposal.reload + expect(notification2).to_not be_valid + end + + it "should be valid if notifications above minium interval" do + proposal = create(:proposal) + + notification1 = create(:proposal_notification, proposal: proposal, created_at: 4.days.ago) + notification2 = build(:proposal_notification, proposal: proposal) + + proposal.reload + expect(notification2).to be_valid + end + + it "should be valid if no notifications sent" do + notification1 = build(:proposal_notification) + + expect(notification1).to be_valid + end + + end + end From 43251585b99398ca38fe962f7a64e3271b23e591 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 7 Jun 2016 13:56:40 +0200 Subject: [PATCH 14/58] pending permissions spec --- spec/models/abilities/everyone_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/models/abilities/everyone_spec.rb b/spec/models/abilities/everyone_spec.rb index 3f1e57278..30ce5c3a6 100644 --- a/spec/models/abilities/everyone_spec.rb +++ b/spec/models/abilities/everyone_spec.rb @@ -26,4 +26,6 @@ describe "Abilities::Everyone" do it { should be_able_to(:index, SpendingProposal) } it { should_not be_able_to(:create, SpendingProposal) } -end + + pending "only authors can access new and create for ProposalNotifications" +end \ No newline at end of file From e550a40f90ad4a1d774a3d06e67ca5300f36e7d4 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Tue, 7 Jun 2016 16:12:16 +0200 Subject: [PATCH 15/58] Adds share and comment button on email --- app/assets/images/icon_mailer_comment.png | Bin 0 -> 251 bytes app/assets/images/icon_mailer_share.png | Bin 0 -> 379 bytes app/mailers/mailer.rb | 2 +- .../mailer/proposal_notification.html.erb | 22 +++++++++++++++++- app/views/proposals/show.html.erb | 2 +- config/locales/mailers.en.yml | 5 +++- config/locales/mailers.es.yml | 3 +++ 7 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 app/assets/images/icon_mailer_comment.png create mode 100644 app/assets/images/icon_mailer_share.png diff --git a/app/assets/images/icon_mailer_comment.png b/app/assets/images/icon_mailer_comment.png new file mode 100644 index 0000000000000000000000000000000000000000..d3c9bff738825499e7c06f8a2adce4b5d17b586c GIT binary patch literal 251 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf4nJ za0`PlBg3pY5@fx({`eF=FuU@JE6u`H t^}0y%m%?NFP723uJSgy8?a}=M%yHKgpUwZrxEbhB22WQ%mvv4FO#oa~T$ca< literal 0 HcmV?d00001 diff --git a/app/assets/images/icon_mailer_share.png b/app/assets/images/icon_mailer_share.png new file mode 100644 index 0000000000000000000000000000000000000000..f95d44141b621be582501edd89e8cbdf98321ba1 GIT binary patch literal 379 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf4nJ za0`PlBg3pY5)2HCvYsxEAr`$yCv5a$P84WK|9|9!JjegHc^wIgON8HiRn572%&hl^ z%(f&|j%i9^N)gdrD^>Uv#FWhL9c6yVHF-@d%U7HJIlaN>jPAel;}um^ntrc(e(FtK zhAXR>q}E>RHMahCkAJg{bO=+4)m+vdx6^K4TwH#CKKm@Twk^ijW!u@Daud1ovpEcl zL>h|IUW=^!Cc9x4x2;Oy9ucP(lZw+>_6S{!o1_xX5VNGpt3mqMM=_VHUDu30dmZ^B zvGQHbSJx*UGxZtH)Jm{62rzZOvNg_smaepkZNbM(5eAnh6GHh8iTgg{%I_2h3;qYyYi)m*Ktk X)PU#K>!xG?Lyy7J)z4*}Q$iB}&@_=P literal 0 HcmV?d00001 diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index b8ca433ce..447daabc4 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -46,7 +46,7 @@ class Mailer < ApplicationMailer @notification = notification with_user(voter) do - mail(to: voter.email, subject: @notification.title) + mail(to: voter.email, subject: @notification.title + ": " + @notification.proposal.title) end end diff --git a/app/views/mailer/proposal_notification.html.erb b/app/views/mailer/proposal_notification.html.erb index 59489840c..3bcfccc1b 100644 --- a/app/views/mailer/proposal_notification.html.erb +++ b/app/views/mailer/proposal_notification.html.erb @@ -4,6 +4,26 @@

- <%= @notification.body %> + <%= @notification.body %>

+ + + + + + + + + +
+ <%= link_to "#comments", style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 200px; display: inline-block;" do %> + <%= image_tag('icon_mailer_share.png', style: "border: 0; display: inline-block; width: 100%; max-width: 16px", alt: "") %> + <%= t('mailers.proposal_notification.share') %> + <% end %> + + <%= link_to "#social-share", style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 200px; display: inline-block;" do %> + <%= image_tag('icon_mailer_comment.png', style: "border: 0; display: inline-block; width: 100%; max-width: 16px; vertical-align: middle;", alt: "") %> + <%= t('mailers.proposal_notification.comment') %> + <% end %> +
diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 8a391a031..2153b23e5 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -103,7 +103,7 @@ { proposal: @proposal, vote_url: vote_proposal_path(@proposal, value: 'yes') } %> - +

<%= t("proposals.show.share") %>

From 29f869046a22598bfb0a03fc158bd61a28d21628 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Fri, 10 Jun 2016 18:01:59 +0200 Subject: [PATCH 28/58] Adds message for no accepting private messages --- app/views/users/show.html.erb | 6 +++++- config/locales/en.yml | 1 + config/locales/es.yml | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 6adb97b37..31c62d13c 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -2,10 +2,14 @@
- <% if @user != current_user %> + <% if @user != current_user %> <%= link_to t("users.show.send_private_message"), new_user_direct_message_path(@user), class: "button hollow float-right" %> + +
+ <%= t("users.show.no_private_messages") %> +
<% end %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index 40403561e..c0a68815b 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -530,6 +530,7 @@ en: one: 1 Spending proposal other: "%{count} Spending proposals" no_activity: User has no public activity + no_private_messages: "This user doesn't accept private messages." private_activity: This user decided to keep the activity list private send_private_message: "Send private message" proposals: diff --git a/config/locales/es.yml b/config/locales/es.yml index 397eca876..2354e4742 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -530,6 +530,7 @@ es: one: 1 Propuesta de inversión other: "%{count} Propuestas de inversión" no_activity: Usuario sin actividad pública + no_private_messages: "Este usuario no acepta mensajes privados." private_activity: Este usuario ha decidido mantener en privado su lista de actividades send_private_message: "Enviar un mensaje privado" proposals: From 988f1f645a27eb0939351c2e9ee48d161c1e03fa Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Fri, 10 Jun 2016 18:02:37 +0200 Subject: [PATCH 29/58] Improves proposal notification mailer and fixes settings.scss --- app/assets/stylesheets/_settings.scss | 2 +- app/views/mailer/proposal_notification.html.erb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/_settings.scss b/app/assets/stylesheets/_settings.scss index 1e181e1c1..57a1afb7c 100644 --- a/app/assets/stylesheets/_settings.scss +++ b/app/assets/stylesheets/_settings.scss @@ -192,7 +192,7 @@ $header-color: inherit; $header-lineheight: 1.4; $header-margin-bottom: 0.5rem; $header-text-rendering: optimizeLegibility; -$small-font-size: 80%; +$small-font-size: rem-calc(14); $header-small-font-color: $medium-gray; $paragraph-lineheight: 1.6; $paragraph-margin-bottom: 1rem; diff --git a/app/views/mailer/proposal_notification.html.erb b/app/views/mailer/proposal_notification.html.erb index 3bcfccc1b..04ca39d86 100644 --- a/app/views/mailer/proposal_notification.html.erb +++ b/app/views/mailer/proposal_notification.html.erb @@ -7,18 +7,18 @@ <%= @notification.body %>

- +
diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index c90ca12c9..66c1c75ea 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -33,5 +33,9 @@ en: proposal_notification: share: Share comment: Comment proposal + proposal_notification_digest: + title: You received the following notifications + share: Share + comment: Comment proposal direct_message: reply: Reply to %{sender} \ No newline at end of file diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 75ff487d1..36343267d 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -33,5 +33,9 @@ es: proposal_notification: share: Compartir comment: Comentar propuesta + proposal_notification_digest: + title: Has recibido las siguientes notificaciones + share: Compartir + comment: Comentar propuesta direct_message: reply: Responder a %{sender} \ No newline at end of file From 143089603cb26250a57be78850fb45880f639d81 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 13 Jun 2016 12:33:46 +0200 Subject: [PATCH 31/58] fixes specs --- app/views/mailer/direct_message.html.erb | 2 +- spec/factories.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/mailer/direct_message.html.erb b/app/views/mailer/direct_message.html.erb index c974a7644..28235089b 100644 --- a/app/views/mailer/direct_message.html.erb +++ b/app/views/mailer/direct_message.html.erb @@ -11,7 +11,7 @@
- <%= link_to "#comments", style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 200px; display: inline-block;" do %> + <%= link_to "#comments", style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block;" do %> <%= image_tag('icon_mailer_share.png', style: "border: 0; display: inline-block; width: 100%; max-width: 16px", alt: "") %> <%= t('mailers.proposal_notification.share') %> <% end %> - <%= link_to "#social-share", style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 200px; display: inline-block;" do %> + <%= link_to "#social-share", style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block;" do %> <%= image_tag('icon_mailer_comment.png', style: "border: 0; display: inline-block; width: 100%; max-width: 16px; vertical-align: middle;", alt: "") %> <%= t('mailers.proposal_notification.comment') %> <% end %> From a417d88f9113219fd491121ea06d56a059613db3 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Fri, 10 Jun 2016 18:03:03 +0200 Subject: [PATCH 30/58] Adds proposal notification digest mailer --- .../proposal_notification_digest.html.erb | 51 +++++++++++++++++++ config/locales/mailers.en.yml | 4 ++ config/locales/mailers.es.yml | 4 ++ 3 files changed, 59 insertions(+) create mode 100644 app/views/mailer/proposal_notification_digest.html.erb diff --git a/app/views/mailer/proposal_notification_digest.html.erb b/app/views/mailer/proposal_notification_digest.html.erb new file mode 100644 index 000000000..4733d900e --- /dev/null +++ b/app/views/mailer/proposal_notification_digest.html.erb @@ -0,0 +1,51 @@ + + + + + + + +
+

+ <%= t('mailers.proposal_notification_digest.title') %> +

+
+ + + + + + + + +
+

+ <%= @notification.title %> +

+

+ <%= @notification.proposal.title %> • <%= @notification.proposal.created_at.to_date %> • <%= @notification.proposal.author.name %> +

+

+ <%= @notification.body %> +

+ + + + + + + +
+ <%= link_to "#comments", style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block;" do %> + <%= image_tag('icon_mailer_share.png', style: "border: 0; display: inline-block; width: 100%; max-width: 16px", alt: "") %> + <%= t('mailers.proposal_notification_digest.share') %> + <% end %> + + <%= link_to "#social-share", style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block; margin-left: 12px;" do %> + <%= image_tag('icon_mailer_comment.png', style: "border: 0; display: inline-block; width: 100%; max-width: 16px; vertical-align: middle;", alt: "") %> + <%= t('mailers.proposal_notification_digest.comment') %> + <% end %> +
+
+ +
- <%= link_to user_path(@direct_message.sender_id), style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 200px; display: inline-block;", target: "_blank" do %> + <%= link_to user_url(@direct_message.sender_id), style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 200px; display: inline-block;", target: "_blank" do %> <%= image_tag('icon_mailer_reply.png', style: "border: 0; display: inline-block; width: 100%; max-width: 12px; vertical-align: sub;", alt: "") %> <%= t('mailers.direct_message.reply', sender: @direct_message.sender.name) %> diff --git a/spec/factories.rb b/spec/factories.rb index f642abaf1..ef9c56c47 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -333,7 +333,7 @@ FactoryGirl.define do end factory :direct_message do - title "Hey!" + title "Hey" body "How are You doing?" association :sender, factory: :user association :receiver, factory: :user From 9b1be8da19f3978d376b39098204e6d9a7a2607b Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 13 Jun 2016 12:33:59 +0200 Subject: [PATCH 32/58] adds direct message specs --- spec/features/direct_messages_spec.rb | 71 +++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 spec/features/direct_messages_spec.rb diff --git a/spec/features/direct_messages_spec.rb b/spec/features/direct_messages_spec.rb new file mode 100644 index 000000000..d9301a29e --- /dev/null +++ b/spec/features/direct_messages_spec.rb @@ -0,0 +1,71 @@ +require 'rails_helper' + +feature 'Direct messages' do + + scenario "Create", :focus do + sender = create(:user, :level_two) + receiver = create(:user, :level_two) + + login_as(sender) + visit user_path(receiver) + + click_link "Send private message" + + expect(page).to have_content "Send private message to #{receiver.name}" + + fill_in 'direct_message_title', with: "Hey!" + fill_in 'direct_message_body', with: "How are you doing?" + click_button "Send message" + + expect(page).to have_content "You message has been sent successfully." + expect(page).to have_content "Hey!" + expect(page).to have_content "How are you doing?" + end + + context "Permissions" do + + scenario "Link to send the message" do + sender = create(:user, :level_two) + + login_as(sender) + visit user_path(sender) + + expect(page).to_not have_link "Send private message" + end + + scenario "Accessing form directly" do + user = create(:user) + author = create(:user) + proposal = create(:proposal, author: author) + + login_as(user) + visit new_proposal_notification_path(proposal_id: proposal.id) + + expect(current_path).to eq(proposals_path) + expect(page).to have_content("You do not have permission to carry out the action") + end + + pending "unverified user" + + end + + scenario "Error messages" do + author = create(:user) + proposal = create(:proposal, author: author) + + login_as(author) + + visit new_proposal_notification_path(proposal_id: proposal.id) + click_button "Send message" + + expect(page).to have_content error_message + end + + context "Limits" do + + pending "Cannot send more than one notification within established interval" + pending "use timecop to make sure notifications can be sent after time interval" + + end + +end \ No newline at end of file From 6e800c512050c6eb576bec65aca96abf39ff3c64 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 14 Jun 2016 17:53:36 +0200 Subject: [PATCH 33/58] adds email digest for proposal notifications --- app/mailers/mailer.rb | 8 +++ app/models/user.rb | 1 + .../proposal_notification_digest.html.erb | 72 ++++++++++--------- ...0160613150659_add_email_digest_to_users.rb | 5 ++ db/schema.rb | 3 +- lib/email_digest.rb | 14 ++++ lib/tasks/emails.rake | 9 +++ spec/factories.rb | 2 +- spec/features/direct_messages_spec.rb | 2 +- spec/features/emails_spec.rb | 47 ++++++++++++ spec/features/proposal_notifications_spec.rb | 47 ++++++++++++ spec/lib/email_digests_spec.rb | 9 +++ spec/support/common_actions.rb | 18 +++++ 13 files changed, 199 insertions(+), 38 deletions(-) create mode 100644 db/migrate/20160613150659_add_email_digest_to_users.rb create mode 100644 lib/email_digest.rb create mode 100644 lib/tasks/emails.rake create mode 100644 spec/lib/email_digests_spec.rb diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 2a81c4bfe..d900fd17d 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -59,6 +59,14 @@ class Mailer < ApplicationMailer end end + def proposal_notification_digest(user) + @notifications = user.notifications.where(notifiable_type: "ProposalNotification") + + with_user(user) do + mail(to: user.email, subject: "Email digest") + end + end + private def with_user(user, &block) diff --git a/app/models/user.rb b/app/models/user.rb index 243781cb3..a3b719859 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -51,6 +51,7 @@ class User < ActiveRecord::Base scope :officials, -> { where("official_level > 0") } scope :for_render, -> { includes(:organization) } scope :by_document, -> (document_type, document_number) { where(document_type: document_type, document_number: document_number) } + scope :email_digest, -> { where(email_digest: true) } before_validation :clean_document_number diff --git a/app/views/mailer/proposal_notification_digest.html.erb b/app/views/mailer/proposal_notification_digest.html.erb index 4733d900e..16e96260c 100644 --- a/app/views/mailer/proposal_notification_digest.html.erb +++ b/app/views/mailer/proposal_notification_digest.html.erb @@ -11,41 +11,43 @@
- - - - - + + +
-

- <%= @notification.title %> -

-

- <%= @notification.proposal.title %> • <%= @notification.proposal.created_at.to_date %> • <%= @notification.proposal.author.name %> -

-

- <%= @notification.body %> -

+ <%= @notifications.each do |notification| %> + + + + + + +
+

+ <%= link_to notification.notifiable.title, notification_url(notification) %> +

+

+ <%= notification.notifiable.proposal.title %> •  + <%= notification.notifiable.proposal.created_at.to_date %> •  + <%= notification.notifiable.proposal.author.name %> +

+

+ <%= notification.notifiable.body %> +

- - - - - - -
- <%= link_to "#comments", style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block;" do %> - <%= image_tag('icon_mailer_share.png', style: "border: 0; display: inline-block; width: 100%; max-width: 16px", alt: "") %> - <%= t('mailers.proposal_notification_digest.share') %> - <% end %> + + + + - - -
+ <%= link_to proposal_url(notification.notifiable.proposal, anchor: "comments"), style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block;" do %> + <%= image_tag('icon_mailer_share.png', style: "border: 0; display: inline-block; width: 100%; max-width: 16px", alt: "") %> + <%= t('mailers.proposal_notification_digest.share') %> + <% end %> - <%= link_to "#social-share", style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block; margin-left: 12px;" do %> - <%= image_tag('icon_mailer_comment.png', style: "border: 0; display: inline-block; width: 100%; max-width: 16px; vertical-align: middle;", alt: "") %> - <%= t('mailers.proposal_notification_digest.comment') %> - <% end %> -
-
- + <%= link_to proposal_url(notification.notifiable.proposal, anchor: "social-share"), style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block; margin-left: 12px;" do %> + <%= image_tag('icon_mailer_comment.png', style: "border: 0; display: inline-block; width: 100%; max-width: 16px; vertical-align: middle;", alt: "") %> + <%= t('mailers.proposal_notification_digest.comment') %> + <% end %> +
+
+ <% end %> diff --git a/db/migrate/20160613150659_add_email_digest_to_users.rb b/db/migrate/20160613150659_add_email_digest_to_users.rb new file mode 100644 index 000000000..d127af78e --- /dev/null +++ b/db/migrate/20160613150659_add_email_digest_to_users.rb @@ -0,0 +1,5 @@ +class AddEmailDigestToUsers < ActiveRecord::Migration + def change + add_column :users, :email_digest, :boolean, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index bbd6dda8f..c4fddf324 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: 20160608174104) do +ActiveRecord::Schema.define(version: 20160613150659) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -460,6 +460,7 @@ ActiveRecord::Schema.define(version: 20160608174104) do t.string "gender", limit: 10 t.datetime "date_of_birth" t.boolean "email_on_proposal_notification", default: true + t.boolean "email_digest", default: true end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree diff --git a/lib/email_digest.rb b/lib/email_digest.rb new file mode 100644 index 000000000..90838f78f --- /dev/null +++ b/lib/email_digest.rb @@ -0,0 +1,14 @@ +class EmailDigest + + def initialize + end + + def create + User.email_digest.each do |user| + if user.notifications.where(notifiable_type: "ProposalNotification").any? + Mailer.proposal_notification_digest(user).deliver_later + end + end + end + +end \ No newline at end of file diff --git a/lib/tasks/emails.rake b/lib/tasks/emails.rake new file mode 100644 index 000000000..6670264a5 --- /dev/null +++ b/lib/tasks/emails.rake @@ -0,0 +1,9 @@ +namespace :emails do + + desc "Sends email digest of proposal notifications to each user" + task digest: :environment do + email_digest = EmailDigest.new + email_digest.create + end + +end diff --git a/spec/factories.rb b/spec/factories.rb index ef9c56c47..4ead8ecac 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -136,7 +136,7 @@ FactoryGirl.define do factory :proposal do sequence(:title) { |n| "Proposal #{n} title" } - summary 'In summary, what we want is...' + sequence(:summary) { |n| "In summary, what we want is... #{n}" } description 'Proposal description' question 'Proposal question' external_url 'http://external_documention.es' diff --git a/spec/features/direct_messages_spec.rb b/spec/features/direct_messages_spec.rb index d9301a29e..142be8cbb 100644 --- a/spec/features/direct_messages_spec.rb +++ b/spec/features/direct_messages_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature 'Direct messages' do - scenario "Create", :focus do + scenario "Create" do sender = create(:user, :level_two) receiver = create(:user, :level_two) diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index ec8ff7b5f..5894d40ed 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -204,4 +204,51 @@ feature 'Emails' do end end + context "Proposal notification digest" do + + scenario "notifications for proposals that I have supported" do + user = create(:user, email_digest: true) + + proposal1 = create(:proposal) + proposal2 = create(:proposal) + proposal3 = create(:proposal) + + create(:vote, votable: proposal1, voter: user) + create(:vote, votable: proposal2, voter: user) + + reset_mailer + + notification1 = create_proposal_notification(proposal1) + notification2 = create_proposal_notification(proposal2) + notification3 = create_proposal_notification(proposal3) + + email_digest = EmailDigest.new + email_digest.create + + email = open_last_email + expect(email).to have_subject("Email digest") + expect(email).to deliver_to(user.email) + + expect(email).to have_body_text(proposal1.title) + expect(email).to have_body_text(notification1.notifiable.title) + expect(email).to have_body_text(notification1.notifiable.body) + expect(email).to have_body_text(proposal1.author.name) + + expect(email).to have_body_text(/#{notification_path(notification1)}/) + 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(/#{notification_path(notification2)}/) + 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).to_not have_body_text(proposal3.title) + end + + end + end diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb index be8b146fd..7785a1236 100644 --- a/spec/features/proposal_notifications_spec.rb +++ b/spec/features/proposal_notifications_spec.rb @@ -51,6 +51,53 @@ feature 'Proposal Notifications' do expect(page).to have_link("the proposal's page", href: proposal_path(proposal)) end + context "Receivers" do + + scenario "Only send a digest to users that have the option set in their profile" do + user1 = create(:user, email_digest: true) + user2 = create(:user, email_digest: true) + user3 = create(:user, email_digest: false) + + proposal = create(:proposal) + + [user1, user2, user3].each do |user| + create(:vote, votable: proposal, voter: user) + end + + create_proposal_notification(proposal) + + reset_mailer + email_digest = EmailDigest.new + email_digest.create + + expect(unread_emails_for(user1.email).size).to eql parse_email_count(1) + expect(unread_emails_for(user2.email).size).to eql parse_email_count(1) + expect(unread_emails_for(user3.email).size).to eql parse_email_count(0) + end + + scenario "Only send a digest to users that have voted for a proposal" do + user1 = create(:user, email_digest: true) + user2 = create(:user, email_digest: true) + user3 = create(:user, email_digest: true) + + proposal = create(:proposal) + + [user1, user2].each do |user| + create(:vote, votable: proposal, voter: user) + end + + create_proposal_notification(proposal) + + reset_mailer + email_digest = EmailDigest.new + email_digest.create + + expect(unread_emails_for(user1.email).size).to eql parse_email_count(1) + expect(unread_emails_for(user2.email).size).to eql parse_email_count(1) + expect(unread_emails_for(user3.email).size).to eql parse_email_count(0) + end + + end context "Permissions" do scenario "Link to send the message" do diff --git a/spec/lib/email_digests_spec.rb b/spec/lib/email_digests_spec.rb new file mode 100644 index 000000000..6fc6eef53 --- /dev/null +++ b/spec/lib/email_digests_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +describe EmailDigest do + + describe "create" do + pending "only send unread notifications" + end + +end \ No newline at end of file diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 18a3f9499..39faf03f5 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -196,4 +196,22 @@ module CommonActions tag_cloud.tags.map(&:name) end + def create_proposal_notification(proposal) + login_as(proposal.author) + visit root_path + + click_link "My activity" + + within("#proposal_#{proposal.id}") do + click_link "Send message" + end + + fill_in 'proposal_notification_title', with: "Thank you for supporting my proposal #{proposal.title}" + fill_in 'proposal_notification_body', with: "Please share it with others so we can make it happen! #{proposal.summary}" + click_button "Send message" + + expect(page).to have_content "Your message has been sent correctly." + Notification.last + end + end From 9f19a5d1439085af9b2ab8cff64bb8d75d0130ca Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 14 Jun 2016 18:08:27 +0200 Subject: [PATCH 34/58] adds option to receive email digest --- app/controllers/account_controller.rb | 2 +- app/views/account/show.html.erb | 9 +++++++++ config/locales/en.yml | 1 + config/locales/es.yml | 1 + spec/features/account_spec.rb | 3 ++- spec/models/user_spec.rb | 6 ++++++ 6 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index d1ac9c9c4..8bcb5f4d0 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -25,7 +25,7 @@ class AccountController < ApplicationController if @account.organization? 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, :email_on_proposal_notification, :newsletter) + params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply, :email_on_proposal_notification, :email_digest, :newsletter) end end diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index b3a84dede..2180ce5f9 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -78,6 +78,15 @@ <% end %>

+
+ <%= f.label :email_digest do %> + <%= f.check_box :email_digest, title: t('account.show.email_digest_label'), label: false %> + + <%= t("account.show.email_digest_label") %> + + <% end %> +
+ <%= f.submit t("account.show.save_changes_submit"), class: "button" %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index c0a68815b..0051fef5c 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -16,6 +16,7 @@ en: save_changes_submit: Save changes subscription_to_website_newsletter_label: Receive by email website relevant information email_on_proposal_notification_label: Receive by email notifications about proposals + email_digest_label: Receive a summary of proposal notifications title: My account user_permission_debates: Participate on debates user_permission_info: With your account you can... diff --git a/config/locales/es.yml b/config/locales/es.yml index 2354e4742..7898cbd65 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -16,6 +16,7 @@ es: save_changes_submit: Guardar cambios 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 + email_digest_label: Recibir resumen de notificaciones sobre propuestas title: Mi cuenta user_permission_debates: Participar en debates user_permission_info: Con tu cuenta ya puedes... diff --git a/spec/features/account_spec.rb b/spec/features/account_spec.rb index f5ba747fb..f8ebf4e3a 100644 --- a/spec/features/account_spec.rb +++ b/spec/features/account_spec.rb @@ -36,6 +36,7 @@ feature 'Account' do check 'account_email_on_comment' check 'account_email_on_comment_reply' uncheck 'account_email_on_proposal_notification' + uncheck 'account_email_digest' click_button 'Save changes' expect(page).to have_content "Changes saved" @@ -45,7 +46,7 @@ feature 'Account' do expect(page).to have_selector("input[value='Larry Bird']") expect(find("#account_email_on_comment")).to be_checked expect(find("#account_email_on_comment_reply")).to be_checked - expect(find("#account_email_on_proposal_notification")).to_not be_checked + expect(find("#account_email_digest")).to_not be_checked end scenario 'Edit Organization' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ca46ff68f..e9c05eeb3 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -89,6 +89,12 @@ describe User do expect(subject.email_on_proposal_notification).to eq(true) end end + + describe 'email_digest' do + it 'should be true by default' do + expect(subject.email_digest).to eq(true) + end + end end describe "administrator?" do From fd672940758e02774bec7c460afbc8ef56f823a3 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 14 Jun 2016 18:20:36 +0200 Subject: [PATCH 35/58] adds option to receive direct messages --- app/controllers/account_controller.rb | 2 +- app/views/account/show.html.erb | 9 +++++++++ config/locales/en.yml | 1 + config/locales/es.yml | 1 + ...160614160949_add_email_on_direct_messages_to_users.rb | 5 +++++ db/schema.rb | 3 ++- spec/features/account_spec.rb | 2 ++ spec/models/user_spec.rb | 6 ++++++ 8 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20160614160949_add_email_on_direct_messages_to_users.rb diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 8bcb5f4d0..496778e5f 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -25,7 +25,7 @@ class AccountController < ApplicationController if @account.organization? 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, :email_on_proposal_notification, :email_digest, :newsletter) + params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply, :email_on_proposal_notification, :email_on_direct_message, :email_digest, :newsletter) end end diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index 2180ce5f9..3d93bc705 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -87,6 +87,15 @@ <% end %> +
+ <%= f.label :email_on_direct_message do %> + <%= f.check_box :email_on_direct_message, title: t('account.show.email_on_direct_message_label'), label: false %> + + <%= t("account.show.email_on_direct_message_label") %> + + <% end %> +
+ <%= f.submit t("account.show.save_changes_submit"), class: "button" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 0051fef5c..de1f1a485 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -16,6 +16,7 @@ en: save_changes_submit: Save changes subscription_to_website_newsletter_label: Receive by email website relevant information email_on_proposal_notification_label: Receive by email notifications about proposals + email_on_direct_message_label: Receive emails about direct messages email_digest_label: Receive a summary of proposal notifications title: My account user_permission_debates: Participate on debates diff --git a/config/locales/es.yml b/config/locales/es.yml index 7898cbd65..c5fa39c91 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -16,6 +16,7 @@ es: save_changes_submit: Guardar cambios 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 + email_on_direct_message_label: Recibir emails con mensajes directos email_digest_label: Recibir resumen de notificaciones sobre propuestas title: Mi cuenta user_permission_debates: Participar en debates diff --git a/db/migrate/20160614160949_add_email_on_direct_messages_to_users.rb b/db/migrate/20160614160949_add_email_on_direct_messages_to_users.rb new file mode 100644 index 000000000..db18e3f27 --- /dev/null +++ b/db/migrate/20160614160949_add_email_on_direct_messages_to_users.rb @@ -0,0 +1,5 @@ +class AddEmailOnDirectMessagesToUsers < ActiveRecord::Migration + def change + add_column :users, :email_on_direct_message, :boolean, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index c4fddf324..f5671b3a3 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: 20160613150659) do +ActiveRecord::Schema.define(version: 20160614160949) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -461,6 +461,7 @@ ActiveRecord::Schema.define(version: 20160613150659) do t.datetime "date_of_birth" t.boolean "email_on_proposal_notification", default: true t.boolean "email_digest", default: true + t.boolean "email_on_direct_message", default: true end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree diff --git a/spec/features/account_spec.rb b/spec/features/account_spec.rb index f8ebf4e3a..b41d676d4 100644 --- a/spec/features/account_spec.rb +++ b/spec/features/account_spec.rb @@ -37,6 +37,7 @@ feature 'Account' do check 'account_email_on_comment_reply' uncheck 'account_email_on_proposal_notification' uncheck 'account_email_digest' + uncheck 'account_email_on_direct_message' click_button 'Save changes' expect(page).to have_content "Changes saved" @@ -47,6 +48,7 @@ feature 'Account' do expect(find("#account_email_on_comment")).to be_checked expect(find("#account_email_on_comment_reply")).to be_checked expect(find("#account_email_digest")).to_not be_checked + expect(find("#account_email_on_direct_message")).to_not be_checked end scenario 'Edit Organization' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index e9c05eeb3..698c4884c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -95,6 +95,12 @@ describe User do expect(subject.email_digest).to eq(true) end end + + describe 'email_on_direct_message' do + it 'should be true by default' do + expect(subject.email_on_direct_message).to eq(true) + end + end end describe "administrator?" do From ce6072d17bbd46bc54163fbb5443cf90a2ea85db Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 14 Jun 2016 18:55:28 +0200 Subject: [PATCH 36/58] sends a copy of the direct message to the sender --- app/controllers/direct_messages_controller.rb | 3 +- app/mailers/mailer.rb | 13 +++++-- ...b => direct_message_for_receiver.html.erb} | 2 +- .../mailer/direct_message_for_sender.html.erb | 11 ++++++ config/locales/mailers.en.yml | 7 ++-- config/locales/mailers.es.yml | 7 ++-- spec/features/direct_messages_spec.rb | 7 ---- spec/features/emails_spec.rb | 35 +++++++++++++++++++ spec/support/common_actions.rb | 16 +++++++++ 9 files changed, 86 insertions(+), 15 deletions(-) rename app/views/mailer/{direct_message.html.erb => direct_message_for_receiver.html.erb} (70%) create mode 100644 app/views/mailer/direct_message_for_sender.html.erb diff --git a/app/controllers/direct_messages_controller.rb b/app/controllers/direct_messages_controller.rb index 912f186a3..07f39d941 100644 --- a/app/controllers/direct_messages_controller.rb +++ b/app/controllers/direct_messages_controller.rb @@ -12,7 +12,8 @@ class DirectMessagesController < ApplicationController @direct_message = DirectMessage.new(parsed_params) if @direct_message.save - Mailer.direct_message(@direct_message).deliver_later + Mailer.direct_message_for_receiver(@direct_message).deliver_later + Mailer.direct_message_for_sender(@direct_message).deliver_later redirect_to [@receiver, @direct_message], notice: I18n.t("flash.actions.create.direct_message") else render :new diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index d900fd17d..6916253f2 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -50,12 +50,21 @@ class Mailer < ApplicationMailer end end - def direct_message(direct_message) + def direct_message_for_receiver(direct_message) @direct_message = direct_message @receiver = @direct_message.receiver with_user(@receiver) do - mail(to: @receiver.email, subject: "Has recibido un nuevo mensaje privado") + mail(to: @receiver.email, subject: t('mailers.direct_message_for_receiver.subject')) + end + end + + def direct_message_for_sender(direct_message) + @direct_message = direct_message + @sender = @direct_message.sender + + with_user(@sender) do + mail(to: @sender.email, subject: t('mailers.direct_message_for_sender.subject')) end end diff --git a/app/views/mailer/direct_message.html.erb b/app/views/mailer/direct_message_for_receiver.html.erb similarity index 70% rename from app/views/mailer/direct_message.html.erb rename to app/views/mailer/direct_message_for_receiver.html.erb index 28235089b..d70c78a28 100644 --- a/app/views/mailer/direct_message.html.erb +++ b/app/views/mailer/direct_message_for_receiver.html.erb @@ -11,7 +11,7 @@ - <%= link_to user_url(@direct_message.sender_id), style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 200px; display: inline-block;", target: "_blank" do %> + <%= link_to user_url(@direct_message.sender), style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 200px; display: inline-block;", target: "_blank" do %> <%= image_tag('icon_mailer_reply.png', style: "border: 0; display: inline-block; width: 100%; max-width: 12px; vertical-align: sub;", alt: "") %> <%= t('mailers.direct_message.reply', sender: @direct_message.sender.name) %> diff --git a/app/views/mailer/direct_message_for_sender.html.erb b/app/views/mailer/direct_message_for_sender.html.erb new file mode 100644 index 000000000..219337705 --- /dev/null +++ b/app/views/mailer/direct_message_for_sender.html.erb @@ -0,0 +1,11 @@ + +

<%= @direct_message.receiver.name %>

+ +

+ <%= @direct_message.title %> +

+ +

+ <%= @direct_message.body %> +

+ diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index 66c1c75ea..ec6e7f45c 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -37,5 +37,8 @@ en: title: You received the following notifications share: Share comment: Comment proposal - direct_message: - reply: Reply to %{sender} \ No newline at end of file + direct_message_for_receiver: + subject: "You have received a new private message" + reply: Reply to %{sender} + direct_message_for_sender: + subject: "You have send a new private message" \ No newline at end of file diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 36343267d..4defbd1ed 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -37,5 +37,8 @@ es: title: Has recibido las siguientes notificaciones share: Compartir comment: Comentar propuesta - direct_message: - reply: Responder a %{sender} \ No newline at end of file + direct_message_for_receiver: + subject: "Has recibido un nuevo mensaje privado" + reply: Responder a %{sender} + direct_message_for_sender: + subject: "Has enviado un nuevo mensaje privado" \ No newline at end of file diff --git a/spec/features/direct_messages_spec.rb b/spec/features/direct_messages_spec.rb index 142be8cbb..2ee1f4365 100644 --- a/spec/features/direct_messages_spec.rb +++ b/spec/features/direct_messages_spec.rb @@ -61,11 +61,4 @@ feature 'Direct messages' do expect(page).to have_content error_message end - context "Limits" do - - pending "Cannot send more than one notification within established interval" - pending "use timecop to make sure notifications can be sent after time interval" - - end - end \ No newline at end of file diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index 5894d40ed..237444f85 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -148,6 +148,41 @@ feature 'Emails' do expect(email).to have_body_text(spending_proposal.feasible_explanation) end + context "Direct Message" do + + scenario "Receiver email" do + sender = create(:user, :level_two) + receiver = create(:user, :level_two) + + direct_message = create_direct_message(sender, receiver) + + email = unread_emails_for(receiver.email).first + + expect(email).to have_subject("You have received a new private message") + 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)}/) + end + + scenario "Sender email" do + sender = create(:user, :level_two) + receiver = create(:user, :level_two) + + direct_message = create_direct_message(sender, receiver) + + email = unread_emails_for(sender.email).first + + expect(email).to have_subject("You have send a new private message") + 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.receiver.name) + end + + pending "In the copy sent to the sender, display the receiver's name" + + end + context "Proposal notifications" do scenario "Proposal notification" do diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 39faf03f5..8eba8b13d 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -214,4 +214,20 @@ module CommonActions Notification.last end + def create_direct_message(sender, receiver) + login_as(sender) + visit user_path(receiver) + + click_link "Send private message" + + expect(page).to have_content "Send private message to #{receiver.name}" + + fill_in 'direct_message_title', with: "Hey #{receiver.name}!" + fill_in 'direct_message_body', with: "How are you doing? This is #{sender.name}" + click_button "Send message" + + expect(page).to have_content "You message has been sent successfully." + DirectMessage.last + end + end From 28d12fe55bcb7bbf73fb7edc803022a1d419f738 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 15 Jun 2016 10:43:02 +0200 Subject: [PATCH 37/58] removes sending individual proposal notifications via email --- app/controllers/account_controller.rb | 2 +- .../proposal_notifications_controller.rb | 3 - app/mailers/mailer.rb | 8 --- app/views/account/show.html.erb | 9 --- .../mailer/proposal_notification.html.erb | 29 ---------- config/locales/en.yml | 1 - config/locales/es.yml | 1 - config/locales/mailers.en.yml | 3 - config/locales/mailers.es.yml | 3 - spec/features/account_spec.rb | 1 - spec/features/emails_spec.rb | 56 ------------------- spec/features/proposal_notifications_spec.rb | 47 ---------------- spec/models/user_spec.rb | 6 -- 13 files changed, 1 insertion(+), 168 deletions(-) delete mode 100644 app/views/mailer/proposal_notification.html.erb diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 496778e5f..9212eb4fa 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -25,7 +25,7 @@ class AccountController < ApplicationController if @account.organization? 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, :email_on_proposal_notification, :email_on_direct_message, :email_digest, :newsletter) + params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply, :email_on_direct_message, :email_digest, :newsletter) end end diff --git a/app/controllers/proposal_notifications_controller.rb b/app/controllers/proposal_notifications_controller.rb index 1fcd9322a..fc9cdf3d8 100644 --- a/app/controllers/proposal_notifications_controller.rb +++ b/app/controllers/proposal_notifications_controller.rb @@ -13,9 +13,6 @@ class ProposalNotificationsController < ApplicationController if @notification.save @proposal.voters.each do |voter| Notification.add(voter.id, @notification) - if voter.email_on_proposal_notification? - Mailer.proposal_notification(@notification, voter).deliver_later - end end redirect_to @notification, notice: I18n.t("flash.actions.create.proposal_notification") else diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 6916253f2..5f7dc5391 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -42,14 +42,6 @@ class Mailer < ApplicationMailer end end - def proposal_notification(notification, voter) - @notification = notification - - with_user(voter) do - mail(to: voter.email, subject: @notification.title + ": " + @notification.proposal.title) - end - end - def direct_message_for_receiver(direct_message) @direct_message = direct_message @receiver = @direct_message.receiver diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index 3d93bc705..98987626d 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -69,15 +69,6 @@ <% end %> -
- <%= 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 %> - - <%= t("account.show.email_on_proposal_notification_label") %> - - <% end %> -
-
<%= f.label :email_digest do %> <%= f.check_box :email_digest, title: t('account.show.email_digest_label'), label: false %> diff --git a/app/views/mailer/proposal_notification.html.erb b/app/views/mailer/proposal_notification.html.erb deleted file mode 100644 index 04ca39d86..000000000 --- a/app/views/mailer/proposal_notification.html.erb +++ /dev/null @@ -1,29 +0,0 @@ - -

- <%= @notification.proposal.title %> -

- -

- <%= @notification.body %> -

- - - - - - - - - -
- <%= link_to "#comments", style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block;" do %> - <%= image_tag('icon_mailer_share.png', style: "border: 0; display: inline-block; width: 100%; max-width: 16px", alt: "") %> - <%= t('mailers.proposal_notification.share') %> - <% end %> - - <%= link_to "#social-share", style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block;" do %> - <%= image_tag('icon_mailer_comment.png', style: "border: 0; display: inline-block; width: 100%; max-width: 16px; vertical-align: middle;", alt: "") %> - <%= t('mailers.proposal_notification.comment') %> - <% end %> -
- diff --git a/config/locales/en.yml b/config/locales/en.yml index de1f1a485..e78f9c4d0 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -15,7 +15,6 @@ en: public_activity_label: Keep my list of activities public save_changes_submit: Save changes subscription_to_website_newsletter_label: Receive by email website relevant information - email_on_proposal_notification_label: Receive by email notifications about proposals email_on_direct_message_label: Receive emails about direct messages email_digest_label: Receive a summary of proposal notifications title: My account diff --git a/config/locales/es.yml b/config/locales/es.yml index c5fa39c91..592bc9213 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -15,7 +15,6 @@ es: public_activity_label: Mostrar públicamente mi lista de actividades save_changes_submit: Guardar cambios 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 email_on_direct_message_label: Recibir emails con mensajes directos email_digest_label: Recibir resumen de notificaciones sobre propuestas title: Mi cuenta diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index ec6e7f45c..7270f81ae 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -30,9 +30,6 @@ en: sorry: "Sorry for the inconvenience and we again thank you for your invaluable participation." subject: "Your investment project '%{code}' has been marked as unfeasible" unfeasible_html: "From the Madrid City Council we want to thank you for your participation in the participatory budgets of the city of Madrid. We regret to inform you that your proposal '%{title}' will be excluded from this participatory process for the following reason:" - proposal_notification: - share: Share - comment: Comment proposal proposal_notification_digest: title: You received the following notifications share: Share diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 4defbd1ed..288fa189e 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -30,9 +30,6 @@ es: sorry: "Sentimos las molestias ocasionadas y volvemos a darte las gracias por tu inestimable participación." subject: "Tu propuesta de inversión '%{code}' ha sido marcada como inviable" unfeasible_html: "Desde el Ayuntamiento de Madrid queremos agradecer tu participación en los Presupuestos Participativos de la ciudad de Madrid. Lamentamos informarte de que tu propuesta '%{title}' quedará excluida de este proceso participativo por el siguiente motivo:" - proposal_notification: - share: Compartir - comment: Comentar propuesta proposal_notification_digest: title: Has recibido las siguientes notificaciones share: Compartir diff --git a/spec/features/account_spec.rb b/spec/features/account_spec.rb index b41d676d4..0d5da38b2 100644 --- a/spec/features/account_spec.rb +++ b/spec/features/account_spec.rb @@ -35,7 +35,6 @@ feature 'Account' do fill_in 'account_username', with: 'Larry Bird' check 'account_email_on_comment' check 'account_email_on_comment_reply' - uncheck 'account_email_on_proposal_notification' uncheck 'account_email_digest' uncheck 'account_email_on_direct_message' click_button 'Save changes' diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index 237444f85..3ea8f16b9 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -183,62 +183,6 @@ feature 'Emails' do end - context "Proposal notifications" do - - scenario "Proposal notification" do - author = create(:user) - - noelia = create(:user) - vega = create(:user) - cristina = create(:user) - - proposal = create(:proposal, author: author) - - create(:vote, voter: noelia, votable: proposal, vote_flag: true) - create(:vote, voter: vega, votable: proposal, vote_flag: true) - - reset_mailer - - login_as(author) - visit root_path - - 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(page).to have_content "Your message has been sent correctly." - - expect(unread_emails_for(noelia.email).size).to eql parse_email_count(1) - 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(email).to have_subject("Thank you for supporting my proposal: #{proposal.title}") - 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, author: author) - 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 - context "Proposal notification digest" do scenario "notifications for proposals that I have supported" do diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb index 7785a1236..be8b146fd 100644 --- a/spec/features/proposal_notifications_spec.rb +++ b/spec/features/proposal_notifications_spec.rb @@ -51,53 +51,6 @@ feature 'Proposal Notifications' do expect(page).to have_link("the proposal's page", href: proposal_path(proposal)) end - context "Receivers" do - - scenario "Only send a digest to users that have the option set in their profile" do - user1 = create(:user, email_digest: true) - user2 = create(:user, email_digest: true) - user3 = create(:user, email_digest: false) - - proposal = create(:proposal) - - [user1, user2, user3].each do |user| - create(:vote, votable: proposal, voter: user) - end - - create_proposal_notification(proposal) - - reset_mailer - email_digest = EmailDigest.new - email_digest.create - - expect(unread_emails_for(user1.email).size).to eql parse_email_count(1) - expect(unread_emails_for(user2.email).size).to eql parse_email_count(1) - expect(unread_emails_for(user3.email).size).to eql parse_email_count(0) - end - - scenario "Only send a digest to users that have voted for a proposal" do - user1 = create(:user, email_digest: true) - user2 = create(:user, email_digest: true) - user3 = create(:user, email_digest: true) - - proposal = create(:proposal) - - [user1, user2].each do |user| - create(:vote, votable: proposal, voter: user) - end - - create_proposal_notification(proposal) - - reset_mailer - email_digest = EmailDigest.new - email_digest.create - - expect(unread_emails_for(user1.email).size).to eql parse_email_count(1) - expect(unread_emails_for(user2.email).size).to eql parse_email_count(1) - expect(unread_emails_for(user3.email).size).to eql parse_email_count(0) - end - - end context "Permissions" do scenario "Link to send the message" do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 698c4884c..143053c77 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -84,12 +84,6 @@ describe User do 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 - describe 'email_digest' do it 'should be true by default' do expect(subject.email_digest).to eq(true) From cdc2bd67a4e99dfb8c0b597e5f4c2b0bfc4291c1 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 15 Jun 2016 10:51:58 +0200 Subject: [PATCH 38/58] adds correct order for email action links --- app/views/mailer/proposal_notification_digest.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/mailer/proposal_notification_digest.html.erb b/app/views/mailer/proposal_notification_digest.html.erb index 16e96260c..500a0fade 100644 --- a/app/views/mailer/proposal_notification_digest.html.erb +++ b/app/views/mailer/proposal_notification_digest.html.erb @@ -11,7 +11,7 @@ - <%= @notifications.each do |notification| %> + <% @notifications.each do |notification| %> @@ -32,12 +32,12 @@ From 95d244003e8b2731faeef2b14afccefac847d154 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 15 Jun 2016 12:03:38 +0200 Subject: [PATCH 40/58] do not display link to send direct message --- app/views/users/show.html.erb | 4 ++-- spec/features/direct_messages_spec.rb | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 31c62d13c..8b4428a09 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -2,11 +2,11 @@
- <% if @user != current_user %> + <% if @user != current_user && @user.email_on_direct_message? %> <%= link_to t("users.show.send_private_message"), new_user_direct_message_path(@user), class: "button hollow float-right" %> - + <% else %>
<%= t("users.show.no_private_messages") %>
diff --git a/spec/features/direct_messages_spec.rb b/spec/features/direct_messages_spec.rb index 2ee1f4365..119cbe6de 100644 --- a/spec/features/direct_messages_spec.rb +++ b/spec/features/direct_messages_spec.rb @@ -24,8 +24,8 @@ feature 'Direct messages' do context "Permissions" do - scenario "Link to send the message" do - sender = create(:user, :level_two) + scenario "Do not display link to send message to myself" do + sender = create(:user, :level_two) login_as(sender) visit user_path(sender) @@ -33,6 +33,17 @@ feature 'Direct messages' do expect(page).to_not have_link "Send private message" end + scenario "Do not display link if direct message for user not allowed" do + sender = create(:user, :level_two) + receiver = create(:user, :level_two, email_on_direct_message: false) + + login_as(sender) + visit user_path(receiver) + + expect(page).to have_content "This user doesn't accept private messages." + expect(page).to_not have_link "Send private message" + end + scenario "Accessing form directly" do user = create(:user) author = create(:user) From e2689d640c3c26b6d672eb707c421b924f1cc8c9 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 15 Jun 2016 12:12:56 +0200 Subject: [PATCH 41/58] refactors notification helpers --- app/helpers/notifications_helper.rb | 11 +------ app/models/notification.rb | 11 +++++++ .../notifications/_notification.html.erb | 2 +- spec/helpers/notifications_helper_spec.rb | 25 --------------- spec/models/notification_spec.rb | 31 +++++++++++++++++++ 5 files changed, 44 insertions(+), 36 deletions(-) delete mode 100644 spec/helpers/notifications_helper_spec.rb diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 6ec5f1b9e..2b907535f 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -1,13 +1,4 @@ module NotificationsHelper - def notification_action(notification) - case notification.notifiable_type - when "ProposalNotification" - "proposal_notification" - when "Comment" - "replies_to" - else - "comments_on" - end - end + end diff --git a/app/models/notification.rb b/app/models/notification.rb index 2e2bedc38..9695c1b01 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -33,6 +33,17 @@ class Notification < ActiveRecord::Base end end + def notifiable_action + case notifiable_type + when "ProposalNotification" + "proposal_notification" + when "Comment" + "replies_to" + else + "comments_on" + end + end + def linkable_resource notifiable.is_a?(ProposalNotification) ? notifiable.proposal : notifiable end diff --git a/app/views/notifications/_notification.html.erb b/app/views/notifications/_notification.html.erb index 237912a10..99b4b7def 100644 --- a/app/views/notifications/_notification.html.erb +++ b/app/views/notifications/_notification.html.erb @@ -2,7 +2,7 @@ <%= link_to notification do %>

- <%= t("notifications.index.#{notification_action(notification)}", + <%= t("notifications.index.#{notification.notifiable_action}", count: notification.counter) %> <%= notification.notifiable_title %> diff --git a/spec/helpers/notifications_helper_spec.rb b/spec/helpers/notifications_helper_spec.rb deleted file mode 100644 index ccb3b3a9d..000000000 --- a/spec/helpers/notifications_helper_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'rails_helper' - -describe NotificationsHelper do - - describe "#notification_action" do - let(:debate) { create :debate } - let(:debate_comment) { create :comment, commentable: debate } - - context "when action was comment on a debate" do - it "returns correct text when someone comments on your debate" do - notification = create :notification, notifiable: debate - expect(notification_action(notification)).to eq "comments_on" - end - end - - context "when action was comment on a debate" do - it "returns correct text when someone replies to your comment" do - notification = create :notification, notifiable: debate_comment - expect(notification_action(notification)).to eq "replies_to" - end - end - end - - -end diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 361211a51..fcf7cab4b 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -47,4 +47,35 @@ describe Notification do end end + describe "#notification_action" do + + context "when action was comment on a debate" do + it "returns correct text when someone comments on your debate" do + debate = create(:debate) + notification = create :notification, notifiable: debate + + expect(notification.notifiable_action).to eq "comments_on" + end + end + + context "when action was comment on a debate" do + it "returns correct text when someone replies to your comment" do + debate = create(:debate) + debate_comment = create :comment, commentable: debate + notification = create :notification, notifiable: debate_comment + + expect(notification.notifiable_action).to eq "replies_to" + end + end + + context "when action was proposal notification" do + it "returns correct text when the author created a proposal notification" do + proposal_notification = create(:proposal_notification) + notification = create :notification, notifiable: proposal_notification + + expect(notification.notifiable_action).to eq "proposal_notification" + end + end + end + end From 0c469bc362a073946dc3c3460ead5d7d37d5326f Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 15 Jun 2016 14:02:13 +0200 Subject: [PATCH 42/58] fixes the way permissions work for proposalnotifications --- app/models/abilities/common.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index 994bf90c0..f82e78b58 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -50,9 +50,7 @@ module Abilities can :show, DirectMessage, sender_id: user.id end - can [:new, :create, :show], ProposalNotification do |notification| - notification.proposal.author_id == user.id - end + can [:create, :show], ProposalNotification, proposal: { author_id: user.id } can :create, Annotation can [:update, :destroy], Annotation, user_id: user.id From 19b6740d370c732461668b9e9a4c9fdf05ad666a Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 15 Jun 2016 16:46:54 +0200 Subject: [PATCH 43/58] updates email from field --- app/mailers/application_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index c1f3e4bb6..8838f522f 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,5 +1,5 @@ class ApplicationMailer < ActionMailer::Base helper :settings - default from: "participacion@madrid.es" + default from: "Decide Madrid " layout 'mailer' end From 60c1fdcb271fe00a581b2fcebeb11bbc9654bd50 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 15 Jun 2016 16:54:13 +0200 Subject: [PATCH 44/58] Changes text to 'share proposal' --- config/locales/mailers.en.yml | 2 +- config/locales/mailers.es.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index 7270f81ae..6d91c52a1 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -32,7 +32,7 @@ en: unfeasible_html: "From the Madrid City Council we want to thank you for your participation in the participatory budgets of the city of Madrid. We regret to inform you that your proposal '%{title}' will be excluded from this participatory process for the following reason:" proposal_notification_digest: title: You received the following notifications - share: Share + share: Share proposal comment: Comment proposal direct_message_for_receiver: subject: "You have received a new private message" diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 288fa189e..7593aac43 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -32,7 +32,7 @@ es: unfeasible_html: "Desde el Ayuntamiento de Madrid queremos agradecer tu participación en los Presupuestos Participativos de la ciudad de Madrid. Lamentamos informarte de que tu propuesta '%{title}' quedará excluida de este proceso participativo por el siguiente motivo:" proposal_notification_digest: title: Has recibido las siguientes notificaciones - share: Compartir + share: Compartir propuesta comment: Comentar propuesta direct_message_for_receiver: subject: "Has recibido un nuevo mensaje privado" From 06596ac4d80a0e56a1e9cbbbb7245ef2b29dd9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Wed, 15 Jun 2016 17:01:50 +0200 Subject: [PATCH 45/58] adds author_of? helper method --- app/helpers/application_helper.rb | 5 +++++ spec/helpers/application_helper_spec.rb | 27 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 spec/helpers/application_helper_spec.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c5f2e6aca..1f52f0eea 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -35,4 +35,9 @@ module ApplicationHelper } Redcarpet::Markdown.new(renderer, extensions).render(text).html_safe end + + def author_of?(authorable, user) + return false if authorable.blank? || user.blank? + authorable.author_id == user.id + end end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb new file mode 100644 index 000000000..61137912d --- /dev/null +++ b/spec/helpers/application_helper_spec.rb @@ -0,0 +1,27 @@ +require 'rails_helper' + +describe ApplicationHelper do + + describe "#author_of?" do + it "should be true if user is the author" do + user = create(:user) + proposal = create(:proposal, author: user) + expect(author_of?(proposal, user)).to eq true + end + + it "should be false if user is not the author" do + user = create(:user) + proposal = create(:proposal) + expect(author_of?(proposal, user)).to eq false + end + + it "should be false if user or authorable is nil" do + user = create(:user) + proposal = create(:proposal) + + expect(author_of?(nil, user)).to eq false + expect(author_of?(proposal, nil)).to eq false + end + end + +end \ No newline at end of file From e87fda2c8d030c8c8612d8b81a6cda24946fba5f Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 15 Jun 2016 17:03:33 +0200 Subject: [PATCH 46/58] Adds comments anchor on form link --- app/views/proposal_notifications/new.html.erb | 7 +++---- config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/views/proposal_notifications/new.html.erb b/app/views/proposal_notifications/new.html.erb index a5f829ecc..b76f218fe 100644 --- a/app/views/proposal_notifications/new.html.erb +++ b/app/views/proposal_notifications/new.html.erb @@ -7,10 +7,9 @@

<%= t("proposal_notifications.new.info_about_receivers_html", - count: @proposal.voters.count) %> - - <%= link_to t("proposal_notifications.new.proposal_page"), - proposal_path(@proposal) %> + count: @proposal.voters.count, + proposal_page: link_to(t("proposal_notifications.new.proposal_page"), + proposal_path(@proposal, anchor: "comments"))).html_safe %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index e78f9c4d0..1002042d7 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -374,7 +374,7 @@ en: title_label: "Title" body_label: "Message" submit_button: "Send message" - info_about_receivers_html: "This message will be send to %{count} people and it will be visible in " + info_about_receivers_html: "This message will be send to %{count} people and it will be visible in %{proposal_page}." proposal_page: "the proposal's page" show: back: "Go back to my activity" diff --git a/config/locales/es.yml b/config/locales/es.yml index 592bc9213..30d573c37 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -374,7 +374,7 @@ es: title_label: "Título" body_label: "Mensaje" submit_button: "Enviar mensaje" - info_about_receivers_html: "Este mensaje se enviará a %{count} usuarios y se publicará en " + info_about_receivers_html: "Este mensaje se enviará a %{count} usuarios y se publicará en %{proposal_page}." proposal_page: "la página de la propuesta" show: back: "Volver a mi actividad" From 2dc39192b800886a65f0c5b1dfd59c691c2e72f4 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 15 Jun 2016 17:13:44 +0200 Subject: [PATCH 47/58] Adds button to proposal's show to 'Send notification' --- app/assets/stylesheets/layout.scss | 4 ++++ app/views/proposals/show.html.erb | 5 +++++ app/views/users/_proposals.html.erb | 2 +- config/locales/en.yml | 3 ++- config/locales/es.yml | 3 ++- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index e9a9f1057..9152955dc 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -253,6 +253,10 @@ a { max-width: none; } +.button.float-right ~ .button.float-right { + margin: 0 $line-height/2; +} + // 02. Header // ---------- diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 2153b23e5..7bb2a92a6 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -12,6 +12,11 @@
<%= render "shared/back_link" %> + <% if author_of?(@proposal, current_user) %> + <%= link_to t("proposals.show.send_notification"), new_proposal_notification_path(proposal_id: @proposal.id), + class: 'button hollow float-right' %> + <% end %> + <% if current_user && @proposal.editable_by?(current_user) %> <%= link_to edit_proposal_path(@proposal), class: 'edit-proposal button hollow float-right' do %> <%= t("proposals.show.edit_proposal_link") %> diff --git a/app/views/users/_proposals.html.erb b/app/views/users/_proposals.html.erb index a56b096f6..f50045635 100644 --- a/app/views/users/_proposals.html.erb +++ b/app/views/users/_proposals.html.erb @@ -9,7 +9,7 @@ <% if author? %>
<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 1002042d7..78ac956a7 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -365,6 +365,7 @@ en: retired_warning_link_to_explanation: Read the explanation before voting for it. retired: Proposal retired by the author share: Share + send_notification: Send notification update: form: submit_button: Save changes @@ -535,7 +536,7 @@ en: private_activity: This user decided to keep the activity list private send_private_message: "Send private message" proposals: - send_message: "Send message" + send_notification: "Send notification" retire: "Retire" retired: "Retired" votes: diff --git a/config/locales/es.yml b/config/locales/es.yml index 30d573c37..219a07dee 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -364,6 +364,7 @@ es: retired_warning: "El autor de esta propuesta considera que ya no debe seguir recogiendo apoyos." retired_warning_link_to_explanation: Revisa su explicación antes de apoyarla. retired: Propuesta retirada por el autor + send_notification: Enviar notificación share: Compartir update: form: @@ -535,7 +536,7 @@ es: private_activity: Este usuario ha decidido mantener en privado su lista de actividades send_private_message: "Enviar un mensaje privado" proposals: - send_message: "Enviar mensaje" + send_notification: "Enviar notificación" retire: "Retirar" retired: "Retirada" votes: From f606a3bcbef34931568412945df329bf865d3293 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 15 Jun 2016 17:33:25 +0200 Subject: [PATCH 48/58] Adds link to unsubscribe in digest email --- .../mailer/proposal_notification_digest.html.erb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/views/mailer/proposal_notification_digest.html.erb b/app/views/mailer/proposal_notification_digest.html.erb index 500a0fade..eda614040 100644 --- a/app/views/mailer/proposal_notification_digest.html.erb +++ b/app/views/mailer/proposal_notification_digest.html.erb @@ -50,4 +50,16 @@
- <%= link_to proposal_url(notification.notifiable.proposal, anchor: "comments"), style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block;" do %> + <%= link_to proposal_url(notification.notifiable.proposal, anchor: "social-share"), style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block;" do %> <%= image_tag('icon_mailer_share.png', style: "border: 0; display: inline-block; width: 100%; max-width: 16px", alt: "") %> <%= t('mailers.proposal_notification_digest.share') %> <% end %> - <%= link_to proposal_url(notification.notifiable.proposal, anchor: "social-share"), style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block; margin-left: 12px;" do %> + <%= link_to proposal_url(notification.notifiable.proposal, anchor: "comments"), style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 160px; display: inline-block; margin-left: 12px;" do %> <%= image_tag('icon_mailer_comment.png', style: "border: 0; display: inline-block; width: 100%; max-width: 16px; vertical-align: middle;", alt: "") %> <%= t('mailers.proposal_notification_digest.comment') %> <% end %> From 90148ffdca758dd4e7d3d7c18770b20f31c8dcff Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 15 Jun 2016 11:34:33 +0200 Subject: [PATCH 39/58] adds missing translation --- app/views/mailer/direct_message_for_receiver.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/mailer/direct_message_for_receiver.html.erb b/app/views/mailer/direct_message_for_receiver.html.erb index d70c78a28..a6b366ce9 100644 --- a/app/views/mailer/direct_message_for_receiver.html.erb +++ b/app/views/mailer/direct_message_for_receiver.html.erb @@ -13,7 +13,7 @@ <%= link_to user_url(@direct_message.sender), style: "font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; background: #f7f5f2; border-radius: 6px; color: #3d3d66!important; font-weight: bold; margin: 0px; padding: 10px 15px; text-align: center; text-decoration: none; min-width: 200px; display: inline-block;", target: "_blank" do %> <%= image_tag('icon_mailer_reply.png', style: "border: 0; display: inline-block; width: 100%; max-width: 12px; vertical-align: sub;", alt: "") %> - <%= t('mailers.direct_message.reply', + <%= t('mailers.direct_message_for_receiver.reply', sender: @direct_message.sender.name) %> <% end %> - <%= link_to t("users.proposals.send_message"), new_proposal_notification_path(proposal_id: proposal.id), + <%= link_to t("users.proposals.send_notification"), new_proposal_notification_path(proposal_id: proposal.id), class: 'button hollow' %>
<% end %> + + + + + + + + From 0366d7efb25f7a8d5ace7d1ef6e5c2ab7a483571 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 15 Jun 2016 17:55:42 +0200 Subject: [PATCH 49/58] Adds translations on mailer message --- app/views/mailer/proposal_notification_digest.html.erb | 4 +++- config/locales/mailers.en.yml | 2 ++ config/locales/mailers.es.yml | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/views/mailer/proposal_notification_digest.html.erb b/app/views/mailer/proposal_notification_digest.html.erb index eda614040..cd194de7f 100644 --- a/app/views/mailer/proposal_notification_digest.html.erb +++ b/app/views/mailer/proposal_notification_digest.html.erb @@ -56,7 +56,9 @@ diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index 6d91c52a1..099b3c182 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -34,6 +34,8 @@ en: title: You received the following notifications share: Share proposal comment: Comment proposal + unsubscribe: "If you don't want receive proposal's notification, visit %{account} and unckeck 'Receive a summary of proposal notifications'." + unsubscribe_account: My account direct_message_for_receiver: subject: "You have received a new private message" reply: Reply to %{sender} diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 7593aac43..e510ec2d8 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -34,6 +34,8 @@ es: title: Has recibido las siguientes notificaciones 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 direct_message_for_receiver: subject: "Has recibido un nuevo mensaje privado" reply: Responder a %{sender} From 0f1d6c1f191ad3b02eab6aa2ce7f1f9a07dbfbc2 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 15 Jun 2016 20:44:32 +0200 Subject: [PATCH 50/58] Adds text in footer about not replying --- app/views/layouts/mailer.html.erb | 4 ++++ app/views/mailer/proposal_notification_digest.html.erb | 2 +- config/locales/mailers.en.yml | 1 + config/locales/mailers.es.yml | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb index e0533ca50..f90b8e39d 100644 --- a/app/views/layouts/mailer.html.erb +++ b/app/views/layouts/mailer.html.erb @@ -32,6 +32,10 @@ diff --git a/app/views/mailer/proposal_notification_digest.html.erb b/app/views/mailer/proposal_notification_digest.html.erb index cd194de7f..97a309d81 100644 --- a/app/views/mailer/proposal_notification_digest.html.erb +++ b/app/views/mailer/proposal_notification_digest.html.erb @@ -17,7 +17,7 @@ diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index 72c201dd7..81efbd30c 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -32,7 +32,7 @@ en: subject: "Your investment project '%{code}' has been marked as unfeasible" unfeasible_html: "From the Madrid City Council we want to thank you for your participation in the participatory budgets of the city of Madrid. We regret to inform you that your proposal '%{title}' will be excluded from this participatory process for the following reason:" proposal_notification_digest: - title: You received the following notifications + title: "Proposal notifications in %{org_name}" share: Share proposal comment: Comment proposal unsubscribe: "If you don't want receive proposal's notification, visit %{account} and unckeck 'Receive a summary of proposal notifications'." diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 41abb53d8..0c9d81ac0 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -32,7 +32,7 @@ es: subject: "Tu propuesta de inversión '%{code}' ha sido marcada como inviable" unfeasible_html: "Desde el Ayuntamiento de Madrid queremos agradecer tu participación en los Presupuestos Participativos de la ciudad de Madrid. Lamentamos informarte de que tu propuesta '%{title}' quedará excluida de este proceso participativo por el siguiente motivo:" proposal_notification_digest: - title: Has recibido las siguientes notificaciones + 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'." From dd7629b5af5d769ff9b435bb30d850a99617d24c Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 15 Jun 2016 21:00:56 +0200 Subject: [PATCH 52/58] Adds notification menu and message for empty notifications --- app/views/proposals/_comments.html.erb | 7 ------- app/views/proposals/_notifications.html.erb | 6 ++++++ app/views/proposals/show.html.erb | 6 ++---- config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/views/proposals/_comments.html.erb b/app/views/proposals/_comments.html.erb index 094814cf1..ed52b1b66 100644 --- a/app/views/proposals/_comments.html.erb +++ b/app/views/proposals/_comments.html.erb @@ -2,13 +2,6 @@
- <% if @notifications.blank? %> -

- <%= t("proposals.show.comments_title") %> - (<%= @proposal.comments_count %>) -

- <% end %> - <%= render 'shared/wide_order_selector', i18n_namespace: "comments" %> <% if user_signed_in? %> diff --git a/app/views/proposals/_notifications.html.erb b/app/views/proposals/_notifications.html.erb index 44bb9f4a2..69389b2c5 100644 --- a/app/views/proposals/_notifications.html.erb +++ b/app/views/proposals/_notifications.html.erb @@ -1,6 +1,12 @@
+ <% if @notifications.blank? %> +
+ <%= t('proposals.show.no_notifications') %> +
+ <% end %> + <% @notifications.each do |notification| %>

<%= notification.title %>

<%= notification.created_at.to_date %>

diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 7bb2a92a6..3a9869d83 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -124,10 +124,8 @@ <% end %>
- <% if @notifications.present? %> - <%= render "proposals/filter_subnav" %> - <%= render "proposals/notifications" %> - <% end %> + <%= render "proposals/filter_subnav" %> + <%= render "proposals/notifications" %>
<%= render "proposals/comments" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 78ac956a7..65d97f997 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -356,7 +356,6 @@ en: other: "%{count} comments" zero: No comments comments_tab: Comments - comments_title: Comments edit_proposal_link: Edit flag: This proposal has been flagged as inappropriate by several users. login_to_comment: You must %{signin} or %{signup} to leave a comment. @@ -366,6 +365,7 @@ en: retired: Proposal retired by the author share: Share send_notification: Send notification + no_notifications: "This proposal has any notifications." update: form: submit_button: Save changes diff --git a/config/locales/es.yml b/config/locales/es.yml index 219a07dee..9ac646584 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -356,7 +356,6 @@ es: other: "%{count} Comentarios" zero: Sin comentarios comments_tab: Comentarios - comments_title: Comentarios edit_proposal_link: Editar propuesta flag: Esta propuesta ha sido marcada como inapropiada por varios usuarios. login_to_comment: Necesitas %{signin} o %{signup} para comentar. @@ -366,6 +365,7 @@ es: retired: Propuesta retirada por el autor send_notification: Enviar notificación share: Compartir + no_notifications: "Esta propuesta no tiene notificaciones." update: form: submit_button: Guardar cambios From 419ced5a18394c5a91586e6b79dfc08b3bd16ace Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 15 Jun 2016 21:14:56 +0200 Subject: [PATCH 53/58] Adds text to form new --- app/views/proposal_notifications/new.html.erb | 6 +++++- config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/views/proposal_notifications/new.html.erb b/app/views/proposal_notifications/new.html.erb index b76f218fe..678e00088 100644 --- a/app/views/proposal_notifications/new.html.erb +++ b/app/views/proposal_notifications/new.html.erb @@ -1,5 +1,5 @@
-
+
<%= render 'shared/back_link' %>

<%= t("proposal_notifications.new.title") %>

@@ -12,7 +12,11 @@ proposal_path(@proposal, anchor: "comments"))).html_safe %>

+
+
+
+
<%= form_for @notification do |f| %> <%= render "shared/errors", resource: @notification %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 65d97f997..7d59f0520 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -375,7 +375,7 @@ en: title_label: "Title" body_label: "Message" submit_button: "Send message" - info_about_receivers_html: "This message will be send to %{count} people and it will be visible in %{proposal_page}." + info_about_receivers_html: "This message will be send to %{count} people and it will be visible in %{proposal_page}.
Message are not sent immediately, users will receive periodically an email with all proposal notifications." proposal_page: "the proposal's page" show: back: "Go back to my activity" diff --git a/config/locales/es.yml b/config/locales/es.yml index 9ac646584..488d0d689 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -375,7 +375,7 @@ es: title_label: "Título" body_label: "Mensaje" submit_button: "Enviar mensaje" - info_about_receivers_html: "Este mensaje se enviará a %{count} usuarios y se publicará en %{proposal_page}." + info_about_receivers_html: "Este mensaje se enviará a %{count} usuarios y se publicará en %{proposal_page}.
El mensaje no se enviará inmediatamente, los usuarios recibirán periódicamente un email con todas las notificaciones de propuestas." proposal_page: "la página de la propuesta" show: back: "Volver a mi actividad" From c83e831cb7a11e19da873ebb0ad25475ce40b4f6 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 15 Jun 2016 21:28:17 +0200 Subject: [PATCH 54/58] Adds link to not receive direct messages --- .../direct_message_for_receiver.html.erb | 14 ++++++++++++++ .../proposal_notification_digest.html.erb | 18 +++++++++--------- config/locales/mailers.en.yml | 2 ++ config/locales/mailers.es.yml | 2 ++ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/views/mailer/direct_message_for_receiver.html.erb b/app/views/mailer/direct_message_for_receiver.html.erb index a6b366ce9..eb1e56fe7 100644 --- a/app/views/mailer/direct_message_for_receiver.html.erb +++ b/app/views/mailer/direct_message_for_receiver.html.erb @@ -20,4 +20,18 @@
+

+ Si no quieres recibir notificaciones de propuestas, puedes entrar en Mi cuenta y desmarcar la opción "Recibir resumen de notificaciones sobre propuestas". +

+

- Si no quieres recibir notificaciones de propuestas, puedes entrar en Mi cuenta y desmarcar la opción "Recibir resumen de notificaciones sobre propuestas". + <%= t('mailers.proposal_notification_digest.unsubscribe', + account: link_to(t('mailers.proposal_notification_digest.unsubscribe_account'), + account_path)).html_safe %>

<%= setting['org_name'] %>

+ +

+ <%= t('mailers.no_reply') %>

+

- <%= link_to notification.notifiable.title, notification_url(notification) %> + <%= link_to notification.notifiable.title, notification_url(notification), style: "color: #2895F1; text-decoration: none;" %>

<%= notification.notifiable.proposal.title %> •  diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index 099b3c182..72c201dd7 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -1,6 +1,7 @@ --- en: mailers: + no_reply: "This message was sent from an email address that does not accept replies." comment: hi: Hi new_comment_by_html: There is a new comment from %{commenter} diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index e510ec2d8..41abb53d8 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -1,6 +1,7 @@ --- es: mailers: + no_reply: "Este mensaje se ha enviado desde una dirección de correo electrónico que no admite respuestas." comment: hi: Hola new_comment_by_html: Hay un nuevo comentario de %{commenter} en From 017ccfb3786a9222e624a23d9ff72e7dfce0dac2 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 15 Jun 2016 20:49:29 +0200 Subject: [PATCH 51/58] Changes title and subject in email --- app/mailers/mailer.rb | 2 +- app/views/mailer/proposal_notification_digest.html.erb | 3 ++- config/locales/mailers.en.yml | 2 +- config/locales/mailers.es.yml | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 5f7dc5391..d987e34cc 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -64,7 +64,7 @@ class Mailer < ApplicationMailer @notifications = user.notifications.where(notifiable_type: "ProposalNotification") with_user(user) do - mail(to: user.email, subject: "Email digest") + mail(to: user.email, subject: t('mailers.proposal_notification_digest.title', org_name: Setting['org_name'])) end end diff --git a/app/views/mailer/proposal_notification_digest.html.erb b/app/views/mailer/proposal_notification_digest.html.erb index 97a309d81..b9592b21a 100644 --- a/app/views/mailer/proposal_notification_digest.html.erb +++ b/app/views/mailer/proposal_notification_digest.html.erb @@ -4,7 +4,8 @@

- <%= t('mailers.proposal_notification_digest.title') %> + <%= t('mailers.proposal_notification_digest.title', + org_name: Setting['org_name']) %>

+ + + + + + + +
+

+ <%= t('mailers.direct_message_for_receiver.unsubscribe', + account: link_to(t('mailers.proposal_notification_digest.unsubscribe_account'), + account_path, style: "color: #2895F1; text-decoration: none;")).html_safe %> +

+
diff --git a/app/views/mailer/proposal_notification_digest.html.erb b/app/views/mailer/proposal_notification_digest.html.erb index b9592b21a..626d46885 100644 --- a/app/views/mailer/proposal_notification_digest.html.erb +++ b/app/views/mailer/proposal_notification_digest.html.erb @@ -56,13 +56,13 @@ -

- <%= t('mailers.proposal_notification_digest.unsubscribe', - account: link_to(t('mailers.proposal_notification_digest.unsubscribe_account'), - account_path)).html_safe %> -

- - - - +

+ <%= t('mailers.proposal_notification_digest.unsubscribe', + account: link_to(t('mailers.proposal_notification_digest.unsubscribe_account'), + account_path, style: "color: #2895F1; text-decoration: none;")).html_safe %> +

+ + + + diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index 81efbd30c..bcf622836 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -40,5 +40,7 @@ en: direct_message_for_receiver: subject: "You have received a new private message" reply: Reply to %{sender} + unsubscribe: "If you don't want receive direct messages, visit %{account} and unckeck 'Receive emails about direct messages'." + unsubscribe_account: My account direct_message_for_sender: subject: "You have send a new private message" \ No newline at end of file diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 0c9d81ac0..84b2a240e 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -40,5 +40,7 @@ es: direct_message_for_receiver: subject: "Has recibido un nuevo mensaje privado" reply: Responder a %{sender} + unsubscribe: "Si no quieres recibir mensajes directos, puedes entrar en %{account} y desmarcar la opción 'Recibir emails con mensajes directos'." + unsubscribe_account: Mi cuenta direct_message_for_sender: subject: "Has enviado un nuevo mensaje privado" \ No newline at end of file From 9f7b49838dc51fc1ff9ed8113ece6c8ca7a41b7f Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 15 Jun 2016 21:37:36 +0200 Subject: [PATCH 55/58] Improves texts for the sender's email --- app/views/mailer/direct_message_for_sender.html.erb | 10 +++++++--- config/locales/mailers.en.yml | 3 ++- config/locales/mailers.es.yml | 5 +++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/views/mailer/direct_message_for_sender.html.erb b/app/views/mailer/direct_message_for_sender.html.erb index 219337705..4cf832414 100644 --- a/app/views/mailer/direct_message_for_sender.html.erb +++ b/app/views/mailer/direct_message_for_sender.html.erb @@ -1,9 +1,13 @@ -

<%= @direct_message.receiver.name %>

-

+

+ <%= t('mailers.direct_message_for_sender.title_html', + receiver: @direct_message.receiver.name ) %> +

+ +

<%= @direct_message.title %> -

+

<%= @direct_message.body %> diff --git a/config/locales/mailers.en.yml b/config/locales/mailers.en.yml index bcf622836..c2e2b5d85 100755 --- a/config/locales/mailers.en.yml +++ b/config/locales/mailers.en.yml @@ -43,4 +43,5 @@ en: unsubscribe: "If you don't want receive direct messages, visit %{account} and unckeck 'Receive emails about direct messages'." unsubscribe_account: My account direct_message_for_sender: - subject: "You have send a new private message" \ No newline at end of file + subject: "You have send a new private message" + title_html: "You have send a new private message to %{receiver} with the content:" \ No newline at end of file diff --git a/config/locales/mailers.es.yml b/config/locales/mailers.es.yml index 84b2a240e..bde81ec86 100644 --- a/config/locales/mailers.es.yml +++ b/config/locales/mailers.es.yml @@ -40,7 +40,8 @@ es: direct_message_for_receiver: subject: "Has recibido un nuevo mensaje privado" reply: Responder a %{sender} - unsubscribe: "Si no quieres recibir mensajes directos, puedes entrar en %{account} y desmarcar la opción 'Recibir emails con mensajes directos'." + unsubscribe: "Si no quieres recibir mensajes privados, puedes entrar en %{account} y desmarcar la opción 'Recibir emails con mensajes directos'." unsubscribe_account: Mi cuenta direct_message_for_sender: - subject: "Has enviado un nuevo mensaje privado" \ No newline at end of file + subject: "Has enviado un nuevo mensaje privado" + title_html: "Has enviado un nuevo mensaje privado a %{receiver} con el siguiente contenido:" \ No newline at end of file From 25ebb325d12d99aa615874c4649f65bab04d62dd Mon Sep 17 00:00:00 2001 From: rgarcia Date: Thu, 16 Jun 2016 11:10:26 +0200 Subject: [PATCH 56/58] limits maximum number of messages able to send per day --- app/models/direct_message.rb | 18 ++++++ app/models/user.rb | 3 +- config/locales/activerecord.en.yml | 4 ++ config/locales/activerecord.es.yml | 4 ++ db/seeds.rb | 1 + spec/features/direct_messages_spec.rb | 29 +++++++++ spec/models/direct_message_spec.rb | 85 +++++++++++++++++++++++++++ 7 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 spec/models/direct_message_spec.rb diff --git a/app/models/direct_message.rb b/app/models/direct_message.rb index 32cf6ac58..14083f2c7 100644 --- a/app/models/direct_message.rb +++ b/app/models/direct_message.rb @@ -1,4 +1,22 @@ class DirectMessage < ActiveRecord::Base belongs_to :sender, class_name: 'User', foreign_key: 'sender_id' belongs_to :receiver, class_name: 'User', foreign_key: 'receiver_id' + + validates :title, presence: true + validates :body, presence: true + validates :sender, presence: true + validates :receiver, presence: true + validate :max_per_day + + scope :today, lambda { where('DATE(created_at) = ?', Date.today) } + + def max_per_day + return if errors.any? + max = Setting[:direct_message_max_per_day] + + if sender.direct_messages_sent.today.count >= max.to_i + errors.add(:title, I18n.t('activerecord.errors.models.direct_message.attributes.max_per_day.invalid', max: max)) + end + end + end diff --git a/app/models/user.rb b/app/models/user.rb index a3b719859..7240c8929 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,7 +23,8 @@ class User < ActiveRecord::Base has_many :spending_proposals, foreign_key: :author_id has_many :failed_census_calls has_many :notifications - has_many :direct_messages + has_many :direct_messages_sent, class_name: 'DirectMessage', foreign_key: :sender_id + has_many :direct_messages_received, class_name: 'DirectMessage', foreign_key: :receiver_id belongs_to :geozone validates :username, presence: true, if: :username_required? diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 524c8906c..9b48c1fc2 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -78,6 +78,10 @@ en: attributes: tag_list: less_than_or_equal_to: "tags must be less than or equal to %{count}" + direct_message: + attributes: + max_per_day: + invalid: "You can only send a maximum of %{max} direct messages per day" proposal: attributes: tag_list: diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index 1999631ab..f14022255 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -78,6 +78,10 @@ es: attributes: tag_list: less_than_or_equal_to: "los temas deben ser menor o igual que %{count}" + direct_message: + attributes: + max_per_day: + invalid: "Sólo puedes enviar %{max} mensajes directos por día" proposal: attributes: tag_list: diff --git a/db/seeds.rb b/db/seeds.rb index 5a6db1574..5644fe493 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -77,3 +77,4 @@ Setting['banner-img.banner-img-three'] = "Banner image 3" # Proposal notifications Setting['proposal_notification_minimum_interval_in_days '] = 3 +Setting['direct_message_max_per_day '] = 3 \ No newline at end of file diff --git a/spec/features/direct_messages_spec.rb b/spec/features/direct_messages_spec.rb index 119cbe6de..76b7a150c 100644 --- a/spec/features/direct_messages_spec.rb +++ b/spec/features/direct_messages_spec.rb @@ -72,4 +72,33 @@ feature 'Direct messages' do expect(page).to have_content error_message end + context "Limits" do + + background do + Setting[:direct_message_max_per_day] = 3 + end + + scenario "Can only send a maximum number of direct messages per day" do + sender = create(:user, :level_two) + receiver = create(:user, :level_two) + + 3.times { create(:direct_message, sender: sender) } + + login_as(sender) + visit user_path(receiver) + + click_link "Send private message" + + expect(page).to have_content "Send private message to #{receiver.name}" + + fill_in 'direct_message_title', with: "Hey!" + fill_in 'direct_message_body', with: "How are you doing?" + click_button "Send message" + + expect(page).to have_content "You can only send a maximum of 3 direct messages per day" + expect(page).to_not have_content "You message has been sent successfully." + end + + end + end \ No newline at end of file diff --git a/spec/models/direct_message_spec.rb b/spec/models/direct_message_spec.rb new file mode 100644 index 000000000..e982f9e56 --- /dev/null +++ b/spec/models/direct_message_spec.rb @@ -0,0 +1,85 @@ +require 'rails_helper' + +describe DirectMessage do + + let(:direct_message) { build(:direct_message) } + + before(:each) do + Setting[:direct_message_max_per_day] = 3 + end + + it "should be valid" do + expect(direct_message).to be_valid + end + + it "should not be valid without a title" do + direct_message.title = nil + expect(direct_message).to_not be_valid + end + + it "should not be valid without a body" do + direct_message.body = nil + expect(direct_message).to_not be_valid + end + + it "should not be valid without an associated sender" do + direct_message.sender = nil + expect(direct_message).to_not be_valid + end + + it "should not be valid without an associated receiver" do + direct_message.receiver = nil + expect(direct_message).to_not be_valid + end + + describe "maximum number of direct messages per day" do + + it "should not be valid if above maximum" do + sender = create(:user) + direct_message1 = create(:direct_message, sender: sender) + direct_message2 = create(:direct_message, sender: sender) + direct_message3 = create(:direct_message, sender: sender) + + direct_message4 = build(:direct_message, sender: sender) + expect(direct_message4).to_not be_valid + end + + it "should be valid if below maximum" do + sender = create(:user) + direct_message1 = create(:direct_message, sender: sender) + direct_message2 = create(:direct_message, sender: sender) + + direct_message3 = build(:direct_message) + expect(direct_message).to be_valid + end + + it "should be valid if no direct_messages sent" do + direct_message = build(:direct_message) + + expect(direct_message).to be_valid + end + + end + + describe "scopes" do + + describe "today" do + it "should return direct messages created today" do + direct_message1 = create(:direct_message, created_at: Time.zone.now.beginning_of_day + 3.hours) + direct_message2 = create(:direct_message, created_at: Time.zone.now) + direct_message3 = create(:direct_message, created_at: Time.zone.now.end_of_day) + + expect(DirectMessage.today.count).to eq 3 + end + + it "should not return direct messages created another day" do + direct_message1 = create(:direct_message, created_at: 1.day.ago) + direct_message2 = create(:direct_message, created_at: 1.day.from_now) + + expect(DirectMessage.today.count).to eq 0 + end + end + + end + +end \ No newline at end of file From 91860cb4097908cd21b9cbccbd64001cec6a7bef Mon Sep 17 00:00:00 2001 From: rgarcia Date: Thu, 16 Jun 2016 11:23:03 +0200 Subject: [PATCH 57/58] validates that a user does not want to receive direct messages --- app/views/direct_messages/new.html.erb | 19 +++++++++-- config/locales/en.yml | 4 +++ config/locales/es.yml | 5 +++ spec/features/direct_messages_spec.rb | 44 ++++++++++++++++++-------- 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/app/views/direct_messages/new.html.erb b/app/views/direct_messages/new.html.erb index 4c888ccd0..3413f26f0 100644 --- a/app/views/direct_messages/new.html.erb +++ b/app/views/direct_messages/new.html.erb @@ -3,11 +3,24 @@ <%= render 'shared/back_link' %>

- <%= t("users.direct_messages.new.title", - receiver: @receiver.name) %> + <%= t("users.direct_messages.new.title", receiver: @receiver.name) %>

- <% if can? :create, @direct_message %> + <% if not current_user %> +
+

+ <%= t("users.direct_messages.new.authenticate", + signin: link_to(t("users.direct_messages.new.signin"), new_user_session_path), + signup: link_to(t("users.direct_messages.new.signup"), new_user_registration_path)).html_safe %> +

+
+ <% elsif not @receiver.email_on_direct_message? %> +
+

+ <%= t("users.direct_messages.new.direct_messages_bloqued") %> +

+
+ <% elsif can? :create, @direct_message %> <%= form_for [@receiver, @direct_message] do |f| %> <%= render "shared/errors", resource: @direct_message %> diff --git a/config/locales/en.yml b/config/locales/en.yml index e78f9c4d0..eb28cf18d 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -504,11 +504,15 @@ en: direct_messages: new: body_label: Message + direct_messages_bloqued: "This user has decided not to receive direct messages" submit_button: Send message title: Send private message to %{receiver} title_label: Title verified_only: To send a private message %{verify_account} verify_account: verify your account + authenticate: You must %{signin} or %{signup} to continue. + signin: sign in + signup: sign up show: receiver: Message sent to %{receiver} show: diff --git a/config/locales/es.yml b/config/locales/es.yml index 592bc9213..bf46a8258 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -143,6 +143,7 @@ es: accept_terms_title: Acepto la Política de privacidad y las Condiciones de uso conditions: Condiciones de uso debate: el debate + direct_message: el mensaje privado error: error errors: errores not_saved: 'impidieron guardar %{resource}:' @@ -504,11 +505,15 @@ es: direct_messages: new: body_label: "Mensaje" + direct_messages_bloqued: "Este usuarios ha decidido no recibir mensajes directos" submit_button: "Enviar mensaje" title: Enviar mensaje privado a %{receiver} title_label: "Título" verified_only: Para enviar un mensaje privado %{verify_account} verify_account: verifica tu cuenta + authenticate: Necesitas %{signin} o %{signup}. + signin: iniciar sesión + signup: registrarte show: receiver: Mensaje enviado a %{receiver} show: diff --git a/spec/features/direct_messages_spec.rb b/spec/features/direct_messages_spec.rb index 76b7a150c..8ec949e9a 100644 --- a/spec/features/direct_messages_spec.rb +++ b/spec/features/direct_messages_spec.rb @@ -2,6 +2,10 @@ require 'rails_helper' feature 'Direct messages' do + background do + Setting[:direct_message_max_per_day] = 3 + end + scenario "Create" do sender = create(:user, :level_two) receiver = create(:user, :level_two) @@ -44,19 +48,37 @@ feature 'Direct messages' do expect(page).to_not have_link "Send private message" end - scenario "Accessing form directly" do - user = create(:user) - author = create(:user) - proposal = create(:proposal, author: author) + scenario "Unverified user" do + sender = create(:user) + receiver = create(:user) - login_as(user) - visit new_proposal_notification_path(proposal_id: proposal.id) + login_as(sender) + visit new_user_direct_message_path(receiver) - expect(current_path).to eq(proposals_path) - expect(page).to have_content("You do not have permission to carry out the action") + expect(page).to have_content "To send a private message verify your account" + expect(page).to_not have_link "Send private message" end - pending "unverified user" + scenario "User not logged in" do + sender = create(:user) + receiver = create(:user) + + visit new_user_direct_message_path(receiver) + + expect(page).to have_content "You must sign in or sign up to continue." + expect(page).to_not have_link "Send private message" + end + + scenario "Accessing form directly" do + sender = create(:user, :level_two) + receiver = create(:user, :level_two, email_on_direct_message: false) + + login_as(sender) + visit new_user_direct_message_path(receiver) + + expect(page).to have_content("This user has decided not to receive direct messages") + expect(page).to_not have_css("#direct_message_title") + end end @@ -74,10 +96,6 @@ feature 'Direct messages' do context "Limits" do - background do - Setting[:direct_message_max_per_day] = 3 - end - scenario "Can only send a maximum number of direct messages per day" do sender = create(:user, :level_two) receiver = create(:user, :level_two) From 18dd9c95f35a7e9bf6b0fd5bda8b3c64e1bd22e9 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Thu, 16 Jun 2016 12:06:26 +0200 Subject: [PATCH 58/58] fixes specs --- app/controllers/management/proposals_controller.rb | 1 + app/views/mailer/direct_message_for_receiver.html.erb | 4 ++-- app/views/mailer/proposal_notification_digest.html.erb | 2 +- config/i18n-tasks.yml | 1 + config/locales/en.yml | 1 + db/seeds.rb | 2 +- spec/features/comments/proposals_spec.rb | 5 ++++- spec/features/emails_spec.rb | 3 ++- spec/features/proposal_notifications_spec.rb | 6 +++--- spec/support/common_actions.rb | 3 ++- 10 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/controllers/management/proposals_controller.rb b/app/controllers/management/proposals_controller.rb index 4f6ca18c4..2ce74d6d5 100644 --- a/app/controllers/management/proposals_controller.rb +++ b/app/controllers/management/proposals_controller.rb @@ -13,6 +13,7 @@ class Management::ProposalsController < Management::BaseController def show super + @notifications = @proposal.notifications redirect_to management_proposal_path(@proposal), status: :moved_permanently if request.path != management_proposal_path(@proposal) end diff --git a/app/views/mailer/direct_message_for_receiver.html.erb b/app/views/mailer/direct_message_for_receiver.html.erb index eb1e56fe7..2523f3502 100644 --- a/app/views/mailer/direct_message_for_receiver.html.erb +++ b/app/views/mailer/direct_message_for_receiver.html.erb @@ -27,8 +27,8 @@

<%= t('mailers.direct_message_for_receiver.unsubscribe', - account: link_to(t('mailers.proposal_notification_digest.unsubscribe_account'), - account_path, style: "color: #2895F1; text-decoration: none;")).html_safe %> + account: link_to(t('mailers.direct_message_for_receiver.unsubscribe_account'), + account_url, style: "color: #2895F1; text-decoration: none;")).html_safe %>

diff --git a/app/views/mailer/proposal_notification_digest.html.erb b/app/views/mailer/proposal_notification_digest.html.erb index 626d46885..0b839150f 100644 --- a/app/views/mailer/proposal_notification_digest.html.erb +++ b/app/views/mailer/proposal_notification_digest.html.erb @@ -59,7 +59,7 @@

<%= t('mailers.proposal_notification_digest.unsubscribe', account: link_to(t('mailers.proposal_notification_digest.unsubscribe_account'), - account_path, style: "color: #2895F1; text-decoration: none;")).html_safe %> + account_url, style: "color: #2895F1; text-decoration: none;")).html_safe %>

diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index d24cc6eab..250ed18f9 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -96,6 +96,7 @@ search: ignore_missing: - 'unauthorized.*' - 'activerecord.errors.models.proposal_notification.*' + - 'activerecord.errors.models.direct_message.*' - 'errors.messages.blank' - 'errors.messages.taken' - 'devise.failure.invalid' diff --git a/config/locales/en.yml b/config/locales/en.yml index 64ee8fb6f..b16f1092a 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -143,6 +143,7 @@ en: accept_terms_title: I agree to the Privacy Policy and the Terms and conditions of use conditions: Terms and conditions of use debate: Debate + direct_message: private message error: error errors: errors not_saved: 'prevented this %{resource} from being saved:' diff --git a/db/seeds.rb b/db/seeds.rb index 5644fe493..4a4741a07 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -77,4 +77,4 @@ Setting['banner-img.banner-img-three'] = "Banner image 3" # Proposal notifications Setting['proposal_notification_minimum_interval_in_days '] = 3 -Setting['direct_message_max_per_day '] = 3 \ No newline at end of file +Setting['direct_message_max_per_day'] = 3 \ No newline at end of file diff --git a/spec/features/comments/proposals_spec.rb b/spec/features/comments/proposals_spec.rb index 53b1006c3..8312176cd 100644 --- a/spec/features/comments/proposals_spec.rb +++ b/spec/features/comments/proposals_spec.rb @@ -168,7 +168,10 @@ feature 'Commenting proposals' do within "#comments" do expect(page).to have_content 'Have you thought about...?' - expect(page).to have_content '(1)' + end + + within "#tab-comments-label" do + expect(page).to have_content 'Comments (1)' end end diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index 3ea8f16b9..f793b5bb7 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -205,7 +205,7 @@ feature 'Emails' do email_digest.create email = open_last_email - expect(email).to have_subject("Email digest") + expect(email).to have_subject("Proposal notifications in Consul") expect(email).to deliver_to(user.email) expect(email).to have_body_text(proposal1.title) @@ -226,6 +226,7 @@ feature 'Emails' do expect(email).to have_body_text(proposal2.author.name) expect(email).to_not have_body_text(proposal3.title) + expect(email).to have_body_text(/#{account_path}/) end end diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb index be8b146fd..6092289f0 100644 --- a/spec/features/proposal_notifications_spec.rb +++ b/spec/features/proposal_notifications_spec.rb @@ -12,7 +12,7 @@ feature 'Proposal Notifications' do click_link "My activity" within("#proposal_#{proposal.id}") do - click_link "Send message" + click_link "Send notification" end fill_in 'proposal_notification_title', with: "Thank you for supporting my proposal" @@ -48,7 +48,7 @@ feature 'Proposal Notifications' do visit new_proposal_notification_path(proposal_id: proposal.id) expect(page).to have_content "This message will be send to 7 people and it will be visible in the proposal's page" - expect(page).to have_link("the proposal's page", href: proposal_path(proposal)) + expect(page).to have_link("the proposal's page", href: proposal_path(proposal, anchor: 'comments')) end context "Permissions" do @@ -62,7 +62,7 @@ feature 'Proposal Notifications' do visit user_path(author) within("#proposal_#{proposal.id}") do - expect(page).to have_link "Send message" + expect(page).to have_link "Send notification" end login_as(user) diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 8eba8b13d..80bdde907 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -203,7 +203,7 @@ module CommonActions click_link "My activity" within("#proposal_#{proposal.id}") do - click_link "Send message" + click_link "Send notification" end fill_in 'proposal_notification_title', with: "Thank you for supporting my proposal #{proposal.title}" @@ -224,6 +224,7 @@ module CommonActions fill_in 'direct_message_title', with: "Hey #{receiver.name}!" fill_in 'direct_message_body', with: "How are you doing? This is #{sender.name}" + click_button "Send message" expect(page).to have_content "You message has been sent successfully."