Class: Decidim::Meetings::MeetingsController

Inherits:
ApplicationController show all
Includes:
AttachmentsHelper, FilterResource, Flaggable, FormFactory, ComponentFilterable, Paginable, SanitizeHelper, Withdrawable
Defined in:
decidim-meetings/app/controllers/decidim/meetings/meetings_controller.rb

Overview

Exposes the meeting resource so users can view them

Constant Summary

Constants included from Paginable

Paginable::OPTIONS

Instance Method Summary collapse

Methods included from SanitizeHelper

#decidim_escape_translated, #decidim_html_escape, #decidim_rich_text, #decidim_sanitize, #decidim_sanitize_admin, #decidim_sanitize_editor, #decidim_sanitize_editor_admin, #decidim_sanitize_newsletter, #decidim_sanitize_translated, #decidim_url_escape, included

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, #extended_navigation_bar, #external_icon, #favicon, #icon, #legacy_favicon, #role

Methods included from TooltipHelper

#with_tooltip

Methods included from Decidim::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 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

#createObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'decidim-meetings/app/controllers/decidim/meetings/meetings_controller.rb', line 29

def create
  enforce_permission_to :create, :meeting

  @form = meeting_form.from_params(params, current_component:)

  CreateMeeting.call(@form) do
    on(:ok) do |meeting|
      flash[:notice] = I18n.t("meetings.create.success", scope: "decidim.meetings")
      redirect_to meeting_path(meeting)
    end

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

#editObject



71
72
73
74
75
# File 'decidim-meetings/app/controllers/decidim/meetings/meetings_controller.rb', line 71

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

  @form = meeting_form.from_model(meeting)
end

#indexObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'decidim-meetings/app/controllers/decidim/meetings/meetings_controller.rb', line 47

def index
  return unless search.result.blank? && params.dig("filter", "date") != %w(past)

  @past_meetings ||= search_with(filter_params.merge(with_any_date: %w(past)))

  if @past_meetings.result.present?
    params[:filter] ||= {}
    params[:filter][:with_any_date] = %w(past)
    @forced_past_meetings = true
    @search = @past_meetings
  end
end

#newObject



23
24
25
26
27
# File 'decidim-meetings/app/controllers/decidim/meetings/meetings_controller.rb', line 23

def new
  enforce_permission_to :create, :meeting

  @form = meeting_form.instance
end

#showObject

Raises:

  • (ActionController::RoutingError)


60
61
62
63
64
65
66
67
68
69
# File 'decidim-meetings/app/controllers/decidim/meetings/meetings_controller.rb', line 60

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

  maybe_show_redirect_notice!

  return if meeting.current_user_can_visit_meeting?(current_user)

  flash[:alert] = I18n.t("meeting.not_allowed", scope: "decidim.meetings")
  redirect_to(ResourceLocatorPresenter.new(meeting).index)
end

#updateObject



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

def update
  enforce_permission_to(:update, :meeting, meeting:)

  @form = meeting_form.from_params(params)

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

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

#withdrawObject



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

def withdraw
  enforce_permission_to(:withdraw, :meeting, meeting:)

  WithdrawMeeting.call(@meeting, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("meetings.withdraw.success", scope: "decidim")
      redirect_to Decidim::ResourceLocatorPresenter.new(@meeting).path
    end
    on(:invalid) do
      flash[:alert] = I18n.t("meetings.withdraw.error", scope: "decidim")
      redirect_to Decidim::ResourceLocatorPresenter.new(@meeting).path
    end
  end
end