Sha256: 72dc8dc1306df40aed40e2518f7faaf631210cd8a6afb6ba0d1d4cee537aba3c
Contents?: true
Size: 1.81 KB
Versions: 19
Compression:
Stored size: 1.81 KB
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 # 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 hideable? hide! send_hide_notification_to_author broadcast(:ok, @reportable) end private def hideable? !@reportable.hidden? && @reportable.reported? end def hide! Decidim.traceability.perform_action!( "hide", @reportable.moderation, @current_user, extra: { reportable_type: @reportable.class.name } ) do @reportable.moderation.update!(hidden_at: Time.current) @reportable.try(:touch) end end def send_hide_notification_to_author data = { event: "decidim.events.reports.resource_hidden", event_class: Decidim::ResourceHiddenEvent, resource: @reportable, extra: { report_reasons: report_reasons }, affected_users: @reportable.try(:authors) || [@reportable.try(:normalized_author)] } Decidim::EventsManager.publish(data) end def report_reasons @reportable.moderation.reports.pluck(:reason).uniq end end end end
Version data entries
19 entries across 19 versions & 1 rubygems