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

Version Path
decidim-admin-0.29.1 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.28.4 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.27.9 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.29.0 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.28.3 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.27.8 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.29.0.rc4 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.29.0.rc3 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.29.0.rc2 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.29.0.rc1 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.28.2 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.27.7 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.28.1 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.27.6 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.28.0 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.27.5 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.27.4 app/commands/decidim/admin/unhide_resource.rb
decidim-admin-0.27.3 app/commands/decidim/admin/unhide_resource.rb