Sha256: 4c9f8204b5d6aa5378b0e986cbb92dff406f289490ea968108cf6ee4599d7447
Contents?: true
Size: 1.14 KB
Versions: 25
Compression:
Stored size: 1.14 KB
Contents
# frozen_string_literal: true module Decidim module Amendable # A command with all the business logic when a user starts amending a resource. class DestroyDraft < Decidim::Command # Public: Initializes the command. # # amendment - The amendment to destroy. # current_user - The current user. def initialize(amendment, current_user) @amendment = amendment @amendable = amendment.amendable @emendation = amendment.emendation @amender = amendment.amender @current_user = current_user end # Executes the command. Broadcasts these events: # # - :ok when everything is valid, together with the amendable. # - :invalid if the amendment is not a draft. # - :invalid if the amender is not the current user. # # Returns nothing. def call return broadcast(:invalid) unless amendment.draft? && amender == current_user emendation.destroy! amendment.delete broadcast(:ok, amendable) end private attr_reader :amendment, :amendable, :emendation, :amender, :current_user end end end
Version data entries
25 entries across 25 versions & 1 rubygems