Sha256: deef3fcc04134641216312a52dd0a74bc54c7ac052cd20e87d1f4786529b22ea

Contents?: true

Size: 1.06 KB

Versions: 12

Compression:

Stored size: 1.06 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 isn't 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

12 entries across 12 versions & 1 rubygems

Version Path
decidim-comments-0.27.9 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.27.8 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.27.7 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.27.6 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.27.5 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.27.4 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.27.3 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.27.2 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.27.1 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.27.0 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.27.0.rc2 app/commands/decidim/comments/delete_comment.rb
decidim-comments-0.27.0.rc1 app/commands/decidim/comments/delete_comment.rb