Sha256: fb73ca36ceafb1311292ed93e4aa6851dbfc0b4a91f7980cbf4e7d935c35e42a

Contents?: true

Size: 1.06 KB

Versions: 19

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 < Rectify::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

19 entries across 19 versions & 1 rubygems

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