From ea7617900297ee16b10f77c5fb8c1c2434060c3c Mon Sep 17 00:00:00 2001 From: rogelio-o Date: Sat, 12 Jan 2019 17:42:55 +0100 Subject: [PATCH] Solves #3153. It refactors images attributes. --- app/controllers/admin/milestones_controller.rb | 2 +- app/controllers/admin/poll/polls_controller.rb | 2 +- app/controllers/admin/widget/cards_controller.rb | 3 +-- app/controllers/budgets/investments_controller.rb | 3 ++- app/controllers/legislation/proposals_controller.rb | 3 ++- app/controllers/proposals_controller.rb | 3 ++- app/helpers/images_helper.rb | 4 ++++ 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/milestones_controller.rb b/app/controllers/admin/milestones_controller.rb index 13a277957..57c0eead9 100644 --- a/app/controllers/admin/milestones_controller.rb +++ b/app/controllers/admin/milestones_controller.rb @@ -1,5 +1,6 @@ class Admin::MilestonesController < Admin::BaseController include Translatable + include ImagesHelper before_action :load_milestoneable, only: [:index, :new, :create, :edit, :update, :destroy] before_action :load_milestone, only: [:edit, :update, :destroy] @@ -41,7 +42,6 @@ class Admin::MilestonesController < Admin::BaseController private def milestone_params - image_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] documents_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] attributes = [:publication_date, :status_id, translation_params(Milestone), diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 863f8769c..6aa70b511 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -1,5 +1,6 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController include Translatable + include ImagesHelper load_and_authorize_resource before_action :load_search, only: [:search_booths, :search_officers] @@ -60,7 +61,6 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController end def poll_params - image_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :results_enabled, :stats_enabled, geozone_ids: [], image_attributes: image_attributes] diff --git a/app/controllers/admin/widget/cards_controller.rb b/app/controllers/admin/widget/cards_controller.rb index 519d5ff94..796e183e1 100644 --- a/app/controllers/admin/widget/cards_controller.rb +++ b/app/controllers/admin/widget/cards_controller.rb @@ -1,5 +1,6 @@ class Admin::Widget::CardsController < Admin::BaseController include Translatable + include ImagesHelper def new @card = ::Widget::Card.new(header: header_card?) @@ -40,8 +41,6 @@ class Admin::Widget::CardsController < Admin::BaseController private def card_params - image_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] - params.require(:widget_card).permit( :link_url, :button_text, :button_url, :alignment, :header, translation_params(Widget::Card), diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index 3d86a2652..fa908a65b 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -4,6 +4,7 @@ module Budgets include FeatureFlags include CommentableActions include FlagActions + include ImagesHelper before_action :authenticate_user!, except: [:index, :show, :json_data] @@ -136,7 +137,7 @@ module Budgets params.require(:budget_investment) .permit(:title, :description, :heading_id, :tag_list, :organization_name, :location, :terms_of_service, :skip_map, - image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], + image_attributes: image_attributes, documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], map_location_attributes: [:latitude, :longitude, :zoom]) end diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb index eb5ce4e2f..755ffa67e 100644 --- a/app/controllers/legislation/proposals_controller.rb +++ b/app/controllers/legislation/proposals_controller.rb @@ -1,6 +1,7 @@ class Legislation::ProposalsController < Legislation::BaseController include CommentableActions include FlagActions + include ImagesHelper before_action :parse_tag_filter, only: :index before_action :load_categories, only: [:index, :new, :create, :edit, :map, :summary] @@ -54,7 +55,7 @@ class Legislation::ProposalsController < Legislation::BaseController params.require(:legislation_proposal).permit(:legislation_process_id, :title, :question, :summary, :description, :video_url, :tag_list, :terms_of_service, :geozone_id, - image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], + image_attributes: image_attributes, documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id]) end diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index fe0599eab..7d152e890 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -2,6 +2,7 @@ class ProposalsController < ApplicationController include FeatureFlags include CommentableActions include FlagActions + include ImagesHelper before_action :parse_tag_filter, only: :index before_action :load_categories, only: [:index, :new, :create, :edit, :map, :summary] @@ -92,7 +93,7 @@ class ProposalsController < ApplicationController def proposal_params params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url, :responsible_name, :tag_list, :terms_of_service, :geozone_id, :skip_map, - image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], + image_attributes: image_attributes, documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], map_location_attributes: [:latitude, :longitude, :zoom]) end diff --git a/app/helpers/images_helper.rb b/app/helpers/images_helper.rb index 208ccf5ab..cf3cdfaab 100644 --- a/app/helpers/images_helper.rb +++ b/app/helpers/images_helper.rb @@ -76,4 +76,8 @@ module ImagesHelper "direct_upload[resource_relation]": "image") end + def image_attributes + [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] + end + end