Class: Decidim::Meetings::MeetingsController

Inherits:
ApplicationController show all
Includes:
FilterResource, Flaggable, FormFactory, Paginable
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 inherited from Components::BaseController

#current_component, #current_manifest, #current_participatory_space, #permission_class_chain, #permission_scope, #redirect_unless_feature_private, #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 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


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'decidim-meetings/app/controllers/decidim/meetings/meetings_controller.rb', line 22

def create
  enforce_permission_to :create, :meeting

  @form = meeting_form.from_params(params, current_component: 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


62
63
64
65
66
# File 'decidim-meetings/app/controllers/decidim/meetings/meetings_controller.rb', line 62

def edit
  enforce_permission_to :update, :meeting, meeting: meeting

  @form = meeting_form.from_model(meeting)
end

#indexObject


40
41
42
43
44
45
46
47
48
49
50
51
# File 'decidim-meetings/app/controllers/decidim/meetings/meetings_controller.rb', line 40

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

  @past_meetings = search_klass.new(search_params.merge(date: %w(past)))

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

#newObject


16
17
18
19
20
# File 'decidim-meetings/app/controllers/decidim/meetings/meetings_controller.rb', line 16

def new
  enforce_permission_to :create, :meeting

  @form = meeting_form.instance
end

#showObject

Raises:

  • (ActionController::RoutingError)

53
54
55
56
57
58
59
60
# File 'decidim-meetings/app/controllers/decidim/meetings/meetings_controller.rb', line 53

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

  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


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'decidim-meetings/app/controllers/decidim/meetings/meetings_controller.rb', line 68

def update
  enforce_permission_to :update, :meeting, meeting: meeting

  @form = meeting_form.from_params(params)

  UpdateMeeting.call(@form, current_user, 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