Sha256: 9cecccef5d329c470326d969a2739e7c1e6515335cefd28275d1ac5b9b9a767e

Contents?: true

Size: 1.14 KB

Versions: 39

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Decidim
  module Amendable
    # A command with all the business logic when a user starts amending a resource.
    class DestroyDraft < Rectify::Command
      # Public: Initializes the command.
      #
      # amendment     - The amendment to destroy.
      # current_user  - The current user.
      def initialize(amendment, current_user)
        @amendment = amendment
        @amendable = amendment.amendable
        @emendation = amendment.emendation
        @amender = amendment.amender
        @current_user = current_user
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid, together with the amendable.
      # - :invalid if the amendment is not a draft.
      # - :invalid if the amender is not the current user.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) unless amendment.draft? && amender == current_user

        emendation.destroy!
        amendment.delete

        broadcast(:ok, amendable)
      end

      private

      attr_reader :amendment, :amendable, :emendation, :amender, :current_user
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
decidim-core-0.26.10 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.26.9 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.26.8 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.26.7 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.26.5 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.26.4 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.26.3 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.26.2 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.26.1 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.26.0 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.26.0.rc2 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.26.0.rc1 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.25.2 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.25.1 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.25.0 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.25.0.rc4 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.25.0.rc3 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.25.0.rc2 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.25.0.rc1 app/commands/decidim/amendable/destroy_draft.rb
decidim-core-0.24.3 app/commands/decidim/amendable/destroy_draft.rb