Sha256: 0aac1f56617905325da04dd7a888c1e6a9652e50dae45fbb634d6b4142695547

Contents?: true

Size: 1.18 KB

Versions: 31

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    # A command with all the business logic when a user or organization unendorses a proposal.
    class UnendorseProposal < Rectify::Command
      # Public: Initializes the command.
      #
      # proposal     - A Decidim::Proposals::Proposal object.
      # current_user - The current user.
      # current_group- (optional) The current_group that is unendorsing from the Proposal.
      def initialize(proposal, current_user, current_group = nil)
        @proposal = proposal
        @current_user = current_user
        @current_group = current_group
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid, together with the proposal.
      # - :invalid if the form wasn't valid and we couldn't proceed.
      #
      # Returns nothing.
      def call
        destroy_proposal_endorsement
        broadcast(:ok, @proposal)
      end

      private

      def destroy_proposal_endorsement
        query = @proposal.endorsements.where(
          author: @current_user,
          decidim_user_group_id: @current_group&.id
        )
        query.destroy_all
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
decidim-proposals-0.21.0 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.20.1 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.20.0 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.19.1 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.18.1 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.19.0 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.17.2 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.18.0 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.17.1 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.16.1 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.17.0 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.16.0 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.15.2 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.15.1 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.15.0 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.14.4 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.14.3 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.14.2 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.14.1 app/commands/decidim/proposals/unendorse_proposal.rb
decidim-proposals-0.13.1 app/commands/decidim/proposals/unendorse_proposal.rb