Sha256: a3eb9f3f598eafe0f3c7057c3ad0cdd5241acc17ac16c8f42ac787d8e4cd9e93
Contents?: true
Size: 910 Bytes
Versions: 8
Compression:
Stored size: 910 Bytes
Contents
# frozen_string_literal: true module Decidim module Admin # A command with all the business logic when a user hides a resource. class HideResource < Rectify::Command # Public: Initializes the command. # # reportable - A Decidim::Reportable def initialize(reportable) @reportable = reportable end # Executes the command. Broadcasts these events: # # - :ok when everything is valid, together with the resource. # - :invalid if the resource is already hidden # # Returns nothing. def call return broadcast(:invalid) unless hideable? hide! broadcast(:ok, @reportable) end private def hideable? !@reportable.hidden? && @reportable.reported? end def hide! @reportable.moderation.update_attributes!(hidden_at: Time.current) end end end end
Version data entries
8 entries across 8 versions & 2 rubygems