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