Sha256: 29f0d9c2c160e8cc2b8a656ef440340efb4a4082022bfcfafb22ef5061e37280

Contents?: true

Size: 1.24 KB

Versions: 19

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic when unofficializing a user.
    class UnofficializeUser < Decidim::Command
      # Public: Initializes the command.
      #
      # user - The user to be unofficialized.
      # current_user - The user performing the action
      def initialize(user, current_user)
        @user = user
        @current_user = current_user
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when the unofficialization suceeds.
      # - :invalid when the form is invalid.
      #
      # Returns nothing.
      def call
        unofficialize_user

        broadcast(:ok)
      end

      private

      attr_reader :user, :current_user

      def unofficialize_user
        Decidim.traceability.perform_action!(
          "unofficialize",
          user,
          current_user,
          extra: {
            officialized_user_badge: nil,
            officialized_user_badge_previous: user.officialized_as,
            officialized_user_at: nil,
            officialized_user_at_previous: user.officialized_at
          }
        ) do
          user.update!(officialized_at: nil, officialized_as: nil)
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-admin-0.28.4 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.27.9 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.28.3 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.27.8 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.28.2 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.27.7 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.28.1 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.27.6 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.28.0 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.27.5 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.27.4 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.27.3 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.27.2 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.27.1 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.27.0 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.27.0.rc2 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.27.0.rc1 app/commands/decidim/admin/unofficialize_user.rb