Sha256: 409ddd79cff18e22717f06f788b1bc0040f6a5bbe2f7b69e233ccd94f87c2218

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    class UnblockUser < Rectify::Command
      # Public: Initializes the command.
      #
      # blocked_user - the user that is unblocked
      # current_user - the user performing the action
      def initialize(blocked_user, current_user)
        @blocked_user = blocked_user
        @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 @blocked_user.blocked?

        unblock!
        broadcast(:ok, @blocked_user)
      end

      private

      def unblock!
        Decidim.traceability.perform_action!(
          "unblock",
          @blocked_user,
          @current_user,
          extra: {
            reportable_type: @blocked_user.class.name
          }
        ) do
          @blocked_user.blocked = false
          @blocked_user.blocked_at = nil
          @blocked_user.block_id = nil
          @blocked_user.name = @blocked_user.extended_data["user_name"]
          @blocked_user.save!
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
decidim-admin-0.26.10 app/commands/decidim/admin/unblock_user.rb
decidim-admin-0.26.9 app/commands/decidim/admin/unblock_user.rb
decidim-admin-0.26.8 app/commands/decidim/admin/unblock_user.rb
decidim-admin-0.26.7 app/commands/decidim/admin/unblock_user.rb
decidim-admin-0.26.5 app/commands/decidim/admin/unblock_user.rb