Sha256: 6189e1d6cb5ff6198fe42ef088a67b76b35d23b54543f9628c80e45ddb5081c3

Contents?: true

Size: 1.15 KB

Versions: 25

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    class UnreportUser < Decidim::Command
      # Public: Initializes the command.
      #
      # reportable - A Decidim::User - The user reported
      # 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.user_moderation,
          @current_user,
          extra: {
            reportable_type: @reportable.class.name,
            username: @reportable.name,
            user_id: @reportable.id
          }
        ) do
          @reportable.user_moderation.destroy!
        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/unreport_user.rb
decidim-admin-0.28.4 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.27.9 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.29.0 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.28.3 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.27.8 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.29.0.rc4 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.29.0.rc3 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.29.0.rc2 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.29.0.rc1 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.28.2 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.27.7 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.28.1 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.27.6 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.28.0 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.27.5 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.27.4 app/commands/decidim/admin/unreport_user.rb
decidim-admin-0.27.3 app/commands/decidim/admin/unreport_user.rb