diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index d1707a8a7..8aa9fd0e6 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -3,7 +3,7 @@ class ProposalsController < ApplicationController include FlagActions before_action :parse_tag_filter, only: :index - before_action :load_categories, only: [:index, :new, :edit, :map, :summary] + before_action :load_categories, only: [:index, :new, :create, :edit, :map, :summary] before_action :load_geozones, only: [:edit, :map, :summary] before_action :authenticate_user!, except: [:index, :show, :map, :summary] @@ -22,6 +22,16 @@ class ProposalsController < ApplicationController redirect_to proposal_path(@proposal), status: :moved_permanently if request.path != proposal_path(@proposal) end + def create + @proposal = Proposal.new(proposal_params.merge(author: current_user)) + + if @proposal.save + redirect_to share_proposal_path(@proposal), notice: I18n.t('flash.actions.create.proposal') + else + render :new + end + end + def index_customization discard_archived load_retired @@ -45,6 +55,12 @@ class ProposalsController < ApplicationController def retire_form end + def share + if Setting['proposal_improvement_url'].present? + @proposal_improvement_url = root_url + Setting['proposal_improvement_url'] + end + end + def vote_featured @proposal.register_vote(current_user, 'yes') set_featured_proposal_votes(@proposal) diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index c2b6cd6d7..2b2b913cc 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -4,7 +4,7 @@ module Abilities def initialize(user) can [:read, :map], Debate - can [:read, :map, :summary], Proposal + can [:read, :map, :summary, :share], Proposal can :read, Comment can :read, Poll can :read, Poll::Question diff --git a/app/views/proposals/share.html.erb b/app/views/proposals/share.html.erb new file mode 100644 index 000000000..d1538e524 --- /dev/null +++ b/app/views/proposals/share.html.erb @@ -0,0 +1,47 @@ +<% provide :title do %><%= @proposal.title %><% end %> +<% provide :social_media_meta_tags do %> +<%= render "shared/social_media_meta_tags", + social_url: proposal_url(@proposal), + social_title: @proposal.title, + social_description: @proposal.summary %> +<% end %> +<% content_for :canonical do %> + <%= render "shared/canonical", href: proposal_url(@proposal) %> +<% end %> + +<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @proposal_votes] do %> +
+
+
+ +

<%= t("proposals.proposal.created") %>

+ +

<%= @proposal.title %>

+

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

+ +

<%= t("proposals.proposal.share.guide").html_safe %>

+ + <%= render partial: 'shared/social_share', locals: { + title: @proposal.title, + url: proposal_url(@proposal) + } %> + +
+ + <% if @proposal_improvement_url.present? %> +

<%= t('proposals.proposal.improve_info', improve_info_link: link_to(t('proposals.proposal.improve_info_link'), @proposal_improvement_url)).html_safe %>

+ <% end %> + +

+ <%= link_to proposal_path(@proposal), class: 'proposal' do %> + <%= t("proposals.proposal.share.view_proposal") %> + <% end %> +

+ +
+
+
+<% end %> diff --git a/app/views/shared/_social_share.html.erb b/app/views/shared/_social_share.html.erb index c911d8e76..e32fa2db5 100644 --- a/app/views/shared/_social_share.html.erb +++ b/app/views/shared/_social_share.html.erb @@ -1,5 +1,7 @@ +<% if local_assigns[:share_title].present? %>

<%= share_title %>

+<% end %>
<%= social_share_button_tag("#{title} #{setting['twitter_hashtag']}") %>
Before it gets shared you'll be able to change the text as you like." + view_proposal: Not now, go to my proposal + improve_info: "You can also %{improve_info_link} about improving your campaign" + improve_info_link: see more information already_supported: You have already supported this proposal. Share it! comments: one: 1 comment diff --git a/config/locales/es.yml b/config/locales/es.yml index e0f2ba001..efc2da5fe 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -351,6 +351,12 @@ es: notice: retired: Propuesta retirada proposal: + created: "¡Has creado una nueva propuesta!" + share: + guide: "Ahora puedes compartirla en Twitter, Facebook, Google+, Telegram o Whatsapp (si utilizas un dispositivo móvil) para que la gente empieze a apoyarla.

Antes de que se publique el texto en las redes sociales podrás modificarlo a tu gusto" + view_proposal: "Ahora no, ver mi propuesta" + improve_info: "También puedes %{improve_info_link} de como mejorar tu campaña" + improve_info_link: ver más información already_supported: "¡Ya has apoyado esta propuesta, compártela!" comments: one: 1 Comentario diff --git a/config/locales/settings.en.yml b/config/locales/settings.en.yml index d76c64bf3..b7b7dbf71 100755 --- a/config/locales/settings.en.yml +++ b/config/locales/settings.en.yml @@ -44,3 +44,4 @@ en: meta_keywords: "Keywords (SEO)" verification_offices_url: Verification offices URL min_age_to_participate: Minimum age needed to participate + proposal_improvement_url: Proposal improvement info internal link diff --git a/config/locales/settings.es.yml b/config/locales/settings.es.yml index 94493651e..4fdce8766 100644 --- a/config/locales/settings.es.yml +++ b/config/locales/settings.es.yml @@ -44,3 +44,4 @@ es: meta_keywords: "Palabras clave (SEO)" verification_offices_url: URL oficinas verificación min_age_to_participate: Edad mínima para participar + proposal_improvement_url: Link a información para mejorar propuestas diff --git a/config/routes.rb b/config/routes.rb index ebd275353..b43f41ad5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -52,6 +52,7 @@ Rails.application.routes.draw do put :flag put :unflag get :retire_form + get :share patch :retire end collection do diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index baf137c2d..945059c8f 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -44,6 +44,7 @@ Setting.create(key: 'meta_description', value: 'Citizen Participation and Open G Setting.create(key: 'meta_keywords', value: 'citizen participation, open government') Setting.create(key: 'verification_offices_url', value: 'http://oficinas-atencion-ciudadano.url/') Setting.create(key: 'min_age_to_participate', value: '16') +Setting.create(key: 'proposal_improvement_url', value: nil) puts " ✅" print "Creating Geozones" diff --git a/db/seeds.rb b/db/seeds.rb index eb6bffcd8..4bcce8eca 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -103,3 +103,6 @@ Setting['mailer_from_address'] = 'noreply@consul.dev' # Verification settings Setting['verification_offices_url'] = 'http://oficinas-atencion-ciudadano.url/' Setting['min_age_to_participate'] = 16 + +# Proposal improvement url path ('more-information/proposal-improvement') +Setting['proposal_improvement_url'] = nil diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index 843b74bf5..fd10208a3 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -90,6 +90,7 @@ feature 'Proposals' do end context "Embedded video" do + scenario "Show YouTube video" do proposal = create(:proposal, video_url: "http://www.youtube.com/watch?v=a7UFm6ErMPU") visit proposal_path(proposal) @@ -138,6 +139,11 @@ feature 'Proposals' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' + expect(page).to have_content 'Help refugees' + expect(page).not_to have_content 'You can also see more information about improving your campaign' + + click_link 'Not now, go to my proposal' + expect(page).to have_content 'Help refugees' expect(page).to have_content '¿Would you like to give assistance to war refugees?' expect(page).to have_content 'In summary, what we want is...' @@ -150,6 +156,34 @@ feature 'Proposals' do expect(page).to have_content I18n.l(Proposal.last.created_at.to_date) end + scenario 'Create with proposal improvement info link' do + Setting['proposal_improvement_url'] = 'more-information/proposal-improvement' + author = create(:user) + login_as(author) + + visit new_proposal_path + fill_in 'proposal_title', with: 'Help refugees' + fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?' + fill_in 'proposal_summary', with: 'In summary, what we want is...' + fill_in 'proposal_description', with: 'This is very important because...' + fill_in 'proposal_external_url', with: 'http://rescue.org/refugees' + fill_in 'proposal_video_url', with: 'http://youtube.com' + fill_in 'proposal_responsible_name', with: 'Isabel Garcia' + fill_in 'proposal_tag_list', with: 'Refugees, Solidarity' + check 'proposal_terms_of_service' + + click_button 'Create proposal' + + expect(page).to have_content 'Proposal created successfully.' + expect(page).to have_content 'You can also see more information about improving your campaign' + + click_link 'Not now, go to my proposal' + + expect(page).to have_content 'Help refugees' + + Setting['proposal_improvement_url'] = nil + end + scenario 'Create with invisible_captcha honeypot field' do author = create(:user) login_as(author) @@ -210,6 +244,9 @@ feature 'Proposals' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' + + click_link 'Not now, go to my proposal' + expect(Proposal.last.responsible_name).to eq('Isabel Garcia') end @@ -228,8 +265,11 @@ feature 'Proposals' do check 'proposal_terms_of_service' click_button 'Create proposal' - expect(page).to have_content 'Proposal created successfully.' + + click_link 'Not now, go to my proposal' + + expect(Proposal.last.responsible_name).to eq(author.document_number) end scenario 'Errors on create' do @@ -238,6 +278,7 @@ feature 'Proposals' do visit new_proposal_path click_button 'Create proposal' + expect(page).to have_content error_message end @@ -257,6 +298,9 @@ feature 'Proposals' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' + + click_link 'Not now, go to my proposal' + expect(page).to have_content 'Testing an attack' expect(page.html).to include '

This is alert("an attack");

' expect(page.html).to_not include '' @@ -278,6 +322,9 @@ feature 'Proposals' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' + + click_link 'Not now, go to my proposal' + expect(page).to have_content 'Testing auto link' expect(page).to have_link('www.example.org', href: 'http://www.example.org') end @@ -297,6 +344,9 @@ feature 'Proposals' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' + + click_link 'Not now, go to my proposal' + expect(page).to have_content 'Testing auto link' expect(page).to have_link('http://example.org', href: 'http://example.org') expect(page).not_to have_link('click me') @@ -329,6 +379,9 @@ feature 'Proposals' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' + + click_link 'Not now, go to my proposal' + within "#geozone" do expect(page).to have_content 'All city' end @@ -355,6 +408,9 @@ feature 'Proposals' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' + + click_link 'Not now, go to my proposal' + within "#geozone" do expect(page).to have_content 'California' end @@ -1437,4 +1493,4 @@ feature 'Successful proposals' do end end -end \ No newline at end of file +end diff --git a/spec/features/tags/proposals_spec.rb b/spec/features/tags/proposals_spec.rb index 9d956fae9..dbab6a95f 100644 --- a/spec/features/tags/proposals_spec.rb +++ b/spec/features/tags/proposals_spec.rb @@ -80,6 +80,9 @@ feature 'Tags' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' + + click_link 'Not now, go to my proposal' + expect(page).to have_content 'Economía' expect(page).to have_content 'Hacienda' end @@ -107,6 +110,8 @@ feature 'Tags' do expect(page).to have_content 'Proposal created successfully.' + click_link 'Not now, go to my proposal' + within "#tags_proposal_#{Proposal.last.id}" do expect(page).to have_content 'Education' expect(page).to_not have_content 'Health' @@ -149,6 +154,9 @@ feature 'Tags' do click_button 'Create proposal' expect(page).to have_content 'Proposal created successfully.' + + click_link 'Not now, go to my proposal' + expect(page).to have_content 'user_id1' expect(page).to have_content 'a3' expect(page).to have_content 'scriptalert("hey");script' @@ -291,4 +299,4 @@ feature 'Tags' do expect(page).to_not have_content proposal3.title end end -end \ No newline at end of file +end