Sha256: f87ba4e657bb610f17e22d63acefc8930a953d637e6709d0566f430ebb2efff4

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

module Decidim
  module Accountability
    module Admin
      module HasResultCommand
        def proposals
          @proposals ||= resource.sibling_scope(:proposals).where(id: form.proposal_ids)
        end

        def projects
          @projects ||= resource.sibling_scope(:projects).where(id: form.project_ids)
        end

        def meeting_ids
          @meeting_ids ||= proposals.flat_map do |proposal|
            proposal.linked_resources(:meetings, "proposals_from_meeting").pluck(:id)
          end.uniq
        end

        def meetings
          @meetings ||= resource.sibling_scope(:meetings).where(id: meeting_ids)
        end

        def link_proposals
          resource.link_resources(proposals, "included_proposals")
        end

        def link_projects
          resource.link_resources(projects, "included_projects")
        end

        def link_meetings
          resource.link_resources(meetings, "meetings_through_proposals")
        end

        def notify_proposal_followers
          proposals.each do |proposal|
            Decidim::EventsManager.publish(
              event: "decidim.events.accountability.proposal_linked",
              event_class: Decidim::Accountability::ProposalLinkedEvent,
              resource:,
              affected_users: proposal.notifiable_identities,
              followers: proposal.followers - proposal.notifiable_identities,
              extra: {
                proposal_id: proposal.id
              }
            )
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-accountability-0.29.1 app/commands/decidim/accountability/admin/has_result_command.rb
decidim-accountability-0.29.0 app/commands/decidim/accountability/admin/has_result_command.rb
decidim-accountability-0.29.0.rc4 app/commands/decidim/accountability/admin/has_result_command.rb
decidim-accountability-0.29.0.rc3 app/commands/decidim/accountability/admin/has_result_command.rb
decidim-accountability-0.29.0.rc2 app/commands/decidim/accountability/admin/has_result_command.rb
decidim-accountability-0.29.0.rc1 app/commands/decidim/accountability/admin/has_result_command.rb