Sha256: 20ed73669543c144e9f2afb706b249d6be0ffead4ea8d2db6fbb32e629dd6385
Contents?: true
Size: 990 Bytes
Versions: 4
Compression:
Stored size: 990 Bytes
Contents
# frozen_string_literal: true module Decidim module Admin # A command with all the business logic to destroy a category in the # system. class DestroyCategory < Decidim::Command # Public: Initializes the command. # # category - A Category that will be destroyed def initialize(category, user) @category = category @user = user end # Executes the command. Broadcasts these events: # # - :ok when everything is valid. # - :invalid if the data wasn't valid and we couldn't proceed. # # Returns nothing. def call return broadcast(:invalid) if category.nil? || category.subcategories.any? || !category.unused? destroy_category broadcast(:ok) end private attr_reader :category def destroy_category Decidim.traceability.perform_action!(:delete, category, @user) do category.destroy! end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems