Class: AccountDeleter

Inherits:
Object
  • Object
show all
Defined in:
lib/account_deleter.rb

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(person) ⇒ AccountDeleter

Returns a new instance of AccountDeleter.


21
22
23
24
# File 'lib/account_deleter.rb', line 21

def initialize(person)
  self.person = person
  self.user = person.owner
end

Instance Attribute Details

#personObject

Things that are not removed from the database:

  • Comments

  • Likes

  • Messages

  • NotificationActors

Given that the User in question will be tombstoned, all of the above will come from an anonomized account (via the UI). The deleted user will appear as “Deleted Account” in the interface.


19
20
21
# File 'lib/account_deleter.rb', line 19

def person
  @person
end

#userObject

Things that are not removed from the database:

  • Comments

  • Likes

  • Messages

  • NotificationActors

Given that the User in question will be tombstoned, all of the above will come from an anonomized account (via the UI). The deleted user will appear as “Deleted Account” in the interface.


19
20
21
# File 'lib/account_deleter.rb', line 19

def user
  @user
end

Instance Method Details

#close_userObject

user deletion methods


38
39
40
41
42
43
44
# File 'lib/account_deleter.rb', line 38

def close_user
  remove_share_visibilities_on_contacts_posts
  disconnect_contacts
  delete_standard_user_associations
  delete_user_invitation_code
  tombstone_user
end

#delete_contacts_of_meObject


95
96
97
# File 'lib/account_deleter.rb', line 95

def delete_contacts_of_me
  Contact.all_contacts_of_person(person).find_each(batch_size: 20, &:destroy)
end

#delete_standard_person_associationsObject


68
69
70
71
72
73
74
# File 'lib/account_deleter.rb', line 68

def delete_standard_person_associations
  normal_ar_person_associates_to_delete.each do |asso|
    person.send(asso).ids.each_slice(20) do |ids|
      Person.reflect_on_association(asso).class_name.constantize.where(id: ids).destroy_all
    end
  end
end

#delete_standard_user_associationsObject


52
53
54
55
56
57
58
# File 'lib/account_deleter.rb', line 52

def delete_standard_user_associations
  normal_ar_user_associates_to_delete.each do |asso|
    user.send(asso).ids.each_slice(20) do |ids|
      User.reflect_on_association(asso).class_name.constantize.where(id: ids).destroy_all
    end
  end
end

#delete_user_invitation_codeObject


60
61
62
# File 'lib/account_deleter.rb', line 60

def delete_user_invitation_code
  InvitationCode.find_by(user_id: user.id).try(:destroy)
end

#disconnect_contactsObject


76
77
78
# File 'lib/account_deleter.rb', line 76

def disconnect_contacts
  user.contacts.destroy_all
end

#mark_account_deletion_completeObject


99
100
101
# File 'lib/account_deleter.rb', line 99

def 
  AccountDeletion.find_by(person: person)&.update_attributes(completed_at: Time.now.utc)
end

#normal_ar_person_associates_to_deleteObject


64
65
66
# File 'lib/account_deleter.rb', line 64

def normal_ar_person_associates_to_delete
  %i[posts photos mentions participations roles blocks conversation_visibilities]
end

#normal_ar_user_associates_to_deleteObject

user deletions


47
48
49
50
# File 'lib/account_deleter.rb', line 47

def normal_ar_user_associates_to_delete
  %i[tag_followings services aspects user_preferences
     notifications blocks authorizations o_auth_applications pairwise_pseudonymous_identifiers]
end

#perform!Object


26
27
28
29
30
31
32
33
34
35
# File 'lib/account_deleter.rb', line 26

def perform!
  # close person
  delete_standard_person_associations
  delete_contacts_of_me
  tombstone_person_and_profile

  close_user if user

  
end

#remove_share_visibilities_on_contacts_postsObject

Currently this would get deleted due to the db foreign key constrainsts, but we'll keep this method here for completeness


82
83
84
# File 'lib/account_deleter.rb', line 82

def remove_share_visibilities_on_contacts_posts
  ShareVisibility.for_a_user(user).find_each(batch_size: 20, &:destroy)
end

#tombstone_person_and_profileObject


86
87
88
89
# File 'lib/account_deleter.rb', line 86

def tombstone_person_and_profile
  person.lock_access!
  person.clear_profile!
end

#tombstone_userObject


91
92
93
# File 'lib/account_deleter.rb', line 91

def tombstone_user
  user.clear_account!
end