Class: Decidim::Meetings::RegistrationsController

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

Overview

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

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

#after_answer_pathObject


86
87
88
# File 'decidim-meetings/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 'decidim-meetings/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 'decidim-meetings/app/controllers/decidim/meetings/registrations_controller.rb', line 9

def answer
  enforce_permission_to :join, :meeting, meeting: meeting

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

  JoinMeeting.call(meeting, current_user, @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 'decidim-meetings/app/controllers/decidim/meetings/registrations_controller.rb', line 32

def create
  enforce_permission_to :register, :meeting, meeting: meeting

  @form = JoinMeetingForm.from_params(params)

  JoinMeeting.call(meeting, current_user, @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 'decidim-meetings/app/controllers/decidim/meetings/registrations_controller.rb', line 66

def decline_invitation
  enforce_permission_to :decline_invitation, :meeting, 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 'decidim-meetings/app/controllers/decidim/meetings/registrations_controller.rb', line 50

def destroy
  enforce_permission_to :leave, :meeting, 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 'decidim-meetings/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 'decidim-meetings/app/controllers/decidim/meetings/registrations_controller.rb', line 92

def update_url
  answer_meeting_registration_path(meeting_id: meeting.id)
end