iz ms wip fixing contactController destroy
This commit is contained in:
parent
8c2e6dd8cb
commit
7ace73b84b
12 changed files with 83 additions and 37 deletions
|
|
@ -30,6 +30,16 @@ class ContactsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
contact = current_user.contacts.where(:id => params[:id]).first
|
||||||
|
if current_user.disconnect(contact)
|
||||||
|
flash[:notice] = I18n.t('contacts.destroy.success', :name => contact.person.name)
|
||||||
|
else
|
||||||
|
flash[:error] = I18n.t('contacts.destroy.failure', :name => contact.person.name)
|
||||||
|
end
|
||||||
|
redirect_to contact.person
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def request_to_aspect(aspect, person)
|
def request_to_aspect(aspect, person)
|
||||||
|
|
|
||||||
|
|
@ -76,11 +76,6 @@ class PeopleController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
|
||||||
current_user.disconnect(Person.where(:id => params[:id]).first)
|
|
||||||
redirect_to root_url
|
|
||||||
end
|
|
||||||
|
|
||||||
def retrieve_remote
|
def retrieve_remote
|
||||||
if params[:diaspora_handle]
|
if params[:diaspora_handle]
|
||||||
webfinger(params[:diaspora_handle], :single_aspect_form => true)
|
webfinger(params[:diaspora_handle], :single_aspect_form => true)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
-# 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.
|
||||||
|
|
||||||
.aspect_list#aspects_list{:data=>{:person_id=>person.id}}
|
.aspect_list#aspects_list(( {:data=>{:contact_id=>contact.id} }) if contact)
|
||||||
%ul
|
%ul
|
||||||
- for aspect in aspects_with_person
|
- for aspect in aspects_with_person
|
||||||
= render :partial => 'aspects/aspect_list_item',
|
= render :partial => 'aspects/aspect_list_item',
|
||||||
|
|
@ -30,4 +30,4 @@
|
||||||
.right
|
.right
|
||||||
= link_to t('aspects.aspect_contacts.done_editing'), "#", :class => "button", :onClick => '$.facebox.close();'
|
= link_to t('aspects.aspect_contacts.done_editing'), "#", :class => "button", :onClick => '$.facebox.close();'
|
||||||
- if contact
|
- 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'), contact, :confirm => t('are_you_sure'), :method => :delete
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
= search_field_tag :contact_search, "", :class => 'contact_list_search', :results => 5, :placeholder => t('.all_contacts')
|
= search_field_tag :contact_search, "", :class => 'contact_list_search', :results => 5, :placeholder => t('.all_contacts')
|
||||||
%ul
|
%ul
|
||||||
- for contact in contacts
|
- for contact in contacts
|
||||||
%li{:data=>{:guid=>contact.person.id}}
|
%li{:data=>{:contact_id=>contact.id}}
|
||||||
= person_image_tag contact.person
|
= person_image_tag contact.person
|
||||||
%h4.name
|
%h4.name
|
||||||
= link_to contact.person.name, contact.person
|
= link_to contact.person.name, contact.person
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,9 @@ en:
|
||||||
one: "1 contact"
|
one: "1 contact"
|
||||||
few: "%{count} contacts"
|
few: "%{count} contacts"
|
||||||
other: "%{count} contacts"
|
other: "%{count} contacts"
|
||||||
|
destroy:
|
||||||
|
success: "Successfully disconnected from %{name}"
|
||||||
|
failure: "Failed to disconnect from %{name}"
|
||||||
new_requests:
|
new_requests:
|
||||||
zero: "no new requests"
|
zero: "no new requests"
|
||||||
one: "new request!"
|
one: "new request!"
|
||||||
|
|
|
||||||
|
|
@ -74,18 +74,19 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def disconnect(bad_contact)
|
def disconnect(bad_contact)
|
||||||
Rails.logger.info("event=disconnect user=#{diaspora_handle} target=#{bad_contact.diaspora_handle}")
|
person = bad_contact.person
|
||||||
|
Rails.logger.info("event=disconnect user=#{diaspora_handle} target=#{person.diaspora_handle}")
|
||||||
retraction = Retraction.for(self)
|
retraction = Retraction.for(self)
|
||||||
retraction.subscribers = [bad_contact]#HAX
|
retraction.subscribers = [person]#HAX
|
||||||
Postzord::Dispatch.new(self, retraction).post
|
Postzord::Dispatch.new(self, retraction).post
|
||||||
remove_contact(bad_contact)
|
remove_contact(bad_contact)
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_contact(bad_person)
|
def remove_contact(contact)
|
||||||
contact = contact_for(bad_person)
|
bad_person_id = contact.person_id
|
||||||
posts = raw_visible_posts.where(:person_id => bad_person.id).all
|
posts = raw_visible_posts.where(:person_id => bad_person_id).all
|
||||||
visibilities = PostVisibility.joins(:post, :aspect).where(
|
visibilities = PostVisibility.joins(:post, :aspect).where(
|
||||||
:posts => {:person_id => bad_person.id},
|
:posts => {:person_id => bad_person_id},
|
||||||
:aspects => {:user_id => self.id}
|
:aspects => {:user_id => self.id}
|
||||||
)
|
)
|
||||||
visibility_ids = visibilities.map{|v| v.id}
|
visibility_ids = visibilities.map{|v| v.id}
|
||||||
|
|
@ -95,12 +96,12 @@ module Diaspora
|
||||||
post.destroy
|
post.destroy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
raise "Contact not deleted" unless contact.destroy
|
contact.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
def disconnected_by(bad_contact)
|
def disconnected_by(person)
|
||||||
Rails.logger.info("event=disconnected_by user=#{diaspora_handle} target=#{bad_contact.diaspora_handle}")
|
Rails.logger.info("event=disconnected_by user=#{diaspora_handle} target=#{person.diaspora_handle}")
|
||||||
remove_contact bad_contact
|
remove_contact(self.contact_for(person))
|
||||||
end
|
end
|
||||||
|
|
||||||
def activate_contact(person, aspect)
|
def activate_contact(person, aspect)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace :backup do
|
||||||
require 'cloudfiles'
|
require 'cloudfiles'
|
||||||
|
|
||||||
task :mysql do
|
task :mysql do
|
||||||
|
NUMBER_OF_DAYS = 3
|
||||||
puts("event=backup status=start type=mysql")
|
puts("event=backup status=start type=mysql")
|
||||||
db = YAML::load(File.open(File.join(File.dirname(__FILE__), '..','..', 'config', 'database.yml')))
|
db = YAML::load(File.open(File.join(File.dirname(__FILE__), '..','..', 'config', 'database.yml')))
|
||||||
user = db['production']['user']
|
user = db['production']['user']
|
||||||
|
|
@ -28,6 +29,12 @@ namespace :backup do
|
||||||
puts("event=backup status=success type=mysql")
|
puts("event=backup status=success type=mysql")
|
||||||
`rm /tmp/backup/#{tar_name}`
|
`rm /tmp/backup/#{tar_name}`
|
||||||
`rm -rf /tmp/backup/mysql/`
|
`rm -rf /tmp/backup/mysql/`
|
||||||
|
|
||||||
|
files = mysql_container.objects
|
||||||
|
files.sort!.pop(NUMBER_OF_DAYS * 24)
|
||||||
|
files.each do |file|
|
||||||
|
mysql_container.delete_object(file)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
puts("event=backup status=failure type=mysql")
|
puts("event=backup status=failure type=mysql")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,13 @@ var List = {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
disconnectUser: function(person_id){
|
disconnectUser: function(contact_id){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/people/" + person_id,
|
url: "/contacts/" + contact_id,
|
||||||
type: "DELETE",
|
type: "DELETE",
|
||||||
success: function(){
|
success: function(){
|
||||||
if( $('.contact_list').length == 1){
|
if( $('.contact_list').length == 1){
|
||||||
$('.contact_list li[data-guid='+person_id+']').fadeOut(200);
|
$('.contact_list li[data-contact_id='+contact_id+']').fadeOut(200);
|
||||||
} else if($('#aspects_list').length == 1) {
|
} else if($('#aspects_list').length == 1) {
|
||||||
$.facebox.close();
|
$.facebox.close();
|
||||||
};
|
};
|
||||||
|
|
@ -60,16 +60,16 @@ $(document).ready(function() {
|
||||||
|
|
||||||
$('.added').live('ajax:failure', function(data, html, xhr) {
|
$('.added').live('ajax:failure', function(data, html, xhr) {
|
||||||
if(confirm(Diaspora.widgets.i18n.t('shared.contact_list.cannot_remove'))){
|
if(confirm(Diaspora.widgets.i18n.t('shared.contact_list.cannot_remove'))){
|
||||||
var person_id;
|
var contact_id;
|
||||||
|
|
||||||
if( $('.contact_list').length == 1){
|
if( $('.contact_list').length == 1){
|
||||||
person_id = $(this).parents('li').attr("data-guid");
|
contact_id = $(this).parents('li').attr("data-contact_id");
|
||||||
$('.contact_list li[data-guid='+person_id+']').fadeOut(200);
|
$('.contact_list li[data-contact_id='+contact_id+']').fadeOut(200);
|
||||||
} else if($('#aspects_list').length == 1) {
|
} else if($('#aspects_list').length == 1) {
|
||||||
person_id = $(this).parents('#aspects_list').attr("data-person_id");
|
contact_id = $(this).parents('#aspects_list').attr("data-contact_id");
|
||||||
};
|
};
|
||||||
|
|
||||||
List.disconnectUser(person_id);
|
List.disconnectUser(contact_id);
|
||||||
};
|
};
|
||||||
$(this).fadeTo(200,1);
|
$(this).fadeTo(200,1);
|
||||||
});
|
});
|
||||||
|
|
@ -88,7 +88,11 @@ $(document).ready(function() {
|
||||||
$(".badges").prepend(json.badge_html);
|
$(".badges").prepend(json.badge_html);
|
||||||
$(this).parent().html(json.button_html);
|
$(this).parent().html(json.button_html);
|
||||||
|
|
||||||
$('.aspect_list ul').find('.add').each(function(a,b){$(b).attr('href', $(b).attr('href').replace('contacts','aspect_memberships'));})
|
if($('#aspects_list').length == 1) {
|
||||||
|
$('.aspect_list').attr('data-contact_id', json.contact_id);
|
||||||
|
alert('^- TODO');
|
||||||
|
$('.aspect_list ul').find('.add').each(function(a,b){$(b).attr('href', $(b).attr('href').replace('contacts','aspect_memberships'));})
|
||||||
|
};
|
||||||
|
|
||||||
$(this).fadeTo(200,1);
|
$(this).fadeTo(200,1);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ describe ContactsController do
|
||||||
request.env["HTTP_REFERER"] = 'http://' + request.host
|
request.env["HTTP_REFERER"] = 'http://' + request.host
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'new' do
|
describe '#new' do
|
||||||
|
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
pending "This is going to be new request"
|
pending "This is going to be new request"
|
||||||
|
|
@ -33,7 +33,7 @@ describe ContactsController do
|
||||||
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)
|
||||||
|
|
@ -74,4 +74,28 @@ describe ContactsController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#destroy' do
|
||||||
|
it 'disconnects from the person' do
|
||||||
|
@user.should_receive(:disconnect).with(@contact)
|
||||||
|
delete :destroy, :id => @contact.id
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'flases success if the contact is not destroyed' do
|
||||||
|
@user.stub!(:disconnect).and_return(true)
|
||||||
|
delete :destroy, :id => @contact.id
|
||||||
|
flash[:notice].should_not be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'flases failure if the contact is not destroyed' do
|
||||||
|
@user.stub!(:disconnect).and_return(false)
|
||||||
|
delete :destroy, :id => @contact.id
|
||||||
|
flash[:error].should_not be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects back to the person page' do
|
||||||
|
delete :destroy, :id => @contact.id
|
||||||
|
response.should redirect_to(@contact.person)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ describe 'a user receives a post' do
|
||||||
|
|
||||||
@user3 = eve
|
@user3 = eve
|
||||||
@aspect3 = @user3.aspects.first
|
@aspect3 = @user3.aspects.first
|
||||||
|
|
||||||
|
@contact = @user1.contact_for(@user2.person)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'streams only one message to the everyone aspect when a multi-aspected contacts posts' do
|
it 'streams only one message to the everyone aspect when a multi-aspected contacts posts' do
|
||||||
|
|
@ -89,7 +91,7 @@ describe 'a user receives a post' do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'removes posts upon disconnecting' do
|
it 'removes posts upon disconnecting' do
|
||||||
@user1.disconnect(@user2.person)
|
@user1.disconnect(@contact)
|
||||||
@user1.reload
|
@user1.reload
|
||||||
@user1.raw_visible_posts.should_not include @status_message
|
@user1.raw_visible_posts.should_not include @status_message
|
||||||
end
|
end
|
||||||
|
|
@ -128,7 +130,7 @@ describe 'a user receives a post' do
|
||||||
@status_message.reload
|
@status_message.reload
|
||||||
@status_message.user_refs.should == 3
|
@status_message.user_refs.should == 3
|
||||||
|
|
||||||
@user1.disconnect(@user2.person)
|
@user1.disconnect(@contact)
|
||||||
@status_message.reload
|
@status_message.reload
|
||||||
@status_message.user_refs.should == 2
|
@status_message.user_refs.should == 2
|
||||||
end
|
end
|
||||||
|
|
@ -146,7 +148,7 @@ describe 'a user receives a post' do
|
||||||
@status_message.post_visibilities.reset
|
@status_message.post_visibilities.reset
|
||||||
@status_message.user_refs.should == 4
|
@status_message.user_refs.should == 4
|
||||||
|
|
||||||
@user1.disconnect(@user2.person)
|
@user1.disconnect(@contact)
|
||||||
@status_message.post_visibilities.reset
|
@status_message.post_visibilities.reset
|
||||||
@status_message.user_refs.should == 3
|
@status_message.user_refs.should == 3
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -138,14 +138,14 @@ describe Person do
|
||||||
it 'should not delete an orphaned contact' do
|
it 'should not delete an orphaned contact' do
|
||||||
@user.activate_contact(@person, @aspect)
|
@user.activate_contact(@person, @aspect)
|
||||||
|
|
||||||
lambda {@user.disconnect(@person)}.should_not change(Person, :count)
|
lambda {@user.disconnect(@user.contact_for(@person))}.should_not change(Person, :count)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not delete an un-orphaned contact' do
|
it 'should not delete an un-orphaned contact' do
|
||||||
@user.activate_contact(@person, @aspect)
|
@user.activate_contact(@person, @aspect)
|
||||||
@user2.activate_contact(@person, @aspect2)
|
@user2.activate_contact(@person, @aspect2)
|
||||||
|
|
||||||
lambda {@user.disconnect(@person)}.should_not change(Person, :count)
|
lambda {@user.disconnect(@user.contact_for(@person))}.should_not change(Person, :count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -250,7 +250,7 @@ describe Diaspora::UserModules::Connecting do
|
||||||
|
|
||||||
it 'should disconnect the other user on the same seed' do
|
it 'should disconnect the other user on the same seed' do
|
||||||
lambda {
|
lambda {
|
||||||
user2.disconnect user.person }.should change {
|
user2.disconnect user2.contact_for(user.person) }.should change {
|
||||||
user2.reload.contacts.count }.by(-1)
|
user2.reload.contacts.count }.by(-1)
|
||||||
aspect2.reload.contacts.count.should == 0
|
aspect2.reload.contacts.count.should == 0
|
||||||
end
|
end
|
||||||
|
|
@ -280,14 +280,14 @@ describe Diaspora::UserModules::Connecting do
|
||||||
|
|
||||||
it "deletes the disconnected user's posts from visible_posts" do
|
it "deletes the disconnected user's posts from visible_posts" do
|
||||||
user2.reload.raw_visible_posts.include?(@message).should be_true
|
user2.reload.raw_visible_posts.include?(@message).should be_true
|
||||||
user2.disconnect user.person
|
user2.disconnect user2.contact_for(user.person)
|
||||||
user2.reload.raw_visible_posts.include?(@message).should be_false
|
user2.reload.raw_visible_posts.include?(@message).should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "deletes the disconnected user's posts from the aspect's posts" do
|
it "deletes the disconnected user's posts from the aspect's posts" do
|
||||||
Post.count.should == 1
|
Post.count.should == 1
|
||||||
aspect2.reload.posts.include?(@message).should be_true
|
aspect2.reload.posts.include?(@message).should be_true
|
||||||
user2.disconnect user.person
|
user2.disconnect user2.contact_for(user.person)
|
||||||
aspect2.reload.posts.include?(@message).should be_false
|
aspect2.reload.posts.include?(@message).should be_false
|
||||||
Post.count.should == 1
|
Post.count.should == 1
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue