diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 20af009daea8682380f344b27452dd254e04ea0f..922d3cdbda6168d8f0cec2e1162fea0d99fa2b12 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -53,7 +53,7 @@ class AspectsController < ApplicationController elsif params[:aspect][:share_with] @contact = Contact.where(:id => params[:aspect][:contact_id]).first @person = Person.where(:id => params[:aspect][:person_id]).first - @contact = current_user.contact_for(@person) + @contact = current_user.contact_for(@person) || Contact.new respond_to do |format| format.js { render :json => {:html => render_to_string( diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index e5404d35157c7b1a238e92dc93d021cd0952675b..c64d51a376a2109ab7b53d6e1ac39d01c92682c7 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -6,31 +6,54 @@ class ContactsController < ApplicationController before_filter :authenticate_user! def new - #should be share_with? - render :nothing => true + @person = Person.find(params[:person_id]) + @aspects_with_person = [] + @aspects_without_person = current_user.aspects + @contact = Contact.new + render :layout => false end def create @person = Person.find(params[:person_id]) @aspect = current_user.aspects.where(:id => params[:aspect_id]).first - request_to_aspect(@aspect, @person) + @contact = request_to_aspect(@aspect, @person) - flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success' + if @contact && @contact.persisted? + flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success' - respond_to do |format| - format.js { render :json => { - :button_html => render_to_string(:partial => 'aspect_memberships/add_to_aspect', - :locals => {:aspect_id => @aspect.id, - :person_id => @person.id}), - :badge_html => render_to_string(:partial => 'aspects/aspect_badge', - :locals => {:aspect => @aspect}), - :contact_id => current_user.contact_for(@person).id - }} - format.html{ redirect_to aspect_path(@aspect.id)} + respond_to do |format| + format.js { render :json => { + :button_html => render_to_string(:partial => 'aspect_memberships/add_to_aspect', + :locals => {:aspect_id => @aspect.id, + :person_id => @person.id}), + :badge_html => render_to_string(:partial => 'aspects/aspect_badge', + :locals => {:aspect => @aspect}), + :contact_id => @contact.id + }} + format.html{ redirect_to aspect_path(@aspect.id)} + end + else + flash[:error] = I18n.t 'contacts.create.failure' + redirect_to :back end end + def edit + @contact = current_user.contacts.find(params[:id]) + + @person = @contact.person + @aspects_with_person = [] + + if @contact + @aspects_with_person = @contact.aspects + end + + @aspects_without_person = @all_aspects - @aspects_with_person + + render :layout => false + end + def destroy contact = current_user.contacts.where(:id => params[:id]).first if current_user.disconnect(contact) @@ -50,5 +73,6 @@ class ContactsController < ApplicationController request.destroy contact.update_attributes(:pending => false) end + contact end end diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index bae6b785ad5a43b86ceb9861191eadc9fb993e70..84d521d5df035da538f75e033e9731e017337bba 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -57,6 +57,9 @@ class PeopleController < ApplicationController if @contact @aspects_with_person = @contact.aspects @contacts_of_contact = @contact.contacts + else + @contact ||= Contact.new + @contacts_of_contact = [] end if (@person != current_user.person) && (!@contact || @contact.pending) @@ -67,7 +70,6 @@ class PeopleController < ApplicationController @posts = current_user.posts_from(@person).where(:type => "StatusMessage").paginate :per_page => 15, :page => params[:page] @fakes = PostsFake.new(@posts) - respond_with @person, :locals => {:post_type => :all} else @@ -85,20 +87,6 @@ class PeopleController < ApplicationController end end - def share_with - @person = Person.find(params[:id]) - @contact = current_user.contact_for(@person) - @aspects_with_person = [] - - if @contact - @aspects_with_person = @contact.aspects - end - - @aspects_without_person = @all_aspects - @aspects_with_person - - render :layout => nil - end - private def webfinger(account, opts = {}) Resque.enqueue(Job::SocketWebfinger, current_user.id, account, opts) diff --git a/app/helpers/aspects_helper.rb b/app/helpers/aspects_helper.rb index b658cc2f4c337b752221bf1891d52f8be3c15129..850404f913cca9ed87ce098fa1f21f0473b9abb5 100644 --- a/app/helpers/aspects_helper.rb +++ b/app/helpers/aspects_helper.rb @@ -42,7 +42,7 @@ module AspectsHelper end def contact_or_membership(contact) - (contact) ? 'aspect_memberships' : 'contacts' + (contact.persisted?) ? 'aspect_memberships' : 'contacts' end def aspect_membership_button(aspect, contact, person) diff --git a/app/views/people/_aspect_list.haml b/app/views/people/_aspect_list.haml index 02784a4083aba564db4daffb87c6164274a01681..8a3e121e5ef2bb87fdeb12e9818a82fd27e5cb27 100644 --- a/app/views/people/_aspect_list.haml +++ b/app/views/people/_aspect_list.haml @@ -4,26 +4,27 @@ - content_for :head do =javascript_include_tag 'contact-list' - .aspects - - if !contact + - if !contact || !contact.persisted? %h4 = link_to truncate(t('people.show.not_connected', :name => person.name), :length => 49, :separator => ' ', :omission => ''), - {:controller => "people", - :action => "share_with", - :id => @person.id}, + {:controller => "contacts", + :action => "new", + :person_id => person.id}, :class => 'share_with button', :rel => 'facebox' - elsif contact.pending %h4 = t('people.person.pending_request') - .badges{:class => ("hidden" if !contact)} - = aspect_badges(aspects_with_person) - %p - = link_to t('.edit_membership'), - {:controller => "people", - :action => "share_with", - :id => @person.id}, - :class => 'button', - :rel => 'facebox' + - else + .badges{:class => ("hidden" if !contact.persisted?)} + = aspect_badges(aspects_with_person) + %p + = link_to t('.edit_membership'), + {:controller => "contacts", + :action => "edit", + :id => contact.id, + :person_id => person.id}, + :class => 'button', + :rel => 'facebox' diff --git a/app/views/people/_person.html.haml b/app/views/people/_person.html.haml index 228ad17e09cc27a50c7b2935fee6b78e56e96a78..01dce704302f2c36bc5a7ccc89fe01ec5afd0495 100644 --- a/app/views/people/_person.html.haml +++ b/app/views/people/_person.html.haml @@ -13,16 +13,16 @@ = t('.pending_request') - elsif request && request.sender == person = link_to t('people.show.incoming_request', :name => truncate(person.name, :length => 20, :separator => ' ', :omission => '')), - {:controller => "people", - :action => "share_with", - :id => person.id}, + {:controller => "contacts", + :action => "new", + :person_id => person.id}, :class => 'share_with button', :rel => 'facebox' - else = link_to t('people.show.start_sharing'), - {:controller => "people", - :action => "share_with", - :id => person.id}, + {:controller => "contacts", + :action => "new", + :person_id => person.id}, :class => 'button', :rel => 'facebox' diff --git a/app/views/people/_person.mobile.haml b/app/views/people/_person.mobile.haml index cc424791d40e4e1b7be5a9160a2d833de41b6b03..45b9f0326b37cde4b1e614c58fe76ef2aef2adb0 100644 --- a/app/views/people/_person.mobile.haml +++ b/app/views/people/_person.mobile.haml @@ -9,12 +9,19 @@ = t('.thats_you') - elsif contact && !contact.pending = t('.already_connected') - - elsif (contact && contact.pending) || request + - elsif (contact && contact.pending) || (request && request.recipient == person) = t('.pending_request') + - elsif request && request.sender == person + = link_to t('people.show.incoming_request', :name => truncate(person.name, :length => 20, :separator => ' ', :omission => '')), + {:controller => "contacts", + :action => "new", + :person_id => person.id}, + :class => 'share_with button', + :rel => 'facebox' - else = link_to t('people.show.start_sharing'), - {:controller => "people", - :action => "share_with", + {:controller => "contacts", + :action => "new", :id => person.id}, :class => 'button', :rel => 'facebox' diff --git a/app/views/people/_share_with_pane.html.haml b/app/views/people/_share_with_pane.html.haml deleted file mode 100644 index b980f18fd003ec903c2b635652546abba17b2a29..0000000000000000000000000000000000000000 --- a/app/views/people/_share_with_pane.html.haml +++ /dev/null @@ -1,33 +0,0 @@ --# Copyright (c) 2010, Diaspora Inc. This file is --# licensed under the Affero General Public License version 3 or later. See --# the COPYRIGHT file. - -.aspect_list#aspects_list{:data=> {:contact_id=> (contact ? contact.id : nil)}} - %ul - - for aspect in aspects_with_person - = render :partial => 'aspects/aspect_list_item', - :locals => {:aspect => aspect, :person => person, - :contact => contact} - - - for aspect in aspects_without_person - = render :partial => 'aspects/aspect_list_item', - :locals => {:aspect => aspect, :person => person, - :contact => contact} -.add_aspect - = form_for(Aspect.new, :remote => true) do |aspect| - .right - = aspect.submit t('.add_new_aspect'), :class => 'button' - = aspect.error_messages - = aspect.hidden_field :person_id, :value => person.id if person - = aspect.hidden_field :contact_id, :value => contact.id if contact - = aspect.hidden_field :share_with, :value => true - %p - = aspect.text_field :name, :style => "display:inline;" - %p.checkbox_select - = aspect.label :contacts_visible, t('aspects.edit.make_aspect_list_visible') - = aspect.check_box :contacts_visible, :checked => true, :default => true -.done - .right - = link_to t('aspects.aspect_contacts.done_editing'), "#", :class => "button", :onClick => '$.facebox.close();' - - if contact - = link_to t('people.profile_sidebar.remove_contact'), contact, :confirm => t('are_you_sure'), :method => :delete diff --git a/app/views/people/share_with.html.haml b/app/views/people/share_with.html.haml deleted file mode 100644 index 851f17ffee6e34d3fe8692769f06c1049963f9d7..0000000000000000000000000000000000000000 --- a/app/views/people/share_with.html.haml +++ /dev/null @@ -1,19 +0,0 @@ --# Copyright (c) 2010, Diaspora Inc. This file is --# licensed under the Affero General Public License version 3 or later. See --# the COPYRIGHT file. - -#share_with - #facebox_header - = person_image_link(@person, :size => :thumb_small) - %h4 - = t('.share_with', :name => @person.name) - - .description - = t('.accepts', :name => @person.first_name) - - = render :partial => 'share_with_pane', - :locals => {:person => @person, - :contact => @contact, - :aspects_with_person => @aspects_with_person, - :aspects_without_person => @aspects_without_person} - diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index cfb8506daef3a994c2ae1493bb462c2006950c84..d40ba3a1d1b7f9e7d9ee0091b8330f41b2001078 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -20,24 +20,24 @@ .span-15.last #author_info - - unless @contact || current_user.person == @person + - unless @contact.persisted? || current_user.person == @person .right - if @incoming_request = link_to t('.incoming_request', :name => truncate(@person.name, :length => 20, :separator => ' ', :omission => '')), - {:controller => "people", - :action => "share_with", - :id => @person.id}, + {:controller => "contacts", + :action => "new", + :person_id => @person.id}, :class => 'share_with button', :rel => 'facebox' -else = link_to t('.start_sharing'), - {:controller => "people", - :action => "share_with", - :id => @person.id}, + {:controller => "contacts", + :action => "new", + :person_id => @person.id}, :class => 'share_with button', :rel => 'facebox' - if @share_with - = javascript_tag "$(document).ready(function() {jQuery.facebox({ ajax: '#{share_with_path(:id => @person.id)}' });});" + = javascript_tag "$(document).ready(function() {jQuery.facebox({ ajax: '#{new_contact_path(:person_id => @person.id)}' });});" - else diff --git a/app/views/people/show.mobile.haml b/app/views/people/show.mobile.haml index da757958b2a601889a344e5539dda5e584caa271..95b0f4eda00d0f4d94e72bcc836d357e0feb0d57 100644 --- a/app/views/people/show.mobile.haml +++ b/app/views/people/show.mobile.haml @@ -10,8 +10,8 @@ - unless @contact || current_user.person == @person .right = link_to "start sharing", - {:controller => "people", - :action => "share_with", + {:controller => "contact", + :action => "new", :id => @person.id}, :class => 'share_with button', :rel => 'facebox' diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 750b6565b4a794ef9c7d82c069fa3f6b4e7996d9..265c279feba0bf91a7bcb0ab3441a530327eed47 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -42,6 +42,10 @@ en: destroy: success: "Successfully disconnected from %{name}" failure: "Failed to disconnect from %{name}" + share_with_pane: + share_with: "Start sharing with %{name}" + accepts: "Once %{name} accepts, you'll start seeing each other's posts on Diaspora" + add_new_aspect: "add to new aspect" new_requests: zero: "no new requests" one: "new request!" @@ -404,13 +408,8 @@ en: helper: results_for: " results for %{params}" people_on_pod_are_aware_of: " people on pod are aware of" - share_with: - share_with: "Start sharing with %{name}" - accepts: "Once %{name} accepts, you'll start seeing each other's posts on Diaspora" aspect_list: edit_membership: "edit aspect membership" - share_with_pane: - add_new_aspect: "add to new aspect" requests: manage_aspect_contacts: manage_within: "Manage contacts within" diff --git a/features/connects_users.feature b/features/connects_users.feature index e6a96148d2ca749569a9fb2d476b0dedaacd5b74..c0ee19a440b18c481c574a7d69699e8c38a1edf3 100644 --- a/features/connects_users.feature +++ b/features/connects_users.feature @@ -8,6 +8,7 @@ Feature: sending and receiving requests And I am on "alice@alice.alice"'s page And I press the first ".share_with.button" within "#author_info" And I press the first ".add.button" within "#facebox #aspects_list ul > li:first-child" + #And I debug And I wait for the ajax to finish Then I should see a ".added.button" within "#facebox #aspects_list ul > li:first-child" Then I go to the destroy user session page diff --git a/spec/controllers/contacts_controller_spec.rb b/spec/controllers/contacts_controller_spec.rb index e2ea06747aca86dfda1a1b94c5c99827e74bed38..5116640e24f804eb4cfbfd6a6fe46d5d3d95368a 100644 --- a/spec/controllers/contacts_controller_spec.rb +++ b/spec/controllers/contacts_controller_spec.rb @@ -25,15 +25,19 @@ describe ContactsController do end describe '#new' do + it 'assigns a person' do + get :new, :person_id => @user2.person.id + assigns[:person].should == @user2.person + end - it 'succeeds' do - pending "This is going to be new request" - get :new - response.should be_success + it 'assigns aspects without person' do + get :new, :person_id => @user2.person.id + assigns[:aspects_without_person].should =~ @user.aspects end end describe '#create' do + context 'with an incoming request' do before do @user3 = Factory.create(:user) @@ -58,6 +62,7 @@ describe ContactsController do before do @person = Factory(:person) end + it 'calls send_contact_request_to' do @user.should_receive(:send_contact_request_to).with(@person, @aspect1) post :create, @@ -65,6 +70,7 @@ describe ContactsController do :person_id => @person.id, :aspect_id => @aspect1.id end + it 'does not call add_contact_to_aspect' do @user.should_not_receive(:add_contact_to_aspect) post :create, @@ -72,6 +78,27 @@ describe ContactsController do :person_id => @person.id, :aspect_id => @aspect1.id end + + it 'failure flashes error' do + @controller.should_receive(:request_to_aspect).and_return(nil) + post :create, + :format => 'js', + :person_id => @person.id, + :aspect_id => @aspect1.id + flash[:error].should_not be_empty + end + end + end + + describe '#edit' do + it 'assigns a contact' do + get :edit, :id => @contact.id + assigns[:contact].should == @contact + end + + it 'assigns a person' do + get :edit, :id => @contact.id + assigns[:person].should == @contact.person end end diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index da3826c1d359c6e91526b3d75d9ae5d015ab7c26..b6b41acceb7fd7184c373ff9819004d47655ad6d 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -13,15 +13,6 @@ describe PeopleController do sign_in :user, @user end - describe '#share_with' do - before do - @person = Factory.create(:person) - end - it 'succeeds' do - get :share_with, :id => @person.id - response.should be_success - end - end describe '#index (search)' do before do @eugene = Factory.create(:person,