diff --git a/app/models/account_deletion.rb b/app/models/account_deletion.rb index 0b6070bf9..3c51e2a66 100644 --- a/app/models/account_deletion.rb +++ b/app/models/account_deletion.rb @@ -17,6 +17,7 @@ class AccountDeletion delete_contacts_of_me disconnect_contacts delete_posts + tombstone_person_and_profile end #user deletions @@ -58,6 +59,12 @@ class AccountDeletion # def comments # end + # + def remove_share_visibilities + #my_contacts = user.contacts.map{|x| x.id} + #others_contacts = person.contacts{|x| x.id} + #ShareVisibility.where(:contact_id => my_contacts + others_contacts) + end # def delete_notification_actors # end @@ -74,12 +81,11 @@ class AccountDeletion self.person.mentions.delete_all end -# def reset_profile -# end + def tombstone_person_and_profile + self.person.close_account! + end def delete_contacts_of_me Contact.all_contacts_of_person(self.person).delete_all end - #private - end diff --git a/app/models/person.rb b/app/models/person.rb index 0d6d40829..eab06e394 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -288,6 +288,13 @@ class Person < ActiveRecord::Base self.update_attributes(:url => newuri) end + def close_account! + self.profile.tombstone! + self.closed_account = true + self.save + self + end + protected def clean_url diff --git a/app/models/profile.rb b/app/models/profile.rb index 7764a4f28..fc41de397 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -146,6 +146,14 @@ class Profile < ActiveRecord::Base self.full_name end + def tombstone! + self.taggings.delete_all + clearable_profile_fields.each do |field| + self[field] = nil + end + self.save + end + protected def strip_names self.first_name.strip! if self.first_name @@ -166,6 +174,10 @@ class Profile < ActiveRecord::Base end private + def clearable_profile_fields + self.attributes.keys - Profile.protected_attributes.to_a - ["created_at", "updated_at", "person_id"] + end + def absolutify_local_url url pod_url = AppConfig[:pod_url].dup pod_url.chop! if AppConfig[:pod_url][-1,1] == '/' diff --git a/app/models/share_visibility.rb b/app/models/share_visibility.rb index 6fd3c0712..eb80309f4 100644 --- a/app/models/share_visibility.rb +++ b/app/models/share_visibility.rb @@ -6,6 +6,13 @@ class ShareVisibility < ActiveRecord::Base belongs_to :contact belongs_to :shareable, :polymorphic => :true + scope :for_a_users_contacts, lambda { |user| + where(:contact_id => user.contacts.map {|c| c.id}) + } + + alias :for_a_users_contacts :for_contacts_of_a_person + + # Perform a batch import, given a set of contacts and a shareable # @note performs a bulk insert in mySQL; performs linear insertions in postgres # @param contacts [Array] Recipients diff --git a/db/migrate/20111103184050_add_closed_account_flag_to_person.rb b/db/migrate/20111103184050_add_closed_account_flag_to_person.rb new file mode 100644 index 000000000..0a845f835 --- /dev/null +++ b/db/migrate/20111103184050_add_closed_account_flag_to_person.rb @@ -0,0 +1,9 @@ +class AddClosedAccountFlagToPerson < ActiveRecord::Migration + def self.up + add_column :people, :closed_account, :boolean, :default => false + end + + def self.down + remove_column :people, :closed_account + end +end diff --git a/db/schema.rb b/db/schema.rb index 4a3992302..7c2d8a731 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20111101202137) do +ActiveRecord::Schema.define(:version => 20111103184050) do create_table "aspect_memberships", :force => true do |t| t.integer "aspect_id", :null => false @@ -238,13 +238,14 @@ ActiveRecord::Schema.define(:version => 20111101202137) do add_index "oauth_clients", ["nonce"], :name => "index_oauth_clients_on_nonce", :unique => true create_table "people", :force => true do |t| - t.string "guid", :null => false - t.text "url", :null => false - t.string "diaspora_handle", :null => false - t.text "serialized_public_key", :null => false + t.string "guid", :null => false + t.text "url", :null => false + t.string "diaspora_handle", :null => false + t.text "serialized_public_key", :null => false t.integer "owner_id" t.datetime "created_at" t.datetime "updated_at" + t.boolean "closed_account", :default => false end add_index "people", ["diaspora_handle"], :name => "index_people_on_diaspora_handle", :unique => true diff --git a/spec/factories.rb b/spec/factories.rb index 24af78f8c..d429b97fa 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -13,9 +13,18 @@ end Factory.define :profile do |p| p.sequence(:first_name) { |n| "Robert#{n}#{r_str}" } p.sequence(:last_name) { |n| "Grimm#{n}#{r_str}" } + p.bio "I am a cat lover and I love to run" + p.gender "robot" + p.location "Earth" p.birthday Date.today end +Factory.define :profile_with_image_url, :parent => :profile do |p| + p.image_url "http://example.com/image.jpg" + p.image_url_medium "http://example.com/image_mid.jpg" + p.image_url_small "http://example.com/image_small.jpg" +end + Factory.define :person do |p| p.sequence(:diaspora_handle) { |n| "bob-person-#{n}#{r_str}@example.net" } p.sequence(:url) { |n| AppConfig[:pod_url] } diff --git a/spec/integration/account_deletion_spec.rb b/spec/integration/account_deletion_spec.rb index f442710f0..053ace48b 100644 --- a/spec/integration/account_deletion_spec.rb +++ b/spec/integration/account_deletion_spec.rb @@ -30,6 +30,7 @@ describe 'deleteing your account' do it 'deletes all of @bob2s share visiblites' do ShareVisibility.where(:contact_id => @bobs_contact_ids).should be_empty + ShareVisibility.where(:contact_id => bob.person.contacts.map(&:id)).should be_empty end it 'deletes all photos' do @@ -48,6 +49,12 @@ describe 'deleteing your account' do @bob2.contacts.should be_empty end + it 'sets the person object as closed and the profile is cleared' do + @bob2.person.reload.closed_account.should be_true + + @bob2.person.profile.reload.first_name.should be_blank + end + it 'deletes the converersation visibilities' do pending end diff --git a/spec/models/account_deletion_spec.rb b/spec/models/account_deletion_spec.rb index a75ecd5ee..9e4dc5c40 100644 --- a/spec/models/account_deletion_spec.rb +++ b/spec/models/account_deletion_spec.rb @@ -10,10 +10,6 @@ describe AccountDeletion do @account_deletion.user = bob end - it 'works' do - pending - end - it "attaches the user" do AccountDeletion.new(bob.person.diaspora_handle).user.should == bob AccountDeletion.new(remote_raphael.diaspora_handle).user.should == nil @@ -49,6 +45,11 @@ describe AccountDeletion do @account_deletion.should_receive(:delete_posts) @account_deletion.perform! end + + it 'calls tombstone_person_and_profile' do + @account_deletion.should_receive(:tombstone_person_and_profile) + @account_deletion.perform! + end end describe "#delete_standard_associations" do @@ -75,7 +76,7 @@ describe AccountDeletion do describe '#delete_photos' do it 'deletes all photos' do @account_deletion.person.photos.should_receive(:delete_all) - @account_deletion.delete_posts + @account_deletion.delete_photos end end @@ -120,6 +121,13 @@ describe AccountDeletion do @account_deletion.delete_contacts_of_me end end + + describe '#tombstone_person_and_profile' do + it 'calls close_account! on person' do + @account_deletion.person.should_receive(:close_account!) + @account_deletion.tombstone_person_and_profile + end + end end it 'has all user association keys accounted for' do diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 48d5f515d..ae1111aef 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -536,4 +536,19 @@ describe Person do end end end + + describe "#close_account!" do + before do + @person = Factory(:person) + end + it 'sets the closed_account flag' do + @person.close_account! + @person.reload.closed_account.should be_true + end + + it 'calls Profile#tombstone!' do + @person.profile.should_receive(:tombstone!) + @person.close_account! + end + end end diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index c93984dcb..9a703fe78 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -275,4 +275,43 @@ describe Profile do end end + + describe "#tombstone!" do + before do + @profile = bob.person.profile + end + it "clears the profile fields" do + attributes = @profile.send(:clearable_profile_fields) + + @profile.tombstone! + @profile.reload + attributes.each{ |attr| + @profile[attr.to_sym].should be_blank + } + end + + it 'removes all the tags from the profile' do + @profile.taggings.should_receive(:delete_all) + @profile.tombstone! + end + end + + describe "#clearable_profile_fields" do + it 'returns the current profile fields' do + profile = Factory.build :profile + profile.send(:clearable_profile_fields).sort.should == + ["diaspora_handle", + "first_name", + "last_name", + "image_url", + "image_url_small", + "image_url_medium", + "birthday", + "gender", + "bio", + "searchable", + "location", + "full_name"].sort + end + end end diff --git a/spec/models/share_visibility_spec.rb b/spec/models/share_visibility_spec.rb index 805c1bbdb..4c72adf21 100644 --- a/spec/models/share_visibility_spec.rb +++ b/spec/models/share_visibility_spec.rb @@ -25,5 +25,28 @@ describe ShareVisibility do ShareVisibility.batch_import([@contact.id], @post) }.should_not raise_error end + + context "scopes" do + describe '.for_a_users_contacts' do + before do + alice.post(:status_message, :text => "Hey", :to => alice.aspects.first) + end + + it 'searches for share visibilies for all users contacts' do + contact_ids = alice.contacts.map{|c| c.id} + ShareVisibility.for_a_users_contacts(alice).should == ShareVisibility.where(:contact_id => contact_ids).all + end + end + + describe '.for_contacts_of_a_person' do + it 'searches for share visibilties generated by a person' do + + contact_ids = alice.person.contacts.map{|c| c.id} + + ShareVisibility.for_contacts_of_a_person(alice.person) == ShareVisibility.where(:contact_id => contact_ids).all + + end + end + end end end