Sha256: 54b9d9aafd5b187271ce8f04b47d9df454cdb3323e1ffc8fdd7d769ce427a99a

Contents?: true

Size: 897 Bytes

Versions: 6

Compression:

Stored size: 897 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module EnhancedTextwork
    module Admin
      # A command with all the business logic when a user destroys a draft paragraph.
      class DestroyParagraph < Rectify::Command
        # Public: Initializes the command.
        #
        # paragraph     - The paragraph to destroy.
        def initialize(paragraph)
          @paragraph = paragraph
        end

        # Executes the command. Broadcasts these events:
        #
        # - :ok when everything is valid and the paragraph is deleted.
        # - :invalid if the paragraph is not a draft.
        # - :invalid if the paragraph's author is not the current user.
        #
        # Returns nothing.
        def call
          return broadcast(:invalid) unless @paragraph.draft?

          @paragraph.destroy!

          broadcast(:ok, @paragraph)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-enhanced_textwork-1.0.5 app/commands/decidim/enhanced_textwork/admin/destroy_paragraph.rb
decidim-enhanced_textwork-1.0.4 app/commands/decidim/enhanced_textwork/admin/destroy_paragraph.rb
decidim-enhanced_textwork-1.0.3 app/commands/decidim/enhanced_textwork/admin/destroy_paragraph.rb
decidim-enhanced_textwork-1.0.2 app/commands/decidim/enhanced_textwork/admin/destroy_paragraph.rb
decidim-enhanced_textwork-1.0.1 app/commands/decidim/enhanced_textwork/admin/destroy_paragraph.rb
decidim-enhanced_textwork-1.0.0 app/commands/decidim/enhanced_textwork/admin/destroy_paragraph.rb