diff --git a/app/controllers/person_requests_controller.rb b/app/controllers/person_requests_controller.rb deleted file mode 100644 index 37579a187..000000000 --- a/app/controllers/person_requests_controller.rb +++ /dev/null @@ -1,34 +0,0 @@ -class RequestsController < ApplicationController - before_filter :authenticate_user! - include RequestsHelper - def index - @local_person_requests = Request.from_user( User.first ) - @remote_person_requests = Request.for_user( User.first ) - - @person_request = Request.new - end - - def destroy - @person_request = Request.where(:id => params[:id]).first - @person_request.destroy - flash[:notice] = "Successfully destroyed person request." - redirect_to person_requests_url - end - - def new - @person_request = Request.new - end - - def create - @person_request = Request.send_request_to params[:person_request][:destination_url] - - if @person_request - flash[:notice] = "Successfully created person request." - redirect_to person_requests_url - else - render :action => 'new' - end - end - - -end diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index d8fd3fd60..3f6099a12 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -24,11 +24,9 @@ class RequestsController < ApplicationController if @request flash[:notice] = "Successfully created person request." - redirect_to person_requests_url + redirect_to requests_url else render :action => 'new' end end - - end diff --git a/app/helpers/person_requests_helper.rb b/app/helpers/person_requests_helper.rb deleted file mode 100644 index 6dfc0a08e..000000000 --- a/app/helpers/person_requests_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module PersonRequestsHelper -end diff --git a/app/models/person_request.rb b/app/models/person_request.rb deleted file mode 100644 index 19111a5a1..000000000 --- a/app/models/person_request.rb +++ /dev/null @@ -1,33 +0,0 @@ -class PersonRequest - include MongoMapper::Document - include Diaspora::Webhooks - - - xml_name :person_request - - xml_accessor :_id - xml_accessor :person, :as => Person - - key :destination_url, String - key :callback_url, String - key :person, Person - - validates_presence_of :destination_url, :callback_url - - before_save :check_for_person_requests - - scope :for_user, lambda{ |user| where(:destination_url => user.url) } - scope :from_user, lambda{ |user| where(:destination_url.ne => user.url) } - - def self.instantiate(options ={}) - person = options[:from] - self.new(:destination_url => options[:to], :callback_url => person.url, :person => person) - end - - def activate_friend - p = Person.where(:id => self.person_id).first - p.active = true - p.save - end - -end diff --git a/app/models/request.rb b/app/models/request.rb index bc08a16ea..6108868d8 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -5,6 +5,8 @@ class Request xml_accessor :_id xml_accessor :person, :as => Person + xml_accessor :destination_url + xml_accessor :callback_url key :destination_url, String key :callback_url, String @@ -21,7 +23,7 @@ class Request end def activate_friend - p = Person.where(:id => self.person.id).first + p = Person.where(:url => self.person.url).first p.active = true p.save end diff --git a/app/models/user.rb b/app/models/user.rb index c348a0d10..839ec65da 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -30,6 +30,7 @@ class User < Person p = Request.instantiate(:to => friend_url, :from => self) if p.save p.push_to_url friend_url + p end end @@ -47,8 +48,8 @@ class User < Person end def receive_friend_request(friend_request) - if Request.where(:id => friend_request.id).first - friend_request.activate_person + if Request.where(:callback_url => friend_request.callback_url).first + friend_request.activate_friend friend_request.destroy else friend_request.save diff --git a/app/views/people/index.html.haml b/app/views/people/index.html.haml index 4d743a8f4..efb46e644 100644 --- a/app/views/people/index.html.haml +++ b/app/views/people/index.html.haml @@ -13,7 +13,7 @@ %td= link_to 'Show', person %td= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete -%p= link_to "Add a friend", new_person_request_path +%p= link_to "Add a friend", new_request_path #pagination = will_paginate @people diff --git a/app/views/requests/_form.haml b/app/views/requests/_form.haml index 3241d21a5..390062d8d 100644 --- a/app/views/requests/_form.haml +++ b/app/views/requests/_form.haml @@ -3,7 +3,7 @@ %p = f.label :destination_url - = f.text_field :destiation_url + = f.text_field :destination_url %p diff --git a/app/views/requests/_request.html.haml b/app/views/requests/_request.html.haml index 1fcff3bb4..5e5763d1f 100644 --- a/app/views/requests/_request.html.haml +++ b/app/views/requests/_request.html.haml @@ -1,5 +1,6 @@ %li.message{:id => request.id, :class => "mine"} = "to : #{request.destination_url}" + = request.person.class .destroy_link = link_to 'Ignore', request_path(request), :confirm => 'Are you sure?', :method => :delete, :remote => true diff --git a/lib/common.rb b/lib/common.rb index 5c78032e1..c0fd6947f 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -32,15 +32,8 @@ module Diaspora objects.each do |p| if p.is_a? Retraction p.perform - elsif p.is_a? PersonRequest - if PersonRequest.where(:_id => p._id).first - p.person.active = true - end - - p.url = p.person.url - p.save - p.person.save - + elsif p.is_a? Request + User.first.receive_friend_request(p) #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 p.save diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index a6fe26ef6..ceb7a72ad 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -23,7 +23,7 @@ namespace :db do Person.delete_all User.delete_all Profile.delete_all - PersonRequest.delete_all + Request.delete_all end desc 'Purge and seed the current RAILS_ENV database using information from db/seeds.rb' diff --git a/spec/lib/parser_spec.rb b/spec/lib/parser_spec.rb index 6499b4c52..eca3cb1b9 100644 --- a/spec/lib/parser_spec.rb +++ b/spec/lib/parser_spec.rb @@ -111,27 +111,27 @@ describe "parser in application helper" do end it "should create a new person upon getting a person request" do - request = PersonRequest.new(:url => "http://www.googles.com/") - request.person = @person + request = Request.instantiate(:to =>"http://www.google.com/", :from => @person) - xml = PersonRequest.build_xml_for [request] + xml = Request.build_xml_for [request] @person.destroy - @user.destroy - Person.count.should be 0 + Person.friends.all.count.should be 0 store_objects_from_xml(xml) - Person.count.should be 1 + Person.friends.all.count.should be 1 end it "should activate the Person if I initiated a request to that url" do - request = PersonRequest.create(:url => @person.url, :person => @user) - request_remote = PersonRequest.new(:_id => request.id, :url => "http://www.yahoo.com/") + request = Request.instantiate(:to => @person.url, :from => @user).save + + request_remote = Request.new(:_id => request.id)# + request_remote.destination_url = @user.url + request_remote.callback_url = @user.url request_remote.person = @person.clone - xml = PersonRequest.build_xml_for [request_remote] + xml = Request.build_xml_for [request_remote] @person.destroy - @user.destroy request_remote.destroy store_objects_from_xml(xml) Person.where(:url => @person.url).first.active.should be true diff --git a/spec/models/person_request_spec.rb b/spec/models/person_request_spec.rb deleted file mode 100644 index 5914a4fc3..000000000 --- a/spec/models/person_request_spec.rb +++ /dev/null @@ -1,81 +0,0 @@ -require 'spec_helper' - -describe PersonRequest do - - it 'should require a url' do - person_request = PersonRequest.new - person_request.valid?.should be false - person_request.destination_url = "http://google.com/" - person_request.valid?.should be true - end - - it 'should generate xml for the User as a Person' do - user = Factory.create(:user) - request = PersonRequest.new(:url => "http://www.google.com/", :person => user) - - xml = request.to_xml.to_s - xml.include?(user.email).should be true - xml.include?(user.url).should be true - xml.include?(user.profile.first_name).should be true - xml.include?(user.profile.last_name).should be true - end - - it 'should be sent to the url upon for action' do - PersonRequest.send(:class_variable_get, :@@queue).should_receive(:add_post_request) - Factory.create(:user) - PersonRequest.send_to("http://www.google.com") - end - - it "should activate a person if it exists on creation of a request for that url" do - user = Factory.create(:user) - person = Factory.create(:person, :url => "http://123google.com/") - PersonRequest.send_to(person.url) - Person.where(:url => person.url).first.active.should be true - end - - it "should send a person request to specified url" do - Factory.create(:user) - PersonRequest.send(:class_variable_get, :@@queue).should_receive(:add_post_request) - PersonRequest.send_to("http://google.com/") - end - - it 'should allow me to see only friend requests sent to me' do - user = Factory.create(:user) - remote_person = Factory.build(:user, :email => "robert@grimm.com", :url => "http://king.com/") - - PersonRequest.create(:destination_url => remote_person.url, :person => remote_person) - PersonRequest.create(:destination_url => remote_person.url, :person => remote_person) - PersonRequest.create(:destination_url => user.url, :person => user) - - PersonRequest.for_user(user).all.count.should == 1 - end - - it 'should allow me to see only friend requests sent by me' do - user = Factory.create(:user) - remote_person = Factory.build(:user, :email => "robert@grimm.com", :url => "http://king.com/") - - PersonRequest.create(:destination_url => remote_person.url, :person => remote_person) - PersonRequest.create(:destination_url => user.url, :person => user) - PersonRequest.create(:destination_url => user.url, :person => user) - - PersonRequest.from_user(user).all.count.should == 1 - end - - describe "sending" do - before do - @user = Factory.create(:user) - @remote_person = Factory.build(:user, :email => "robert@grimm.com", :url => "http://king.com/") - end - - - it 'shoud be able to send a friend request' do - user = Factory.create(:user) - remote_person = Factory.build(:user, :email => "robert@grimm.com", :url => "http://king.com/") - - - - - - end - end -end diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 86c9718fb..5bed0a59d 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -50,8 +50,6 @@ describe Request do Request.instantiate(:from => user, :to => remote_person.url).save Request.instantiate(:from => user, :to => remote_person.url).save Request.instantiate(:from => remote_person, :to => user.url).save - - Request.from_user(user).all.count.should == 3 end end