Sha256: a1d1d6cc8a9cbe5dbbace6095a3c2301af0ae6139d11ad0fa760c182d27ee3df

Contents?: true

Size: 1.16 KB

Versions: 15

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    module Admin
      # This command is executed when the user destroys a Meeting from the admin
      # panel.
      class DestroyMeeting < Rectify::Command
        # Initializes a CloseMeeting Command.
        #
        # meeting - The current instance of the page to be closed.
        # current_user - the user performing the action
        def initialize(meeting, current_user)
          @meeting = meeting
          @current_user = current_user
        end

        # Destroys the meeting if valid.
        #
        # Broadcasts :ok if successful, :invalid otherwise.
        def call
          return broadcast(:invalid, proposals.size) if proposals.any?

          destroy_meeting
          broadcast(:ok)
        end

        private

        attr_reader :current_user, :meeting

        def destroy_meeting
          Decidim.traceability.perform_action!(
            :delete,
            meeting,
            current_user
          ) do
            meeting.destroy!
          end
        end

        def proposals
          @proposals ||= meeting.authored_proposals.load
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
decidim-meetings-0.24.3 app/commands/decidim/meetings/admin/destroy_meeting.rb
decidim-meetings-0.23.6 app/commands/decidim/meetings/admin/destroy_meeting.rb
decidim-meetings-0.24.2 app/commands/decidim/meetings/admin/destroy_meeting.rb
decidim-meetings-0.23.5 app/commands/decidim/meetings/admin/destroy_meeting.rb
decidim-meetings-0.24.1 app/commands/decidim/meetings/admin/destroy_meeting.rb
decidim-meetings-0.24.0 app/commands/decidim/meetings/admin/destroy_meeting.rb
decidim-meetings-0.24.0.rc2 app/commands/decidim/meetings/admin/destroy_meeting.rb
decidim-meetings-0.23.4 app/commands/decidim/meetings/admin/destroy_meeting.rb
decidim-meetings-0.24.0.rc1 app/commands/decidim/meetings/admin/destroy_meeting.rb
decidim-meetings-0.23.3 app/commands/decidim/meetings/admin/destroy_meeting.rb
decidim-meetings-0.23.2 app/commands/decidim/meetings/admin/destroy_meeting.rb
decidim-meetings-0.23.1 app/commands/decidim/meetings/admin/destroy_meeting.rb
decidim-meetings-0.23.1.rc1 app/commands/decidim/meetings/admin/destroy_meeting.rb
decidim-meetings-0.23.0 app/commands/decidim/meetings/admin/destroy_meeting.rb
decidim-meetings-0.22.0 app/commands/decidim/meetings/admin/destroy_meeting.rb