Sha256: db585051e0e10973941087de90539f9bd0647162a7c6808152a2319ba60c2f7d

Contents?: true

Size: 1.24 KB

Versions: 65

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 < Rectify::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

65 entries across 65 versions & 1 rubygems

Version Path
decidim-admin-0.26.10 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.26.9 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.26.8 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.26.7 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.26.5 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.26.4 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.26.3 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.26.2 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.26.1 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.26.0 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.26.0.rc2 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.26.0.rc1 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.25.2 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.25.1 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.25.0 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.25.0.rc4 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.25.0.rc3 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.25.0.rc2 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.25.0.rc1 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.24.3 app/commands/decidim/admin/unofficialize_user.rb