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.23.6 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.24.2 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.23.5 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.24.1 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.24.0 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.24.0.rc2 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.23.4 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.24.0.rc1 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.23.3 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.23.2 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.23.1 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.23.1.rc1 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.23.0 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.22.0 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.21.0 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.20.1 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.20.0 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.19.1 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.18.1 app/commands/decidim/admin/unofficialize_user.rb
decidim-admin-0.19.0 app/commands/decidim/admin/unofficialize_user.rb