Class: Decidim::Posts::MeetingsController

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

Overview

Exposes the meeting resource so users can view them

Instance Method Summary collapse

Methods inherited from ApplicationController

#user_has_no_permission_path

Instance Method Details

#createObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/decidim/posts/meetings_controller.rb', line 28

def create
  enforce_permission_to :create, :meeting

  copy_location_to_address

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

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

    on(:invalid) do
      error_messages = @form.errors.full_messages.join(", ")
      general_error_message = I18n.t("meetings.create.invalid", scope: "decidim.meetings")
      flash.now[:alert] = [general_error_message, error_messages].join(": ")

      set_meeting_context

      render template: "decidim/posts/meetings/new", status: :unprocessable_entity
      #render template: "decidim/posts/posts/index", layout: "decidim/application", status: :unprocessable_entity
      #redirect_to posts_path
    end
  end
end

#editObject



55
56
57
58
59
60
# File 'app/controllers/decidim/posts/meetings_controller.rb', line 55

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

  set_meeting_context
  @form = meeting_form.from_model(meeting).with_context(@context)
end

#newObject



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

def new
  enforce_permission_to :create, :meeting

  @form = meeting_form.instance
end

#updateObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/decidim/posts/meetings_controller.rb', line 62

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

  copy_location_to_address

  @form = meeting_form.from_params(params)

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

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

#withdrawObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/decidim/posts/meetings_controller.rb', line 82

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

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