Sha256: 85240d2e2e51aede8ce75bbd0973859f2e2f09cb04f7df5907057e85c2a27b13

Contents?: true

Size: 1.12 KB

Versions: 15

Compression:

Stored size: 1.12 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 < 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 hideable?

        with_events do
          tool = Decidim::ModerationTools.new(@reportable, @current_user)
          tool.hide!
          tool.send_notification_to_author
        end

        broadcast(:ok, @reportable)
      end

      private

      def event_arguments
        { resource: @reportable }
      end

      def hideable?
        !@reportable.hidden? && @reportable.reported?
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
decidim-admin-0.29.2 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.28.5 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.29.1 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.28.4 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.29.0 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.28.3 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.29.0.rc4 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.29.0.rc3 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.29.0.rc2 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.29.0.rc1 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.28.2 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.28.1 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.28.0 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/hide_resource.rb