Commit 16b7ec39 authored by zhitomirskiyi's avatar zhitomirskiyi

pulled out share_with to be contact new and contact show

parent 25671f07
......@@ -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(
......
......@@ -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
......@@ -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)
......
......@@ -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)
......
......@@ -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'
......@@ -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'
......
......@@ -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'
......
-# 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
-# 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
#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
......
......@@ -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'
......
......@@ -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"
......
......@@ -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
......
......@@ -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
......
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment