app/models/person.rb
# Null out personal information, but keep all models around.
# Yeah, I know I am using destroy instead of delete_all. I want validations to run.
Null out personal information, but keep all models around.
Yeah, I know I am using destroy instead of delete_all. I want validations to run.
Null out personal information but keep all models around . Yeah I know I am using destroy instead of delete_all . I want validations to run .
def safe_destroy
    ActiveRecord::Base.transaction do
      self.first_name = '[deleted]'
      self.last_name = '[deleted]'
      self.email = "null-#{id}@bountysource.com"
      self.display_name = '[deleted]'
      self.paypal_email = nil
      self.image_url = nil
      self.bio = nil
      self.location = nil
      self.public_email = nil
      self.url = nil
      self.company = nil
      self.save!
      ActiveRecord::Base.connection.execute("update people set cloudinary_id = NULL where id = #{id}")
      fundraisers.where(published: false).find_each(&:destroy)
      fundraisers.where(published: true).find_each { |fundraiser| fundraiser.delete if fundraiser.pledges.empty? }
      bounties.find_each { |bounty| bounty.owner_id = nil ; bounty.owner_type = nil ; bounty.save! }
      pledges.find_each { |pledge| pledge.owner_id = nil ; pledge.owner_type = nil ; pledge.save! }
      ActiveRecord::Base.connection.execute("update bounties set anonymous = 't' where person_id = #{id}")
      ActiveRecord::Base.connection.execute("update pledges set anonymous = 't' where person_id = #{id}")
      bounty_claims.where(collected: false).each(&:destroy)
      searches.find_each { |search| search.update_attribute(:person, nil) }
      solutions.find_each(&:destroy)
      developer_goals.find_each(&:destroy)
      team_member_relations.find_each(&:destroy)
      shopping_cart.destroy
      access_tokens.find_each(&:destroy)
      saved_search_tabs.find_each(&:destroy)
      addresses.find_each(&:destroy)
      person_relations.find_each(&:destroy)
      tracker_relations.find_each(&:destroy)
      tag_votes.find_each(&:destroy)
      follow_relations.find_each(&:destroy)
      team_member_relations.find_each(&:destroy)
      language_relations.find_each(&:destroy)
      activity_logs.find_each(&:destroy)
      issue_rank_caches.find_each(&:destroy)
      tracker_rank_caches.find_each(&:destroy)
      tracker_person_relations.find_each(&:destroy)
      if github_account
        github_account.oauth_token = nil
        github_account.permissions = nil
        github_account.person_id = nil
        github_account.save!
      end
      linked_accounts.where.not(type: 'LinkedAccount::Github::User').find_each(&:destroy)
      update_attribute(:deleted, true)
    end
  end
def safe_destroy ActiveRecord :: Base . transaction do self . first_name = '[deleted]' self . last_name = '[deleted]' self . email = "null-#{id}@bountysource.com" self . display_name = '[deleted]' self . paypal_email = nil self . image_url = nil self . bio = nil self . location = nil self . public_email = nil self . url = nil self . company = nil self . save! ActiveRecord :: Base . connection . execute ( "update people set cloudinary_id = NULL where id = #{id}" ) fundraisers . where ( published : false ) . find_each ( & :destroy ) fundraisers . where ( published : true ) . find_each { | fundraiser | fundraiser . delete if fundraiser . pledges . empty? } bounties . find_each { | bounty | bounty . owner_id = nil ; bounty . owner_type = nil ; bounty . save! } pledges . find_each { | pledge | pledge . owner_id = nil ; pledge . owner_type = nil ; pledge . save! } ActiveRecord :: Base . connection . execute ( "update bounties set anonymous = 't' where person_id = #{id}" ) ActiveRecord :: Base . connection . execute ( "update pledges set anonymous = 't' where person_id = #{id}" ) bounty_claims . where ( collected : false ) . each ( & :destroy ) searches . find_each { | search | search . update_attribute ( :person , nil ) } solutions . find_each ( & :destroy ) developer_goals . find_each ( & :destroy ) team_member_relations . find_each ( & :destroy ) shopping_cart . destroy access_tokens . find_each ( & :destroy ) saved_search_tabs . find_each ( & :destroy ) addresses . find_each ( & :destroy ) person_relations . find_each ( & :destroy ) tracker_relations . find_each ( & :destroy ) tag_votes . find_each ( & :destroy ) follow_relations . find_each ( & :destroy ) team_member_relations . find_each ( & :destroy ) language_relations . find_each ( & :destroy ) activity_logs . find_each ( & :destroy ) issue_rank_caches . find_each ( & :destroy ) tracker_rank_caches . find_each ( & :destroy ) tracker_person_relations . find_each ( & :destroy ) if github_account github_account . oauth_token = nil github_account . permissions = nil github_account . person_id = nil github_account . save! end linked_accounts . where . not ( type : 'LinkedAccount::Github::User' ) . find_each ( & :destroy ) update_attribute ( :deleted , true ) end end
Null out personal information, but keep all models around.
Null out personal information but keep all models around .
# Person attributes stripped away # Clear image_url # Delete unpublished Fundraisers # Delete published fundraisers with no Pledges # Make Pledges and Bounties anonymous # Can safely delete BountyClaims that were never accepted # Null out person on logged searches # Delete all of the things that we can # Unclaim some linked accounts