adding a task to fix person object with spaces in their name
This commit is contained in:
parent
5d336d20e8
commit
6bd42874e8
3 changed files with 97 additions and 8 deletions
|
|
@ -28,4 +28,53 @@ module RakeHelpers
|
|||
end
|
||||
churn_through
|
||||
end
|
||||
|
||||
def fix_diaspora_handle_spaces(test = true)
|
||||
offenders = {}
|
||||
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
|
||||
totally_messed_up_people = space_people.find_all{|x| x.owner.nil?}
|
||||
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.each do |person|
|
||||
user = person.owner
|
||||
new_diaspora_handle = "#{user.username}@#{APP_CONFIG[:pod_uri].host}"
|
||||
|
||||
user.my_posts.all.each do |post|
|
||||
post.diaspora_handle = new_diaspora_handle
|
||||
if test
|
||||
(puts "TEST: saving post w/id #{post.id}")
|
||||
else
|
||||
post.save(:safe => true)
|
||||
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
|
||||
|
||||
mail = <<mail
|
||||
Hi, #{person.name}, 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!
|
||||
|
||||
- The Diaspora Team
|
||||
mail
|
||||
Notifier.admin(mail, [user]).each{|x| x.deliver unless test}
|
||||
end
|
||||
end
|
||||
|
||||
def fix_periods
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
namespace :migrations do
|
||||
|
||||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
|
||||
require File.join(Rails.root, 'lib/rake_helpers')
|
||||
include RakeHelpers
|
||||
|
||||
namespace :migrations do
|
||||
desc 'make old registered services into the new class specific services'
|
||||
task :service_reclassify do
|
||||
require File.join(Rails.root,"config/environment")
|
||||
Service.all.each do |s|
|
||||
puts s.inspect
|
||||
|
||||
provider = s.provider
|
||||
if provider
|
||||
|
|
@ -17,12 +23,16 @@ namespace :migrations do
|
|||
puts "all done"
|
||||
end
|
||||
|
||||
desc 'allow to upgrade old image urls to use rel path'
|
||||
task :swtich_image_urls do
|
||||
|
||||
desc 'fix people with spaces in their diaspora handles'
|
||||
task :fix_space_in_diaspora_handles do
|
||||
RakeHelpers::fix_diaspora_handle_spaces(false)
|
||||
end
|
||||
|
||||
desc 'move all posts and photos to new schema'
|
||||
task :migrate_status_message_to_posts do
|
||||
desc 'fix usernames with periods in them'
|
||||
task :fix_periods_in_username do
|
||||
end
|
||||
|
||||
desc 'purge broken contacts'
|
||||
task :purge_broken_contacts do
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -35,7 +35,37 @@ describe RakeHelpers do
|
|||
User.count.should == 1
|
||||
User.first.invites.should == 10
|
||||
end
|
||||
end
|
||||
|
||||
describe '#fix_spaces' do
|
||||
|
||||
before do
|
||||
Factory(:person)
|
||||
5.times do |number|
|
||||
f = Factory.create(:user)
|
||||
f.person.diaspora_handle = "#{f.username} #{APP_CONFIG[:pod_uri].host}"
|
||||
f.person.url = APP_CONFIG[:pod_url]
|
||||
f.person.save(:validate => false)
|
||||
end
|
||||
p = Factory(:person)
|
||||
p.diaspora_handle = "bubblegoose @#{APP_CONFIG[:pod_uri].host}"
|
||||
p.url = APP_CONFIG[:pod_url]
|
||||
p.save(:validate => false)
|
||||
end
|
||||
|
||||
it 'should fix diaspora handles' do
|
||||
|
||||
|
||||
RakeHelpers::fix_diaspora_handle_spaces(false)
|
||||
|
||||
Person.all.all?{|x| !x.diaspora_handle.include?(" ")}.should == true
|
||||
end
|
||||
|
||||
it 'should delete broken space people with no users' do
|
||||
expect{
|
||||
RakeHelpers::fix_diaspora_handle_spaces(false)
|
||||
}.to change(Person, :count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue