Merge pull request #1906 from consul/1856-legislation_processes_proposals_phase

[WIP] Legislation Process Proposals
This commit is contained in:
Alberto García
2017-10-27 12:41:09 +02:00
committed by GitHub
62 changed files with 1227 additions and 31 deletions

View File

@@ -19,8 +19,10 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll
def update
if @process.update(process_params)
set_tag_list
link = legislation_process_path(@process).html_safe
redirect_to edit_admin_legislation_process_path(@process), notice: t('admin.legislation.processes.update.notice', link: link)
redirect_to :back, notice: t('admin.legislation.processes.update.notice', link: link)
else
flash.now[:error] = t('admin.legislation.processes.update.error')
render :edit
@@ -47,12 +49,22 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll
:draft_publication_date,
:allegations_start_date,
:allegations_end_date,
:proposals_phase_start_date,
:proposals_phase_end_date,
:result_publication_date,
:debate_phase_enabled,
:allegations_phase_enabled,
:proposals_phase_enabled,
:draft_publication_enabled,
:result_publication_enabled,
:published
:published,
:proposals_description,
:custom_list
)
end
def set_tag_list
@process.set_tag_list_on(:customs, process_params[:custom_list])
@process.save
end
end

View File

@@ -0,0 +1,7 @@
class Admin::Legislation::ProposalsController < Admin::Legislation::BaseController
load_and_authorize_resource :process, class: "Legislation::Process"
load_and_authorize_resource :proposal, class: "Legislation::Proposal", through: :process
def index
end
end

View File

@@ -2,4 +2,8 @@ class Legislation::BaseController < ApplicationController
include FeatureFlags
feature_flag :legislation
def set_legislation_proposal_votes(proposals)
@legislation_proposal_votes = current_user ? current_user.legislation_proposal_votes(proposals) : {}
end
end

View File

@@ -14,6 +14,8 @@ class Legislation::ProcessesController < Legislation::BaseController
redirect_to legislation_process_draft_version_path(@process, draft_version)
elsif @process.debate_phase.enabled?
redirect_to debate_legislation_process_path(@process)
elsif @process.proposals_phase.enabled?
redirect_to proposals_legislation_process_path(@process)
else
redirect_to allegations_legislation_process_path(@process)
end
@@ -81,6 +83,18 @@ class Legislation::ProcessesController < Legislation::BaseController
end
end
def proposals
set_process
@phase = :proposals_phase
if @process.proposals_phase.started?
set_legislation_proposal_votes(@process.proposals)
render :proposals
else
render :phase_not_open
end
end
private
def member_method?

View File

@@ -0,0 +1,70 @@
class Legislation::ProposalsController < Legislation::BaseController
include CommentableActions
include FlagActions
load_and_authorize_resource :process, class: "Legislation::Process"
load_and_authorize_resource :proposal, class: "Legislation::Proposal", through: :process
before_action :parse_tag_filter, only: :index
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]
invisible_captcha only: [:create, :update], honeypot: :subtitle
has_orders %w{confidence_score created_at}, only: :index
has_orders %w{most_voted newest oldest}, only: :show
helper_method :resource_model, :resource_name
respond_to :html, :js
def show
super
set_legislation_proposal_votes(@process.proposals)
@document = Document.new(documentable: @proposal)
redirect_to legislation_process_proposal_path(params[:process_id], @proposal),
status: :moved_permanently if request.path != legislation_process_proposal_path(params[:process_id], @proposal)
end
def create
@proposal = Legislation::Proposal.new(proposal_params.merge(author: current_user))
if @proposal.save
redirect_to legislation_process_proposal_path(params[:process_id], @proposal), notice: I18n.t('flash.actions.create.proposal')
else
render :new
end
end
def index_customization
load_successful_proposals
load_featured unless @proposal_successful_exists
end
def vote
@proposal.register_vote(current_user, params[:value])
set_legislation_proposal_votes(@proposal)
end
private
def proposal_params
params.require(:legislation_proposal).permit(:legislation_process_id, :title,
:question, :summary, :description, :video_url, :tag_list,
:terms_of_service, :geozone_id,
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id] )
end
def resource_model
Legislation::Proposal
end
def resource_name
'proposal'
end
def load_successful_proposals
@proposal_successful_exists = Legislation::Proposal.successful.exists?
end
end