Sha256: 16f723c22d7e074d0a2fa286be18790931cad033c356679c48450451b63b7f3a

Contents?: true

Size: 1.07 KB

Versions: 15

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Decidim
  module Comments
    # A command with all the business logic to delete a comment
    class DeleteComment < Decidim::Command
      # Public: Initializes the command.
      #
      # comment - The comment to delete.
      # current_user - The user performing the action.
      def initialize(comment, current_user)
        @comment = comment
        @current_user = current_user
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid.
      # - :invalid if comment is not authored by current_user.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) unless comment.authored_by?(current_user)

        delete_comment

        broadcast(:ok)
      end

      private

      attr_reader :comment, :current_user

      def delete_comment
        Decidim.traceability.perform_action!(
          :delete,
          comment,
          current_user,
          visibility: "public-only"
        ) do
          comment.delete!
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
decidim-comments-0.29.2 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.28.5 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.29.1 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.28.4 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.29.0 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.28.3 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.29.0.rc4 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.29.0.rc3 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.29.0.rc2 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.29.0.rc1 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.28.2 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.28.1 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.28.0 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.28.0.rc5 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.28.0.rc4 app/commands/decidim/comments/delete_comment.rb