From b4174c664e34eddcd5020f721e34769876037ce1 Mon Sep 17 00:00:00 2001 From: maxwell Date: Wed, 25 Aug 2010 18:07:31 -0700 Subject: [PATCH] you can now reassign a peson's group --- app/controllers/groups_controller.rb | 10 ++++++++-- app/controllers/people_controller.rb | 4 ++++ app/models/user.rb | 2 -- app/views/people/show.html.haml | 10 ++++++---- config/routes.rb | 2 +- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 4810d6452..b3abcf607 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -50,8 +50,14 @@ class GroupsController < ApplicationController end def move_person - current_user.move_friend( :friend_id => params[:person_id], :from => params[:old_group_id], :to => params[:new_group_id]) - render :nothing => true + 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 diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 8b6ae849b..0a6a44dfc 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -16,6 +16,10 @@ class PeopleController < ApplicationController @profile = @person.profile @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' @latest_status_message = current_user.raw_visible_posts.find_all_by__type_and_person_id("StatusMessage", params[:id]).last diff --git a/app/models/user.rb b/app/models/user.rb index f3b0fcabf..ea8b917ad 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -51,10 +51,8 @@ class User puts posts_to_move.inspect to_group.people << friend to_group.posts << posts_to_move - puts to_group.inspect from_group.person_ids.delete(ensure_bson(friend.id)) posts_to_move.each{ |x| from_group.post_ids.delete(x.id)} - puts from_group.inspect from_group.save to_group.save return true diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 850307863..76fc3acef 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -18,10 +18,12 @@ %li ="groups: #{@person_groups}" = "edit" - = form_for Request.new do |f| - = f.select(:group_id, @groups_array) - = f.hidden_field :destination_url, :value => person.email - = f.submit "add friend" + = @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 url: = @person.url diff --git a/config/routes.rb b/config/routes.rb index 25a243172..e3c5b352a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,7 @@ Diaspora::Application.routes.draw do match 'login', :to => 'devise/sessions#new', :as => "new_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 'groups/move_person', :to => 'groups#move_person', :as => 'move_person' #public routes # match 'webfinger', :to => 'publics#webfinger'