Class: Decidim::Proposals::CollaborativeDraftsController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper, FilterResource, Flaggable, FormFactory, IconHelper, Decidim::Paginable, CollaborativeOrderable
Defined in:
decidim-proposals/app/controllers/decidim/proposals/collaborative_drafts_controller.rb

Overview

Exposes Collaborative Drafts resource so users can view and create them.

Constant Summary

Constants included from Decidim::Paginable

Decidim::Paginable::OPTIONS

Constants included from IconHelper

IconHelper::DEFAULT_RESOURCE_TYPE_ICONS

Constants included from AmendmentsHelper

AmendmentsHelper::TOTAL_STEPS

Instance Method Summary collapse

Methods included from 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_user_unread_data, #extended_navigation_bar, #external_icon, #favicon, #icon, #legacy_favicon, #organization_colors, #role

Methods included from TooltipHelper

#with_tooltip

Methods included from ModalHelper

#decidim_modal

Methods included from ApplicationHelper

#cell, #edit_link, #extra_admin_link, #html_truncate, #present, #prevent_timeout_seconds, #resolve_presenter_class, #step_cta_url

Methods included from CacheHelper

#cache

Methods included from AmendmentsHelper

#accept_and_reject_buttons_for, #action_button_card_for, #allowed_to_accept_and_reject?, #allowed_to_promote?, #amend_button_for, #amendments_enabled?, #amendments_form_field_for, #amendments_form_fields_label, #amendments_form_fields_value, #can_participate_in_private_space?, #can_react_to_emendation?, #current_step, #emendation_actions_for, #emendation_announcement_for, #promote_button_for, #render_emendation_body, #total_steps, #wizard_aside_back_url, #wizard_header_title

Methods included from RichTextEditorHelper

included, #text_editor_for

Methods included from ContextualHelpHelper

#floating_help

Methods included from ScopesHelper

#has_visible_scopes?, #scope_name_for_picker, #scopes_picker_field, #scopes_picker_filter, #scopes_select_field, #scopes_select_tag

Methods included from TranslatableAttributes

#default_locale?

Methods included from DecidimFormHelper

#areas_for_select, #base_error_messages, #decidim_form_for, #decidim_form_slug_url, #editor_field_tag, #form_field_has_error?, #form_required_explanation, #name_with_locale, #ordered_scopes_descendants, #ordered_scopes_descendants_for_select, #scopes_picker_field_tag, #tab_element_class_for, #translated_field_tag

Methods included from OmniauthHelper

#normalize_provider_name, #oauth_icon, #provider_name

Methods inherited from ApplicationController

#proposal_limit, #proposal_limit_reached?, #proposals

Methods inherited from Components::BaseController

#current_component, #current_manifest, #current_participatory_space, #permission_class_chain, #permission_scope, #redirect_unless_feature_private, #set_component_breadcrumb_item, #share_token

Methods included from RegistersPermissions

register_permissions

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

#createObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'decidim-proposals/app/controllers/decidim/proposals/collaborative_drafts_controller.rb', line 53

def create
  enforce_permission_to :create, :collaborative_draft
  @form = form(CollaborativeDraftForm).from_params(params)

  CreateCollaborativeDraft.call(@form, current_user) do
    on(:ok) do |collaborative_draft|
      flash[:notice] = I18n.t("proposals.collaborative_drafts.create.success", scope: "decidim")

      redirect_to Decidim::ResourceLocatorPresenter.new(collaborative_draft).path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("proposals.collaborative_drafts.create.error", scope: "decidim")
      render :new
    end
  end
end

#editObject



71
72
73
74
75
76
# File 'decidim-proposals/app/controllers/decidim/proposals/collaborative_drafts_controller.rb', line 71

def edit
  enforce_permission_to :edit, :collaborative_draft, collaborative_draft: @collaborative_draft

  @form = form(CollaborativeDraftForm).from_model(@collaborative_draft)
  @form.attachment = form(AttachmentForm).from_model(@collaborative_draft.attachments.first)
end

#indexObject



26
27
28
29
30
31
32
33
34
35
# File 'decidim-proposals/app/controllers/decidim/proposals/collaborative_drafts_controller.rb', line 26

def index
  @collaborative_drafts = search
                          .result
                          .not_hidden
                          .includes(:category)
                          .includes(:scope)

  @collaborative_drafts = reorder(@collaborative_drafts)
  @collaborative_drafts = paginate(@collaborative_drafts)
end

#newObject



45
46
47
48
49
50
51
# File 'decidim-proposals/app/controllers/decidim/proposals/collaborative_drafts_controller.rb', line 45

def new
  enforce_permission_to :create, :collaborative_draft

  @form = form(CollaborativeDraftForm).from_params(
    attachment: form(AttachmentForm).from_params({})
  )
end

#publishObject



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'decidim-proposals/app/controllers/decidim/proposals/collaborative_drafts_controller.rb', line 108

def publish
  PublishCollaborativeDraft.call(@collaborative_draft, current_user) do
    on(:ok) do |proposal|
      flash[:notice] = I18n.t("publish.success", scope: "decidim.proposals.collaborative_drafts.collaborative_draft")
      redirect_to Decidim::ResourceLocatorPresenter.new(proposal).path
    end

    on(:invalid) do
      flash.now[:alert] = t("publish.error", scope: "decidim.proposals.collaborative_drafts.collaborative_draft")
      redirect_to Decidim::ResourceLocatorPresenter.new(@collaborative_draft).path
    end
  end
end

#showObject

Raises:

  • (ActionController::RoutingError)


37
38
39
40
41
42
43
# File 'decidim-proposals/app/controllers/decidim/proposals/collaborative_drafts_controller.rb', line 37

def show
  raise ActionController::RoutingError, "Not Found" unless retrieve_collaborative_draft

  @request_access_form = form(RequestAccessToCollaborativeDraftForm).from_params({})
  @accept_request_form = form(AcceptAccessToCollaborativeDraftForm).from_params({})
  @reject_request_form = form(RejectAccessToCollaborativeDraftForm).from_params({})
end

#updateObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'decidim-proposals/app/controllers/decidim/proposals/collaborative_drafts_controller.rb', line 78

def update
  enforce_permission_to :edit, :collaborative_draft, collaborative_draft: @collaborative_draft

  @form = form(CollaborativeDraftForm).from_params(params)
  UpdateCollaborativeDraft.call(@form, current_user, @collaborative_draft) do
    on(:ok) do |collaborative_draft|
      flash[:notice] = I18n.t("proposals.collaborative_drafts.update.success", scope: "decidim")
      redirect_to Decidim::ResourceLocatorPresenter.new(collaborative_draft).path
    end

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

#withdrawObject



95
96
97
98
99
100
101
102
103
104
105
106
# File 'decidim-proposals/app/controllers/decidim/proposals/collaborative_drafts_controller.rb', line 95

def withdraw
  WithdrawCollaborativeDraft.call(@collaborative_draft, current_user) do
    on(:ok) do
      flash[:notice] = t("withdraw.success", scope: "decidim.proposals.collaborative_drafts.collaborative_draft")
    end

    on(:invalid) do
      flash.now[:alert] = t("withdraw.error", scope: "decidim.proposals.collaborative_drafts.collaborative_draft")
    end
  end
  redirect_to Decidim::ResourceLocatorPresenter.new(@collaborative_draft).path
end