DG IZ; fixed person requesting (friend requests).
This commit is contained in:
parent
3d105e7c1e
commit
a33acd134e
11 changed files with 81 additions and 58 deletions
|
|
@ -1,30 +1,26 @@
|
||||||
class PersonRequest
|
class PersonRequest
|
||||||
include MongoMapper::Document
|
include MongoMapper::Document
|
||||||
include Diaspora::Webhooks
|
include Diaspora::Webhooks
|
||||||
|
include ROXML
|
||||||
|
|
||||||
|
xml_name :person_request
|
||||||
|
|
||||||
|
xml_accessor :_id
|
||||||
|
xml_accessor :person, :as => Person
|
||||||
|
|
||||||
key :url, String
|
key :url, String
|
||||||
|
key :person, Person
|
||||||
attr_accessor :sender
|
|
||||||
|
|
||||||
validates_presence_of :url
|
validates_presence_of :url
|
||||||
|
|
||||||
before_save :check_for_person_requests
|
before_save :check_for_person_requests
|
||||||
|
|
||||||
def to_person_xml
|
|
||||||
person = Person.new
|
|
||||||
person.email = sender.email
|
|
||||||
person.url = sender.url
|
|
||||||
person.profile = sender.profile.clone
|
|
||||||
|
|
||||||
person.to_xml
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.for(url)
|
def self.for(url)
|
||||||
person_request = PersonRequest.new(:url => url)
|
request = PersonRequest.new(:url => url)
|
||||||
person_request.sender = User.first
|
request.person = User.first
|
||||||
person_request.save
|
request.save
|
||||||
|
|
||||||
person_request.push_person_request_to_url(person_request.url)
|
request.push_to([request])
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_for_person_requests
|
def check_for_person_requests
|
||||||
|
|
|
||||||
9
app/views/person_requests/_form.html.haml
Normal file
9
app/views/person_requests/_form.html.haml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
= form_for @person_request do |f|
|
||||||
|
= f.error_messages
|
||||||
|
|
||||||
|
%p
|
||||||
|
= f.label :url
|
||||||
|
= f.text_field :url
|
||||||
|
|
||||||
|
%p
|
||||||
|
= f.submit
|
||||||
9
app/views/person_requests/_new_person_request.haml
Normal file
9
app/views/person_requests/_new_person_request.haml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
= form_for @person_request, :remote => true do |f|
|
||||||
|
= f.error_messages
|
||||||
|
|
||||||
|
%p
|
||||||
|
= f.label :url
|
||||||
|
= f.text_field :url
|
||||||
|
|
||||||
|
%p
|
||||||
|
= f.submit
|
||||||
2
app/views/person_requests/_person_request.html.haml
Normal file
2
app/views/person_requests/_person_request.html.haml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
%li.message{:id => person_request.id}
|
||||||
|
= person_request.inspect
|
||||||
8
app/views/person_requests/edit.html.haml
Normal file
8
app/views/person_requests/edit.html.haml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
- title "Edit Person Request"
|
||||||
|
|
||||||
|
= render 'form'
|
||||||
|
|
||||||
|
%p
|
||||||
|
= link_to "Show", person_request_path(@person_request)
|
||||||
|
|
|
||||||
|
= link_to "View All", person_request_path
|
||||||
7
app/views/person_requests/index.html.haml
Normal file
7
app/views/person_requests/index.html.haml
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
%h1 person requests
|
||||||
|
= render "person_requests/new_person_request", :person_request => @person_request
|
||||||
|
%ul#stream
|
||||||
|
- for person_request in @person_requests
|
||||||
|
= render "person_request", :person_request => person_request
|
||||||
|
#pagination
|
||||||
|
= will_paginate @person_requests
|
||||||
5
app/views/person_requests/new.html.haml
Normal file
5
app/views/person_requests/new.html.haml
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
- title "New Person Request"
|
||||||
|
|
||||||
|
= render 'form'
|
||||||
|
|
||||||
|
%p= link_to "Back to List", person_requests_path
|
||||||
11
app/views/person_requests/show.html.haml
Normal file
11
app/views/person_requests/show.html.haml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
- title "Person Request"
|
||||||
|
|
||||||
|
%p
|
||||||
|
= person_request.inspect
|
||||||
|
|
||||||
|
%p
|
||||||
|
= link_to "Edit", edit_person_request_path(@person_request)
|
||||||
|
|
|
||||||
|
= link_to "Destroy", @person_request, :confirm => 'Are you sure?', :method => :delete
|
||||||
|
|
|
||||||
|
= link_to "View All", person_requests_path
|
||||||
|
|
@ -33,11 +33,12 @@ module Diaspora
|
||||||
objects.each do |p|
|
objects.each do |p|
|
||||||
if p.is_a? Retraction
|
if p.is_a? Retraction
|
||||||
p.perform
|
p.perform
|
||||||
elsif p.is_a? Person
|
elsif p.is_a? PersonRequest
|
||||||
if PersonRequest.where(:url => p.url).first
|
if PersonRequest.where(:url => p.url).first
|
||||||
p.active = true
|
p.active = true
|
||||||
end
|
end
|
||||||
p.save
|
p.save
|
||||||
|
p.person.save
|
||||||
#This line checks if the sender was in the database, among other things?
|
#This line checks if the sender was in the database, among other things?
|
||||||
elsif p.respond_to?(:person) && !(p.person.nil?) && !(p.person.is_a? User) #WTF
|
elsif p.respond_to?(:person) && !(p.person.nil?) && !(p.person.is_a? User) #WTF
|
||||||
p.save
|
p.save
|
||||||
|
|
@ -68,19 +69,6 @@ module Diaspora
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def push_person_request_to_url(url)
|
|
||||||
if url
|
|
||||||
url = url + "receive/"
|
|
||||||
xml = "<XML>
|
|
||||||
<posts><post>
|
|
||||||
#{self.to_person_xml.to_s}
|
|
||||||
</post></posts>
|
|
||||||
</XML>"
|
|
||||||
@@queue.add_post_request( [url], xml )
|
|
||||||
@@queue.process
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def prep_webhook
|
def prep_webhook
|
||||||
"<post>#{self.to_xml.to_s}</post>"
|
"<post>#{self.to_xml.to_s}</post>"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -111,13 +111,10 @@ describe "parser in application helper" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should create a new person upon getting a person request" do
|
it "should create a new person upon getting a person request" do
|
||||||
person_request = PersonRequest.new(:url => "http://www.googles.com/")
|
request = PersonRequest.new(:url => "http://www.googles.com/")
|
||||||
person_request.sender = @person
|
request.person = @person
|
||||||
xml = "<XML>
|
|
||||||
<posts><post>
|
xml = Post.build_xml_for [request]
|
||||||
#{person_request.to_person_xml.to_s}
|
|
||||||
</post></posts>
|
|
||||||
</XML>"
|
|
||||||
|
|
||||||
@person.destroy
|
@person.destroy
|
||||||
@user.destroy
|
@user.destroy
|
||||||
|
|
@ -127,22 +124,13 @@ describe "parser in application helper" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should activate the Person if I initiated a request to that url" do
|
it "should activate the Person if I initiated a request to that url" do
|
||||||
person_request = PersonRequest.create(:url => @person.url, :sender => @user)
|
request = PersonRequest.create(:url => @person.url, :person => @user)
|
||||||
|
request_remote = PersonRequest.new(:url => "http://www.yahoo.com/")
|
||||||
|
request_remote.person = @person.clone
|
||||||
|
|
||||||
person_request_remote = PersonRequest.new(:url => "http://www.yahoo.com/")
|
xml = Post.build_xml_for [request_remote]
|
||||||
person_request_remote.sender = @person.clone
|
|
||||||
xml = "<XML>
|
|
||||||
<posts><post>
|
|
||||||
#{person_request_remote.to_person_xml.to_s}
|
|
||||||
</post></posts>
|
|
||||||
</XML>"
|
|
||||||
|
|
||||||
@person.destroy
|
Person.where(:url => @person.url).first.active.should be true
|
||||||
@user.destroy
|
|
||||||
Person.count.should be 0
|
|
||||||
store_objects_from_xml(xml)
|
|
||||||
Person.count.should be 1
|
|
||||||
Person.first.active.should be true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,14 @@ describe PersonRequest do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate xml for the User as a Person' do
|
it 'should generate xml for the User as a Person' do
|
||||||
person_request = PersonRequest.new(:url => "http://www.google.com")
|
|
||||||
user = Factory.create(:user)
|
user = Factory.create(:user)
|
||||||
person_request.sender = user
|
request = PersonRequest.new(:url => "http://www.google.com/", :person => user)
|
||||||
person_xml = person_request.to_person_xml.to_s
|
|
||||||
person_xml.include?(user.email).should be true
|
xml = request.to_xml.to_s
|
||||||
person_xml.include?(user.url).should be true
|
xml.include?(user.email).should be true
|
||||||
person_xml.include?(user.profile.first_name).should be true
|
xml.include?(user.url).should be true
|
||||||
person_xml.include?(user.profile.last_name).should be true
|
xml.include?(user.profile.first_name).should be true
|
||||||
|
xml.include?(user.profile.last_name).should be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be sent to the url upon for action' do
|
it 'should be sent to the url upon for action' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue