Sha256: 4fe66a4dd5b65005ff141f45cc05d3b42421d033d2b367deebe9aeb074169eb5

Contents?: true

Size: 860 Bytes

Versions: 54

Compression:

Stored size: 860 Bytes

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
      def initialize(reportable)
        @reportable = reportable
      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!
        @reportable.moderation.update_attributes!(report_count: 0, hidden_at: nil)
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 2 rubygems

Version Path
decidim-admin-0.9.3 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.9.2 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.9.1 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.9.0 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.8.4 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.8.3 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.8.2 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.8.1 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.8.0 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.7.4 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.7.3 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.7.2 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.7.1 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.7.0 app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.6.8 app/commands/decidim/admin/unreport_resource.rb
decidim-0.6.8 decidim-admin/app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.6.7 app/commands/decidim/admin/unreport_resource.rb
decidim-0.6.7 decidim-admin/app/commands/decidim/admin/unreport_resource.rb
decidim-admin-0.6.6 app/commands/decidim/admin/unreport_resource.rb
decidim-0.6.6 decidim-admin/app/commands/decidim/admin/unreport_resource.rb