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.8.4 app/commands/decidim/destroy_account.rb
decidim-core-0.8.3 app/commands/decidim/destroy_account.rb
decidim-core-0.8.2 app/commands/decidim/destroy_account.rb
decidim-core-0.8.1 app/commands/decidim/destroy_account.rb
decidim-core-0.8.0 app/commands/decidim/destroy_account.rb
decidim-core-0.7.4 app/commands/decidim/destroy_account.rb
decidim-core-0.7.3 app/commands/decidim/destroy_account.rb
decidim-core-0.7.2 app/commands/decidim/destroy_account.rb
decidim-core-0.7.1 app/commands/decidim/destroy_account.rb
decidim-core-0.7.0 app/commands/decidim/destroy_account.rb
decidim-core-0.6.8 app/commands/decidim/destroy_account.rb
decidim-0.6.8 decidim-core/app/commands/decidim/destroy_account.rb
decidim-core-0.6.7 app/commands/decidim/destroy_account.rb
decidim-0.6.7 decidim-core/app/commands/decidim/destroy_account.rb
decidim-core-0.6.6 app/commands/decidim/destroy_account.rb
decidim-0.6.6 decidim-core/app/commands/decidim/destroy_account.rb
decidim-core-0.6.5 app/commands/decidim/destroy_account.rb
decidim-0.6.5 decidim-core/app/commands/decidim/destroy_account.rb
decidim-core-0.6.4 app/commands/decidim/destroy_account.rb
decidim-0.6.4 decidim-core/app/commands/decidim/destroy_account.rb