Send requests from the aspect list on the person show page

This commit is contained in:
Raphael 2010-12-15 14:47:55 -08:00
parent 80a9b97f8d
commit b22398951e
11 changed files with 88 additions and 54 deletions

View file

@ -112,7 +112,11 @@ class AspectsController < ApplicationController
@aspect = current_user.aspects.find(params[:aspect_id]) @aspect = current_user.aspects.find(params[:aspect_id])
@contact = current_user.contact_for(@person) @contact = current_user.contact_for(@person)
if @contact
current_user.add_contact_to_aspect(@contact, @aspect) current_user.add_contact_to_aspect(@contact, @aspect)
else
current_user.send_contact_request_to(@person, @aspect)
end
flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success' flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
respond_to do |format| respond_to do |format|

View file

@ -16,11 +16,23 @@ module AspectsHelper
end end
def add_to_aspect_button(aspect_id, person_id) def add_to_aspect_button(aspect_id, person_id)
link_to image_tag('icons/monotone_plus_add_round.png'), {:controller => "aspects", :action => 'add_to_aspect', :aspect_id => aspect_id, :person_id => person_id}, :remote => true, :class => 'add button' link_to image_tag('icons/monotone_plus_add_round.png'),
{:controller => "aspects",
:action => 'add_to_aspect',
:aspect_id => aspect_id,
:person_id => person_id},
:remote => true,
:class => 'add button'
end end
def remove_from_aspect_button(aspect_id, person_id) def remove_from_aspect_button(aspect_id, person_id)
link_to image_tag('icons/monotone_check_yes.png'), {:controller => "aspects", :action => 'remove_from_aspect', :aspect_id => aspect_id, :person_id => person_id}, :remote => true, :class => 'added button' link_to image_tag('icons/monotone_check_yes.png'),
{:controller => "aspects",
:action => 'remove_from_aspect',
:aspect_id => aspect_id,
:person_id => person_id},
:remote => true,
:class => 'added button'
end end
def aspect_membership_button(aspect_id, contact, person) def aspect_membership_button(aspect_id, contact, person)

View file

@ -25,7 +25,7 @@ class Person
one :profile, :class_name => 'Profile' one :profile, :class_name => 'Profile'
validates_associated :profile validates_associated :profile
delegate :first_name, :last_name, :to => :profile delegate :last_name, :to => :profile
before_save :downcase_diaspora_handle before_save :downcase_diaspora_handle
def downcase_diaspora_handle def downcase_diaspora_handle
@ -74,7 +74,13 @@ class Person
"#{profile.first_name.to_s} #{profile.last_name.to_s}" "#{profile.first_name.to_s} #{profile.last_name.to_s}"
end end
end end
def first_name
@first_name ||= if profile.first_name.nil? || profile.first_name.blank?
self.diaspora_handle.split('@').first
else
profile.first_name.to_s
end
end
def owns?(post) def owns?(post)
self.id == post.person.id self.id == post.person.id
end end

View file

@ -23,6 +23,13 @@
}); });
.aspects .aspects
- if !contact
%h4
= t('people.show.not_connected', :name => person.first_name)
- elsif contact.pending
%h4
= t('people.person.pending_request')
.badges{:class => ("hidden" if !contact)} .badges{:class => ("hidden" if !contact)}
- for aspect in aspects_with_person - for aspect in aspects_with_person
= render :partial => 'aspects/aspect_badge', :locals => {:aspect => aspect} = render :partial => 'aspects/aspect_badge', :locals => {:aspect => aspect}
@ -30,17 +37,17 @@
= link_to "edit aspect membership", "#", :id=> "edit_contact_aspects" = link_to "edit aspect membership", "#", :id=> "edit_contact_aspects"
.edit{:class => ("hidden" if contact)} .edit{:class => ("hidden" if contact)}
.contact_list .contact_list#aspects_list
%ul %ul
- for aspect in aspects_with_person - for aspect in aspects_with_person
%li %li{:data=>{:guid=>aspect.id}}
%span.name %span.name
= link_to aspect.name, aspect = link_to aspect.name, aspect
.right .right
= aspect_membership_button(aspect.id, contact, person) = aspect_membership_button(aspect.id, contact, person)
- for aspect in aspects_without_person - for aspect in aspects_without_person
%li %li{:data=>{:guid=>aspect.id}}
%span.name %span.name
= link_to aspect.name, aspect = link_to aspect.name, aspect
.right .right
@ -48,4 +55,5 @@
.right .right
= link_to "done editing", "#", :id => "done_contact_aspects" = link_to "done editing", "#", :id => "done_contact_aspects"
- if contact
= link_to t('people.profile_sidebar.remove_contact'), person, :confirm => t('are_you_sure'), :method => :delete = link_to t('people.profile_sidebar.remove_contact'), person, :confirm => t('are_you_sure'), :method => :delete

View file

@ -25,7 +25,7 @@
%hr{:style=>"width:300px;"} %hr{:style=>"width:300px;"}
%ul %ul
- if contact - unless person == current_user.person
%li %li
= render :partial => 'people/aspect_list', = render :partial => 'people/aspect_list',
:locals => {:person => person, :locals => {:person => person,

View file

@ -31,23 +31,6 @@
= link_to t('.return_to_aspects'), aspects_manage_path = link_to t('.return_to_aspects'), aspects_manage_path
= t('.to_accept_or_ignore') = t('.to_accept_or_ignore')
- else
.floating
%h3
= t('.not_connected', :name => @person.name)
- unless @outgoing_request
%h3
.description
= t('.request_people')
= render :partial =>'requests/new_request_to_person', :locals => {:aspects => @aspects, :destination_handle => @person.diaspora_handle}
- else
%h3
.description
= t('.already_requested', :name => @person.name)
- if @posts.count > 0 - if @posts.count > 0
-if @post_type == :photos -if @post_type == :photos
%h4 %h4

View file

@ -334,10 +334,8 @@ en:
incoming_request: "You have an incoming request from this person." incoming_request: "You have an incoming request from this person."
return_to_aspects: "Return to your aspects page" return_to_aspects: "Return to your aspects page"
to_accept_or_ignore: "to accept or ignore it." to_accept_or_ignore: "to accept or ignore it."
request_people: "If you'd like, you can request to place him/her in one of your aspects."
already_requested: "You have already sent a request to %{name}."
does_not_exist: "Person does not exist!" does_not_exist: "Person does not exist!"
not_connected: "You are not connected with this person" not_connected: "You are not sharing with %{name}"
recent_posts: "Recent Posts" recent_posts: "Recent Posts"
recent_public_posts: "Recent Public Posts" recent_public_posts: "Recent Public Posts"
edit: edit:

View file

@ -8,9 +8,9 @@ Feature: sending and receiving requests
Scenario: initiating and accepting a contact request Scenario: initiating and accepting a contact request
When I sign in as "bob@bob.bob" When I sign in as "bob@bob.bob"
And I am on "alice@alice.alice"'s page And I am on "alice@alice.alice"'s page
And I press "add contact" And I press the first ".add.button" within "#aspects_list ul > li:first-child"
And I wait for the ajax to finish And I wait for the ajax to finish
Then I should see "sent!" Then I should see a ".added.button" within "#aspects_list ul > li:first-child"
Then I go to the destroy user session page Then I go to the destroy user session page
When I sign in as "alice@alice.alice" When I sign in as "alice@alice.alice"
@ -23,4 +23,9 @@ Feature: sending and receiving requests
When I go to the home page When I go to the home page
Then I go to the aspects manage page Then I go to the aspects manage page
Then I should see 1 contact in "Besties" Then I should see 1 contact in "Besties"
Then I go to the destroy user session page
When I sign in as "bob@bob.bob"
And I am on the aspects manage page
Then I should see 1 contact in "Besties"

View file

@ -16,6 +16,16 @@ When /^(.*) in the aspect list$/ do |action|
end end
end end
When /^I press the first "([^"]*)"(?: within "([^"]*)")?$/ do |link_selector, within_selector|
with_scope(within_selector) do
find(:css, link_selector).click
end
end
Then /^(?:|I )should see a "([^"]*)"(?: within "([^"]*)")?$/ do |selector, scope_selector|
with_scope(scope_selector) do
page.has_css?(selector).should be_true
end
end
Then /^I should see "([^\"]*)" in the main content area$/ do |stuff| Then /^I should see "([^\"]*)" in the main content area$/ do |stuff|
within("#main_stream") do within("#main_stream") do
Then "I should see #{stuff}" Then "I should see #{stuff}"

View file

@ -21,6 +21,7 @@ describe AspectsController do
@user.getting_started = false @user.getting_started = false
@user.save @user.save
sign_in :user, @user sign_in :user, @user
@controller.stub(:current_user).and_return(@user)
request.env["HTTP_REFERER"] = 'http://' + request.host request.env["HTTP_REFERER"] = 'http://' + request.host
end end
@ -231,25 +232,37 @@ describe AspectsController 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)
post 'add_to_aspect',
:format => 'js',
: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 'add_to_aspect',
:format => 'js',
:person_id => @person.id,
:aspect_id => @aspect1.id
end end
end end
it 'adds the users to the aspect' do it 'adds the users to the aspect' do
@aspect1.reload @user.should_receive(:add_contact_to_aspect)
@aspect1.contacts.include?(@contact).should be_false post 'add_to_aspect',
post 'add_to_aspect', :format => 'js', :person_id => @user2.person.id, :aspect_id => @aspect1.id :format => 'js',
:person_id => @user2.person.id,
:aspect_id => @aspect1.id
response.should be_success response.should be_success
@aspect1.reload
@aspect1.contacts.include?(@contact).should be_true
end end
end end
describe "#remove_from_aspect" do describe "#remove_from_aspect" do
it 'removes contacts from an aspect' do it 'removes contacts from an aspect' do
@user.add_contact_to_aspect(@contact, @aspect1) @user.add_contact_to_aspect(@contact, @aspect1)
@aspect.reload post 'remove_from_aspect',
@aspect.contacts.include?(@contact).should be true :format => 'js',
post 'remove_from_aspect', :format => 'js', :person_id => @user2.person.id, :aspect_id => @aspect.id :person_id => @user2.person.id,
:aspect_id => @aspect.id
response.should be_success response.should be_success
@aspect.reload @aspect.reload
@aspect.contacts.include?(@contact).should be false @aspect.contacts.include?(@contact).should be false

View file

@ -14,11 +14,6 @@ describe Person do
end end
describe "delegating" do describe "delegating" do
it "delegates first_name to the profile" do
@person.first_name.should == @person.profile.first_name
@person.profile.update_attributes(:first_name => "Jane")
@person.reload.first_name.should == "Jane"
end
it "delegates last_name to the profile" do it "delegates last_name to the profile" do
@person.last_name.should == @person.profile.last_name @person.last_name.should == @person.profile.last_name
@person.profile.update_attributes(:last_name => "Heathers") @person.profile.update_attributes(:last_name => "Heathers")