Sha256: 642e2cccc5aaa7b729558daf47c63d0e2c5086a7cf677e9f32a328b6954e1ec0

Contents?: true

Size: 1.21 KB

Versions: 40

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 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!
        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
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
decidim-admin-0.23.6 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.23.5 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.23.4 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.23.3 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.23.2 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.23.1 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.23.1.rc1 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.23.0 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.22.0 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.21.0 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.20.1 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.20.0 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.19.1 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.18.1 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.19.0 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.17.2 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.18.0 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.17.1 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.16.1 app/commands/decidim/admin/hide_resource.rb
decidim-admin-0.17.0 app/commands/decidim/admin/hide_resource.rb