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.show.code") %> + <%= @proposal.code %> +
+ +<%= t("proposals.proposal.share.guide").html_safe %>
+ + <%= render partial: 'shared/social_share', locals: { + title: @proposal.title, + url: proposal_url(@proposal) + } %> + +<%= 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 %> +
+ +