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_response_pathObject



113
114
115
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 113

def after_response_path
  meeting_path(meeting)
end

#allow_responses?Boolean

Returns:

  • (Boolean)


107
108
109
110
111
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 107

def allow_responses?
  return false unless meeting.registrations_enabled? && meeting.registration_form_enabled?

  meeting.has_available_slots? || should_join_waitlist?
end

#createObject



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

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



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 87

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



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 71

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

#join_waitlistObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 53

def join_waitlist
  enforce_permission_to(:join_waitlist, :meeting, meeting:)

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

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

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

#questionnaire_forObject



123
124
125
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 123

def questionnaire_for
  meeting
end

#respondObject



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

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

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

  command = should_join_waitlist? ? JoinWaitlist : JoinMeeting
  joining_waitlist = should_join_waitlist?

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

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

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

#should_join_waitlist?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 103

def should_join_waitlist?
  meeting.waitlist_enabled? && !meeting.has_available_slots? && !meeting.has_registration_for?(current_user)
end

#update_urlObject

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



119
120
121
# File 'app/controllers/decidim/meetings/registrations_controller.rb', line 119

def update_url
  respond_meeting_registration_path(meeting_id: meeting.id)
end