Sha256: 1c4868d3c49691ab660565f53a11e5ab4f40447410ef97b2a6f3b29e224f9620
Contents?: true
Size: 1.78 KB
Versions: 6
Compression:
Stored size: 1.78 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) 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
6 entries across 6 versions & 1 rubygems