Class: Decidim::Meetings::MeetingsController

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

Overview

Exposes the meeting resource so users can view them

Instance Method Summary collapse

Instance Method Details

#createObject



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

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



68
69
70
71
72
# File 'app/controllers/decidim/meetings/meetings_controller.rb', line 68

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

  @form = meeting_form.from_model(meeting)
end

#indexObject



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

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



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

def new
  enforce_permission_to :create, :meeting

  @form = meeting_form.instance
end

#showObject

Raises:

  • (ActionController::RoutingError)


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

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



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/decidim/meetings/meetings_controller.rb', line 74

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



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/controllers/decidim/meetings/meetings_controller.rb', line 92

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