Sha256: 75bd4f0a0b982a3ec39b1db71a47da76e58c1557ab833d3dbd75e47dbf1590cb

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 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
        authorize! :join, meeting

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

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

      def destroy
        authorize! :leave, meeting

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

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

      private

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-meetings-0.11.2 app/controllers/decidim/meetings/registrations_controller.rb
decidim-meetings-0.11.1 app/controllers/decidim/meetings/registrations_controller.rb
decidim-meetings-0.11.0.pre1 app/controllers/decidim/meetings/registrations_controller.rb