Sha256: 86dd93048be9a0c8221a75a5a68e426d3164138e4557a76045ac84351e477def
Contents?: true
Size: 982 Bytes
Versions: 56
Compression:
Stored size: 982 Bytes
Contents
# frozen_string_literal: true module Decidim module Proposals # A command with all the business logic when a user destroys a draft proposal. class DestroyProposal < Rectify::Command # Public: Initializes the command. # # proposal - The proposal to destroy. # current_user - The current user. def initialize(proposal, current_user) @proposal = proposal @current_user = current_user end # Executes the command. Broadcasts these events: # # - :ok when everything is valid and the proposal is deleted. # - :invalid if the proposal is not a draft. # - :invalid if the proposal's author is not the current user. # # Returns nothing. def call return broadcast(:invalid) unless @proposal.draft? return broadcast(:invalid) unless @proposal.authored_by?(@current_user) @proposal.destroy! broadcast(:ok, @proposal) end end end end
Version data entries
56 entries across 56 versions & 1 rubygems