adding task to fix users with periods
This commit is contained in:
parent
6bd42874e8
commit
0119de4afc
4 changed files with 70 additions and 20 deletions
|
|
@ -397,7 +397,7 @@ en:
|
||||||
thanks: "Thanks,"
|
thanks: "Thanks,"
|
||||||
diaspora: "the diaspora email robot"
|
diaspora: "the diaspora email robot"
|
||||||
single_admin:
|
single_admin:
|
||||||
subject: "A message from your Diaspora administrator:"
|
subject: "A message about your Diaspora account:"
|
||||||
admin: "Your Diaspora administrator"
|
admin: "Your Diaspora administrator"
|
||||||
new_request:
|
new_request:
|
||||||
subject: "new Diaspora* contact request from %{from}"
|
subject: "new Diaspora* contact request from %{from}"
|
||||||
|
|
|
||||||
|
|
@ -33,20 +33,39 @@ module RakeHelpers
|
||||||
offenders = {}
|
offenders = {}
|
||||||
space_people = Person.all(:diaspora_handle => / /, :url => APP_CONFIG[:pod_url]) # this is every person with a space....
|
space_people = Person.all(:diaspora_handle => / /, :url => APP_CONFIG[:pod_url]) # this is every person with a space....
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#these people dont even have users.... they are totally messed up
|
#these people dont even have users.... they are totally messed up
|
||||||
totally_messed_up_people = space_people.find_all{|x| x.owner.nil?}
|
totally_messed_up_people = space_people.find_all{|x| x.owner.nil?}
|
||||||
totally_messed_up_people.each{|x| x.delete}
|
totally_messed_up_people.each{|x| x.delete}
|
||||||
|
|
||||||
|
|
||||||
space_people = Person.all(:diaspora_handle => / /, :owner_id.ne => nil, :url => APP_CONFIG[:pod_url]) # this is every person with a space....
|
space_people = Person.all(:diaspora_handle => / /, :owner_id.ne => nil, :url => APP_CONFIG[:pod_url]) # this is every person with a space....
|
||||||
|
|
||||||
|
|
||||||
space_people.each do |person|
|
space_people.each do |person|
|
||||||
user = person.owner
|
user = person.owner
|
||||||
new_diaspora_handle = "#{user.username}@#{APP_CONFIG[:pod_uri].host}"
|
new_diaspora_handle = new_diaspora_handle(user)
|
||||||
|
update_my_posts_with_new_diaspora_handle(user, new_diaspora_handle, test)
|
||||||
|
person.diaspora_handle = new_diaspora_handle
|
||||||
|
|
||||||
|
if test
|
||||||
|
(puts "TEST:saving person w/handle #{person.diaspora_handle}")
|
||||||
|
else
|
||||||
|
person.save(:safe => true)
|
||||||
|
end
|
||||||
|
|
||||||
|
mail = <<mail
|
||||||
|
You may have noticed that your Diaspora handle contained spaces, or was different than your login name.
|
||||||
|
This was due to a weird error in the early days of Diaspora, and while we fixed the bug,
|
||||||
|
there still may have been a problem with your account. When logging into your account #{user.username},
|
||||||
|
your Diaspora handle is now #{person.diaspora_handle}. Sorry for the confusion!
|
||||||
|
mail
|
||||||
|
Notifier.admin(mail, [user]).each{|x| x.deliver unless test}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_diaspora_handle(user)
|
||||||
|
"#{user.username}@#{APP_CONFIG[:pod_uri].host}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_my_posts_with_new_diaspora_handle(user, new_diaspora_handle, test)
|
||||||
user.my_posts.all.each do |post|
|
user.my_posts.all.each do |post|
|
||||||
post.diaspora_handle = new_diaspora_handle
|
post.diaspora_handle = new_diaspora_handle
|
||||||
if test
|
if test
|
||||||
|
|
@ -55,26 +74,34 @@ module RakeHelpers
|
||||||
post.save(:safe => true)
|
post.save(:safe => true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
person.diaspora_handle = new_diaspora_handle
|
|
||||||
if test
|
|
||||||
(puts "TEST:saving person w/handle #{person.diaspora_handle}")
|
|
||||||
else
|
|
||||||
person.save(:safe => true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fix_periods_in_username(test = true)
|
||||||
|
bad_users = User.all(:username => /\./)
|
||||||
|
bad_users.each do |bad_user|
|
||||||
|
bad_user.username.delete!('.')
|
||||||
|
bad_user.username.delete!(' ')
|
||||||
|
new_diaspora_handle = new_diaspora_handle(bad_user)
|
||||||
|
|
||||||
|
update_my_posts_with_new_diaspora_handle(bad_user, new_diaspora_handle, test)
|
||||||
|
bad_user.person.diaspora_handle = new_diaspora_handle
|
||||||
|
|
||||||
|
if test
|
||||||
|
puts "saving person and user with #{new_diaspora_handle}"
|
||||||
|
else
|
||||||
|
bad_user.person.save(:safe => true)
|
||||||
|
bad_user.save(:safe => true)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mail = <<mail
|
mail = <<mail
|
||||||
Hi, #{person.name}, you may have noticed that your Diaspora handle contained spaces, or was different than your login name.
|
We noticed that your Diaspora username contained periods.
|
||||||
This was due to a weird error in the early days of Diaspora, and while we fixed the bug,
|
This was due to a weird error in the early days of Diaspora, and while we fixed the bug,
|
||||||
there still may have been a problem with your account. When logging into your account #{user.username},
|
there still may have been a problem with your account. Log into your account with #{bad_user.username},
|
||||||
your Diaspora handle is now #{person.diaspora_handle}. Sorry for the confusion!
|
you improved, period-less, username!
|
||||||
|
|
||||||
- The Diaspora Team
|
|
||||||
mail
|
mail
|
||||||
Notifier.admin(mail, [user]).each{|x| x.deliver unless test}
|
Notifier.admin(mail, [bad_user]).each{|x| x.deliver unless test}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def fix_periods
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ namespace :migrations do
|
||||||
|
|
||||||
desc 'fix usernames with periods in them'
|
desc 'fix usernames with periods in them'
|
||||||
task :fix_periods_in_username do
|
task :fix_periods_in_username do
|
||||||
|
RakeHelpers::fix_periods_in_usernames(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'purge broken contacts'
|
desc 'purge broken contacts'
|
||||||
|
|
|
||||||
|
|
@ -67,5 +67,27 @@ describe RakeHelpers do
|
||||||
}.to change(Person, :count).by(-1)
|
}.to change(Person, :count).by(-1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
describe '#fix_periods_in_username' do
|
||||||
|
it 'should update a users username, his persons diaspora hande, and posts' do
|
||||||
|
billy = Factory.create(:user)
|
||||||
|
billy.username = "ma.x"
|
||||||
|
billy.person.diaspora_handle = "ma.x@#{APP_CONFIG[:pod_uri].host}"
|
||||||
|
billy.person.save(:validate => false)
|
||||||
|
billy.save(:validate => false)
|
||||||
|
|
||||||
|
aspect = billy.aspects.create :name => "foo"
|
||||||
|
billy.post :status_message, :message => "hi mom", :to => aspect.id
|
||||||
|
|
||||||
|
RakeHelpers::fix_periods_in_username(false)
|
||||||
|
|
||||||
|
new_d_handle = "max@#{APP_CONFIG[:pod_uri].host}"
|
||||||
|
|
||||||
|
User.first.username.should == 'max'
|
||||||
|
User.first.person.diaspora_handle.should == new_d_handle
|
||||||
|
User.first.my_posts.all.all?{|x| x.diaspora_handle == new_d_handle}.should == true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue