diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9b41b1fc9..0ee354dfb 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,6 +4,7 @@ class UsersController < ApplicationController require File.expand_path('../../../lib/diaspora/ostatus_builder', __FILE__) + require File.expand_path('../../../lib/diaspora/exporter', __FILE__) before_filter :authenticate_user!, :except => [:new, :create, :public] @@ -56,6 +57,11 @@ class UsersController < ApplicationController end end + def export + exporter = Diaspora::Exporter.new(Diaspora::Exporters::XML) + render :xml => exporter.execute(current_user) + end + private def prep_image_url(params) url = APP_CONFIG[:pod_url].chop if APP_CONFIG[:pod_url][-1,1] == '/' diff --git a/config/routes.rb b/config/routes.rb index 12fae72e6..6f9f529db 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,9 +10,12 @@ Diaspora::Application.routes.draw do resources :photos, :except => [:index] resources :albums + devise_for :users, :controllers => {:registrations => "registrations", + :password => "devise/passwords"} # added public route to user match 'public/:username', :to => 'users#public' - resources :users, :except => [:create, :new, :show] + match 'users/export', :to => 'users#export' + resources :users, :except => [:create, :new, :show] match 'aspects/move_friends', :to => 'aspects#move_friends', :as => 'move_friends' match 'aspects/move_friend', :to => 'aspects#move_friend', :as => 'move_friend' @@ -31,7 +34,6 @@ Diaspora::Application.routes.draw do match 'set_profile_photo', :to => "dev_utilities#set_profile_photo" #routes for devise, not really sure you will need to mess with this in the future, lets put default, #non mutable stuff in anohter file - devise_for :users, :controllers => {:registrations => "registrations"} match 'login', :to => 'devise/sessions#new', :as => "new_user_session" match 'logout', :to => 'devise/sessions#destroy', :as => "destroy_user_session" match 'signup', :to => 'registrations#new', :as => "new_user_registration" diff --git a/lib/diaspora/exporter.rb b/lib/diaspora/exporter.rb index 9e2f719a5..f23ed7681 100644 --- a/lib/diaspora/exporter.rb +++ b/lib/diaspora/exporter.rb @@ -4,11 +4,6 @@ module Diaspora - def self.bone(user) - exporter = Diaspora::Exporter.new(Diaspora::Exporters::XML) - exporter.execute(user) - end - class Exporter def initialize(strategy) self.class.send(:include, strategy) @@ -21,9 +16,9 @@ module Diaspora builder = Nokogiri::XML::Builder.new do |xml| xml.user { xml.username user.username + xml.parent << user.person.to_xml xml.serialized_private_key user.serialized_private_key - xml.person user.person.to_xml - + xml.aspects { user.aspects.each do |aspect| xml.aspect { @@ -36,8 +31,14 @@ module Diaspora end } xml.posts { - aspect.posts.each do |post| - xml.post post.to_xml if post.respond_to? :to_xml + aspect.posts.find_all_by_person_id(user.person.id).each do |post| + post_doc = post.to_xml + + post.comments.each do |comment| + post_doc << comment.to_xml + end + + xml.post post_doc end } } diff --git a/spec/lib/exporter_spec.rb b/spec/lib/exporter_spec.rb new file mode 100644 index 000000000..2831b8ef7 --- /dev/null +++ b/spec/lib/exporter_spec.rb @@ -0,0 +1,33 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3. See +# the COPYRIGHT file. + +require 'spec_helper' +require File.dirname(__FILE__) + '/../../lib/diaspora/exporter' + +describe Diaspora::Exporter do + + let!(:user1) { Factory(:user) } + let!(:user2) { Factory(:user) } + + let(:aspect1) { user1.aspect(:name => "Work") } + let(:aspect2) { user2.aspect(:name => "Family") } + + let!(:status_message1) { user1.post(:status_message, :message => "One", :public => true, :to => aspect1.id) } + let!(:status_message2) { user1.post(:status_message, :message => "Two", :public => true, :to => aspect1.id) } + let!(:status_message3) { user2.post(:status_message, :message => "Three", :public => false, :to => aspect2.id) } + + let!(:exported) { Diaspora::Exporter.new(Diaspora::Exporters::XML).execute(user1) } + + it 'should include a users posts' do + exported.should include status_message1.to_xml.to_s + exported.should include status_message2.to_xml.to_s + exported.should_not include status_message3.to_xml.to_s + end + + it 'should include a users private key' do + exported.should include user1.serialized_private_key + end + +end +