user can now remove contact from aspects on contact's profile page. a contact's posts are retained in a given aspect reflecting the duration of said contact's inclusion.
This commit is contained in:
parent
4742f61925
commit
b3ec4d10c2
10 changed files with 108 additions and 87 deletions
|
|
@ -51,7 +51,11 @@ class AspectsController < ApplicationController
|
||||||
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
|
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
|
||||||
else
|
else
|
||||||
@aspect_contacts = @aspect.contacts
|
@aspect_contacts = @aspect.contacts
|
||||||
@posts = current_user.visible_posts( :by_members_of => @aspect, :_type => "StatusMessage" ).paginate :per_page => 15, :order => 'created_at DESC'
|
#@posts = current_user.visible_posts( :by_members_of => @aspect, :_type => "StatusMessage" ).paginate :per_page => 15, :order => 'created_at DESC'
|
||||||
|
@posts = @aspect.posts.find_all_by__type("StatusMessage", :order => 'created_at desc').paginate :per_page => 15
|
||||||
|
|
||||||
|
pp @aspect.post_ids
|
||||||
|
|
||||||
respond_with @aspect
|
respond_with @aspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -97,15 +101,12 @@ class AspectsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_from_aspect
|
def remove_from_aspect
|
||||||
if current_user.delete_person_from_aspect( params[:person_id], params[:aspect_id])
|
begin current_user.delete_person_from_aspect(params[:person_id], params[:aspect_id])
|
||||||
flash[:notice] = I18n.t 'aspects.remove_from_aspect.success'
|
flash.now[:notice] = I18n.t 'aspects.remove_from_aspect.success'
|
||||||
else
|
render :nothing => true, :status => 200
|
||||||
flash[:error] = I18n.t 'aspects.remove_from_aspect.failure'
|
rescue Exception => e
|
||||||
end
|
flash.now[:error] = I18n.t 'aspects.remove_from_aspect.failure'
|
||||||
if params[:manage]
|
render :text => e, :status => 403
|
||||||
redirect_to aspects_manage_path
|
|
||||||
else
|
|
||||||
redirect_to aspect_path(params[:aspect_id])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,5 @@ class Contact
|
||||||
|
|
||||||
key :aspect_ids, Array, :typecast => 'ObjectId'
|
key :aspect_ids, Array, :typecast => 'ObjectId'
|
||||||
many :aspects, :in => :aspect_ids, :class_name => 'Aspect'
|
many :aspects, :in => :aspect_ids, :class_name => 'Aspect'
|
||||||
validates_presence_of :aspects
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -98,40 +98,39 @@ class User
|
||||||
end
|
end
|
||||||
|
|
||||||
def move_contact(opts = {})
|
def move_contact(opts = {})
|
||||||
return true if opts[:to] == opts[:from]
|
if opts[:to] == opts[:from]
|
||||||
if opts[:person_id] && opts[:to] && opts[:from]
|
true
|
||||||
from_aspect = self.aspects.first(:_id => opts[:from])
|
elsif opts[:person_id] && opts[:to] && opts[:from]
|
||||||
posts_to_move = from_aspect.posts.find_all_by_person_id(opts[:person_id])
|
from_aspect = self.aspects.find_by_id(opts[:from])
|
||||||
if add_person_to_aspect(opts[:person_id], opts[:to], :posts => posts_to_move)
|
|
||||||
delete_person_from_aspect(opts[:person_id], opts[:from], :posts => posts_to_move)
|
if add_person_to_aspect(opts[:person_id], opts[:to])
|
||||||
return true
|
delete_person_from_aspect(opts[:person_id], opts[:from])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_person_to_aspect(person_id, aspect_id, opts = {})
|
def add_person_to_aspect(person_id, aspect_id)
|
||||||
contact = contact_for(Person.find(person_id))
|
contact = contact_for(Person.find(person_id))
|
||||||
raise "Can not add person to an aspect you do not own" unless aspect = self.aspects.find_by_id(aspect_id)
|
raise "Can not add person to an aspect you do not own" unless aspect = self.aspects.find_by_id(aspect_id)
|
||||||
raise "Can not add person you are not connected to" unless contact
|
raise "Can not add person you are not connected to" unless contact
|
||||||
raise 'Can not add person who is already in the aspect' if aspect.contacts.include?(contact)
|
raise 'Can not add person who is already in the aspect' if aspect.contacts.include?(contact)
|
||||||
contact.aspects << aspect
|
contact.aspects << aspect
|
||||||
opts[:posts] ||= self.raw_visible_posts.all(:person_id => person_id)
|
contact.save!
|
||||||
|
aspect.save!
|
||||||
aspect.posts += opts[:posts]
|
|
||||||
contact.save
|
|
||||||
aspect.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_person_from_aspect(person_id, aspect_id, opts = {})
|
def delete_person_from_aspect(person_id, aspect_id, opts = {})
|
||||||
aspect = Aspect.find(aspect_id)
|
aspect = Aspect.find(aspect_id)
|
||||||
raise "Can not delete a person from an aspect you do not own" unless aspect.user == self
|
raise "Can not delete a person from an aspect you do not own" unless aspect.user == self
|
||||||
contact = contact_for Person.find(person_id)
|
contact = contact_for Person.find(person_id)
|
||||||
|
|
||||||
|
if opts[:force] || contact.aspect_ids.count > 1
|
||||||
contact.aspect_ids.delete aspect.id
|
contact.aspect_ids.delete aspect.id
|
||||||
opts[:posts] ||= aspect.posts.all(:person_id => person_id)
|
contact.save!
|
||||||
aspect.posts -= opts[:posts]
|
aspect.save!
|
||||||
contact.save
|
else
|
||||||
aspect.save
|
raise "Can not delete a person from last aspect"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
######## Posting ########
|
######## Posting ########
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,19 @@
|
||||||
-# licensed under the Affero General Public License version 3 or later. See
|
-# licensed under the Affero General Public License version 3 or later. See
|
||||||
-# the COPYRIGHT file.
|
-# the COPYRIGHT file.
|
||||||
|
|
||||||
|
- content_for :head do
|
||||||
|
:javascript
|
||||||
|
$(document).ready(function(){
|
||||||
|
$('.delete').bind('ajax:success', function() {
|
||||||
|
$(this).closest('li').fadeOut(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.delete').bind('ajax:failure', function() {
|
||||||
|
alert("Cannot remove #{person.real_name} from last aspect.");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
#profile
|
#profile
|
||||||
.profile_photo
|
.profile_photo
|
||||||
= person_image_link(person, :to => :photos)
|
= person_image_link(person, :to => :photos)
|
||||||
|
|
@ -9,16 +22,16 @@
|
||||||
= action_link(person, is_contact)
|
= action_link(person, is_contact)
|
||||||
|
|
||||||
%ul
|
%ul
|
||||||
/- if @posts.first
|
|
||||||
/%li
|
|
||||||
/%i= t(".last_seen",:how_long_ago => how_long_ago(@posts.first))
|
|
||||||
- if is_contact
|
- if is_contact
|
||||||
%li
|
%li
|
||||||
%ul#aspects_for_person
|
%ul#aspects_for_person
|
||||||
%b= t('.in_aspects')
|
%b= t('.in_aspects')
|
||||||
%br
|
%br
|
||||||
- for aspect in @aspects_with_person
|
- for aspect in @aspects_with_person
|
||||||
%li= link_to aspect.name, aspect
|
%li
|
||||||
|
= link_to aspect.name, aspect
|
||||||
|
= link_to "x", {:controller => "aspects", :action => "remove_from_aspect", :person_id => person.id, :aspect_id => aspect.id}, :confirm => "Remove #{person.real_name} from #{aspect}?", :remote => true, :class => "delete"
|
||||||
|
|
||||||
|
|
||||||
-if is_contact || person == current_user.person
|
-if is_contact || person == current_user.person
|
||||||
%ul#profile_information
|
%ul#profile_information
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
- content_for :head do
|
- content_for :head do
|
||||||
:javascript
|
:javascript
|
||||||
|
$(document).ready(function(){
|
||||||
$("#new_aspect").live("ajax:success", function(data,stat,xhr){
|
$("#new_aspect").live("ajax:success", function(data,stat,xhr){
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
|
|
@ -15,6 +16,8 @@
|
||||||
aspectElement.fadeOut(300, function(){aspectElement.remove();});
|
aspectElement.fadeOut(300, function(){aspectElement.remove();});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
- if current_user.getting_started == true
|
- if current_user.getting_started == true
|
||||||
:javascript
|
:javascript
|
||||||
|
|
|
||||||
|
|
@ -1561,15 +1561,14 @@ h3 span.current_gs_step
|
||||||
|
|
||||||
#profile
|
#profile
|
||||||
ul#aspects_for_person
|
ul#aspects_for_person
|
||||||
|
|
||||||
> li
|
> li
|
||||||
|
|
||||||
:display inline-block
|
:display inline-block
|
||||||
:padding 4px 2px 0 0
|
:padding 4px 6px 0 0
|
||||||
|
|
||||||
a
|
a
|
||||||
:border-radius 6px
|
|
||||||
:padding 2px 4px
|
:padding 2px 4px
|
||||||
|
:margin
|
||||||
|
:left -3px
|
||||||
:background
|
:background
|
||||||
:color #eee
|
:color #eee
|
||||||
:font
|
:font
|
||||||
|
|
@ -1601,6 +1600,17 @@ h3 span.current_gs_step
|
||||||
:color #eee
|
:color #eee
|
||||||
:text-shadow none
|
:text-shadow none
|
||||||
|
|
||||||
|
a:first-child
|
||||||
|
:-webkit-border-radius 6px 0 0 6px
|
||||||
|
:-moz-border-radius 6px 0 0 6px
|
||||||
|
:border-radius 6px 0 0 6px
|
||||||
|
|
||||||
|
a:last-child
|
||||||
|
:-webkit-border-radius 0 6px 6px 0
|
||||||
|
:-moz-border-radius 0 6px 6px 0
|
||||||
|
:border-radius 0 6px 6px 0
|
||||||
|
|
||||||
|
|
||||||
ul#request_result
|
ul#request_result
|
||||||
:list-style none
|
:list-style none
|
||||||
:padding 0
|
:padding 0
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,16 @@ describe AspectsController do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@user = make_user
|
@user = make_user
|
||||||
|
@user2 = make_user
|
||||||
|
|
||||||
@aspect = @user.aspects.create(:name => "lame-os")
|
@aspect = @user.aspects.create(:name => "lame-os")
|
||||||
@aspect1 = @user.aspects.create(:name => "another aspect")
|
@aspect1 = @user.aspects.create(:name => "another aspect")
|
||||||
@user2 = make_user
|
|
||||||
@aspect2 = @user2.aspects.create(:name => "party people")
|
@aspect2 = @user2.aspects.create(:name => "party people")
|
||||||
|
|
||||||
connect_users(@user, @aspect, @user2, @aspect2)
|
connect_users(@user, @aspect, @user2, @aspect2)
|
||||||
|
|
||||||
@contact = @user.contact_for(@user2.person)
|
@contact = @user.contact_for(@user2.person)
|
||||||
|
|
||||||
sign_in :user, @user
|
sign_in :user, @user
|
||||||
request.env["HTTP_REFERER"] = 'http://' + request.host
|
request.env["HTTP_REFERER"] = 'http://' + request.host
|
||||||
end
|
end
|
||||||
|
|
@ -116,15 +120,17 @@ describe AspectsController do
|
||||||
describe "#add_to_aspect" do
|
describe "#add_to_aspect" do
|
||||||
it 'adds the users to the aspect' do
|
it 'adds the users to the aspect' do
|
||||||
@aspect1.reload
|
@aspect1.reload
|
||||||
@aspect1.contacts.include?(@contact).should be false
|
@aspect1.contacts.include?(@contact).should be_false
|
||||||
post 'add_to_aspect', {:person_id => @user2.person.id, :aspect_id => @aspect1.id}
|
post 'add_to_aspect', {:person_id => @user2.person.id, :aspect_id => @aspect1.id}
|
||||||
@aspect1.reload
|
@aspect1.reload
|
||||||
@aspect1.contacts.include?(@contact).should be true
|
@aspect1.contacts.include?(@contact).should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#remove_from_aspect" do
|
describe "#remove_from_aspect" do
|
||||||
it 'adds the users to the aspect' do
|
it 'removes contacts from an aspect' do
|
||||||
|
pending 'this needs to test with another aspect present'
|
||||||
|
|
||||||
@aspect.reload
|
@aspect.reload
|
||||||
@aspect.contacts.include?(@contact).should be true
|
@aspect.contacts.include?(@contact).should be true
|
||||||
post 'remove_from_aspect', {:person_id => @user2.person.id, :aspect_id => @aspect1.id}
|
post 'remove_from_aspect', {:person_id => @user2.person.id, :aspect_id => @aspect1.id}
|
||||||
|
|
|
||||||
|
|
@ -196,11 +196,21 @@ describe Aspect do
|
||||||
user.delete_person_from_aspect(user2.person.id, aspect1.id)
|
user.delete_person_from_aspect(user2.person.id, aspect1.id)
|
||||||
}.should_not change(Post, :count)
|
}.should_not change(Post, :count)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should not allow removing a contact from their last aspect' do
|
||||||
|
proc{user.delete_person_from_aspect(user2.person.id, aspect.id) }.should raise_error /Can not delete a person from last aspect/
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should allow a force removal of a contact from an aspect' do
|
||||||
|
contact.aspect_ids.should_receive(:count).exactly(0).times
|
||||||
|
|
||||||
|
user.add_person_to_aspect(user2.person.id, aspect1.id)
|
||||||
|
user.delete_person_from_aspect(user2.person.id, aspect.id, :force => true)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'moving and removing posts' do
|
context 'moving and removing posts' do
|
||||||
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@message = user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)
|
@message = user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)
|
||||||
aspect.reload
|
aspect.reload
|
||||||
|
|
@ -210,22 +220,17 @@ describe Aspect do
|
||||||
user.reload
|
user.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'moves the persons posts into the new aspect' do
|
it 'should keep the contact\'s posts in previous aspect' do
|
||||||
user.add_person_to_aspect(user2.person.id, aspect1.id, :posts => [@message] )
|
aspect.post_ids.count.should == 1
|
||||||
aspect1.reload
|
user.delete_person_from_aspect(user2.person.id, aspect.id, :force => true)
|
||||||
aspect1.posts.should == [@message]
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
it 'should remove the users posts from that aspect' do
|
|
||||||
user.delete_person_from_aspect(user2.person.id, aspect.id)
|
|
||||||
aspect.reload
|
aspect.reload
|
||||||
aspect.posts.count.should == @post_count - 1
|
aspect.post_ids.count.should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not delete other peoples posts' do
|
it 'should not delete other peoples posts' do
|
||||||
connect_users(user, aspect, user3, aspect3)
|
connect_users(user, aspect, user3, aspect3)
|
||||||
user.delete_person_from_aspect(user3.person.id, aspect.id)
|
user.delete_person_from_aspect(user3.person.id, aspect.id, :force => true)
|
||||||
aspect.reload
|
aspect.reload
|
||||||
aspect.posts.should == [@message]
|
aspect.posts.should == [@message]
|
||||||
end
|
end
|
||||||
|
|
@ -256,15 +261,6 @@ describe Aspect do
|
||||||
aspect2.contacts.include?(contact).should be false
|
aspect2.contacts.include?(contact).should be false
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should move all posts by that user to the new aspect' do
|
|
||||||
user.move_contact(:person_id => user2.person.id, :from => aspect.id, :to => aspect1.id)
|
|
||||||
aspect.reload
|
|
||||||
aspect1.reload
|
|
||||||
|
|
||||||
aspect1.posts.count.should == @post_count1 + 1
|
|
||||||
aspect.posts.count.should == @post_count - 1
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not try to delete if add person did not go through' do
|
it 'does not try to delete if add person did not go through' do
|
||||||
user.should_receive(:add_person_to_aspect).and_return(false)
|
user.should_receive(:add_person_to_aspect).and_return(false)
|
||||||
user.should_not_receive(:delete_person_from_aspect)
|
user.should_not_receive(:delete_person_from_aspect)
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,5 @@ describe Contact do
|
||||||
it 'has many aspects' do
|
it 'has many aspects' do
|
||||||
contact.associations[:aspects].type.should == :many
|
contact.associations[:aspects].type.should == :many
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has at least one aspect' do
|
|
||||||
contact.valid?
|
|
||||||
contact.errors.full_messages.should include "Aspects can't be blank"
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue