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(diaspora_handle) ⇒ AccountDeleter


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

def initialize(diaspora_handle)
  self.person = Person.where(:diaspora_handle => diaspora_handle).first
  self.user = self.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.


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

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.


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

def user
  @user
end

Instance Method Details

#delete_contacts_of_meObject


103
104
105
# File 'lib/account_deleter.rb', line 103

def delete_contacts_of_me
  Contact.all_contacts_of_person(self.person).destroy_all
end

#delete_standard_person_associationsObject


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

def delete_standard_person_associations
  normal_ar_person_associates_to_delete.each do |asso|
    self.person.send(asso).destroy_all
  end
end

#delete_standard_user_associationsObject


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

def delete_standard_user_associations
  normal_ar_user_associates_to_delete.each do |asso|
    self.user.send(asso).each{|model| model.destroy }
  end
end

#disassociate_invitationsObject


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

def disassociate_invitations
  user.invitations_from_me.each do |inv|
    inv.convert_to_admin!
  end
end

#disconnect_contactsObject


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

def disconnect_contacts
  user.contacts.destroy_all
end

#ignored_ar_user_associationsObject


54
55
56
# File 'lib/account_deleter.rb', line 54

def ignored_ar_user_associations
  [:followed_tags, :invited_by, :contact_people, :aspect_memberships, :ignored_people, :conversation_visibilities, :conversations, :reports]
end

#ignored_or_special_ar_person_associationsObject


111
112
113
# File 'lib/account_deleter.rb', line 111

def ignored_or_special_ar_person_associations
  [:comments, :contacts, :notification_actors, :notifications, :owner, :profile, :conversation_visibilities]
end

#normal_ar_person_associates_to_deleteObject


107
108
109
# File 'lib/account_deleter.rb', line 107

def normal_ar_person_associates_to_delete
  [:posts, :photos, :mentions, :participations, :roles]
end

#normal_ar_user_associates_to_deleteObject

user deletions


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

def normal_ar_user_associates_to_delete
  [:tag_followings, :invitations_to_me, :services, :aspects, :user_preferences, :notifications, :blocks]
end

#perform!Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/account_deleter.rb', line 25

def perform!
  ActiveRecord::Base.transaction do
    #person
    delete_standard_person_associations
    remove_conversation_visibilities
    remove_share_visibilities_on_persons_posts
    delete_contacts_of_me
    tombstone_person_and_profile

    if self.user
      #user deletion methods
      remove_share_visibilities_on_contacts_posts
      delete_standard_user_associations
      disassociate_invitations
      disconnect_contacts
      tombstone_user
    end
  end
end

#remove_conversation_visibilitiesObject


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

def remove_conversation_visibilities
  ConversationVisibility.where(:person_id => person.id).destroy_all
end

#remove_share_visibilities_on_contacts_postsObject


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

def remove_share_visibilities_on_contacts_posts
  ShareVisibility.for_a_users_contacts(user).destroy_all
end

#remove_share_visibilities_on_persons_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_persons_posts
  ShareVisibility.for_contacts_of_a_person(person).destroy_all
end

#special_ar_user_associationsObject


50
51
52
# File 'lib/account_deleter.rb', line 50

def special_ar_user_associations
  [:invitations_from_me, :person, :contacts, :auto_follow_back_aspect]
end

#tombstone_person_and_profileObject


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

def tombstone_person_and_profile
  self.person.lock_access!
  self.person.clear_profile!
end

#tombstone_userObject


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

def tombstone_user
  self.user.clear_account!
end