Sha256: 0011f4771c750957fad4ad10661d50f1b5a69eb3ce5f416fc63794e83730b282

Contents?: true

Size: 1.4 KB

Versions: 22

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

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

        # Closes the meeting if valid.
        #
        # Broadcasts :ok if successful, :invalid otherwise.
        def call
          return broadcast(:invalid) if @form.invalid?

          transaction do
            close_meeting
            link_proposals
          end

          broadcast(:ok)
        end

        private

        def close_meeting
          @meeting.update_attributes!(
            closing_report: @form.closing_report,
            attendees_count: @form.attendees_count,
            contributions_count: @form.contributions_count,
            attending_organizations: @form.attending_organizations,
            closed_at: @form.closed_at
          )
        end

        def proposals
          @meeting.sibling_scope(:proposals).where(id: @form.proposal_ids)
        end

        def link_proposals
          @meeting.link_resources(proposals, "proposals_from_meeting")
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
decidim-meetings-0.5.1 app/commands/decidim/meetings/admin/close_meeting.rb
decidim-0.5.1 decidim-meetings/app/commands/decidim/meetings/admin/close_meeting.rb
decidim-meetings-0.5.0 app/commands/decidim/meetings/admin/close_meeting.rb
decidim-0.5.0 decidim-meetings/app/commands/decidim/meetings/admin/close_meeting.rb
decidim-meetings-0.4.4 app/commands/decidim/meetings/admin/close_meeting.rb
decidim-0.4.4 decidim-meetings/app/commands/decidim/meetings/admin/close_meeting.rb
decidim-meetings-0.4.3 app/commands/decidim/meetings/admin/close_meeting.rb
decidim-meetings-0.4.2 app/commands/decidim/meetings/admin/close_meeting.rb
decidim-meetings-0.4.1 app/commands/decidim/meetings/admin/close_meeting.rb
decidim-0.4.3 decidim-meetings/app/commands/decidim/meetings/admin/close_meeting.rb
decidim-0.4.2 decidim-meetings/app/commands/decidim/meetings/admin/close_meeting.rb
decidim-0.4.1 decidim-meetings/app/commands/decidim/meetings/admin/close_meeting.rb
decidim-meetings-0.4.0 app/commands/decidim/meetings/admin/close_meeting.rb
decidim-0.4.0 decidim-meetings/app/commands/decidim/meetings/admin/close_meeting.rb
decidim-meetings-0.3.2 app/commands/decidim/meetings/admin/close_meeting.rb
decidim-0.3.2 decidim-meetings/app/commands/decidim/meetings/admin/close_meeting.rb
decidim-meetings-0.3.1 app/commands/decidim/meetings/admin/close_meeting.rb
decidim-0.3.1 decidim-meetings/app/commands/decidim/meetings/admin/close_meeting.rb
decidim-meetings-0.3.0 app/commands/decidim/meetings/admin/close_meeting.rb
decidim-0.3.0 decidim-meetings/app/commands/decidim/meetings/admin/close_meeting.rb