Sha256: 48310ee77c39463098653b98f799036b1e7201bcbc94d4921f004d7fb4777282

Contents?: true

Size: 1.55 KB

Versions: 7

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    # Exposes the registration resource so users can join and leave meetings.
    class RegistrationsController < Decidim::Meetings::ApplicationController
      def create
        enforce_permission_to :join, :meeting, meeting: meeting

        JoinMeeting.call(meeting, current_user) 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

      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

      private

      def meeting
        @meeting ||= Meeting.where(component: current_component).find(params[:meeting_id])
      end

      def redirect_after_path
        referer = request.headers["Referer"]
        return redirect_to(meeting_path(meeting)) if referer =~ /invitation_token/
        redirect_back fallback_location: meeting_path(meeting)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-meetings-0.13.1 app/controllers/decidim/meetings/registrations_controller.rb
decidim-meetings-0.12.2 app/controllers/decidim/meetings/registrations_controller.rb
decidim-meetings-0.13.0 app/controllers/decidim/meetings/registrations_controller.rb
decidim-meetings-0.12.1 app/controllers/decidim/meetings/registrations_controller.rb
decidim-meetings-0.13.0.pre1 app/controllers/decidim/meetings/registrations_controller.rb
decidim-meetings-0.12.0 app/controllers/decidim/meetings/registrations_controller.rb
decidim-meetings-0.12.0.pre app/controllers/decidim/meetings/registrations_controller.rb