Sha256: 0808dc778ba846752abaddd95fd447b65d346880e593c8036199b1b7427b6c12

Contents?: true

Size: 1.03 KB

Versions: 20

Compression:

Stored size: 1.03 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.nickname = ""
      @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

20 entries across 20 versions & 1 rubygems

Version Path
decidim-core-0.14.4 app/commands/decidim/destroy_account.rb
decidim-core-0.14.3 app/commands/decidim/destroy_account.rb
decidim-core-0.14.2 app/commands/decidim/destroy_account.rb
decidim-core-0.14.1 app/commands/decidim/destroy_account.rb
decidim-core-0.13.1 app/commands/decidim/destroy_account.rb
decidim-core-0.12.2 app/commands/decidim/destroy_account.rb
decidim-core-0.13.0 app/commands/decidim/destroy_account.rb
decidim-core-0.12.1 app/commands/decidim/destroy_account.rb
decidim-core-0.13.0.pre1 app/commands/decidim/destroy_account.rb
decidim-core-0.12.0 app/commands/decidim/destroy_account.rb
decidim-core-0.11.2 app/commands/decidim/destroy_account.rb
decidim-core-0.12.0.pre app/commands/decidim/destroy_account.rb
decidim-core-0.11.1 app/commands/decidim/destroy_account.rb
decidim-core-0.11.0.pre1 app/commands/decidim/destroy_account.rb
decidim-core-0.10.1 app/commands/decidim/destroy_account.rb
decidim-core-0.10.0 app/commands/decidim/destroy_account.rb
decidim-core-0.9.3 app/commands/decidim/destroy_account.rb
decidim-core-0.9.2 app/commands/decidim/destroy_account.rb
decidim-core-0.9.1 app/commands/decidim/destroy_account.rb
decidim-core-0.9.0 app/commands/decidim/destroy_account.rb