Class: Decidim::Debates::DebatesController

Inherits:
ApplicationController show all
Includes:
AttachmentsHelper, Orderable, FilterResource, Flaggable, FormFactory, Paginable
Defined in:
decidim-debates/app/controllers/decidim/debates/debates_controller.rb

Overview

Exposes the debate resource so users can view them

Constant Summary

Constants included from Paginable

Paginable::OPTIONS

Instance Method Summary collapse

Methods included from AttachmentsHelper

#attachment_title, #attachments_for, #attachments_tab_panel_items

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_url, #current_user_unread_data, #external_icon, #favicon, #icon, #legacy_favicon, #role, #root_url

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

#attachment?, #default_locale?

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

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

#closeObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'decidim-debates/app/controllers/decidim/debates/debates_controller.rb', line 71

def close
  enforce_permission_to(:close, :debate, debate:)

  @form = form(CloseDebateForm).from_params(params)

  CloseDebate.call(@form) do
    on(:ok) do |debate|
      flash[:notice] = I18n.t("debates.close.success", scope: "decidim.debates")
      redirect_back fallback_location: Decidim::ResourceLocatorPresenter.new(debate).path
    end

    on(:invalid) do
      flash[:alert] = I18n.t("debates.close.invalid", scope: "decidim.debates")
      redirect_back fallback_location: Decidim::ResourceLocatorPresenter.new(debate).path
    end
  end
end

#createObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'decidim-debates/app/controllers/decidim/debates/debates_controller.rb', line 25

def create
  enforce_permission_to :create, :debate

  @form = form(DebateForm).from_params(params)

  CreateDebate.call(@form) do
    on(:ok) do |debate|
      flash[:notice] = I18n.t("debates.create.success", scope: "decidim.debates")
      redirect_to Decidim::ResourceLocatorPresenter.new(debate).path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("debates.create.invalid", scope: "decidim.debates")
      render action: "new", status: :unprocessable_entity
    end
  end
end

#editObject



47
48
49
50
51
# File 'decidim-debates/app/controllers/decidim/debates/debates_controller.rb', line 47

def edit
  enforce_permission_to(:edit, :debate, debate:)

  @form = form(DebateForm).from_model(debate)
end

#newObject



19
20
21
22
23
# File 'decidim-debates/app/controllers/decidim/debates/debates_controller.rb', line 19

def new
  enforce_permission_to :create, :debate

  @form = form(DebateForm).instance
end

#showObject

Raises:

  • (ActionController::RoutingError)


43
44
45
# File 'decidim-debates/app/controllers/decidim/debates/debates_controller.rb', line 43

def show
  raise ActionController::RoutingError, "Not Found" if debate.blank?
end

#updateObject



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

def update
  enforce_permission_to(:edit, :debate, debate:)

  @form = form(DebateForm).from_params(params)

  UpdateDebate.call(@form, debate) do
    on(:ok) do |debate|
      flash[:notice] = I18n.t("debates.update.success", scope: "decidim.debates")
      redirect_to Decidim::ResourceLocatorPresenter.new(debate).path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("debates.update.invalid", scope: "decidim.debates")
      render :edit, status: :unprocessable_entity
    end
  end
end