Sha256: 2a68ec4a334ad16e0280ffd007fdf2aaa05a8ba1e7db705fa9d1cac983d97d47

Contents?: true

Size: 1.16 KB

Versions: 21

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic when a user unreports a resource.
    class UnreportResource < Rectify::Command
      # Public: Initializes the command.
      #
      # reportable - A Decidim::Reportable
      # current_user - the user performing 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 not reported
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) unless @reportable.reported?

        unreport!
        broadcast(:ok, @reportable)
      end

      private

      def unreport!
        Decidim.traceability.perform_action!(
          "unreport",
          @reportable.moderation,
          @current_user,
          extra: {
            reportable_type: @reportable.class.name
          }
        ) do
          @reportable.moderation.update!(report_count: 0, hidden_at: nil)
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
decidim-admin-0.16.1 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.16.0 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.15.2 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.15.1 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.15.0 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.14.4 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.14.3 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.14.2 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.14.1 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.13.1 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.12.2 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.13.0 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.12.1 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.13.0.pre1 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.12.0 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.11.2 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.12.0.pre app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.11.1 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.11.0.pre1 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.10.1 app/commands/decidim/admin/unreport_resource.rb