Support creates follow (Merge pull request #3895)
* Supporting a proposal will create a follow relationship * Only followers receive notifications
This commit is contained in:
@@ -37,6 +37,7 @@ class Management::ProposalsController < Management::BaseController
|
||||
end
|
||||
|
||||
def vote
|
||||
@follow = Follow.find_or_create_by!(user: current_user, followable: @proposal)
|
||||
@proposal.register_vote(managed_user, "yes")
|
||||
set_proposal_votes(@proposal)
|
||||
end
|
||||
|
||||
@@ -57,6 +57,7 @@ class ProposalsController < ApplicationController
|
||||
end
|
||||
|
||||
def vote
|
||||
@follow = Follow.find_or_create_by!(user: current_user, followable: @proposal)
|
||||
@proposal.register_vote(current_user, "yes")
|
||||
set_proposal_votes(@proposal)
|
||||
end
|
||||
@@ -73,6 +74,7 @@ class ProposalsController < ApplicationController
|
||||
end
|
||||
|
||||
def vote_featured
|
||||
@follow = Follow.find_or_create_by!(user: current_user, followable: @proposal)
|
||||
@proposal.register_vote(current_user, "yes")
|
||||
set_featured_proposal_votes(@proposal)
|
||||
end
|
||||
|
||||
@@ -232,7 +232,7 @@ class Proposal < ApplicationRecord
|
||||
end
|
||||
|
||||
def users_to_notify
|
||||
(voters + followers).uniq - [author]
|
||||
followers - [author]
|
||||
end
|
||||
|
||||
def self.proposals_orders(user)
|
||||
|
||||
@@ -48,6 +48,15 @@
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px; margin: 0; padding-bottom: 20px;">
|
||||
<%= sanitize(link_to(t("mailers.proposal_notification_digest.unfollow"),
|
||||
proposal_url(notification.notifiable.proposal),
|
||||
style: "color: #2895F1; text-decoration: none;")) %>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
$("#<%= dom_id(@proposal) %>_votes").html("<%= j render("proposals/votes", proposal: @proposal) %>");
|
||||
App.Followable.update("<%= dom_id(@follow.followable) %>",
|
||||
"<%= j render("follows/follow_button", follow: @follow) %>",
|
||||
"<%= j render("layouts/flash") %>")
|
||||
|
||||
@@ -539,7 +539,7 @@ en:
|
||||
comments: Comments
|
||||
latest_comments: Latest messages
|
||||
messages:
|
||||
send_notification: Send message to proposal supporters
|
||||
send_notification: Send message to proposal followers
|
||||
previous_notifications: See previous notifications
|
||||
polls:
|
||||
index:
|
||||
|
||||
@@ -26,12 +26,13 @@ en:
|
||||
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 uncheck 'Receive a summary of proposal notifications'."
|
||||
unsubscribe: "If you don't want to receive any proposal notifications, visit %{account} and uncheck 'Receive a summary of proposal notifications'."
|
||||
unsubscribe_account: My account
|
||||
unfollow: "Visit this proposal and unfollow it to stop receiving notifications."
|
||||
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 uncheck 'Receive emails about direct messages'."
|
||||
unsubscribe: "If you don't want to receive direct messages, visit %{account} and uncheck 'Receive emails about direct messages'."
|
||||
unsubscribe_account: My account
|
||||
direct_message_for_sender:
|
||||
subject: "You have sent a new private message"
|
||||
|
||||
@@ -79,7 +79,7 @@ en:
|
||||
poster_description_description: Detailed description of the poster feature
|
||||
analytics_url: "Analytics URL"
|
||||
proposal_notification_minimum_interval_in_days: "Minimum interval (in days) for authors of proposals to send new proposal notifications"
|
||||
proposal_notification_minimum_interval_in_days_description: "The number of days user can send a notification for all supporters of their proposal"
|
||||
proposal_notification_minimum_interval_in_days_description: "The number of days user can send a notification for all followers of their proposal"
|
||||
direct_message_max_per_day: "Direct Message max number per day"
|
||||
direct_message_max_per_day_description: "Number max of direct messages one user can send per day"
|
||||
feature:
|
||||
|
||||
@@ -539,7 +539,7 @@ es:
|
||||
comments: Comentarios
|
||||
latest_comments: Últimos mensajes
|
||||
messages:
|
||||
send_notification: Enviar mensaje a los que han apoyado la propuesta
|
||||
send_notification: Enviar mensaje a los que siguen la propuesta
|
||||
previous_notifications: Ver notificaciones anteriores
|
||||
polls:
|
||||
index:
|
||||
|
||||
@@ -28,6 +28,7 @@ es:
|
||||
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
|
||||
unfollow: "Si no quieres recibir más notificaciones, visita esta propuesta y deja de seguirla."
|
||||
direct_message_for_receiver:
|
||||
subject: "Has recibido un nuevo mensaje privado"
|
||||
reply: Responder a %{sender}
|
||||
|
||||
@@ -79,7 +79,7 @@ es:
|
||||
poster_description_description: Descripción detallada de la funcionalidad de póster
|
||||
analytics_url: "URL de estadísticas externas"
|
||||
proposal_notification_minimum_interval_in_days: "Intervalo mínimo (en días) para que los autores de propuestas puedan enviar nuevas notificaciones de propuesta"
|
||||
proposal_notification_minimum_interval_in_days_description: "El número de días en los que un usuario puede enviar una notificación a todos los que apoyan su propuesta"
|
||||
proposal_notification_minimum_interval_in_days_description: "El número de días en los que un usuario puede enviar una notificación a todos los que siguen su propuesta"
|
||||
direct_message_max_per_day: "Mensajes directos máximos por día"
|
||||
direct_message_max_per_day_description: "Número de mensajes directos máximos que un usuario puede enviar por día"
|
||||
feature:
|
||||
|
||||
@@ -365,13 +365,13 @@ describe "Proposal's dashboard" do
|
||||
click_link "Message to users"
|
||||
end
|
||||
|
||||
expect(page).to have_link("Send message to proposal supporters")
|
||||
expect(page).to have_link("Send message to proposal followers")
|
||||
expect(page).to have_link("See previous notifications")
|
||||
end
|
||||
|
||||
scenario "Dashboard has a link to send message to proposal supporters" do
|
||||
visit messages_proposal_dashboard_path(proposal)
|
||||
click_link("Send message to proposal supporters")
|
||||
click_link("Send message to proposal followers")
|
||||
|
||||
fill_in "Title", with: "Thank you for supporting my proposal"
|
||||
fill_in "Message", with: "Please share it with others!"
|
||||
|
||||
@@ -249,11 +249,11 @@ describe "Emails" do
|
||||
end
|
||||
|
||||
context "Proposal notification digest" do
|
||||
scenario "notifications for proposals that I have supported" do
|
||||
scenario "notifications for proposals that I'm following" do
|
||||
user = create(:user, email_digest: true)
|
||||
|
||||
proposal1 = create(:proposal, voters: [user])
|
||||
proposal2 = create(:proposal, voters: [user])
|
||||
proposal1 = create(:proposal, followers: [user])
|
||||
proposal2 = create(:proposal, followers: [user])
|
||||
proposal3 = create(:proposal)
|
||||
|
||||
reset_mailer
|
||||
@@ -288,6 +288,7 @@ describe "Emails" do
|
||||
|
||||
expect(email).not_to have_body_text(proposal3.title)
|
||||
expect(email).to have_body_text(/#{account_path}/)
|
||||
expect(email).to have_body_text("Visit this proposal and unfollow it to stop receiving notifications.")
|
||||
|
||||
notification1.reload
|
||||
notification2.reload
|
||||
|
||||
@@ -157,6 +157,7 @@ describe "Proposals" do
|
||||
|
||||
expect(page).to have_content "1 support"
|
||||
expect(page).to have_content "You have already supported this proposal. Share it!"
|
||||
expect(page).to have_content "Following"
|
||||
expect(page).to have_current_path(management_proposal_path(proposal))
|
||||
end
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ describe "Proposal Notifications" do
|
||||
click_link "Message to users"
|
||||
end
|
||||
|
||||
click_link "Send message to proposal supporters"
|
||||
click_link "Send message to proposal followers"
|
||||
|
||||
fill_in "proposal_notification_title", with: "Thank you for supporting my proposal"
|
||||
fill_in "proposal_notification_body", with: "Please share it with "\
|
||||
@@ -29,7 +29,7 @@ describe "Proposal Notifications" do
|
||||
scenario "Send a notification (Active voter)" do
|
||||
proposal = create(:proposal)
|
||||
|
||||
create(:user, :level_two, votables: [proposal])
|
||||
create(:user, :level_two, votables: [proposal], followables: [proposal])
|
||||
create_proposal_notification(proposal)
|
||||
|
||||
expect(Notification.count).to eq(1)
|
||||
@@ -93,21 +93,6 @@ describe "Proposal Notifications" do
|
||||
expect(page).to have_content "We are almost there please share with your peoples!"
|
||||
end
|
||||
|
||||
scenario "Message about receivers (Voters)" 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 sent 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,
|
||||
anchor: "comments"))
|
||||
end
|
||||
|
||||
scenario "Message about receivers (Followers)" do
|
||||
author = create(:user)
|
||||
proposal = create(:proposal, author: author)
|
||||
@@ -133,7 +118,7 @@ describe "Proposal Notifications" do
|
||||
login_as(author)
|
||||
visit new_proposal_notification_path(proposal_id: proposal.id)
|
||||
|
||||
expect(page).to have_content "This message will be sent to 14 people and it will "\
|
||||
expect(page).to have_content "This message will be sent 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,
|
||||
anchor: "comments"))
|
||||
@@ -172,7 +157,7 @@ describe "Proposal Notifications" do
|
||||
click_link "Message to users"
|
||||
end
|
||||
|
||||
expect(page).to have_link "Send message to proposal supporters"
|
||||
expect(page).to have_link "Send message to proposal followers"
|
||||
end
|
||||
|
||||
scenario "Accessing form directly" do
|
||||
@@ -189,13 +174,13 @@ describe "Proposal Notifications" do
|
||||
end
|
||||
|
||||
context "In-app notifications from the proposal's author" do
|
||||
scenario "Voters should receive a notification", :js do
|
||||
scenario "Voters who are followed should receive a notification", :js do
|
||||
author = create(:user)
|
||||
proposal = create(:proposal, author: author)
|
||||
|
||||
user1 = create(:user, votables: [proposal])
|
||||
user2 = create(:user, votables: [proposal])
|
||||
user3 = create(:user)
|
||||
user1 = create(:user, votables: [proposal], followables: [proposal])
|
||||
user2 = create(:user, votables: [proposal], followables: [proposal])
|
||||
user3 = create(:user, votables: [proposal])
|
||||
|
||||
login_as(author)
|
||||
visit root_path
|
||||
@@ -297,7 +282,7 @@ describe "Proposal Notifications" do
|
||||
scenario "Proposal hidden", :js do
|
||||
author = create(:user)
|
||||
user = create(:user)
|
||||
proposal = create(:proposal, author: author, voters: [user])
|
||||
proposal = create(:proposal, author: author, voters: [user], followers: [user])
|
||||
|
||||
login_as(author)
|
||||
visit root_path
|
||||
|
||||
@@ -889,22 +889,14 @@ describe Proposal do
|
||||
end
|
||||
|
||||
describe "#user_to_notify" do
|
||||
it "returns voters and followers" do
|
||||
it "returns followers" do
|
||||
proposal = create(:proposal)
|
||||
voter = create(:user, :level_two, votables: [proposal])
|
||||
follower = create(:user, :level_two, followables: [proposal])
|
||||
|
||||
expect(proposal.users_to_notify).to eq([voter, follower])
|
||||
expect(proposal.users_to_notify).to eq([follower])
|
||||
end
|
||||
|
||||
it "returns voters and followers discarding duplicates" do
|
||||
proposal = create(:proposal)
|
||||
voter_and_follower = create(:user, :level_two, votables: [proposal], followables: [proposal])
|
||||
|
||||
expect(proposal.users_to_notify).to eq([voter_and_follower])
|
||||
end
|
||||
|
||||
it "returns voters and followers except the proposal author" do
|
||||
it "returns followers except the proposal author" do
|
||||
author = create(:user, :level_two)
|
||||
voter_and_follower = create(:user, :level_two)
|
||||
proposal = create(:proposal, author: author,
|
||||
|
||||
@@ -27,7 +27,7 @@ module Notifications
|
||||
click_link "Message to users"
|
||||
end
|
||||
|
||||
click_link "Send message to proposal supporters"
|
||||
click_link "Send message to proposal followers"
|
||||
|
||||
fill_in "proposal_notification_title", with: "Thanks for supporting proposal: #{proposal.title}"
|
||||
fill_in "proposal_notification_body", with: "Please share it with others! #{proposal.summary}"
|
||||
|
||||
Reference in New Issue
Block a user