added close account to user
This commit is contained in:
parent
cd6f97fa0e
commit
e6ed2d397a
7 changed files with 89 additions and 14 deletions
|
|
@ -33,6 +33,7 @@ class AccountDeletion
|
||||||
delete_photos
|
delete_photos
|
||||||
delete_posts
|
delete_posts
|
||||||
tombstone_person_and_profile
|
tombstone_person_and_profile
|
||||||
|
tombstone_user
|
||||||
end
|
end
|
||||||
|
|
||||||
#user deletions
|
#user deletions
|
||||||
|
|
@ -89,6 +90,10 @@ class AccountDeletion
|
||||||
self.person.close_account!
|
self.person.close_account!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tombstone_user
|
||||||
|
self.user.close_account!
|
||||||
|
end
|
||||||
|
|
||||||
def delete_contacts_of_me
|
def delete_contacts_of_me
|
||||||
Contact.all_contacts_of_person(self.person).destroy_all
|
Contact.all_contacts_of_person(self.person).destroy_all
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ class Person < ActiveRecord::Base
|
||||||
|
|
||||||
before_destroy :remove_all_traces
|
before_destroy :remove_all_traces
|
||||||
before_validation :clean_url
|
before_validation :clean_url
|
||||||
|
|
||||||
validates :url, :presence => true
|
validates :url, :presence => true
|
||||||
validates :profile, :presence => true
|
validates :profile, :presence => true
|
||||||
validates :serialized_public_key, :presence => true
|
validates :serialized_public_key, :presence => true
|
||||||
|
|
@ -78,7 +78,7 @@ class Person < ActiveRecord::Base
|
||||||
super
|
super
|
||||||
self.profile ||= Profile.new unless profile_set
|
self.profile ||= Profile.new unless profile_set
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_from_id_or_username(params)
|
def self.find_from_id_or_username(params)
|
||||||
p = if params[:id].present?
|
p = if params[:id].present?
|
||||||
Person.where(:id => params[:id]).first
|
Person.where(:id => params[:id]).first
|
||||||
|
|
@ -91,7 +91,6 @@ class Person < ActiveRecord::Base
|
||||||
p
|
p
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def self.search_query_string(query)
|
def self.search_query_string(query)
|
||||||
query = query.downcase
|
query = query.downcase
|
||||||
like_operator = postgres? ? "ILIKE" : "LIKE"
|
like_operator = postgres? ? "ILIKE" : "LIKE"
|
||||||
|
|
@ -276,8 +275,6 @@ class Person < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# @param person [Person]
|
# @param person [Person]
|
||||||
# @param url [String]
|
# @param url [String]
|
||||||
def update_url(url)
|
def update_url(url)
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ class Profile < ActiveRecord::Base
|
||||||
|
|
||||||
def tombstone!
|
def tombstone!
|
||||||
self.taggings.delete_all
|
self.taggings.delete_all
|
||||||
clearable_profile_fields.each do |field|
|
clearable_fields.each do |field|
|
||||||
self[field] = nil
|
self[field] = nil
|
||||||
end
|
end
|
||||||
self.save
|
self.save
|
||||||
|
|
@ -174,7 +174,7 @@ class Profile < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def clearable_profile_fields
|
def clearable_fields
|
||||||
self.attributes.keys - Profile.protected_attributes.to_a - ["created_at", "updated_at", "person_id"]
|
self.attributes.keys - Profile.protected_attributes.to_a - ["created_at", "updated_at", "person_id"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -488,4 +488,16 @@ class User < ActiveRecord::Base
|
||||||
errors[:base] << 'That username has already been taken'
|
errors[:base] << 'That username has already been taken'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def close_account!
|
||||||
|
clearable_fields.each do |field|
|
||||||
|
self[field] = nil
|
||||||
|
end
|
||||||
|
self.save
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def clearable_fields
|
||||||
|
self.attributes.keys - ["username", "encrypted_password", "created_at", "updated_at"]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@ describe AccountDeletion do
|
||||||
:delete_posts,
|
:delete_posts,
|
||||||
:tombstone_person_and_profile,
|
:tombstone_person_and_profile,
|
||||||
:remove_share_visibilities,
|
:remove_share_visibilities,
|
||||||
:remove_conversation_visibilities].each do |method|
|
:remove_conversation_visibilities,
|
||||||
|
:tombstone_user].each do |method|
|
||||||
|
|
||||||
it "calls ##{method.to_s}" do
|
it "calls ##{method.to_s}" do
|
||||||
@account_deletion.should_receive(method)
|
@account_deletion.should_receive(method)
|
||||||
|
|
@ -141,6 +142,13 @@ describe AccountDeletion do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#tombstone_user" do
|
||||||
|
it 'calls strip_model on user' do
|
||||||
|
bob.should_receive(:close_account!)
|
||||||
|
@account_deletion.tombstone_user
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'has all user association keys accounted for' do
|
it 'has all user association keys accounted for' do
|
||||||
all_keys = (@account_deletion.normal_ar_user_associates_to_delete + @account_deletion.special_ar_user_associations + @account_deletion.ignored_ar_user_associations)
|
all_keys = (@account_deletion.normal_ar_user_associates_to_delete + @account_deletion.special_ar_user_associations + @account_deletion.ignored_ar_user_associations)
|
||||||
all_keys.sort{|x, y| x.to_s <=> y.to_s}.should == User.reflections.keys.sort{|x, y| x.to_s <=> y.to_s}
|
all_keys.sort{|x, y| x.to_s <=> y.to_s}.should == User.reflections.keys.sort{|x, y| x.to_s <=> y.to_s}
|
||||||
|
|
|
||||||
|
|
@ -264,7 +264,6 @@ describe Profile do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#receive' do
|
describe '#receive' do
|
||||||
|
|
||||||
it 'updates the profile in place' do
|
it 'updates the profile in place' do
|
||||||
local_luke, local_leia, remote_raphael = set_up_friends
|
local_luke, local_leia, remote_raphael = set_up_friends
|
||||||
new_profile = Factory.build :profile
|
new_profile = Factory.build :profile
|
||||||
|
|
@ -281,8 +280,8 @@ describe Profile do
|
||||||
@profile = bob.person.profile
|
@profile = bob.person.profile
|
||||||
end
|
end
|
||||||
it "clears the profile fields" do
|
it "clears the profile fields" do
|
||||||
attributes = @profile.send(:clearable_profile_fields)
|
attributes = @profile.send(:clearable_fields)
|
||||||
|
|
||||||
@profile.tombstone!
|
@profile.tombstone!
|
||||||
@profile.reload
|
@profile.reload
|
||||||
attributes.each{ |attr|
|
attributes.each{ |attr|
|
||||||
|
|
@ -296,10 +295,10 @@ describe Profile do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#clearable_profile_fields" do
|
describe "#clearable_fields" do
|
||||||
it 'returns the current profile fields' do
|
it 'returns the current profile fields' do
|
||||||
profile = Factory.build :profile
|
profile = Factory.build :profile
|
||||||
profile.send(:clearable_profile_fields).sort.should ==
|
profile.send(:clearable_fields).sort.should ==
|
||||||
["diaspora_handle",
|
["diaspora_handle",
|
||||||
"first_name",
|
"first_name",
|
||||||
"last_name",
|
"last_name",
|
||||||
|
|
|
||||||
|
|
@ -1003,6 +1003,60 @@ describe User do
|
||||||
user = Factory :user
|
user = Factory :user
|
||||||
Resque.should_receive(:enqueue).with(Jobs::ResetPassword, user.id)
|
Resque.should_receive(:enqueue).with(Jobs::ResetPassword, user.id)
|
||||||
user.send_reset_password_instructions
|
user.send_reset_password_instructions
|
||||||
|
|
||||||
|
context "close account" do
|
||||||
|
before do
|
||||||
|
@user = bob
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#close_account!" do
|
||||||
|
it 'resets the password to a random string' do
|
||||||
|
random_pass = "12345678909876543210"
|
||||||
|
ActiveSupport::SecureRandom.should_receive(:hex).and_return(random_pass)
|
||||||
|
@user.close_account!
|
||||||
|
@user.valid_password?(random_pass)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'clears all the clearable fields' do
|
||||||
|
attributes = @user.send(:clearable_fields)
|
||||||
|
@user.close_account!
|
||||||
|
|
||||||
|
attributes.each do |attr|
|
||||||
|
@user.send(attr.to_sym).should be_blank
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#clearable_attributes" do
|
||||||
|
it 'has all the attributes' do
|
||||||
|
user = Factory.build :user
|
||||||
|
user.send(:clearable_fields).sort.should == %w{
|
||||||
|
serialized_private_key
|
||||||
|
getting_started
|
||||||
|
disable_mail
|
||||||
|
language
|
||||||
|
email
|
||||||
|
invitation_token
|
||||||
|
invitation_sent_at
|
||||||
|
reset_password_token
|
||||||
|
remember_token
|
||||||
|
remember_created_at
|
||||||
|
sign_in_count
|
||||||
|
current_sign_in_at
|
||||||
|
last_sign_in_at
|
||||||
|
current_sign_in_ip
|
||||||
|
last_sign_in_ip
|
||||||
|
invitation_service
|
||||||
|
invitation_identifier
|
||||||
|
invitation_limit
|
||||||
|
invited_by_id
|
||||||
|
invited_by_type
|
||||||
|
authentication_token
|
||||||
|
unconfirmed_email
|
||||||
|
confirm_email_token
|
||||||
|
locked_at
|
||||||
|
show_community_spotlight_in_stream
|
||||||
|
}.sort
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue