Commit b2239895 authored by Raphael's avatar Raphael

Send requests from the aspect list on the person show page

parent 80a9b97f
......@@ -112,7 +112,11 @@ class AspectsController < ApplicationController
@aspect = current_user.aspects.find(params[:aspect_id])
@contact = current_user.contact_for(@person)
current_user.add_contact_to_aspect(@contact, @aspect)
if @contact
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'
respond_to do |format|
......
......@@ -16,11 +16,23 @@ module AspectsHelper
end
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
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
def aspect_membership_button(aspect_id, contact, person)
......
......@@ -25,9 +25,9 @@ class Person
one :profile, :class_name => 'Profile'
validates_associated :profile
delegate :first_name, :last_name, :to => :profile
before_save :downcase_diaspora_handle
delegate :last_name, :to => :profile
before_save :downcase_diaspora_handle
def downcase_diaspora_handle
diaspora_handle.downcase!
end
......@@ -35,7 +35,7 @@ class Person
belongs_to :owner, :class_name => 'User'
timestamps!
before_destroy :remove_all_traces
before_validation :clean_url
validates_presence_of :url, :profile, :serialized_public_key
......@@ -63,7 +63,7 @@ class Person
| Person.searchable.all('diaspora_handle' => /^#{q}/i, 'limit' => 30) \
| p
end
return p
end
......@@ -74,7 +74,13 @@ class Person
"#{profile.first_name.to_s} #{profile.last_name.to_s}"
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)
self.id == post.person.id
end
......
......@@ -23,6 +23,13 @@
});
.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)}
- for aspect in aspects_with_person
= render :partial => 'aspects/aspect_badge', :locals => {:aspect => aspect}
......@@ -30,17 +37,17 @@
= link_to "edit aspect membership", "#", :id=> "edit_contact_aspects"
.edit{:class => ("hidden" if contact)}
.contact_list
.contact_list#aspects_list
%ul
- for aspect in aspects_with_person
%li
%li{:data=>{:guid=>aspect.id}}
%span.name
= link_to aspect.name, aspect
.right
= aspect_membership_button(aspect.id, contact, person)
- for aspect in aspects_without_person
%li
%li{:data=>{:guid=>aspect.id}}
%span.name
= link_to aspect.name, aspect
.right
......@@ -48,4 +55,5 @@
.right
= link_to "done editing", "#", :id => "done_contact_aspects"
= link_to t('people.profile_sidebar.remove_contact'), person, :confirm => t('are_you_sure'), :method => :delete
- if contact
= link_to t('people.profile_sidebar.remove_contact'), person, :confirm => t('are_you_sure'), :method => :delete
......@@ -25,7 +25,7 @@
%hr{:style=>"width:300px;"}
%ul
- if contact
- unless person == current_user.person
%li
= render :partial => 'people/aspect_list',
:locals => {:person => person,
......
......@@ -31,23 +31,6 @@
= link_to t('.return_to_aspects'), aspects_manage_path
= 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 @post_type == :photos
%h4
......
......@@ -334,10 +334,8 @@ en:
incoming_request: "You have an incoming request from this person."
return_to_aspects: "Return to your aspects page"
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!"
not_connected: "You are not connected with this person"
not_connected: "You are not sharing with %{name}"
recent_posts: "Recent Posts"
recent_public_posts: "Recent Public Posts"
edit:
......
......@@ -8,9 +8,9 @@ Feature: sending and receiving requests
Scenario: initiating and accepting a contact request
When I sign in as "bob@bob.bob"
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
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
When I sign in as "alice@alice.alice"
......@@ -23,4 +23,9 @@ Feature: sending and receiving requests
When I go to the home page
Then I go to the aspects manage page
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"
......@@ -16,6 +16,16 @@ When /^(.*) in the aspect list$/ do |action|
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|
within("#main_stream") do
Then "I should see #{stuff}"
......
......@@ -21,6 +21,7 @@ describe AspectsController do
@user.getting_started = false
@user.save
sign_in :user, @user
@controller.stub(:current_user).and_return(@user)
request.env["HTTP_REFERER"] = 'http://' + request.host
end
......@@ -231,25 +232,37 @@ describe AspectsController do
@person = Factory(:person)
end
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
it 'adds the users to the aspect' do
@aspect1.reload
@aspect1.contacts.include?(@contact).should be_false
post 'add_to_aspect', :format => 'js', :person_id => @user2.person.id, :aspect_id => @aspect1.id
@user.should_receive(:add_contact_to_aspect)
post 'add_to_aspect',
:format => 'js',
:person_id => @user2.person.id,
:aspect_id => @aspect1.id
response.should be_success
@aspect1.reload
@aspect1.contacts.include?(@contact).should be_true
end
end
describe "#remove_from_aspect" do
it 'removes contacts from an aspect' do
@user.add_contact_to_aspect(@contact, @aspect1)
@aspect.reload
@aspect.contacts.include?(@contact).should be true
post 'remove_from_aspect', :format => 'js', :person_id => @user2.person.id, :aspect_id => @aspect.id
post 'remove_from_aspect',
:format => 'js',
:person_id => @user2.person.id,
:aspect_id => @aspect.id
response.should be_success
@aspect.reload
@aspect.contacts.include?(@contact).should be false
......
......@@ -14,11 +14,6 @@ describe Person do
end
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
@person.last_name.should == @person.profile.last_name
@person.profile.update_attributes(:last_name => "Heathers")
......@@ -121,7 +116,7 @@ describe Person do
Factory.create(:comment, :person_id => person.id, :diaspora_handle => person.diaspora_handle, :text => "i love you", :post => status_message)
Factory.create(:comment, :person_id => @person.id,:diaspora_handle => @person.diaspora_handle, :text => "you are creepy", :post => status_message)
lambda {person.destroy}.should_not change(Comment, :count)
end
......@@ -245,14 +240,14 @@ describe Person do
Person.by_account_identifier("tom@tom.joindiaspora.com").diaspora_handle.should == "tom@tom.joindiaspora.com"
end
it 'should only find people who are exact matches (2/2)' do
it 'should only find people who are exact matches (2/2)' do
person = Factory(:person, :diaspora_handle => "tomtom@tom.joindiaspora.com")
person1 = Factory(:person, :diaspora_handle => "tom@tom.joindiaspora.comm")
f = Person.by_account_identifier("tom@tom.joindiaspora.com")
f = Person.by_account_identifier("tom@tom.joindiaspora.com")
f.should be nil
end
end
describe '.local_by_account_identifier' do
......
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