Sha256: 1967ae010c7ff23bc7a8128c68264060dc549a5432f13d66482124c3aea3237e
Contents?: true
Size: 1.21 KB
Versions: 25
Compression:
Stored size: 1.21 KB
Contents
# frozen_string_literal: true module Decidim module Admin # A command with all the business logic when a user hides a resource. class UnhideResource < Decidim::Command # Public: Initializes the command. # # reportable - A Decidim::Reportable # current_user - the user that performs the action def initialize(reportable, current_user) @reportable = reportable @current_user = current_user 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 unhideable? unhide! broadcast(:ok, @reportable) end private def unhideable? @reportable.hidden? && @reportable.reported? end def unhide! Decidim.traceability.perform_action!( "unhide", @reportable.moderation, @current_user, extra: { reportable_type: @reportable.class.name } ) do @reportable.moderation.update!(hidden_at: nil) end end end end end
Version data entries
25 entries across 25 versions & 1 rubygems