diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 434f4f97b..efe8bf9f0 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -1,9 +1,9 @@ class DashboardController < Dashboard::BaseController helper_method :dashboard_action, :active_resources, :course before_action :set_done_and_pending_actions, only: [:recommended_actions, :progress] + before_action :authorize_dashboard, only: [:show, :progress, :community, :recommended_actions, :messages] def show - authorize! :dashboard, proposal end def publish @@ -14,15 +14,15 @@ class DashboardController < Dashboard::BaseController end def progress - authorize! :dashboard, proposal end def community - authorize! :dashboard, proposal end def recommended_actions - authorize! :dashboard, proposal + end + + def messages end private @@ -42,4 +42,8 @@ class DashboardController < Dashboard::BaseController @done_actions = proposed_actions.joins(:proposals).where("proposals.id = ?", proposal.id) @pending_actions = proposed_actions - @done_actions end + + def authorize_dashboard + authorize! :dashboard, proposal + end end diff --git a/app/helpers/proposals_dashboard_helper.rb b/app/helpers/proposals_dashboard_helper.rb index 619308c01..b7abee430 100644 --- a/app/helpers/proposals_dashboard_helper.rb +++ b/app/helpers/proposals_dashboard_helper.rb @@ -7,6 +7,10 @@ module ProposalsDashboardHelper controller_name == "dashboard" && action_name == "community" end + def messages_menu_active? + controller_name == "dashboard" && action_name == "messages" + end + def progress_menu_active? is_proposed_action_request? || (controller_name == "dashboard" && action_name == "progress") end diff --git a/app/views/dashboard/_menu.html.erb b/app/views/dashboard/_menu.html.erb index f38e492ba..2948f35eb 100644 --- a/app/views/dashboard/_menu.html.erb +++ b/app/views/dashboard/_menu.html.erb @@ -35,9 +35,9 @@ diff --git a/app/views/dashboard/messages.html.erb b/app/views/dashboard/messages.html.erb new file mode 100644 index 000000000..7c17d9854 --- /dev/null +++ b/app/views/dashboard/messages.html.erb @@ -0,0 +1,7 @@ +<% content_for :action_title, t("dashboard.menu.messages") %> + +<%= link_to t("dashboard.messages.send_notification"), + new_proposal_notification_path(proposal_id: proposal.id), class: "button" %> + +<%= link_to t("dashboard.messages.previous_notifications"), + proposal_path(proposal, anchor: "tab-notifications"), class: "button hollow" %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index cae636d1e..c2db67ec0 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -483,6 +483,7 @@ en: mailing: E-mail poster: Poster recommended_actions: Recommended actions + messages: Message to users form: request: Request create_request: @@ -544,6 +545,9 @@ en: debates: Debates comments: Comments latest_comments: Latest messages + messages: + send_notification: Send message to proposal supporters + previous_notifications: See previous notifications polls: index: title: Polls diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index f6a387cb2..8530ade01 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -483,6 +483,7 @@ es: mailing: Correo electrónico poster: Póster recommended_actions: Acciones recomendadas + messages: Mensajes a usuarios form: request: Solicitar create_request: @@ -544,6 +545,9 @@ es: debates: Debates comments: Comentarios latest_comments: Últimos mensajes + messages: + send_notification: Enviar mensaje a los que han apoyado la propuesta + previous_notifications: Ver notificaciones anteriores polls: index: title: Encuestas diff --git a/config/routes/proposal.rb b/config/routes/proposal.rb index 6ead4dff3..131c1f402 100644 --- a/config/routes/proposal.rb +++ b/config/routes/proposal.rb @@ -5,6 +5,7 @@ resources :proposals do get :progress get :community get :recommended_actions + get :messages end resources :resources, only: [:index], controller: "dashboard/resources" diff --git a/spec/features/dashboard/dashboard_spec.rb b/spec/features/dashboard/dashboard_spec.rb index 34fdd7e38..f7b653ebe 100644 --- a/spec/features/dashboard/dashboard_spec.rb +++ b/spec/features/dashboard/dashboard_spec.rb @@ -358,6 +358,37 @@ describe "Proposal's dashboard" do expect(page).to have_content("Done") end + scenario "Dashboard has a link to messages" do + expect(page).to have_link("Message to users") + + within("#side_menu") do + click_link "Message to users" + end + + expect(page).to have_link("Send message to proposal supporters") + 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") + + fill_in "Title", with: "Thank you for supporting my proposal" + fill_in "Message", with: "Please share it with others!" + 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" + expect(page).to have_content "Please share it with others!" + end + + scenario "Dashboard has a link to see previous notifications" do + visit messages_proposal_dashboard_path(proposal) + + expect(page).to have_link("See previous notifications", href: proposal_path(proposal, + anchor: "tab-notifications")) + end + scenario "On recommended actions section display from the fourth proposed actions when click see_proposed_actions_link", js: true do create_list(:dashboard_action, 4, :proposed_action, :active) diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb index 6b12286f3..b277d8506 100644 --- a/spec/features/proposal_notifications_spec.rb +++ b/spec/features/proposal_notifications_spec.rb @@ -4,15 +4,19 @@ describe "Proposal Notifications" do scenario "Send a notification" do author = create(:user) - proposal = create(:proposal, author: author) + create(:proposal, author: author) login_as(author) visit root_path click_link "My content" - click_link proposal.title - click_link "Access the community" - click_link "Send message to the community" + click_link "Dashboard" + + within("#side_menu") do + click_link "Message to users" + end + + click_link "Send message to proposal supporters" fill_in "proposal_notification_title", with: "Thank you for supporting my proposal" fill_in "proposal_notification_body", with: "Please share it with "\ @@ -178,9 +182,19 @@ describe "Proposal Notifications" do proposal = create(:proposal, author: author) login_as(author) - visit community_path(proposal.community) + visit root_path - expect(page).to have_link "Send message to the community" + click_link "My content" + + within("#proposal_#{proposal.id}") do + click_link "Dashboard" + end + + within("#side_menu") do + click_link "Message to users" + end + + expect(page).to have_link "Send message to proposal supporters" end scenario "Accessing form directly" do diff --git a/spec/support/common_actions/notifications.rb b/spec/support/common_actions/notifications.rb index 2d10fab21..f014be220 100644 --- a/spec/support/common_actions/notifications.rb +++ b/spec/support/common_actions/notifications.rb @@ -20,11 +20,14 @@ module Notifications click_link "My content" within("#proposal_#{proposal.id}") do - click_link proposal.title + click_link "Dashboard" end - click_link "Access the community" - click_link "Send message to the community" + within("#side_menu") do + click_link "Message to users" + end + + click_link "Send message to proposal supporters" 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}"