diff --git a/.gitignore b/.gitignore index a17dc3a1b..379d97a20 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ public/stylesheets/ui.css # Uploded files and local files public/uploads/* -public/source.tar* +public/source.tar tmp/**/* db/*.sqlite3 diff --git a/Gemfile b/Gemfile index 83cb3ea08..aefce4437 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,6 @@ source 'http://rubygems.org' gem 'rails', '>= 3.0.0' - gem 'bundler', '>= 1.0.0' #Security @@ -42,7 +41,6 @@ gem 'aws' group :test, :development do gem 'factory_girl_rails' - gem 'ruby-debug19' if RUBY_VERSION.include? "1.9" gem 'ruby-debug' if RUBY_VERSION.include? "1.8" end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 75745a0ab..ec9bd7f1b 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -9,7 +9,6 @@ class RegistrationsController < Devise::RegistrationsController rescue MongoMapper::DocumentNotValid => e flash[:error] = e.message redirect_to new_user_registration_path - return end if user.save flash[:notice] = I18n.t 'registrations.create.success' @@ -20,7 +19,7 @@ class RegistrationsController < Devise::RegistrationsController end end - def update + def update super end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b9bd53ab5..0a2c2b0ad 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,11 +5,10 @@ class UsersController < ApplicationController require File.join(Rails.root, 'lib/diaspora/ostatus_builder') require File.join(Rails.root, 'lib/diaspora/exporter') - require File.join(Rails.root, 'lib/diaspora/importer') require File.join(Rails.root, 'lib/collect_user_photos') - before_filter :authenticate_user!, :except => [:new, :create, :public, :import] + before_filter :authenticate_user!, :except => [:new, :create, :public] respond_to :html @@ -79,31 +78,6 @@ class UsersController < ApplicationController send_data( File.open(tar_path).read, :filename => "#{current_user.id}.tar" ) end - def invite - User.invite!(:email => params[:email]) - end - - - def import - xml = params[:upload][:file].read - - params[:user][:diaspora_handle] = 'asodij@asodij.asd' - - - begin - importer = Diaspora::Importer.new(Diaspora::Parsers::XML) - importer.execute(xml, params[:user]) - flash[:notice] = "hang on a sec, try logging in!" - - rescue Exception => e - flash[:error] = "Derp, something went wrong: #{e.message}" - end - - redirect_to new_user_registration_path - #redirect_to user_session_path - end - - private def prep_image_url(params) url = APP_CONFIG[:pod_url].dup diff --git a/app/models/post.rb b/app/models/post.rb index 0e1fc1959..aa68dc897 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -14,7 +14,6 @@ class Post xml_accessor :_id xml_accessor :person, :as => Person xml_reader :public - xml_reader :created_at key :public , Boolean, :default => false diff --git a/app/models/profile.rb b/app/models/profile.rb index 328fa45c0..ecc0fb5ef 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -19,8 +19,6 @@ class Profile validates_presence_of :first_name, :last_name - before_save :strip_names - def person_id self._parent_document.id end @@ -29,9 +27,4 @@ class Profile self._parent_document end - private - def strip_names - first_name.strip! - last_name.strip! - end end diff --git a/app/models/user.rb b/app/models/user.rb index 9c1305430..83ce569f6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -56,7 +56,7 @@ class User many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post' many :aspects, :class_name => 'Aspect' - #after_create :seed_aspects + after_create :seed_aspects before_destroy :unfriend_everyone, :remove_person, :remove_all_aspects @@ -395,11 +395,7 @@ class User opts[:serialized_private_key] = generate_key opts[:person][:serialized_public_key] = opts[:serialized_private_key].public_key - - u = User.new(opts) - u.seed_aspects - u.save! - u + User.create(opts) end def seed_aspects diff --git a/app/views/albums/_new_album.haml b/app/views/albums/_new_album.haml index d7bd2d997..07431d20c 100644 --- a/app/views/albums/_new_album.haml +++ b/app/views/albums/_new_album.haml @@ -2,14 +2,12 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -.span-12.last - .modal_title_bar - %h4= t('.add_a_new_album') +%h1=t('.add_a_new_album') - = form_for Album.new do |f| - = f.error_messages - %p - = f.label :name - = f.text_field :name - = f.hidden_field :to, :value => aspect - = f.submit t('.create'), :class => 'button' += form_for Album.new do |f| + = f.error_messages + %p + = f.label :name + = f.text_field :name + = f.hidden_field :to, :value => aspect + = f.submit t('.create'), :class => 'button' diff --git a/app/views/aspects/_new_aspect.haml b/app/views/aspects/_new_aspect.haml index a3dec9d31..151ab07d4 100644 --- a/app/views/aspects/_new_aspect.haml +++ b/app/views/aspects/_new_aspect.haml @@ -2,14 +2,10 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -.span-12.last - .modal_title_bar - %h4= t('.add_a_new_aspect') - - = form_for Aspect.new do |aspect| - = aspect.error_messages - %p - = aspect.label :name - = aspect.text_field :name - = aspect.submit t('.create'), :class => 'button' - +%h1=t('.add_a_new_aspect') += form_for Aspect.new do |aspect| + = aspect.error_messages + %p + = aspect.label :name + = aspect.text_field :name + = aspect.submit t('.create'), :class => 'button' diff --git a/app/views/invitations/_new.haml b/app/views/invitations/_new.haml index 8619562a3..8c540092b 100644 --- a/app/views/invitations/_new.haml +++ b/app/views/invitations/_new.haml @@ -1,18 +1,15 @@ -.span-12.last - .modal_title_bar - %h4 Send invitation +%h2 Send invitation += form_for User.new, :url => invitation_path(User) do |invite| + %p + = invite.label :email + = invite.text_field :email + To + - unless @aspect.is_a? Aspect + = invite.select(:aspects, @aspects_dropdown_array) + - else + = invite.select(:aspects, @aspects_dropdown_array, :selected => @aspect.id) + Message: + = invite.text_area :invite_messages - = form_for User.new, :url => invitation_path(User) do |invite| - %p - = invite.label :email - = invite.text_field :email - To - - unless @aspect.is_a? Aspect - = invite.select(:aspects, @aspects_dropdown_array) - - else - = invite.select(:aspects, @aspects_dropdown_array, :selected => @aspect.id) - Message: - = invite.text_area :invite_messages - - %p= invite.submit "Send an invitation" + %p= invite.submit "Send an invitation" diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 0defb3463..84fb4d812 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -62,5 +62,5 @@ .span-24.last = yield - .span-19.prepend-5.last + .span-24.last = render "posts/debug" diff --git a/app/views/photos/_photo.haml b/app/views/photos/_photo.haml index 01baaf74e..5b7d8462e 100644 --- a/app/views/photos/_photo.haml +++ b/app/views/photos/_photo.haml @@ -27,8 +27,7 @@ %br %br - = render "albums/album", :post => post.album, :current_user => current_user - = link_to (image_tag post.url(:thumb_medium)), object_path(post) + = link_to (image_tag post.url(:thumb_large)), object_path(post) .info %span.time= link_to(how_long_ago(post), photo_path(post)) diff --git a/app/views/registrations/new.html.haml b/app/views/registrations/new.html.haml index cea31ff78..7e74a2157 100644 --- a/app/views/registrations/new.html.haml +++ b/app/views/registrations/new.html.haml @@ -24,27 +24,3 @@ = pr.text_field :last_name = f.submit t('.sign_up') = render :partial => "devise/shared/links" - - -%br -%br - -%h2 or, upload yourself - - -= form_tag '/users/import', :multipart => true do - - %p - = label_tag 'user[email]' - = text_field_tag 'user[email]' - %p - = label_tag 'user[password]' - = password_field_tag 'user[password]' - %p - = label_tag 'user[password_confirmation]' - = password_field_tag 'user[password_confirmation]' - - %label Select File - = file_field 'upload', 'file' - = submit_tag "Upload" - diff --git a/app/views/requests/_new_request.haml b/app/views/requests/_new_request.haml index 4c12486b8..68ee5922e 100644 --- a/app/views/requests/_new_request.haml +++ b/app/views/requests/_new_request.haml @@ -2,22 +2,20 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -.span-12.last - .modal_title_bar - %h4 - =t('.add_a_new_friend_to') - %i= aspect.name +%h1 + =t('.add_a_new_friend_to') + %i= aspect.name - = form_for Request.new do |fr_request| - = fr_request.error_messages += form_for Request.new do |fr_request| + = fr_request.error_messages - =t('.enter_a_diaspora_username') - %br - %i= t '.your_diaspora_username_is', :diaspora_handle => current_user.diaspora_handle + =t('.enter_a_diaspora_username') + %br + %i= t '.your_diaspora_username_is', :diaspora_handle => current_user.diaspora_handle - %p - = fr_request.label :destination_url, t(".friends_username") - = fr_request.text_field :destination_url - = fr_request.hidden_field :aspect_id, :value => aspect.id - = fr_request.submit + %p + = fr_request.label :destination_url, t(".friends_username") + = fr_request.text_field :destination_url + = fr_request.hidden_field :aspect_id, :value => aspect.id + = fr_request.submit diff --git a/app/views/shared/_public_explain.haml b/app/views/shared/_public_explain.haml index ca1a2b1d7..b1d2048b2 100644 --- a/app/views/shared/_public_explain.haml +++ b/app/views/shared/_public_explain.haml @@ -1,18 +1,12 @@ --# Copyright (c) 2010, Diaspora Inc. This file is --# licensed under the Affero General Public License version 3 or later. See --# the COPYRIGHT file. - -.span-12.last - .modal_title_bar - %h4 You are about to post a public message! - %p - Public messages will be available for others outside of Diaspora to see. - %br - %br - - if @logged_in - = connected_fb_as(@access_token) - - else - = link_to "Connect to Facebook", @fb_access_url - %br - %br - = link_to "OK", '#', :class => "button", :onClick => '$.fancybox.close();' +%h3 You are about to post a public message! +%p + Public messages will be available for others outside of Diaspora to see. + %br + %br + - if @logged_in + = connected_fb_as(@access_token) + - else + = link_to "Connect to Facebook", @fb_access_url + %br + %br + = link_to "OK", '#', :class => "button", :onClick => '$.fancybox.close();' diff --git a/app/views/shared/_reshare.haml b/app/views/shared/_reshare.haml index 44c8f00dd..2ac09a78f 100644 --- a/app/views/shared/_reshare.haml +++ b/app/views/shared/_reshare.haml @@ -2,6 +2,16 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. +:javascript + $(".reshare_button").toggle(function(e){ + e.preventDefault(); + $(this).parent(".reshare_pane").children(".reshare_box").fadeIn(200); + }, function(e) { + e.preventDefault(); + $(this).parent(".reshare_pane").children(".reshare_box").fadeOut(200); + }); + + - unless current_user.aspects.size == current_user.aspects_with_post(post.id).size .reshare_pane %span.reshare_button diff --git a/app/views/status_messages/show.html.haml b/app/views/status_messages/show.html.haml index 4521bae5a..7046c69a2 100644 --- a/app/views/status_messages/show.html.haml +++ b/app/views/status_messages/show.html.haml @@ -2,14 +2,22 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -%h1 - = link_to @status_message.person.real_name, @status_message.person - = @status_message.message +.span-14.append-1.last + #stream + %h1.show_text + = person_image_link(@status_message.person) + = link_to @status_message.person.real_name, @status_message.person + = make_links(@status_message.message) -%h4= "#{t('.comments')} (#{@status_message.comments.count})" + = "Posted #{how_long_ago(@status_message)} to" + - for aspect in current_user.aspects_with_post( @status_message.id ) + = link_to aspect.name, aspect -= render "comments/comments", :post => @status_message - -%p - if current_user.owns? @status_message - = link_to t('.destroy'), @status_message, :confirm => t('are_you_sure?'), :method => :delete + %p + = link_to t('.destroy'), @status_message, :confirm => t('.are_you_sure'), :method => :delete + +.span-9.last + #stream.show + %li.message{:id => @status_message.id} + = render "comments/comments", :post => @status_message diff --git a/config/app_config.yml.example b/config/app_config.yml.example index 0bd3771f7..90d9ac9f4 100644 --- a/config/app_config.yml.example +++ b/config/app_config.yml.example @@ -7,6 +7,7 @@ default: debug: false socket_debug : false socket_host: 0.0.0.0 + socket_pidfile: log/diaspora-wsd.pid socket_port: 8080 socket_collection_name: 'websocket' pubsub_server: 'https://pubsubhubbub.appspot.com/' diff --git a/config/routes.rb b/config/routes.rb index 47e73807b..8fbd132a8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,7 +16,6 @@ Diaspora::Application.routes.draw do # added public route to user match 'public/:username', :to => 'users#public' match 'users/export', :to => 'users#export' - match 'users/import', :to => 'users#import' match 'users/export_photos', :to => 'users#export_photos' resources :users, :except => [:create, :new, :show] diff --git a/lib/diaspora/exporter.rb b/lib/diaspora/exporter.rb index 5f40322fb..b560f729c 100644 --- a/lib/diaspora/exporter.rb +++ b/lib/diaspora/exporter.rb @@ -14,51 +14,36 @@ module Diaspora module XML def execute(user) builder = Nokogiri::XML::Builder.new do |xml| - user_person_id = user.person.id - xml.export { - xml.user { - xml.username user.username - xml.serialized_private_key user.serialized_private_key - - xml.parent << user.person.to_xml - } + xml.user { + xml.username user.username + xml.parent << user.person.to_xml + xml.serialized_private_key user.serialized_private_key + xml.aspects { user.aspects.each do |aspect| xml.aspect { + xml.id_ aspect.id xml.name aspect.name - - xml.person_ids { - aspect.person_ids.each do |id| - xml.person_id id + + xml.people { + aspect.people.each do |person| + xml.person person.to_xml end } + xml.posts { + 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_ids { - aspect.posts.find_all_by_person_id(user_person_id).each do |post| - xml.post_id post.id + xml.post post_doc end } } end } - - xml.people { - user.friends.each do |friend| - xml.parent << friend.to_xml - end - } - - xml.posts { - user.raw_visible_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.parent << post.to_xml - end - } } end diff --git a/lib/diaspora/importer.rb b/lib/diaspora/importer.rb deleted file mode 100644 index e1e8ad97f..000000000 --- a/lib/diaspora/importer.rb +++ /dev/null @@ -1,179 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -module Diaspora - - class Importer - def initialize(strategy) - self.class.send(:include, strategy) - end - - def commit(user, person, aspects, people, posts, opts = {}) - filter = verify_and_clean(user, person, people, aspects, posts) - #assume data is good - - # to go - user.email = opts[:email] - user.password= opts[:password] - user.password_confirmation = opts[:pasword_confirmation] - - - - user.person = person - - - user.person.diaspora_handle = opts[:diaspora_handle] - - user.visible_post_ids = filter[:whitelist].keys - - user.friend_ids = people.collect{ |x| x.id } - user.visible_person_ids = user.friend_ids - - user.save! - user.person.save! - - posts.each do |post| - post.save! if filter[:unknown].include? post.id - end - - - - aspects.each do |aspect| - user.aspects << aspect - end - - - - people.each do |p| - p.save! if filter[:people].include? p.id.to_s - end - end - - ### verification (to be module) ################ - - def verify_and_clean(user, person, people, aspects, posts) - verify_user(user) - verify_person_for_user(user, person) - filters = filter_posts(posts, person) - - - clean_aspects(aspects, filters[:whitelist]) - - - filters[:people] = filter_people(people) - filters - end - - def verify_user(user) - User.find_by_id(user.id).nil? ? true : raise("User already exists!") - end - - def verify_person_for_user(user, person) - local_person = Person.find_by_id(person.id) - if local_person - unless user.encryption_key.public_key.to_s == local_person.public_key.to_s - raise "local person found with different owner" - end - end - true - end - - - def filter_people(people) - person_ids = people.collect{|x| x.id} - people_from_db = Person.find_all_by_id(person_ids) #this query should be limited to only return person_id - person_ids = person_ids - people_from_db.collect{ |x| x.id } - - person_hash = {} - person_ids.each{|x| person_hash[x.to_s] = true } - person_hash - end - - def filter_posts(posts, person) - post_ids = posts.collect{|x| x.id} - posts_from_db = Post.find_all_by_id(post_ids) #this query should be limited to only return post id and owner id - - unknown_posts = post_ids - posts_from_db.collect{|x| x.id} - - posts_from_db.delete_if{|x| x.person_id == person.id} - unauthorized_post_ids = posts_from_db.collect{|x| x.id} - post_whitelist = post_ids - unauthorized_post_ids - - unknown = {} - unknown_posts.each{|x| unknown[x.to_s] = true } - - whitelist = {} - post_whitelist.each{|x| whitelist[x.to_s] = true } - - return { - :unknown => unknown, - :whitelist => whitelist } - end - - - def clean_aspects(aspects, whitelist) - aspects.each do |aspect| - aspect.post_ids.delete_if{ |x| !whitelist.include? x.to_s } - end - end - end - - module Parsers - module XML - def execute(xml, opts = {}) - doc = Nokogiri::XML.parse(xml) - - user, person = parse_user_and_person(doc) - aspects = parse_aspects(doc) - people = parse_people(doc) - posts = parse_posts(doc) - - user - commit(user, person, aspects, people, posts, opts) - end - - def parse_user_and_person(doc) - user = User.new - user_doc = doc.xpath('/export/user') - user.username = user_doc.xpath('//user/username').text - user.serialized_private_key= user_doc.xpath('//user/serialized_private_key').text - person = Person.from_xml(user_doc.xpath('//user/person').to_s) - [user, person] - end - - def parse_aspects(doc) - aspects = [] - aspect_doc = doc.xpath('/export/aspects/aspect') - - aspect_doc.each do |x| - a = Nokogiri::XML.parse(x.to_s) - - aspect = Aspect.new - aspect.name = a.xpath('/aspect/name').text - aspect.post_ids = a.xpath('/aspect/post_ids/post_id').collect{ |x| x.text.to_id } - aspect.person_ids = a.xpath('/aspect/person_ids/person_id').collect{ |x| x.text.to_id } - aspects << aspect - end - aspects - end - - def parse_people(doc) - people_doc = doc.xpath('/export/people/person') - people_doc.inject([]) do |people,curr| - people << Person.from_xml(curr.to_s) - end - end - - - def parse_posts(doc) - post_doc = doc.xpath('/export/posts/status_message') - post_doc.inject([]) do |posts,curr| - posts << StatusMessage.from_xml(curr.to_s) - end - end - - end - - end -end diff --git a/lib/diaspora/user/receiving.rb b/lib/diaspora/user/receiving.rb index 3a8fc5fa6..f459862ba 100644 --- a/lib/diaspora/user/receiving.rb +++ b/lib/diaspora/user/receiving.rb @@ -17,17 +17,23 @@ module Diaspora sender_in_xml = sender(object, xml) if (salmon_author == sender_in_xml) - if object.is_a? Retraction - receive_retraction object, xml - elsif object.is_a? Request + + if object.is_a? Request receive_request object, sender_in_xml - elsif object.is_a? Profile - receive_profile object, xml - elsif object.is_a?(Comment) - receive_comment object, xml + elsif self.friend_ids.include? salmon_author.id + if object.is_a? Retraction + receive_retraction object, xml + elsif object.is_a? Profile + receive_profile object, xml + elsif object.is_a?(Comment) + receive_comment object, xml + else + receive_post object, xml + end else - receive_post object, xml + raise "Not friends with that person" end + else raise "Malicious Post, #{salmon_author.real_name} with id #{salmon_author.id} is sending a #{object.class} as #{sender_in_xml.real_name} with id #{sender_in_xml.id} " end diff --git a/pkg/fedora/README.md b/pkg/fedora/README.md index e294302ce..7c5c9e3a2 100644 --- a/pkg/fedora/README.md +++ b/pkg/fedora/README.md @@ -12,11 +12,11 @@ aimed for packaging purposes. Prerequisites: - ruby-1.8, rubygem, git and rake as described in - http://github.com/diaspora/diaspora/wiki/Rpm-installation-on-fedora - or http://github.com/diaspora/diaspora/wiki/Installing-on-CentOS-Fedora + [RPM installation Fedora](http://github.com/diaspora/diaspora/wiki/Rpm-installation-on-fedora) + or [Installing-on-CentOS-Fedora](http://github.com/diaspora/diaspora/wiki/Installing-on-CentOS-Fedora) - A personal environment to build RPM:s, also described in - http://github.com/diaspora/diaspora/wiki/Rpm-installation-on-fedora + [RPM installation Fedora](http://github.com/diaspora/diaspora/wiki/Rpm-installation-on-fedora) Install g++ (possibly unnnecessary?): % yum install gcc-c++ @@ -46,7 +46,7 @@ Start development server: cd /usr/share/diaspora/master ./script/server -See http://github.com/diaspora/diaspora/wiki/Using-apache for +See [Using Apache](http://github.com/diaspora/diaspora/wiki/Using-apache) for apache/passenger setup. After configuration, start with: /sbin/service diaspora-wsd start /sbin/service httpd restart @@ -120,7 +120,8 @@ directory, copy-paste previous version nr. It will be updated. This has been confirmed to start up and provide basic functionality both using the thin webserver and apache passenger, on 32/64 bit systems and in the -mock build environment. +mock build environment. Irregular nightly builds are available form time to time +at [ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds](ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds) #### Implementation diff --git a/pkg/fedora/diaspora-setup b/pkg/fedora/diaspora-setup index 0fa90dc9e..8ce4bae60 100755 --- a/pkg/fedora/diaspora-setup +++ b/pkg/fedora/diaspora-setup @@ -39,18 +39,20 @@ else exit 1 fi -# %attr(0777, diaspora, diaspora) doesn't work in specfile due to umask 022. -chmod 777 /var/lib/diaspora/uploads chown -R diaspora /var/log/diaspora +sed -i '/socket_pidfile:/s|:.*|: /var/run/diaspora/diaspora-wsd.pid|' \ + config/app_config.yml + hostname=$( awk '/pod_url:/ { print $2; exit }' > dirs && mv -f dirs files sed -i -e '\|.*/master/config.ru"$|d' \ -e '\|.*/master/config/environment.rb"$|d' \ + -e '\|.*/run/diaspora"$|d' \ + -e '\|.*/pkg/fedora/dist"$|d' \ -e 's|%{buildroot}||' -e 's|//|/|' -e '/""/d' \ files @@ -101,6 +104,7 @@ sed -i -e '\|.*/master/config.ru"$|d' \ %post wsd /sbin/chkconfig --add diaspora-wsd || : + %preun wsd if [ $1 -eq 0 ] ; then service diaspora-wsd stop &>/dev/null || : @@ -117,9 +121,11 @@ rm -fr $RPM_BUILD_ROOT %doc AUTHORS README.md GNU-AGPL-3.0 COPYRIGHT README-Fedora.md %attr(-, diaspora, diaspora) %{_datadir}/diaspora/master/config.ru %attr(-, diaspora, diaspora) %{_datadir}/diaspora/master/config/environment.rb +%attr(-, diaspora, diaspora) %{_datadir}/diaspora/master/pkg/fedora/dist %attr(-, diaspora, diaspora) %{_localstatedir}/log/diaspora %attr(-, diaspora, diaspora) %{_localstatedir}/lib/diaspora/uploads %attr(-, diaspora, diaspora) %{_localstatedir}/lib/diaspora/tmp +%attr(-, diaspora, diaspora) %{_localstatedir}/run/diaspora %{_datadir}/diaspora/master/tmp %{_datadir}/diaspora/master/public/uploads diff --git a/pkg/fedora/dist/.gitkeep b/pkg/fedora/dist/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/pkg/fedora/make-dist.sh b/pkg/fedora/make-dist.sh index 6777ae773..dcfafb6e1 100755 --- a/pkg/fedora/make-dist.sh +++ b/pkg/fedora/make-dist.sh @@ -126,8 +126,7 @@ function checkout() git clone --quiet $GIT_REPO; ( cd diaspora; - git remote add upstream \ - git://github.com/diaspora/diaspora.git + git remote add upstream $GIT_REPO for p in ../../*.patch; do git apply --whitespace=fix $p > /dev/null done &> /dev/null || : @@ -181,7 +180,6 @@ function make_bundle() # Usage: make_bundle [ commit, defaults to HEAD] # { -set -x checkout ${1:-'HEAD'} >/dev/null bundle_id=$( git_id dist/diaspora/Gemfile) bundle_name="diaspora-bundle-$VERSION-$bundle_id" diff --git a/pkg/ubuntu/README.md b/pkg/ubuntu/README.md index 15a4947dc..cd633fdfb 100644 --- a/pkg/ubuntu/README.md +++ b/pkg/ubuntu/README.md @@ -5,6 +5,7 @@ work as a first step towards packaging, but should be usable as is. ### Synopsis + Bootstrap the distribution from git: % sudo apt-get install git-core % git clone git://github.com/diaspora/diaspora.git @@ -79,19 +80,11 @@ dependencies lives in the application - nothing is installed by user or on system level. This has been tested on a Ubuntu 32-bit 10.10 , clean server and on 10.04 -Lucid desktop, also clean installation. +Lucid desktop, also clean installation. Irregular nightly builds are +available from time to time at +[ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds](ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds) mongodb is having problems occasionally. Sometimes the dependencies are not installed, and mongod refuses to start. invoke */usr/bin/mongod -f /etc/mongodb.conf* to test. The lockfile /var/lib/mongodb/mongod.conf is also a potential problem. Remove to make it start again. - -The diaspora-wsd is just placeholder FTM, it does **not** work. - - - - - - - - diff --git a/pkg/ubuntu/diaspora-install b/pkg/ubuntu/diaspora-install index e7cef8f31..0685aa3ae 100755 --- a/pkg/ubuntu/diaspora-install +++ b/pkg/ubuntu/diaspora-install @@ -30,7 +30,7 @@ sed -i '/BUNDLE_PATH/s|:.*|: /usr/lib/diaspora-bundle/bundle|' \ cp master/GNU-AGPL-3.0 master/COPYRIGHT master/README.md master/AUTHORS . cp master/config/app_config.yml.example ./app_config.yml -cp master/pkg/ubuntu/diaspora-wsd /etc/init.d +cp master/pkg/ubuntu/diaspora-wsd.conf /etc/init sed -i '/^cd /s|.*|cd /usr/share/diaspora/master|' /etc/init.d/diaspora-wsd @@ -41,8 +41,8 @@ cp master/pkg/ubuntu/diaspora-setup . mkdir -p /var/log/diaspora mkdir -p /var/lib/diaspora/uploads mkdir -p /var/lib/diaspora/tmp +mkdir -p /var/run/diaspora mkdir -p /etc/diaspora -mkdir -p /usr/share/diaspora/master/pkg/ubuntu/dist ln -sf /var/log/diaspora ./master/log cp master/config/app_config.yml.example /etc/diaspora/app_config.yml @@ -65,5 +65,6 @@ chown diaspora:diaspora /var/log/diaspora chown diaspora:diaspora /var/lib/diaspora/uploads chown diaspora:diaspora /var/lib/diaspora/tmp chown diaspora:diaspora /var/lib/diaspora +chown diaspora:diaspora /var/run/diaspora chown diaspora:diaspora /usr/share/diaspora/master/pkg/ubuntu/dist diff --git a/pkg/ubuntu/diaspora-setup b/pkg/ubuntu/diaspora-setup index 3f2c0266c..109e460bd 100755 --- a/pkg/ubuntu/diaspora-setup +++ b/pkg/ubuntu/diaspora-setup @@ -43,9 +43,11 @@ else exit 1 fi -chmod 777 /var/lib/diaspora/uploads chown -R diaspora /var/log/diaspora +sed -i '/socket_pidfile:/s|:.*|: /var/run/diaspora/diaspora-wsd.pid|' \ + config/app_config.yml + hostname=$( awk '/pod_url:/ { print $2; exit }' >$logfile 2>&1 &" - RETVAL=$? - echo - if test $RETVAL = 0; then - touch $lockfile - pgrep -f "$ruby_cmd" > $pidfile || { - echo "Warning: cannot find running diaspora-webserver" - exit 7 - } - fi -} - -stop() { - [ $UID -eq 0 ] || exit 4 - echo -n $"Stopping $prog: " - killproc -p $pidfile $exec - RETVAL=$? - [ $RETVAL -eq 0 ] && rm -f $lockfile - echo -} - -# -# See how we were called. -# -case "$1" in - start) - start - ;; - stop) - stop - ;; - force-reload|restart) - stop - sleep 1 - start - RETVAL=$? - ;; - condrestart|try-restart) - if [ -f $lockfile ]; then - stop - sleep 3 - start - fi - ;; - status) - status -p $pidfile $exec - RETVAL=$? - ;; - *) - echo $"Usage: $0 {condrestart|try-restart|start|stop|restart|force-reload|status}" - RETVAL=2 - [ "$1" = 'usage' ] && RETVAL=0 -esac - -exit $RETVAL diff --git a/pkg/ubuntu/diaspora-wsd.conf b/pkg/ubuntu/diaspora-wsd.conf new file mode 100644 index 000000000..95d78118e --- /dev/null +++ b/pkg/ubuntu/diaspora-wsd.conf @@ -0,0 +1,19 @@ +# Ubuntu upstart file at /etc/init/diaspora-wsd.conf + +start on runlevel [5] +stop on runlevel [06] + +export fork + +script + if [ -f /etc/default/diaspora ]; then + . /etc/default/diaspora; + fi; + cd /usr/share/diaspora/master; + start-stop-daemon --start \ + --chuid diaspora:diaspora \ + --chdir $PWD \ + --exec "/usr/local/bin/bundle" \ + -- exec ruby -C $PWD script/websocket_server.rb; + +end script diff --git a/pkg/ubuntu/dist/.gitkeep b/pkg/ubuntu/dist/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/public/javascripts/stream.js b/public/javascripts/stream.js index c7ec199d6..d4f72bcbc 100644 --- a/public/javascripts/stream.js +++ b/public/javascripts/stream.js @@ -29,7 +29,7 @@ $(".show_post_comments").live('click', function(event) { $(this).toggleClass( "visible" ); }); -$(".comment_box").toggle(function(evt){ +$(".comment_box").live('focus', function(evt){ var $this = $(this); $this.attr("rows", 2); $this.parents("p").parents("form").children("p").children(".comment_submit").fadeIn(200); @@ -47,10 +47,3 @@ $(".comment_submit").live('click', function(evt){ $(this).closest("form").children("p .comment_box").attr("rows", 1); }); -$(".reshare_button").live("click", function(e){ - e.preventDefault(); - var button = $(this); - button.parent(".reshare_pane").children(".reshare_box").show(); - button.addClass("active"); -}); - diff --git a/public/javascripts/view.js b/public/javascripts/view.js index 1096b532c..677a36979 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -53,21 +53,6 @@ $(document).ready(function(){ } }); - $("#user_menu").click( function(){ - $(this).toggleClass("active"); - }); - - $('body').click( function(event){ - if(!$(event.target).closest('#user_menu').length){ - $("#user_menu").removeClass("active"); - }; - if(!$(event.target).closest('.reshare_box').length){ - $(".reshare_button").removeClass("active"); - $(".reshare_box").hide(); - }; - }); - - });//end document ready diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 5f1106f03..e7afb9c26 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -22,7 +22,7 @@ a :color #22AAE0 &:active :color #005D9C - + h1, h2, h3, h4 :color #444 @@ -48,14 +48,14 @@ h3 :width 100% :padding 1em - + :box-shadow 0 1px 2px #333 :-moz-box-shadow 0 1px 2px #333 :-webkit-box-shadow 0 1px 2px #333 :font :weight bold - + #flash_notice :background :color rgba(127,255,36,0.85) @@ -128,9 +128,9 @@ header a :text-shadow 0 1px 0 #000 - :width 100px - :z-index 10 + :font + :size 14px :padding 5px 10px :left 40px :margin 0 @@ -152,7 +152,11 @@ header a :display block - &.active + &:hover + li + :display block + + &:hover :margin :top -3px :right -6px @@ -164,14 +168,11 @@ header :-webkit-box-shadow 0 1px 2px #333 :-moz-box-shadow 0 1px 2px #333 - li - :display block - .avatar :height 20px :width 20px :position absolute - :left 5px + :left 5px :display block @@ -179,14 +180,13 @@ header :margin :left 425px -ul#stream +#stream :margin 0 :padding 0 > li :min-height 50px :list-style none :padding 12px 0 - :right 12px :border :bottom 1px solid #eee @@ -275,7 +275,7 @@ li.message :weight bold :margin :right 5px - + &:hover div.info, .time a @@ -293,16 +293,6 @@ li.message :decoration none :cursor default -.right .reshare_pane .reshare_button - :padding 5px - &.active - :background - :color #333 - :border-radius 5px 5px 0 0 - a - :color #fff - :text-shadow none - .right .reshare_pane :margin :left 5px @@ -310,14 +300,13 @@ li.message :display inline :position relative - ul.reshare_box :width 150px :display none :z-index 10 :position absolute :margin - :top 0 + :top 5px :padding 0 :background @@ -326,7 +315,9 @@ li.message :list :style none - :border 5px solid #333 + :border 5px solid #666 + :-webkit-box-shadow 0 0 5px #666 + :-moz-box-shadow 0 0 5px #666 :text-shadow 0 2px #fff :color #000 @@ -349,7 +340,6 @@ li.message :display block :height 100% :padding 2px 5px - :cursor default &:hover :background @@ -404,6 +394,20 @@ form :margin :right 1em +#stream.show + div.comments + :display block + ul.comment_set + :margin + :top 0 + > li + :border none + :padding 0 + &:hover + > li + :background none + :border none + #stream div.comments :display none @@ -794,8 +798,8 @@ h1.big_text :margin 0 a - :-webkit-border-radius 5px 5px 0 0 - :-moz-border-radius 5px 5px 0 0 + :-webkit-border-radius 5px 5px 0 0 + :-moz-border-radius 5px 5px 0 0 :text-shadow 0 1px 0 #444 :line @@ -923,7 +927,7 @@ h1.big_text :color #333 :border-radius 5px - + a :color #ccc @@ -1066,3 +1070,7 @@ header :font :size small +.show_text + img + :height 27px + :width 27px diff --git a/script/websocket_server.rb b/script/websocket_server.rb index 65199175e..4dddca11e 100644 --- a/script/websocket_server.rb +++ b/script/websocket_server.rb @@ -5,6 +5,26 @@ require File.dirname(__FILE__) + '/../config/environment' require File.dirname(__FILE__) + '/../lib/diaspora/websocket' +at_exit do + begin + File.delete(PID_FILE) + rescue + puts 'Cannot remove pidfile: ' + (PID_FILE ? PID_FILE : "NIL") + end +end + +def write_pidfile + begin + f = File.open(PID_FILE, "w") + f.write(Process.pid) + f.close + rescue => e + puts "Can't write to pidfile!" + puts e.inspect + puts e.backtrace + end +end + CHANNEL = Magent::GenericChannel.new('websocket') def process_message if CHANNEL.queue_count > 0 @@ -37,6 +57,8 @@ begin } end + PID_FILE = APP_CONFIG[:socket_pidfile] + write_pidfile puts "Websocket server started." process_message } diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index 113ca4a9b..cf1a71d88 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -8,7 +8,8 @@ describe PublicsController do render_views let(:user) {Factory.create :user} let(:user2){Factory.create :user} - + let(:aspect1){user.aspect(:name => "foo")} + let(:aspect2){user2.aspect(:name => "far")} before do sign_in :user, user end @@ -21,7 +22,8 @@ describe PublicsController do it 'should accept a post from another node and save the information' do message = user2.build_post(:status_message, :message => "hi") - + friend_users(user, aspect1, user2, aspect2) + user.reload user.visible_post_ids.include?(message.id).should be false diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb index 3b9e090f9..3f51cea96 100644 --- a/spec/lib/diaspora_parser_spec.rb +++ b/spec/lib/diaspora_parser_spec.rb @@ -12,6 +12,8 @@ describe Diaspora::Parser do @user3 = Factory.create :user @person = @user3.person @user2 = Factory.create(:user) + @aspect2 = @user2.aspect(:name => "pandas") + friend_users(@user, @aspect, @user2, @aspect2) end describe "parsing compliant XML object" do @@ -49,7 +51,7 @@ describe Diaspora::Parser do end it 'should marshal retractions' do - person = Factory.create(:person) + person = @user2.person message = Factory.create(:status_message, :person => person) retraction = Retraction.for(message) xml = retraction.to_diaspora_xml @@ -97,17 +99,17 @@ describe Diaspora::Parser do end it "should activate the Person if I initiated a request to that url" do - request = @user.send_friend_request_to( @user2.person, @aspect) + request = @user.send_friend_request_to( @user3.person, @aspect) @user.reload - request.reverse_for @user2 + request.reverse_for @user3 xml = request.to_diaspora_xml - @user2.person.destroy - @user2.destroy + @user3.person.destroy + @user3.destroy - @user.receive xml, @user2.person - new_person = Person.first(:url => @user2.person.url) + @user.receive xml, @user3.person + new_person = Person.first(:url => @user3.person.url) new_person.nil?.should be false @user.reload @@ -117,18 +119,20 @@ describe Diaspora::Parser do end it 'should process retraction for a person' do + user4 = Factory(:user) + person_count = Person.all.count - request = @user.send_friend_request_to( @user2.person, @aspect) + request = @user.send_friend_request_to( user4.person, @aspect) @user.reload - request.reverse_for @user2 + request.reverse_for user4 xml = request.to_diaspora_xml - retraction = Retraction.for(@user2) + retraction = Retraction.for(user4) retraction_xml = retraction.to_diaspora_xml - @user2.person.destroy - @user2.destroy - @user.receive xml, @user2.person + user4.person.destroy + user4.destroy + @user.receive xml, user4.person @aspect.reload @@ -136,7 +140,7 @@ describe Diaspora::Parser do #They are now friends Person.count.should == person_count - @user.receive retraction_xml, @user2.person + @user.receive retraction_xml, user4.person @aspect.reload @@ -145,7 +149,7 @@ describe Diaspora::Parser do it 'should marshal a profile for a person' do #Create person - person = Factory.create(:person) + person = @user2.person id = person.id person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com") person.save diff --git a/spec/lib/exporter_spec.rb b/spec/lib/exporter_spec.rb index 88369dacf..fb3e6d29f 100644 --- a/spec/lib/exporter_spec.rb +++ b/spec/lib/exporter_spec.rb @@ -9,57 +9,25 @@ describe Diaspora::Exporter do let!(:user1) { Factory(:user) } let!(:user2) { Factory(:user) } - let!(:user3) { Factory(:user) } let(:aspect1) { user1.aspect(:name => "Work") } let(:aspect2) { user2.aspect(:name => "Family") } - let(:aspect3) { user3.aspect(:name => "Pivots") } 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) } + let!(:exported) { Diaspora::Exporter.new(Diaspora::Exporters::XML).execute(user1) } it 'should include a users posts' do - exported.should include status_message1.message - exported.should include status_message2.message - exported.should_not include status_message3.message + 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 - it 'should include post_ids' do - doc = Nokogiri::XML::parse(exported) - doc.xpath('//aspects').to_s.should include status_message1.id.to_s - - doc.xpath('//aspects').to_s.should include status_message2.id.to_s - doc.xpath('//posts').to_s.should include status_message1.id.to_s - end - - it 'should include post created at time' do - doc = Nokogiri::XML::parse(exported) - Time.parse(doc.xpath('//posts/status_message/created_at').first.text).should == status_message1.created_at - end - - it 'should include a list of users posts' do - doc = Nokogiri::XML::parse(exported) - posts = doc.xpath('//posts').to_s - posts.should include(status_message1.message) - end - - it 'should serialize a users friends' do - friend_users(user1, aspect1, user3, aspect3) - doc = Nokogiri::XML::parse(exported) - doc.xpath('/export/people').to_s.should include user3.person.id.to_s - end - - it 'should serialize only a users posts within his aspects' do - message = Factory(:status_message, :message => "Shouldn't be here", :person => user3.person) - aspect1.posts << message - doc = Nokogiri::XML::parse(exported) - doc.xpath('/export/aspects').to_s.should_not include message.message - end end + diff --git a/spec/lib/importer_spec.rb b/spec/lib/importer_spec.rb deleted file mode 100644 index 268b0f5e1..000000000 --- a/spec/lib/importer_spec.rb +++ /dev/null @@ -1,234 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require 'spec_helper' -require File.join(Rails.root, 'lib/diaspora/exporter') -require File.join(Rails.root, 'lib/diaspora/importer') - -describe Diaspora::Importer do - - before(:each) do - # Five users on pod - @user1 = Factory(:user) - @user2 = Factory(:user) - @user3 = Factory(:user) - @user4 = Factory(:user) - @user5 = Factory(:user) - - # Two external people referenced on pod - @person1 = Factory(:person) - @person2 = Factory(:person) - - # User1 has four aspects(1-4), each following user has one aspect - @aspect1 = @user1.aspect(:name => "Dudes") - @aspect2 = @user1.aspect(:name => "Girls") - @aspect3 = @user1.aspect(:name => "Bros") - @aspect4 = @user1.aspect(:name => "People") - @aspect5 = @user2.aspect(:name => "Abe Lincolns") - @aspect6 = @user3.aspect(:name => "Cats") - @aspect7 = @user4.aspect(:name => "Dogs") - @aspect8 = @user5.aspect(:name => "Hamsters") - @aspect9 = @user5.aspect(:name => "Gophers") - - @aspect10 = @user1.aspect(:name => "Work") - @aspect11 = @user1.aspect(:name => "Family") - - # User1 posts one status messages to aspects (1-4), two other users post message to one aspect - @status_message1 = @user1.post(:status_message, :message => "One", :public => false, :to => @aspect1.id) - @status_message2 = @user1.post(:status_message, :message => "Two", :public => false, :to => @aspect2.id) - @status_message3 = @user1.post(:status_message, :message => "Three", :public => false, :to => @aspect3.id) - @status_message4 = @user1.post(:status_message, :message => "Four", :public => false, :to => @aspect4.id) - @status_message5 = @user2.post(:status_message, :message => "Five", :public => false, :to => @aspect5.id) - @status_message6 = @user3.post(:status_message, :message => "Six", :public => false, :to => @aspect6.id) - @status_message7 = @user5.post(:status_message, :message => "Seven", :public => false, :to => @aspect9.id) - - @aspect1.posts << @status_message1 - @aspect2.posts << @status_message2 - @aspect3.posts << @status_message3 - @aspect4.posts << @status_message4 - - # Friend users with user1 - friend_users( @user1, @aspect1, @user2, @aspect5 ) - friend_users( @user1, @aspect2, @user3, @aspect6 ) - friend_users( @user1, @aspect3, @user4, @aspect7 ) - friend_users( @user1, @aspect4, @user5, @aspect8 ) - - # Friend users 4 and 5 - friend_users( @user5, @aspect9, @user4, @aspect7 ) - - # Generate status messages and receive for user1 - @user2.receive @status_message1.to_diaspora_xml, @user1.person - @user3.receive @status_message2.to_diaspora_xml, @user1.person - @user4.receive @status_message3.to_diaspora_xml, @user1.person - @user5.receive @status_message4.to_diaspora_xml, @user1.person - @user1.receive @status_message5.to_diaspora_xml, @user2.person - @user1.receive @status_message6.to_diaspora_xml, @user3.person - - # Generate status message and recieve between user4 and user5 - @user4.receive @status_message7.to_diaspora_xml, @user5.person - end - - it 'should gut check this test' do - - @user1.friends.count.should be 4 - - @user1.friends.should include @user2.person - @user1.friends.should include @user3.person - @user1.friends.should include @user4.person - @user1.friends.should include @user5.person - - # User is generated with two pre-populated aspects - @user1.aspects.count.should be 6 - @user1.aspects.find_by_name("Dudes").people.should include @user2.person - @user1.aspects.find_by_name("Dudes").posts.should include @status_message5 - - @user1.raw_visible_posts.count.should be 6 - @user1.raw_visible_posts.find_all_by_person_id(@user1.person.id).count.should be 4 - @user1.raw_visible_posts.find_all_by_person_id(@user1.person.id).should_not include @status_message7 - end - - context 'parsing a user' do - - before(:each) do - # Generate exported XML for user1 - exporter = Diaspora::Exporter.new(Diaspora::Exporters::XML) - @user1.aspects.reload - @xml = exporter.execute(@user1) - - @old_user = @user1 - - # Remove user1 from the server - @user1.aspects.each( &:delete ) - @user1.raw_visible_posts.find_all_by_person_id(@user1.person.id).each( &:delete ) - @user1.delete - - @importer = Diaspora::Importer.new(Diaspora::Parsers::XML) - @doc = Nokogiri::XML::parse(@xml) - end - - describe '#parse_user_and_person' do - before(:each) do - @user, @person = @importer.parse_user_and_person(@doc) - end - - it 'should set username' do - @user.username.should == @old_user.username - end - - it 'should set private key' do - @user.serialized_private_key.should_not be nil - @user.serialized_private_key.should == @old_user.serialized_private_key - end - - end - - describe '#parse_aspects' do - let(:aspects) { @importer.parse_aspects(@doc) } - - it 'should return valid aspects' do - aspects.all?(&:valid?).should be true - end - - it 'should return an array' do - aspects.count.should == 6 - end - - it 'should should have post ids' do - aspects.any?{|x| x.post_ids.count > 0}.should be true - end - - it 'should have person ids' do - aspects.any?{|x| x.person_ids.count > 0}.should be true - end - end - - describe '#parse_people' do - let(:people) { @importer.parse_people(@doc) } - - it 'should return an array' do - people.count.should == 4 - end - end - - describe '#parse_posts' do - let(:posts) { @importer.parse_posts(@doc) } - - it 'should return an array' do - posts.count.should == 4 - end - - it 'should return vaild posts' do - posts.all?(&:valid?).should be true - end - end - - end - - describe 'importing a user' do - - context '#execute' do - before(:each) do - # Generate exported XML for user1 - exporter = Diaspora::Exporter.new(Diaspora::Exporters::XML) - @xml = exporter.execute(@user1) - - # Remove user1 from the server - @user1.aspects.each( &:delete ) - @user1.raw_visible_posts.find_all_by_person_id(@user1.person.id).each( &:delete ) - @user1.delete - - @importer = Diaspora::Importer.new(Diaspora::Parsers::XML) - end - - it 'should import' do - pending "there is some weirdness with diaspora handle we need to look into... and this test is terrible" - User.delete_all - Person.delete_all - Post.delete_all - StatusMessage.delete_all - Aspect.delete_all - - User.count.should == 0 - Person.count.should == 0 - - @importer.execute(@xml, - :email => "bob@bob.com", - :password => "bobbybob", - :password => "bobbybob", - :diaspora_handle => "bob@diaspora.com") - - User.count.should == 1 - n = User.first - Post.count.should == 4 - n.aspects.count.should == 6 - Person.count.should be == 5 - - User.first.person.diaspora_handle.should == User.first.diaspora_handle - - - Person.find_by_id( @user1.person.id ).nil?.should == false - Person.find_by_id( @user2.person.id ).nil?.should == false - - n.aspects.count.should == 6 - - people_count = 0 - n.aspects.each{|x| people_count += x.people.count } - people_count.should == 4 - - post_count = 0 - n.aspects.reload - n.aspects.each{ |x| post_count += x.post_ids.count } - post_count.should == 4 - - n.friends.count.should be 4 - end - - - - end - - end - -end - diff --git a/spec/lib/verify_spec.rb b/spec/lib/verify_spec.rb deleted file mode 100644 index b0b8a0de6..000000000 --- a/spec/lib/verify_spec.rb +++ /dev/null @@ -1,109 +0,0 @@ -# Copyright (c) 2010, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require 'spec_helper' -require File.join(Rails.root, 'lib/diaspora/importer') - -describe Diaspora::Importer do - - let!(:user1) { Factory(:user) } - let!(:user2) { Factory(:user) } - let!(:user3) { Factory(:user) } - - let(:aspect1) { user1.aspect(:name => "Work") } - let(:aspect2) { user2.aspect(:name => "Family") } - let(:aspect3) { user3.aspect(:name => "Pivots") } - - 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(:importer) { Diaspora::Importer.new(Diaspora::Parsers::XML) } - - context 'serialized user' do - describe '#verify_user' do - it 'should return true for a new valid user' do - new_user = Factory(:user) - new_user.delete - importer.verify_user(new_user).should be true - end - - it 'should return false if vaild user already exists' do - u = User.first - lambda{ importer.verify_user(user1) }.should raise_error - end - end - - describe '#verify_person_for_user' do - it 'should pass if keys match' do - importer.verify_person_for_user(user1, user1.person).should be true - end - - it 'should fail if private and public keys do not match' do - person = Factory(:person) - lambda{ importer.verify_person_for_user(user1, person) }.should raise_error - end - - it 'should pass if the person does not exist' do - user = Factory.build(:user) - importer.verify_person_for_user(user, user.person) - end - end - - - describe '#filter_posts' do - it 'should make sure all found posts are owned by the user' do - posts = [status_message1, status_message2] - whitelist = importer.filter_posts(posts, user1.person)[:whitelist] - - whitelist.should have(2).posts - whitelist.should include status_message1.id.to_s - whitelist.should include status_message2.id.to_s - end - - it 'should remove posts not owned by the user' do - posts = [status_message1, status_message2, status_message3] - whitelist = importer.filter_posts(posts, user1.person)[:whitelist] - - whitelist.should have(2).posts - whitelist.should_not include status_message3.id - end - - it 'should return a list of unknown posts' do - posts = [status_message1, status_message2, Factory.build(:status_message)] - unknown = importer.filter_posts(posts, user1.person)[:unknown] - - unknown.should have(1).post - end - - it 'should generate a whitelist, unknown posts inclusive' do - posts = [status_message1, status_message2, Factory.build(:status_message)] - filters = importer.filter_posts(posts, user1.person) - - filters[:whitelist].should include filters[:unknown].keys.first - end - end - - describe '#clean_aspects' do - it 'should purge posts not in whitelist that are present in aspects' do - whitelist = {status_message1.id.to_s => true, status_message2.id.to_s => true} - - aspect1.reload - aspect1.post_ids << status_message3.id.to_s - - proc{ importer.clean_aspects([aspect1], whitelist) }.should change(aspect1.post_ids, :count).by(-1) - aspect1.post_ids.should_not include status_message3.id - end - end - - describe '#filter_people' do - it 'should filter people who already exist in the database' do - new_peep = Factory.build(:person) - people = [user1.person, user2.person, new_peep] - - importer.filter_people(people).keys.should == [new_peep.id.to_s] - end - end - end -end diff --git a/spec/models/aspect_spec.rb b/spec/models/aspect_spec.rb index fa714e012..abb995ebd 100644 --- a/spec/models/aspect_spec.rb +++ b/spec/models/aspect_spec.rb @@ -65,7 +65,7 @@ describe Aspect do it 'belong to a user' do @aspect.user.id.should == @user.id - @user.aspects.size.should == 1 + @user.aspects.size.should == 3 end it 'should have people' do diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index de70ce030..7fcf5967e 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -103,10 +103,18 @@ describe Photo do end it 'should set the remote_photo on marshalling' do + pending "did the socket get unstubbed?" @photo.image.store! File.open(@fixture_name) + + #security hax + user2 = Factory.create(:user) + aspect2 = user2.aspect(:name => "foobars") + friend_users(@user, @aspect, user2, aspect2) + @photo.person = user2.person + @photo.save - @photo.reload + #@photo.reload url = @photo.url thumb_url = @photo.url :thumb_medium diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index 4830652f8..7bba8311c 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -9,15 +9,6 @@ describe Profile do @person = Factory.build(:person) end - describe 'sanitization' do - it 'strips the names' do - @person.profile = Factory.build(:profile, :first_name => " Bob", :last_name => "Bobson ") - @person.profile.save - @person.profile.first_name.should == "Bob" - @person.profile.last_name.should == "Bobson" - end - end - describe 'requirements' do it "should include a first name" do @person.profile = Factory.build(:profile,:first_name => nil) @@ -32,5 +23,7 @@ describe Profile do @person.profile.last_name = "Smith" @person.profile.valid?.should be true end + end + end diff --git a/spec/models/user/attack_vectors_spec.rb b/spec/models/user/attack_vectors_spec.rb index ebab7cf37..4ae9184dd 100644 --- a/spec/models/user/attack_vectors_spec.rb +++ b/spec/models/user/attack_vectors_spec.rb @@ -8,8 +8,6 @@ describe User do let(:user) { Factory(:user) } let(:aspect) { user.aspect(:name => 'heroes') } - - let(:bad_user) { Factory(:user)} let(:user2) { Factory(:user) } let(:aspect2) { user2.aspect(:name => 'losers') } @@ -23,9 +21,8 @@ describe User do end context 'non-friend valid user' do - + it 'raises if receives post by non-friend' do - pending "need to that posts come from friends.... requests need special treatment(because the person may not be in the db)" post_from_non_friend = bad_user.build_post( :status_message, :message => 'hi') xml = bad_user.salmon(post_from_non_friend).xml_for(user.person) @@ -43,7 +40,7 @@ describe User do end context 'malicious friend attack vector' do - it 'overwrites messages with a different user' do + it 'overwrites messages with a different user' do original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id user.receive_salmon(user2.salmon(original_message).xml_for(user.person)) @@ -55,8 +52,8 @@ describe User do user.raw_visible_posts.count.should be 1 user.raw_visible_posts.first.message.should == "store this!" end - - it 'overwrites messages which apear to be from the same user' do + + it 'overwrites messages which apear to be from the same user' do original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id user.receive_salmon(user2.salmon(original_message).xml_for(user.person)) user.raw_visible_posts.count.should be 1 @@ -79,12 +76,12 @@ describe User do user2.reload user2.profile.first_name.should == "Robert" end - + it 'should not overwrite another persons profile through comment' do pending user_status = user.post(:status_message, :message => "hi", :to => 'all') comment = Comment.new(:person_id => user3.person.id, :text => "hey", :post => user_status) - + comment.creator_signature = comment.sign_with_key(user3.encryption_key) comment.post_creator_signature = comment.sign_with_key(user.encryption_key) @@ -92,14 +89,14 @@ describe User do original_url = person.url original_id = person.id puts original_url - + comment.person.url = "http://bad.com/" user3.delete person.delete - + comment.to_diaspora_xml.include?("bad.com").should be true user2.receive_salmon(user.salmon(comment).xml_for(user2.person)) - + comment.person.url.should == original_url Person.first(:id => original_id).url.should == original_url end