Class: Decidim::Initiatives::InitiativesController

Inherits:
ApplicationController show all
Includes:
FilterResource, FormFactory, Decidim::IconHelper, InitiativeSlug, NeedsInitiative, Orderable, SingleInitiativeType, TypeSelectorOptions, Paginable, ParticipatorySpaceContext
Defined in:
decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb

Overview

This controller contains the logic regarding participants initiatives

Constant Summary

Constants included from Paginable

Paginable::OPTIONS

Instance Method Summary collapse

Methods included from Decidim::IconHelper

#component_icon, #manifest_icon, #resource_icon, #resource_type_icon, #resource_type_icon_key, #text_with_resource_icon

Methods included from LayoutHelper

#_icon_classes, #apple_favicon, #application_path, #current_url, #current_user_unread_data, #extended_navigation_bar, #external_icon, #favicon, #icon, #legacy_favicon, #role

Methods included from TooltipHelper

#with_tooltip

Methods included from ModalHelper

#decidim_drawer, #decidim_modal

Methods included from OrganizationHelper

#current_organization_name, #organization_colors, #organization_description_label, #organization_name

Methods included from TranslatableAttributes

#default_locale?

Methods included from TranslationsHelper

empty_translatable, ensure_translatable, multi_translation, translated_in_current_locale?

Methods included from InitiativeSlug

#id_from_slug, #slug_from_id

Methods inherited from ApplicationController

#permission_class_chain, #permission_scope, #permissions_context

Methods included from RegistersPermissions

register_permissions

Methods inherited from ApplicationController

#store_share_token

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#editObject

GET /initiatives/:slug/edit



76
77
78
79
80
81
82
83
84
85
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb', line 76

def edit
  enforce_permission_to :edit, :initiative, initiative: current_initiative
  form_attachment_model = form(AttachmentForm).from_model(current_initiative.attachments.first)
  @form = form(Decidim::Initiatives::InitiativeForm)
          .from_model(
            current_initiative,
            initiative: current_initiative
          )
  @form.attachment = form_attachment_model
end

#indexObject

GET /initiatives



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb', line 37

def index
  enforce_permission_to :list, :initiative
  return unless search.result.blank? && params.dig("filter", "with_any_state") != %w(closed)

  @closed_initiatives ||= search_with(filter_params.merge(with_any_state: %w(closed)))

  if @closed_initiatives.result.present?
    params[:filter] ||= {}
    params[:filter][:with_any_state] = %w(closed)
    @forced_closed_initiatives = true

    @search = @closed_initiatives
  end
end


109
110
111
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb', line 109

def print
  enforce_permission_to :print, :initiative, initiative: current_initiative
end

#send_to_technical_validationObject

GET /initiatives/:id/send_to_technical_validation



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb', line 60

def send_to_technical_validation
  enforce_permission_to :send_to_technical_validation, :initiative, initiative: current_initiative

  SendInitiativeToTechnicalValidation.call(current_initiative, current_user) do
    on(:ok) do
      redirect_to EngineRouter.main_proxy(current_initiative).initiatives_path(initiative_slug: nil), flash: {
        notice: I18n.t(
          "success",
          scope: "decidim.initiatives.admin.initiatives.edit"
        )
      }
    end
  end
end

#showObject

GET /initiatives/:id



53
54
55
56
57
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb', line 53

def show
  enforce_permission_to :read, :initiative, initiative: current_initiative

  render layout: "decidim/initiative_head"
end

#updateObject

PUT /initiatives/:id



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb', line 88

def update
  enforce_permission_to :update, :initiative, initiative: current_initiative

  params[:id] = params[:slug]
  params[:type_id] = current_initiative.type&.id
  @form = form(Decidim::Initiatives::InitiativeForm)
          .from_params(params, initiative_type: current_initiative.type, initiative: current_initiative)

  UpdateInitiative.call(current_initiative, @form) do
    on(:ok) do |initiative|
      flash[:notice] = I18n.t("success", scope: "decidim.initiatives.update")
      redirect_to initiative_path(initiative)
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("error", scope: "decidim.initiatives.update")
      render :edit, layout: "decidim/initiative"
    end
  end
end