Merge branch 'master' of github.com:diaspora/diaspora
This commit is contained in:
commit
3866b83dab
5 changed files with 24 additions and 29 deletions
|
|
@ -27,21 +27,12 @@ class Person
|
||||||
|
|
||||||
timestamps!
|
timestamps!
|
||||||
|
|
||||||
before_save :strip_and_downcase_diaspora_handle
|
|
||||||
before_destroy :remove_all_traces
|
before_destroy :remove_all_traces
|
||||||
before_validation :clean_url
|
before_validation :clean_url
|
||||||
validates_presence_of :url, :profile, :serialized_public_key
|
validates_presence_of :url, :profile, :serialized_public_key
|
||||||
validates_format_of :url, :with =>
|
validates_format_of :url, :with =>
|
||||||
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
|
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
|
||||||
|
|
||||||
|
|
||||||
def strip_and_downcase_diaspora_handle
|
|
||||||
if self.diaspora_handle
|
|
||||||
self.diaspora_handle.strip!
|
|
||||||
self.diaspora_handle.downcase!
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.search(query)
|
def self.search(query)
|
||||||
return Person.all if query.to_s.empty?
|
return Person.all if query.to_s.empty?
|
||||||
query_tokens = query.to_s.strip.split(" ")
|
query_tokens = query.to_s.strip.split(" ")
|
||||||
|
|
@ -95,12 +86,14 @@ class Person
|
||||||
|
|
||||||
def self.by_webfinger(identifier, opts = {})
|
def self.by_webfinger(identifier, opts = {})
|
||||||
#need to check if this is a valid email structure, maybe should do in JS
|
#need to check if this is a valid email structure, maybe should do in JS
|
||||||
local_person = Person.first(:diaspora_handle => identifier.gsub('acct:', '').to_s)
|
query = /#{Regexp.escape(identifier.gsub('acct:', '').to_s)}/i
|
||||||
|
local_person = Person.first(:diaspora_handle => query)
|
||||||
|
|
||||||
if local_person
|
if local_person
|
||||||
Rails.logger.info("Do not need to webfinger, found a local person #{local_person.real_name}")
|
Rails.logger.info("Do not need to webfinger, found a local person #{local_person.real_name}")
|
||||||
local_person
|
local_person
|
||||||
elsif !identifier.include?("localhost") && !opts[:local]
|
elsif !identifier.include?("localhost") && !opts[:local]
|
||||||
|
#Get remote profile
|
||||||
begin
|
begin
|
||||||
Rails.logger.info("Webfingering #{identifier}")
|
Rails.logger.info("Webfingering #{identifier}")
|
||||||
f = Redfinger.finger(identifier)
|
f = Redfinger.finger(identifier)
|
||||||
|
|
|
||||||
|
|
@ -388,7 +388,7 @@ class User
|
||||||
end
|
end
|
||||||
|
|
||||||
def diaspora_handle
|
def diaspora_handle
|
||||||
"#{self.username}@#{APP_CONFIG[:terse_pod_url]}".downcase
|
"#{self.username}@#{APP_CONFIG[:terse_pod_url]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def as_json(opts={})
|
def as_json(opts={})
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ if [ -n "$services" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if Mongo is running
|
# Check if Mongo is running
|
||||||
if ! pgrep mongod >/dev/null
|
if ! ps ax | grep -v grep | grep mongod >/dev/null
|
||||||
then
|
then
|
||||||
echo "Error: Mongod not started. Exiting" >&2
|
echo "Error: Mongod not started. Exiting" >&2
|
||||||
exit 64
|
exit 64
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,6 @@ describe Person do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#diaspora_handle' do
|
describe '#diaspora_handle' do
|
||||||
it 'should downcase and strip the handle before it saves' do
|
|
||||||
p = Factory.build(:person, :diaspora_handle => " FOOBaR@example.com ")
|
|
||||||
p.save
|
|
||||||
p.diaspora_handle.should == "foobar@example.com"
|
|
||||||
end
|
|
||||||
context 'local people' do
|
context 'local people' do
|
||||||
it 'uses the pod config url to set the diaspora_handle' do
|
it 'uses the pod config url to set the diaspora_handle' do
|
||||||
@user.person.diaspora_handle.should == @user.username + "@" + APP_CONFIG[:terse_pod_url]
|
@user.person.diaspora_handle.should == @user.username + "@" + APP_CONFIG[:terse_pod_url]
|
||||||
|
|
@ -30,14 +25,20 @@ describe Person do
|
||||||
@person.diaspora_handle.include?(APP_CONFIG[:terse_pod_url]).should be false
|
@person.diaspora_handle.include?(APP_CONFIG[:terse_pod_url]).should be false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
describe 'validation' do
|
||||||
|
it 'is unique' do
|
||||||
|
person_two = Factory.build(:person, :url => @person.diaspora_handle)
|
||||||
|
person_two.valid?.should be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'is case insensitive' do
|
||||||
|
person_two = Factory.build(:person, :url => @person.diaspora_handle.upcase)
|
||||||
|
person_two.valid?.should be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not allow two people with the same diaspora_handle' do
|
describe 'xml' do
|
||||||
person_two = Factory.build(:person, :url => @person.diaspora_handle)
|
|
||||||
person_two.valid?.should == false
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'xml' do
|
|
||||||
before do
|
before do
|
||||||
@xml = @person.to_xml.to_s
|
@xml = @person.to_xml.to_s
|
||||||
end
|
end
|
||||||
|
|
@ -52,7 +53,7 @@ describe Person do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should know when a post belongs to it' do
|
it '#owns? posts' do
|
||||||
person_message = Factory.create(:status_message, :person => @person)
|
person_message = Factory.create(:status_message, :person => @person)
|
||||||
person_two = Factory.create(:person)
|
person_two = Factory.create(:person)
|
||||||
|
|
||||||
|
|
@ -188,6 +189,12 @@ describe Person do
|
||||||
person = Person.by_webfinger(user.person.diaspora_handle)
|
person = Person.by_webfinger(user.person.diaspora_handle)
|
||||||
person.should == user.person
|
person.should == user.person
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "is case insensitive" do
|
||||||
|
user = Factory(:user, :username => "SaMaNtHa")
|
||||||
|
person = Person.by_webfinger(user.person.diaspora_handle.upcase)
|
||||||
|
person.should == user.person
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a stub for a remote user' do
|
it 'creates a stub for a remote user' do
|
||||||
|
|
|
||||||
|
|
@ -83,11 +83,6 @@ describe User do
|
||||||
it 'uses the pod config url to set the diaspora_handle' do
|
it 'uses the pod config url to set the diaspora_handle' do
|
||||||
user.diaspora_handle.should == user.username + "@" + APP_CONFIG[:terse_pod_url]
|
user.diaspora_handle.should == user.username + "@" + APP_CONFIG[:terse_pod_url]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be lowercase, even if username is uppercase' do
|
|
||||||
user.username = "fooBAR"
|
|
||||||
user.diaspora_handle.should == (user.username + "@" + APP_CONFIG[:terse_pod_url]).downcase
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'profiles' do
|
context 'profiles' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue