drop requests table wip

This commit is contained in:
danielgrippi 2011-04-06 19:01:41 -07:00
parent 2e5b5e1efe
commit 4f972a23f6
20 changed files with 63 additions and 148 deletions

View file

@ -8,7 +8,6 @@ class ApplicationController < ActionController::Base
before_filter :ensure_http_referer_is_set
before_filter :set_header_data, :except => [:create, :update]
before_filter :count_requests
before_filter :set_invites
before_filter :set_locale
before_filter :set_git_header if (AppConfig[:git_update] && AppConfig[:git_revision])
@ -34,10 +33,6 @@ class ApplicationController < ActionController::Base
end
end
def count_requests
@request_count = Request.where(:recipient_id => current_user.person.id).count if current_user
end
def set_invites
if user_signed_in?
@invites = current_user.invites

View file

@ -12,9 +12,6 @@ class PhotosController < ApplicationController
@person = Person.find_by_id(params[:person_id])
if @person
@incoming_request = Request.where(:recipient_id => current_user.person.id, :sender_id => @person.id).first
@outgoing_request = Request.where(:sender_id => current_user.person.id, :recipient_id => @person.id).first
@profile = @person.profile
@contact = current_user.contact_for(@person)
@is_contact = @person != current_user.person && @contact

View file

@ -3,7 +3,6 @@
# the COPYRIGHT file.
class PostsController < ApplicationController
skip_before_filter :count_requests
skip_before_filter :set_invites
skip_before_filter :which_action_and_user
skip_before_filter :set_grammatical_gender

View file

@ -7,7 +7,6 @@ class PublicsController < ApplicationController
include Diaspora::Parser
skip_before_filter :set_header_data
skip_before_filter :count_requests
skip_before_filter :set_invites
skip_before_filter :which_action_and_user
skip_before_filter :set_grammatical_gender

View file

@ -3,7 +3,6 @@
# the COPYRIGHT file.
class TagsController < ApplicationController
skip_before_filter :count_requests
skip_before_filter :set_invites
skip_before_filter :which_action_and_user
skip_before_filter :set_grammatical_gender

View file

@ -106,10 +106,8 @@ class UsersController < ApplicationController
end
if @step == 3
@requests = Request.where(:recipient_id => @person.id).includes(:sender => :profile).all
@friends = service ? service.finder(:local => true) : []
@friends ||= []
@friends.delete_if{|f| @requests.any?{ |r| r.sender_id == f.person.id} }
end

View file

@ -25,9 +25,9 @@ class Contact < ActiveRecord::Base
end
def generate_request
Request.new(:sender => self.user.person,
:recipient => self.person,
:aspect => aspects.first)
Request.diaspora_initialize(:from => self.user.person,
:to => self.person,
:into => aspects.first)
end
def receive_post(post)

View file

@ -5,4 +5,15 @@ class Notifications::StartedSharing < Notification
def translation_key
'started_sharing'
end
def email_the_user(target, actor)
super(target.sender, actor)
end
private
def self.make_notification(recipient, target, actor, notification_type)
super(recipient, target.sender, actor, notification_type)
end
end

View file

@ -72,9 +72,8 @@ class Person < ActiveRecord::Base
sql, tokens = self.search_query_string(query)
Person.searchable.where(sql, *tokens).joins(
"LEFT OUTER JOIN `contacts` ON `contacts`.user_id = #{user.id} AND `contacts`.person_id = `people`.id"
).joins("LEFT OUTER JOIN `requests` ON `requests`.recipient_id = #{user.person.id} AND `requests`.sender_id = `people`.id"
).includes(:profile
).order("contacts.user_id DESC", "requests.recipient_id DESC", "profiles.last_name ASC", "profiles.first_name ASC")
).order("contacts.user_id DESC", "profiles.last_name ASC", "profiles.first_name ASC")
end

View file

@ -2,29 +2,26 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Request < ActiveRecord::Base
require File.join(Rails.root, 'lib/diaspora/webhooks')
require File.join(Rails.root, 'lib/postzord/dispatch')
include Diaspora::Webhooks
class Request
include ROXML
include Diaspora::Webhooks
include ActiveModel::Validations
attr_accessor :sender, :recipient, :aspect
xml_accessor :sender_handle
xml_accessor :recipient_handle
belongs_to :sender, :class_name => 'Person'
belongs_to :recipient, :class_name => 'Person'
belongs_to :aspect
validates_uniqueness_of :sender_id, :scope => :recipient_id
validates_presence_of :sender, :recipient
validate :not_already_connected
validate :not_friending_yourself
def self.diaspora_initialize(opts = {})
self.new(:sender => opts[:from],
:recipient => opts[:to],
:aspect => opts[:into])
req = self.new
req.sender = opts[:from]
req.recipient = opts[:to]
req.aspect = opts[:into]
req
end
def reverse_for accepting_user
@ -63,7 +60,6 @@ class Request < ActiveRecord::Base
def receive(user, person)
Rails.logger.info("event=receive payload_type=request sender=#{self.sender} to=#{self.recipient}")
user.contacts.create(:person_id => person.id)
self.save
self
end

View file

@ -22,11 +22,6 @@
.description
= link_to current_user.diaspora_handle, person_path(current_user.person)
- if @notification_count > 0 || @request_count > 0
#new_requests
- if @request_count > 0
%h4
= new_request_link(@request_count)
%h4.section.invite_friends
!= t('bookmarklet.explanation', :link => link_to(t('bookmarklet.explanation_link_text'), bookmarklet))
- if @invites > 0

View file

@ -11,10 +11,6 @@
%br
#people_stream.stream
- for pending_req in @requests
- person = pending_req.sender
= render :partial => 'people/person', :locals => {:request => pending_req, :person => person, :contact => nil}
- for friend in @friends
= render :partial => 'people/person', :locals => {:request => friend.request, :person => friend.person, :contact => friend.contact}

View file

@ -41,8 +41,8 @@ SQL
remove_foreign_key :conversation_visibilities, :people
remove_foreign_key :messages, :conversations
remove_foreign_key :messages, :people, :column => :author_id
remove_foreign_key :messages, :column => :author_id
remove_foreign_key :conversations, :people, :column => :author_id
remove_foreign_key :conversations, :column => :author_id
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110405171412) do
ActiveRecord::Schema.define(:version => 20110406202932) do
create_table "aspect_memberships", :force => true do |t|
t.integer "aspect_id", :null => false
@ -275,20 +275,6 @@ ActiveRecord::Schema.define(:version => 20110405171412) do
add_index "profiles", ["mongo_id"], :name => "index_profiles_on_mongo_id"
add_index "profiles", ["person_id"], :name => "index_profiles_on_person_id"
create_table "requests", :force => true do |t|
t.integer "sender_id", :null => false
t.integer "recipient_id", :null => false
t.integer "aspect_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "mongo_id"
end
add_index "requests", ["mongo_id"], :name => "index_requests_on_mongo_id"
add_index "requests", ["recipient_id"], :name => "index_requests_on_recipient_id"
add_index "requests", ["sender_id", "recipient_id"], :name => "index_requests_on_sender_id_and_recipient_id", :unique => true
add_index "requests", ["sender_id"], :name => "index_requests_on_sender_id"
create_table "service_users", :force => true do |t|
t.string "uid", :null => false
t.string "name", :null => false
@ -413,9 +399,6 @@ ActiveRecord::Schema.define(:version => 20110405171412) do
add_foreign_key "profiles", "people", :name => "profiles_person_id_fk", :dependent => :delete
add_foreign_key "requests", "people", :name => "requests_recipient_id_fk", :column => "recipient_id", :dependent => :delete
add_foreign_key "requests", "people", :name => "requests_sender_id_fk", :column => "sender_id", :dependent => :delete
add_foreign_key "services", "users", :name => "services_user_id_fk", :dependent => :delete
end

View file

@ -1,38 +0,0 @@
Feature: managing contact requests
Background:
Given I am signed in
And I have an aspect called "Family"
And I have one follower
Scenario: seeing contact request notifications
When I am on the home page
Then I should see "All Aspects" in the header
When I follow "All Aspects"
Then I should see "new request!"
@javascript
Scenario: viewing a requests profile
When I am on the manage aspects page
When I click on the contact request
And I wait for "the requestors profile" to load
Then I should be on the requestors profile
And I should see "wants to share with you"
@javascript
Scenario: accepting a contact request
When I am on the home page
And I follow "new request!"
Then I should see 0 contacts in "Family"
When I drag the contact request to the "Family" aspect
And I wait for the ajax to finish
Then I should see 1 contact in "Family"
@javascript @wip
Scenario: ignoring a contact request
When I am on the aspects manage page
Then I should see 1 contact request
When I click "X" on the contact request
And I wait for the ajax to finish
Then I should see 0 contact requests

View file

@ -11,7 +11,7 @@ describe PostVisibilitiesController do
a2 = bob.aspects.create(:name => "two")
bob.contacts.create(:person => alice.person, :aspects => [a2])
@status = bob.post(:status_message, :text => "hello", :public => true, :to => a2)
@status = bob.post(:status_message, :text => "hello", :to => a2)
@vis = @status.post_visibilities.first
end

View file

@ -131,10 +131,6 @@ describe Contact do
Postzord::Dispatch.should_receive(:new).and_return(m)
@contact.dispatch_request
end
it 'persists no request' do
@contact.dispatch_request
Request.where(:sender_id => @user.person.id, :recipient_id => @person.id).should be_empty
end
end
end
end

View file

@ -49,6 +49,7 @@ describe Notification do
before do
@request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
end
it 'calls Notification.create if the object has a notification_type' do
Notification.should_receive(:make_notification).once
Notification.notify(@user, @request, @person)
@ -56,7 +57,7 @@ describe Notification do
it 'creates the notification already read' do
n = Notification.notify(@user, @request, @person)
n.unread?.should be_false
n.should_not be_unread
end
it 'sockets to the recipient' do

View file

@ -6,86 +6,85 @@ require 'spec_helper'
describe Request do
before do
@user = alice
@user2 = eve
@person = Factory :person
@aspect = @user.aspects.first
@aspect2 = @user2.aspects.first
@aspect = alice.aspects.first
end
describe 'validations' do
before do
@request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
@request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
end
it 'is valid' do
@request.sender.should == @user.person
@request.recipient.should == @user2.person
@request.sender.should == alice.person
@request.recipient.should == eve.person
@request.aspect.should == @aspect
@request.should be_valid
end
it 'is from a person' do
@request.sender = nil
@request.should_not be_valid
end
it 'is to a person' do
@request.recipient = nil
@request.should_not be_valid
end
it 'is not necessarily into an aspect' do
@request.aspect = nil
@request.should be_valid
end
it 'is not from an existing friend' do
Contact.create(:user => @user2, :person => @user.person, :aspects => [@aspect2])
Contact.create(:user => eve, :person => alice.person, :aspects => [eve.aspects.first])
@request.should_not be_valid
end
it 'is not a duplicate of an existing pending request' do
@request.save
duplicate_request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
duplicate_request.should_not be_valid
end
it 'is not to yourself' do
@request = Request.diaspora_initialize(:from => @user.person, :to => @user.person, :into => @aspect)
@request = Request.diaspora_initialize(:from => alice.person, :to => alice.person, :into => @aspect)
@request.should_not be_valid
end
end
describe '#notification_type' do
it 'returns request_accepted' do
request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
@user.contacts.create(:person_id => @person.id)
person = Factory :person
request.notification_type(@user, @person).should == Notifications::StartedSharing
request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
alice.contacts.create(:person_id => person.id)
request.notification_type(alice, person).should == Notifications::StartedSharing
end
end
describe '#subscribers' do
it 'returns an array with to field on a request' do
request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
request.subscribers(@user).should =~ [@user2.person]
request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
request.subscribers(alice).should =~ [eve.person]
end
end
describe '#receive' do
it 'creates a contact' do
request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
@user2.contacts.should_receive(:create).with(hash_including(:person_id => @user.person.id))
request.receive(@user2, @user.person)
request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
eve.contacts.should_receive(:create).with(hash_including(:person_id => alice.person.id))
request.receive(eve, alice.person)
end
end
context 'xml' do
before do
@request = Request.new(:sender => @user.person, :recipient => @user2.person, :aspect => @aspect)
@request = Request.diaspora_initialize(:from => alice.person, :to => eve.person, :into => @aspect)
@xml = @request.to_xml.to_s
end
describe 'serialization' do
it 'produces valid xml' do
@xml.should include @user.person.diaspora_handle
@xml.should include @user2.person.diaspora_handle
@xml.should_not include @user.person.exported_key
@xml.should_not include @user.person.profile.first_name
@xml.should include alice.person.diaspora_handle
@xml.should include eve.person.diaspora_handle
@xml.should_not include alice.person.exported_key
@xml.should_not include alice.person.profile.first_name
end
end
@ -93,8 +92,8 @@ describe Request do
it 'produces a request object' do
marshalled = Request.from_xml @xml
marshalled.sender.should == @user.person
marshalled.recipient.should == @user2.person
marshalled.sender.should == alice.person
marshalled.recipient.should == eve.person
marshalled.aspect.should be_nil
end
end

View file

@ -18,13 +18,11 @@ describe Diaspora::UserModules::Connecting do
context 'contact requesting' do
describe '#receive_contact_request' do
before do
@r = Request.diaspora_initialize(:to => alice.person, :from => person)
end
it 'creates a contact' do
r = Request.diaspora_initialize(:to => alice.person, :from => person)
lambda {
received_req = @r.receive(alice, person_one)
received_req = r.receive(alice, person_one)
}.should change(Contact, :count).by(1)
end
end
@ -55,14 +53,6 @@ describe Diaspora::UserModules::Connecting do
end
context 'received a contact request' do
before do
Request.diaspora_initialize(:from => person, :to => alice.person).save
Request.diaspora_initialize(:from => person_one, :to => alice.person).save
@received_request = Request.where(:sender_id => person.id, :recipient_id => alice.person.id).first
@received_request2 = Request.where(:sender_id => person_one.id, :recipient_id => alice.person.id).first
end
it 'should ignore a contact request from yourself' do
request_from_myself = Request.diaspora_initialize(:to => alice.person, :from => alice.person)
reversed_request = request_from_myself.reverse_for(alice)