ms iz wip, clearing profile, started deleting post visibilities

This commit is contained in:
Ilya Zhitomirskiy 2011-11-03 20:43:47 -07:00 committed by Maxwell Salzberg
parent 05612ef733
commit 3035f173bd
12 changed files with 157 additions and 14 deletions

View file

@ -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

View file

@ -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

View file

@ -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] == '/'

View file

@ -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<Contact>] Recipients

View file

@ -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

View file

@ -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

View file

@ -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] }

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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