Merge branch 'master' of github.com:diaspora/diaspora
This commit is contained in:
commit
6d3d37b7c6
9 changed files with 118 additions and 4 deletions
|
|
@ -49,4 +49,15 @@ class GroupsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def move_person
|
||||||
|
unless current_user.move_friend( :friend_id => params[:friend_id], :from => params[:from], :to => params[:to][:to])
|
||||||
|
flash[:error] = "didn't work #{params.inspect}"
|
||||||
|
end
|
||||||
|
if group = Group.first(:id => params[:to][:to])
|
||||||
|
redirect_to group
|
||||||
|
else
|
||||||
|
redirect_to Person.first(:id => params[:friend_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,10 @@ class PeopleController < ApplicationController
|
||||||
@profile = @person.profile
|
@profile = @person.profile
|
||||||
@person_groups = current_user.groups_with_person(@person)
|
@person_groups = current_user.groups_with_person(@person)
|
||||||
|
|
||||||
|
|
||||||
|
@groups_array = current_user.groups.collect{|x| [x.to_s, x.id]}
|
||||||
|
|
||||||
|
|
||||||
@posts = Post.where(:person_id => @person.id, :_id.in => current_user.visible_post_ids).paginate :page => params[:page], :order => 'created_at DESC'
|
@posts = Post.where(:person_id => @person.id, :_id.in => current_user.visible_post_ids).paginate :page => params[:page], :order => 'created_at DESC'
|
||||||
|
|
||||||
@latest_status_message = current_user.raw_visible_posts.find_all_by__type_and_person_id("StatusMessage", params[:id]).last
|
@latest_status_message = current_user.raw_visible_posts.find_all_by__type_and_person_id("StatusMessage", params[:id]).last
|
||||||
|
|
|
||||||
|
|
@ -19,5 +19,10 @@ class Group
|
||||||
def to_s
|
def to_s
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def posts_by_person_id( id )
|
||||||
|
id = ensure_bson id
|
||||||
|
posts.detect{|x| x.person.id == id }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,26 @@ class User
|
||||||
Group.create(opts)
|
Group.create(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def move_friend( opts = {})
|
||||||
|
return true if opts[:to] == opts[:from]
|
||||||
|
friend = Person.first(:_id => opts[:friend_id])
|
||||||
|
if self.friend_ids.include?(friend.id)
|
||||||
|
from_group = self.group_by_id(opts[:from])
|
||||||
|
to_group = self.group_by_id(opts[:to])
|
||||||
|
if from_group && to_group
|
||||||
|
posts_to_move = from_group.posts.find_all_by_person_id(friend.id)
|
||||||
|
puts posts_to_move.inspect
|
||||||
|
to_group.people << friend
|
||||||
|
to_group.posts << posts_to_move
|
||||||
|
from_group.person_ids.delete(ensure_bson(friend.id))
|
||||||
|
posts_to_move.each{ |x| from_group.post_ids.delete(x.id)}
|
||||||
|
from_group.save
|
||||||
|
to_group.save
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
false
|
||||||
|
end
|
||||||
######## Posting ########
|
######## Posting ########
|
||||||
def post(class_name, options = {})
|
def post(class_name, options = {})
|
||||||
options[:person] = self.person
|
options[:person] = self.person
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,15 @@
|
||||||
%h1.big_text
|
%h1.big_text
|
||||||
.back
|
.back
|
||||||
= link_to "⇧ #{@group.name}", @group
|
= link_to "⇧ #{@group.name}", @group
|
||||||
|
|
||||||
= "Editing Groups"
|
= "Editing Groups"
|
||||||
|
|
||||||
|
|
||||||
%ul
|
|
||||||
- for group in @groups
|
- for group in @groups
|
||||||
%li.group
|
%li.group
|
||||||
= group.name
|
= group.name
|
||||||
%ul
|
%ul
|
||||||
-for person in group.people
|
-for person in group.people
|
||||||
%li..person
|
%li.person
|
||||||
= person.real_name
|
= person.real_name
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,13 @@
|
||||||
%i= "friends since: #{how_long_ago(@person)}"
|
%i= "friends since: #{how_long_ago(@person)}"
|
||||||
%li
|
%li
|
||||||
="groups: #{@person_groups}"
|
="groups: #{@person_groups}"
|
||||||
|
= "edit"
|
||||||
|
= @groups_array.inspect
|
||||||
|
= form_tag move_person_path
|
||||||
|
= select :to, :to, @groups_array
|
||||||
|
= hidden_field_tag :from, :from, :value => @person_groups.first.id
|
||||||
|
= hidden_field_tag :friend_id, :friend_id, :value => @person.id
|
||||||
|
= submit_tag "save"
|
||||||
%li
|
%li
|
||||||
url:
|
url:
|
||||||
= @person.url
|
= @person.url
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ Diaspora::Application.routes.draw do
|
||||||
match 'login', :to => 'devise/sessions#new', :as => "new_user_session"
|
match 'login', :to => 'devise/sessions#new', :as => "new_user_session"
|
||||||
match 'logout', :to => 'devise/sessions#destroy', :as => "destroy_user_session"
|
match 'logout', :to => 'devise/sessions#destroy', :as => "destroy_user_session"
|
||||||
match 'get_to_the_choppa', :to => 'devise/registrations#new', :as => "new_user_registration"
|
match 'get_to_the_choppa', :to => 'devise/registrations#new', :as => "new_user_registration"
|
||||||
|
match 'groups/move_person', :to => 'groups#move_person', :as => 'move_person'
|
||||||
#public routes
|
#public routes
|
||||||
#
|
#
|
||||||
match 'webfinger', :to => 'publics#webfinger'
|
match 'webfinger', :to => 'publics#webfinger'
|
||||||
|
|
|
||||||
14
public/javascripts/group-edit.js
Normal file
14
public/javascripts/group-edit.js
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
$(function() {
|
||||||
|
$("li .person").draggable({
|
||||||
|
helper: 'clone',
|
||||||
|
cursor: 'move'
|
||||||
|
});
|
||||||
|
$("li .group").droppable({
|
||||||
|
drop: function(event, ui) {
|
||||||
|
//alert('dropped!');
|
||||||
|
$("<li class='person'></li>").text(ui.draggable.text()).appendTo(this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -110,4 +110,59 @@ describe Group do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "group editing" do
|
||||||
|
before do
|
||||||
|
@group = @user.group(:name => 'losers')
|
||||||
|
@group2 = @user2.group(:name => 'failures')
|
||||||
|
friend_users(@user, @group, @user2, @group2)
|
||||||
|
@group.reload
|
||||||
|
@group3 = @user.group(:name => 'cats')
|
||||||
|
@user.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be able to move a friend from one of users existing groups to another' do
|
||||||
|
@user.move_friend(:friend_id => @user2.person.id, :from => @group.id, :to => @group3.id)
|
||||||
|
@group.reload
|
||||||
|
@group3.reload
|
||||||
|
|
||||||
|
@group.person_ids.include?(@user2.person.id).should be false
|
||||||
|
@group3.people.include?(@user2.person).should be true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not move a person who is not a friend" do
|
||||||
|
@user.move_friend(:friend_id => @friend.id, :from => @group.id, :to => @group3.id)
|
||||||
|
@group.reload
|
||||||
|
@group3.reload
|
||||||
|
@group.people.include?(@friend).should be false
|
||||||
|
@group3.people.include?(@friend).should be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not move a person to a group that's not his" do
|
||||||
|
@user.move_friend(:friend_id => @user2.person.id, :from => @group.id, :to => @group2.id)
|
||||||
|
@group.reload
|
||||||
|
@group2.reload
|
||||||
|
@group.people.include?(@user2.person).should be true
|
||||||
|
@group2.people.include?(@user2.person).should be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should move all the by that user to the new group' do
|
||||||
|
message = @user2.post(:status_message, :message => "Hey Dude", :to => @group2.id)
|
||||||
|
|
||||||
|
@user.receive message.to_diaspora_xml
|
||||||
|
@group.reload
|
||||||
|
|
||||||
|
@group.posts.count.should be 1
|
||||||
|
@group3.posts.count.should be 0
|
||||||
|
|
||||||
|
@user.reload
|
||||||
|
@user.move_friend(:friend_id => @user2.person.id, :from => @group.id, :to => @group3.id)
|
||||||
|
@group.reload
|
||||||
|
@group3.reload
|
||||||
|
|
||||||
|
@group3.posts.count.should be 1
|
||||||
|
@group.posts.count.should be 0
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue