Class: Decidim::Meetings::RegistrationsController

Inherits:
ApplicationController show all
Includes:
Forms::Concerns::HasQuestionnaire
Defined in:
app/controllers/decidim/meetings/registrations_controller.rb

Overview

Exposes the registration resource so users can join and leave meetings.

Instance Method Summary collapse

Instance Method Details

#after_answer_pathObject



86
87
88
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 86

def after_answer_path
  meeting_path(meeting)
end

#allow_answers?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 82

def allow_answers?
  meeting.registrations_enabled? && meeting.registration_form_enabled? && meeting.has_available_slots?
end

#answerObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 9

def answer
  enforce_permission_to(:join, :meeting, meeting:)

  @form = form(Decidim::Forms::QuestionnaireForm).from_params(params, session_token:)

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

    on(:invalid) do
      flash.now[:alert] = I18n.t("registrations.create.invalid", scope: "decidim.meetings")
      render template: "decidim/forms/questionnaires/show"
    end

    on(:invalid_form) do
      flash.now[:alert] = I18n.t("answer.invalid", scope: i18n_flashes_scope)
      render template: "decidim/forms/questionnaires/show"
    end
  end
end

#createObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 32

def create
  enforce_permission_to(:register, :meeting, meeting:)

  @form = JoinMeetingForm.from_params(params).with_context(current_user:)

  JoinMeeting.call(meeting, @form) do
    on(:ok) do
      flash[:notice] = I18n.t("registrations.create.success", scope: "decidim.meetings")
      redirect_after_path
    end

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

#decline_invitationObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 66

def decline_invitation
  enforce_permission_to(:decline_invitation, :meeting, meeting:)

  DeclineInvitation.call(meeting, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("registrations.decline_invitation.success", scope: "decidim.meetings")
      redirect_after_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("registrations.decline_invitation.invalid", scope: "decidim.meetings")
      redirect_after_path
    end
  end
end

#destroyObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 50

def destroy
  enforce_permission_to(:leave, :meeting, meeting:)

  LeaveMeeting.call(meeting, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("registrations.destroy.success", scope: "decidim.meetings")
      redirect_after_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("registrations.destroy.invalid", scope: "decidim.meetings")
      redirect_after_path
    end
  end
end

#questionnaire_forObject



96
97
98
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 96

def questionnaire_for
  meeting
end

#update_urlObject

You can implement this method in your controller to change the URL where the questionnaire will be submitted.



92
93
94
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 92

def update_url
  answer_meeting_registration_path(meeting_id: meeting.id)
end