Skip to content
Extraits de code Groupes Projets
Valider 408b58cb rédigé par maxwell's avatar maxwell
Parcourir les fichiers

Merge branch 'safe-without-gpg'

parents 6cc9deaa 583d3d0c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
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
......@@ -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
module PersonRequestsHelper
end
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
......@@ -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
......
......@@ -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
......
......@@ -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
......@@ -3,7 +3,7 @@
%p
= f.label :destination_url
= f.text_field :destiation_url
= f.text_field :destination_url
%p
......
%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
......@@ -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
......
......@@ -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'
......
......@@ -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
......
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
......@@ -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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter