Sha256: 50e04a8929f0700a4d0e932bdf0f23c65ca8f2fac0741882cbc49f3938dcad12

Contents?: true

Size: 1 KB

Versions: 40

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module Decidim
  # This command destroys the user's account.
  class DestroyAccount < Rectify::Command
    # Destroy a user's account.
    #
    # user - The user to be updated.
    # form - The form with the data.
    def initialize(user, form)
      @user = user
      @form = form
    end

    def call
      return broadcast(:invalid) unless @form.valid?

      Decidim::User.transaction do
        destroy_user_account!
        destroy_user_identities
        destroy_user_group_memberships
      end

      broadcast(:ok)
    end

    private

    def destroy_user_account!
      @user.name = ""
      @user.email = ""
      @user.delete_reason = @form.delete_reason
      @user.deleted_at = Time.current
      @user.skip_reconfirmation!
      @user.remove_avatar!
      @user.save!
    end

    def destroy_user_identities
      @user.identities.destroy_all
    end

    def destroy_user_group_memberships
      Decidim::UserGroupMembership.where(user: @user).destroy_all
    end
  end
end

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
decidim-core-0.6.3 app/commands/decidim/destroy_account.rb
decidim-0.6.3 decidim-core/app/commands/decidim/destroy_account.rb
decidim-core-0.6.2 app/commands/decidim/destroy_account.rb
decidim-0.6.2 decidim-core/app/commands/decidim/destroy_account.rb
decidim-core-0.6.1 app/commands/decidim/destroy_account.rb
decidim-0.6.1 decidim-core/app/commands/decidim/destroy_account.rb
decidim-core-0.6.0 app/commands/decidim/destroy_account.rb
decidim-0.6.0 decidim-core/app/commands/decidim/destroy_account.rb
decidim-core-0.5.1 app/commands/decidim/destroy_account.rb
decidim-0.5.1 decidim-core/app/commands/decidim/destroy_account.rb
decidim-core-0.5.0 app/commands/decidim/destroy_account.rb
decidim-0.5.0 decidim-core/app/commands/decidim/destroy_account.rb
decidim-core-0.4.4 app/commands/decidim/destroy_account.rb
decidim-core-0.4.2 app/commands/decidim/destroy_account.rb
decidim-core-0.4.1 app/commands/decidim/destroy_account.rb
decidim-core-0.4.3 app/commands/decidim/destroy_account.rb
decidim-core-0.4.0 app/commands/decidim/destroy_account.rb
decidim-core-0.3.2 app/commands/decidim/destroy_account.rb
decidim-core-0.3.1 app/commands/decidim/destroy_account.rb
decidim-core-0.3.0 app/commands/decidim/destroy_account.rb