pulled out share_with to be contact new and contact show
This commit is contained in:
parent
25671f07c7
commit
16b7ec3990
15 changed files with 120 additions and 134 deletions
|
|
@ -53,7 +53,7 @@ class AspectsController < ApplicationController
|
||||||
elsif params[:aspect][:share_with]
|
elsif params[:aspect][:share_with]
|
||||||
@contact = Contact.where(:id => params[:aspect][:contact_id]).first
|
@contact = Contact.where(:id => params[:aspect][:contact_id]).first
|
||||||
@person = Person.where(:id => params[:aspect][:person_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|
|
respond_to do |format|
|
||||||
format.js { render :json => {:html => render_to_string(
|
format.js { render :json => {:html => render_to_string(
|
||||||
|
|
|
||||||
|
|
@ -6,31 +6,54 @@ class ContactsController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
def new
|
def new
|
||||||
#should be share_with?
|
@person = Person.find(params[:person_id])
|
||||||
render :nothing => true
|
@aspects_with_person = []
|
||||||
|
@aspects_without_person = current_user.aspects
|
||||||
|
@contact = Contact.new
|
||||||
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@person = Person.find(params[:person_id])
|
@person = Person.find(params[:person_id])
|
||||||
@aspect = current_user.aspects.where(:id => params[:aspect_id]).first
|
@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|
|
respond_to do |format|
|
||||||
format.js { render :json => {
|
format.js { render :json => {
|
||||||
:button_html => render_to_string(:partial => 'aspect_memberships/add_to_aspect',
|
:button_html => render_to_string(:partial => 'aspect_memberships/add_to_aspect',
|
||||||
:locals => {:aspect_id => @aspect.id,
|
:locals => {:aspect_id => @aspect.id,
|
||||||
:person_id => @person.id}),
|
:person_id => @person.id}),
|
||||||
:badge_html => render_to_string(:partial => 'aspects/aspect_badge',
|
:badge_html => render_to_string(:partial => 'aspects/aspect_badge',
|
||||||
:locals => {:aspect => @aspect}),
|
:locals => {:aspect => @aspect}),
|
||||||
:contact_id => current_user.contact_for(@person).id
|
:contact_id => @contact.id
|
||||||
}}
|
}}
|
||||||
format.html{ redirect_to aspect_path(@aspect.id)}
|
format.html{ redirect_to aspect_path(@aspect.id)}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
flash[:error] = I18n.t 'contacts.create.failure'
|
||||||
|
redirect_to :back
|
||||||
end
|
end
|
||||||
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
|
def destroy
|
||||||
contact = current_user.contacts.where(:id => params[:id]).first
|
contact = current_user.contacts.where(:id => params[:id]).first
|
||||||
if current_user.disconnect(contact)
|
if current_user.disconnect(contact)
|
||||||
|
|
@ -50,5 +73,6 @@ class ContactsController < ApplicationController
|
||||||
request.destroy
|
request.destroy
|
||||||
contact.update_attributes(:pending => false)
|
contact.update_attributes(:pending => false)
|
||||||
end
|
end
|
||||||
|
contact
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,9 @@ class PeopleController < ApplicationController
|
||||||
if @contact
|
if @contact
|
||||||
@aspects_with_person = @contact.aspects
|
@aspects_with_person = @contact.aspects
|
||||||
@contacts_of_contact = @contact.contacts
|
@contacts_of_contact = @contact.contacts
|
||||||
|
else
|
||||||
|
@contact ||= Contact.new
|
||||||
|
@contacts_of_contact = []
|
||||||
end
|
end
|
||||||
|
|
||||||
if (@person != current_user.person) && (!@contact || @contact.pending)
|
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]
|
@posts = current_user.posts_from(@person).where(:type => "StatusMessage").paginate :per_page => 15, :page => params[:page]
|
||||||
@fakes = PostsFake.new(@posts)
|
@fakes = PostsFake.new(@posts)
|
||||||
|
|
||||||
respond_with @person, :locals => {:post_type => :all}
|
respond_with @person, :locals => {:post_type => :all}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
@ -85,20 +87,6 @@ class PeopleController < ApplicationController
|
||||||
end
|
end
|
||||||
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
|
private
|
||||||
def webfinger(account, opts = {})
|
def webfinger(account, opts = {})
|
||||||
Resque.enqueue(Job::SocketWebfinger, current_user.id, account, opts)
|
Resque.enqueue(Job::SocketWebfinger, current_user.id, account, opts)
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ module AspectsHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def contact_or_membership(contact)
|
def contact_or_membership(contact)
|
||||||
(contact) ? 'aspect_memberships' : 'contacts'
|
(contact.persisted?) ? 'aspect_memberships' : 'contacts'
|
||||||
end
|
end
|
||||||
|
|
||||||
def aspect_membership_button(aspect, contact, person)
|
def aspect_membership_button(aspect, contact, person)
|
||||||
|
|
|
||||||
|
|
@ -4,26 +4,27 @@
|
||||||
|
|
||||||
- content_for :head do
|
- content_for :head do
|
||||||
=javascript_include_tag 'contact-list'
|
=javascript_include_tag 'contact-list'
|
||||||
|
|
||||||
.aspects
|
.aspects
|
||||||
- if !contact
|
- if !contact || !contact.persisted?
|
||||||
%h4
|
%h4
|
||||||
= link_to truncate(t('people.show.not_connected', :name => person.name), :length => 49, :separator => ' ', :omission => ''),
|
= link_to truncate(t('people.show.not_connected', :name => person.name), :length => 49, :separator => ' ', :omission => ''),
|
||||||
{:controller => "people",
|
{:controller => "contacts",
|
||||||
:action => "share_with",
|
:action => "new",
|
||||||
:id => @person.id},
|
:person_id => person.id},
|
||||||
:class => 'share_with button',
|
:class => 'share_with button',
|
||||||
:rel => 'facebox'
|
:rel => 'facebox'
|
||||||
- elsif contact.pending
|
- elsif contact.pending
|
||||||
%h4
|
%h4
|
||||||
= t('people.person.pending_request')
|
= t('people.person.pending_request')
|
||||||
|
|
||||||
.badges{:class => ("hidden" if !contact)}
|
- else
|
||||||
= aspect_badges(aspects_with_person)
|
.badges{:class => ("hidden" if !contact.persisted?)}
|
||||||
%p
|
= aspect_badges(aspects_with_person)
|
||||||
= link_to t('.edit_membership'),
|
%p
|
||||||
{:controller => "people",
|
= link_to t('.edit_membership'),
|
||||||
:action => "share_with",
|
{:controller => "contacts",
|
||||||
:id => @person.id},
|
:action => "edit",
|
||||||
:class => 'button',
|
:id => contact.id,
|
||||||
:rel => 'facebox'
|
:person_id => person.id},
|
||||||
|
:class => 'button',
|
||||||
|
:rel => 'facebox'
|
||||||
|
|
|
||||||
|
|
@ -13,16 +13,16 @@
|
||||||
= t('.pending_request')
|
= t('.pending_request')
|
||||||
- elsif request && request.sender == person
|
- elsif request && request.sender == person
|
||||||
= link_to t('people.show.incoming_request', :name => truncate(person.name, :length => 20, :separator => ' ', :omission => '')),
|
= link_to t('people.show.incoming_request', :name => truncate(person.name, :length => 20, :separator => ' ', :omission => '')),
|
||||||
{:controller => "people",
|
{:controller => "contacts",
|
||||||
:action => "share_with",
|
:action => "new",
|
||||||
:id => person.id},
|
:person_id => person.id},
|
||||||
:class => 'share_with button',
|
:class => 'share_with button',
|
||||||
:rel => 'facebox'
|
:rel => 'facebox'
|
||||||
- else
|
- else
|
||||||
= link_to t('people.show.start_sharing'),
|
= link_to t('people.show.start_sharing'),
|
||||||
{:controller => "people",
|
{:controller => "contacts",
|
||||||
:action => "share_with",
|
:action => "new",
|
||||||
:id => person.id},
|
:person_id => person.id},
|
||||||
:class => 'button',
|
:class => 'button',
|
||||||
:rel => 'facebox'
|
:rel => 'facebox'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,19 @@
|
||||||
= t('.thats_you')
|
= t('.thats_you')
|
||||||
- elsif contact && !contact.pending
|
- elsif contact && !contact.pending
|
||||||
= t('.already_connected')
|
= t('.already_connected')
|
||||||
- elsif (contact && contact.pending) || request
|
- elsif (contact && contact.pending) || (request && request.recipient == person)
|
||||||
= t('.pending_request')
|
= 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
|
- else
|
||||||
= link_to t('people.show.start_sharing'),
|
= link_to t('people.show.start_sharing'),
|
||||||
{:controller => "people",
|
{:controller => "contacts",
|
||||||
:action => "share_with",
|
:action => "new",
|
||||||
:id => person.id},
|
:id => person.id},
|
||||||
:class => 'button',
|
:class => 'button',
|
||||||
:rel => 'facebox'
|
:rel => 'facebox'
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -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}
|
|
||||||
|
|
||||||
|
|
@ -20,24 +20,24 @@
|
||||||
|
|
||||||
.span-15.last
|
.span-15.last
|
||||||
#author_info
|
#author_info
|
||||||
- unless @contact || current_user.person == @person
|
- unless @contact.persisted? || current_user.person == @person
|
||||||
.right
|
.right
|
||||||
- if @incoming_request
|
- if @incoming_request
|
||||||
= link_to t('.incoming_request', :name => truncate(@person.name, :length => 20, :separator => ' ', :omission => '')),
|
= link_to t('.incoming_request', :name => truncate(@person.name, :length => 20, :separator => ' ', :omission => '')),
|
||||||
{:controller => "people",
|
{:controller => "contacts",
|
||||||
:action => "share_with",
|
:action => "new",
|
||||||
:id => @person.id},
|
:person_id => @person.id},
|
||||||
:class => 'share_with button',
|
:class => 'share_with button',
|
||||||
:rel => 'facebox'
|
:rel => 'facebox'
|
||||||
-else
|
-else
|
||||||
= link_to t('.start_sharing'),
|
= link_to t('.start_sharing'),
|
||||||
{:controller => "people",
|
{:controller => "contacts",
|
||||||
:action => "share_with",
|
:action => "new",
|
||||||
:id => @person.id},
|
:person_id => @person.id},
|
||||||
:class => 'share_with button',
|
:class => 'share_with button',
|
||||||
:rel => 'facebox'
|
:rel => 'facebox'
|
||||||
- if @share_with
|
- 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
|
- else
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@
|
||||||
- unless @contact || current_user.person == @person
|
- unless @contact || current_user.person == @person
|
||||||
.right
|
.right
|
||||||
= link_to "start sharing",
|
= link_to "start sharing",
|
||||||
{:controller => "people",
|
{:controller => "contact",
|
||||||
:action => "share_with",
|
:action => "new",
|
||||||
:id => @person.id},
|
:id => @person.id},
|
||||||
:class => 'share_with button',
|
:class => 'share_with button',
|
||||||
:rel => 'facebox'
|
:rel => 'facebox'
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,10 @@ en:
|
||||||
destroy:
|
destroy:
|
||||||
success: "Successfully disconnected from %{name}"
|
success: "Successfully disconnected from %{name}"
|
||||||
failure: "Failed to disconnect 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:
|
new_requests:
|
||||||
zero: "no new requests"
|
zero: "no new requests"
|
||||||
one: "new request!"
|
one: "new request!"
|
||||||
|
|
@ -404,13 +408,8 @@ en:
|
||||||
helper:
|
helper:
|
||||||
results_for: " results for %{params}"
|
results_for: " results for %{params}"
|
||||||
people_on_pod_are_aware_of: " people on pod are aware of"
|
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:
|
aspect_list:
|
||||||
edit_membership: "edit aspect membership"
|
edit_membership: "edit aspect membership"
|
||||||
share_with_pane:
|
|
||||||
add_new_aspect: "add to new aspect"
|
|
||||||
requests:
|
requests:
|
||||||
manage_aspect_contacts:
|
manage_aspect_contacts:
|
||||||
manage_within: "Manage contacts within"
|
manage_within: "Manage contacts within"
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ Feature: sending and receiving requests
|
||||||
And I am on "alice@alice.alice"'s page
|
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 ".share_with.button" within "#author_info"
|
||||||
And I press the first ".add.button" within "#facebox #aspects_list ul > li:first-child"
|
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
|
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 should see a ".added.button" within "#facebox #aspects_list ul > li:first-child"
|
||||||
Then I go to the destroy user session page
|
Then I go to the destroy user session page
|
||||||
|
|
|
||||||
|
|
@ -25,15 +25,19 @@ describe ContactsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#new' do
|
describe '#new' do
|
||||||
|
it 'assigns a person' do
|
||||||
|
get :new, :person_id => @user2.person.id
|
||||||
|
assigns[:person].should == @user2.person
|
||||||
|
end
|
||||||
|
|
||||||
it 'succeeds' do
|
it 'assigns aspects without person' do
|
||||||
pending "This is going to be new request"
|
get :new, :person_id => @user2.person.id
|
||||||
get :new
|
assigns[:aspects_without_person].should =~ @user.aspects
|
||||||
response.should be_success
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#create' do
|
describe '#create' do
|
||||||
|
|
||||||
context 'with an incoming request' do
|
context 'with an incoming request' do
|
||||||
before do
|
before do
|
||||||
@user3 = Factory.create(:user)
|
@user3 = Factory.create(:user)
|
||||||
|
|
@ -58,6 +62,7 @@ describe ContactsController do
|
||||||
before do
|
before do
|
||||||
@person = Factory(:person)
|
@person = Factory(:person)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls send_contact_request_to' do
|
it 'calls send_contact_request_to' do
|
||||||
@user.should_receive(:send_contact_request_to).with(@person, @aspect1)
|
@user.should_receive(:send_contact_request_to).with(@person, @aspect1)
|
||||||
post :create,
|
post :create,
|
||||||
|
|
@ -65,6 +70,7 @@ describe ContactsController do
|
||||||
:person_id => @person.id,
|
:person_id => @person.id,
|
||||||
:aspect_id => @aspect1.id
|
:aspect_id => @aspect1.id
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not call add_contact_to_aspect' do
|
it 'does not call add_contact_to_aspect' do
|
||||||
@user.should_not_receive(:add_contact_to_aspect)
|
@user.should_not_receive(:add_contact_to_aspect)
|
||||||
post :create,
|
post :create,
|
||||||
|
|
@ -72,6 +78,27 @@ describe ContactsController do
|
||||||
:person_id => @person.id,
|
:person_id => @person.id,
|
||||||
:aspect_id => @aspect1.id
|
:aspect_id => @aspect1.id
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,15 +13,6 @@ describe PeopleController do
|
||||||
sign_in :user, @user
|
sign_in :user, @user
|
||||||
end
|
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
|
describe '#index (search)' do
|
||||||
before do
|
before do
|
||||||
@eugene = Factory.create(:person,
|
@eugene = Factory.create(:person,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue