diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 034eef546..052df272a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 1291513d1..573236b41 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -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 diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index baecafd1a..838a0d39d 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -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 diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index 6e5461506..41e3d13b3 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -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 diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 22dbbe286..c3d1e7df1 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a76ccabbf..6f04621ea 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/models/contact.rb b/app/models/contact.rb index cfab568a7..f6eb06fe9 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -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) diff --git a/app/models/notifications/started_sharing.rb b/app/models/notifications/started_sharing.rb index e97d69c70..85c3dd5a4 100644 --- a/app/models/notifications/started_sharing.rb +++ b/app/models/notifications/started_sharing.rb @@ -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 diff --git a/app/models/person.rb b/app/models/person.rb index 6c4f6eb1a..87fc82aff 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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 diff --git a/app/models/request.rb b/app/models/request.rb index b2c610d52..39c1b1ad0 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -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 diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index 0fc41d645..0709c208b 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -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 diff --git a/app/views/users/getting_started/_step_3.html.haml b/app/views/users/getting_started/_step_3.html.haml index 83edbc25c..232ef0ef5 100644 --- a/app/views/users/getting_started/_step_3.html.haml +++ b/app/views/users/getting_started/_step_3.html.haml @@ -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} diff --git a/db/migrate/20110330230206_pm_foreign_keys.rb b/db/migrate/20110330230206_pm_foreign_keys.rb index 98fcd3a1d..7430cb9c0 100644 --- a/db/migrate/20110330230206_pm_foreign_keys.rb +++ b/db/migrate/20110330230206_pm_foreign_keys.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index db74ad98e..9bc78e22d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/features/manages_contact_requests.feature b/features/manages_contact_requests.feature deleted file mode 100644 index 3a35d62fe..000000000 --- a/features/manages_contact_requests.feature +++ /dev/null @@ -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 diff --git a/spec/controllers/post_visibilities_controller_spec.rb b/spec/controllers/post_visibilities_controller_spec.rb index 5760f7203..6a082da8a 100644 --- a/spec/controllers/post_visibilities_controller_spec.rb +++ b/spec/controllers/post_visibilities_controller_spec.rb @@ -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 diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index f2829765f..3297075c2 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -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 diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 57f23cbc4..856db7e9a 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -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 diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index da060e561..9793fbd2b 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -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 diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index 78c259901..0f60989e9 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -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)