diff --git a/.gitignore b/.gitignore index dafc5e44d9b2dfc28e2bd042e6126f44a36b3b2b..d57f5a3387a0088a6448b4bf2f34d8479f786ccb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ *~ .bundle db/*.sqlite3 -log/*.log +log/* tmp/**/* Gemfile.lock gpg/diaspora-development/*.gpg diff --git a/.pairs b/.pairs new file mode 100644 index 0000000000000000000000000000000000000000..3930858be20722fa96de9c14cf7813059cf45176 --- /dev/null +++ b/.pairs @@ -0,0 +1,8 @@ +pairs: + dg: Daniel Grippi; daniel + rs: Raphael Sofaer; raphael + iz: Ilya Zhitomirskiy; ilya + ms: Maxwell Salzberg; maxwell +email: + prefix: pair + domain: joindiaspora.com diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index b3abcf6070fedf5afc52bfcadf1c3447d17b02c9..145db190cddf07a9ea51b84dce0b2e72dfd7b3c9 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -42,14 +42,30 @@ class GroupsController < ApplicationController def update @group = Group.first(:id => params[:id]) if @group.update_attributes(params[:group]) - flash[:notice] = "Successfully updated group." + #flash[:notice] = "Successfully updated group." redirect_to @group else render :action => 'edit' end end - def move_person + def move_friends + pp params + + params[:moves].each{ |move| + move = move[1] + unless current_user.move_friend(move) + flash[:error] = "Group editing failed for friend #{Person.find_by_id( move[:friend_id] ).real_name}." + redirect_to Group.first, :action => "edit" + return + end + } + + flash[:notice] = "Groups edited successfully." + redirect_to Group.first, :action => "edit" + + end + def move_friend 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 @@ -59,5 +75,4 @@ class GroupsController < ApplicationController 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 0a6a44dfc862531f3e0f612c203490553c3cf1a4..861eb0817a7c9415bfea78c887ff2ebc3e48a4eb 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -14,11 +14,9 @@ class PeopleController < ApplicationController def show @person = current_user.visible_person_by_id(params[:id]) @profile = @person.profile - @person_groups = current_user.groups_with_person(@person) - - - @groups_array = current_user.groups.collect{|x| [x.to_s, x.id]} + @groups_with_person = current_user.groups_with_person(@person) + @groups_dropdown_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' diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index e7b994ff506413463524c9babd0be7ef9ed61191..011996829b8ece7050ea68b1684876acf17e7842 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -29,7 +29,6 @@ class PublicsController < ApplicationController Rails.logger.error("Received post #{params[:xml]} for nonexistent person #{params[:id]}") return end - Rails.logger.debug "PublicsController has received: #{params[:xml]}" @user.receive params[:xml] if params[:xml] end diff --git a/app/models/comment.rb b/app/models/comment.rb index b4f2fb2d97b46cafceb2b272d0fd2a3f490a63b8..3057b98e4aedaaa0d36c73a07baa09f0c6ce5ef9 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -57,6 +57,9 @@ class Comment verify_signature(post_creator_signature, post.person) end + def signature_valid? + verify_signature(creator_signature, person) + end protected def sign_if_my_post diff --git a/app/models/group.rb b/app/models/group.rb index 432ff697c091094e323a28f4c1227b565f6c27b8..ae33ada7bb75042a6563d62dfffc39603c82bd3d 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -21,7 +21,7 @@ class Group end def posts_by_person_id( id ) - id = ensure_bson id + id = id.to_id posts.detect{|x| x.person.id == id } end end diff --git a/app/models/person.rb b/app/models/person.rb index 84edbed3d815a525cc750538449606025ae541f0..8c44ca60b14d1e020b7b0bbb1327f762a18f01c7 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -6,6 +6,7 @@ class Person xml_accessor :email xml_accessor :url xml_accessor :profile, :as => Profile + xml_reader :exported_key key :email, String, :unique => true @@ -52,13 +53,17 @@ class Person end def public_key_hash - Base64.encode64 OpenSSL::Digest::SHA256.new(self.export_key).to_s + Base64.encode64 OpenSSL::Digest::SHA256.new(self.exported_key).to_s end - def export_key + def exported_key encryption_key.public_key.export end + def exported_key= new_key + raise "Don't change a key" if serialized_key + @serialized_key = new_key + end def owns?(post) self.id == post.person.id @@ -77,6 +82,7 @@ class Person end protected + def clean_url self.url ||= "http://localhost:3000/" if self.class == User if self.url @@ -84,7 +90,9 @@ class Person self.url = self.url + '/' if self.url[-1,1] != '/' end end + private + def remove_all_traces Post.all(:person_id => id).each{|p| p.delete} Album.all(:person_id => id).each{|p| p.delete} diff --git a/app/models/photo.rb b/app/models/photo.rb index 5fcb0ea700e53a2236e437f765b58555497b0d75..153aee214f45168108208e34b5059216a7a4d9c3 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -63,6 +63,6 @@ class Photo < Post end def thumb_hash - {:thumb_url => image.url(:thumb_medium), :id => id, :album_id => album_id} + {:thumb_url => url(:thumb_medium), :id => id, :album_id => album_id} end end diff --git a/app/models/profile.rb b/app/models/profile.rb index 8ba7b4def7e45cc71a51e6c8a742e329d442655e..9bea4fdb06afdcf88f535c548a1be77c62bb8c17 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -21,7 +21,7 @@ class Profile end def person - Person.first(:id => self.person_id) + self._parent_document end ##this needs to go once we move to Salmon diff --git a/app/models/request.rb b/app/models/request.rb index 5289c757ac49a389eefd20cf218036052d6f8d0b..d8dd322e066bdf90a0dc93fb50b1f267f812ef55 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -30,13 +30,13 @@ class Request self.new(:destination_url => options[:to], :callback_url => person.receive_url, :person => person, - :exported_key => person.export_key, + :exported_key => person.exported_key, :group_id => options[:into]) end def reverse_for accepting_user self.person = accepting_user.person - self.exported_key = accepting_user.export_key + self.exported_key = accepting_user.exported_key self.destination_url = self.callback_url self.save end diff --git a/app/models/user.rb b/app/models/user.rb index 409e964e3232f3a56cb697fa95b95fe4aaf4d7e5..db4de26a5bc38a532cc98a4c2a8529619adbe36e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,10 +9,12 @@ class User key :friend_ids, Array key :pending_request_ids, Array key :visible_post_ids, Array + key :visible_person_ids, Array one :person, :class_name => 'Person', :foreign_key => :owner_id many :friends, :in => :friend_ids, :class_name => 'Person' + many :visible_people, :in => :visible_person_ids, :class_name => 'Person' # One of these needs to go many :pending_requests, :in => :pending_request_ids, :class_name => 'Request' many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post' @@ -48,10 +50,9 @@ class User 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)) + from_group.person_ids.delete(friend.id.to_id) posts_to_move.each{ |x| from_group.post_ids.delete(x.id)} from_group.save to_group.save @@ -166,7 +167,9 @@ class User def receive xml object = Diaspora::Parser.from_xml(xml) Rails.logger.debug("Receiving object:\n#{object.inspect}") - raise "Signature was not valid on: #{object.inspect}" unless object.signature_valid? + Rails.logger.debug("From: #{object.person.inspect}") if object.person + raise "In receive for #{self.real_name}, signature was not valid on: #{object.inspect}" unless object.signature_valid? + if object.is_a? Retraction if object.type == 'Person' && object.signature_valid? @@ -181,7 +184,7 @@ class User } end elsif object.is_a? Request - person = Diaspora::Parser.get_or_create_person_object_from_xml( xml ) + person = Diaspora::Parser.parse_or_find_person_from_xml( xml ) person.serialized_key ||= object.exported_key object.person = person object.person.save @@ -195,6 +198,14 @@ class User person.save elsif object.is_a?(Comment) + object.person = Diaspora::Parser.parse_or_find_person_from_xml( xml ).save if object.person.nil? + self.visible_people << object.person + self.save + Rails.logger.debug("The person parsed from comment xml is #{object.person.inspect}") unless object.person.nil? + object.person.save + Rails.logger.debug("From: #{object.person.inspect}") if object.person + raise "In receive for #{self.real_name}, signature was not valid on: #{object.inspect}" unless object.post.person == self.person || object.verify_post_creator_signature + object.save dispatch_comment object unless owns?(object) object.socket_to_uid(id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object)) else @@ -237,7 +248,9 @@ class User def visible_person_by_id( id ) id = id.to_id return self.person if id == self.person.id - friends.detect{|x| x.id == id } + result = friends.detect{|x| x.id == id } + result = visible_people.detect{|x| x.id == id } unless result + result end def group_by_id( id ) @@ -260,7 +273,7 @@ class User end def setup_person - self.person.serialized_key ||= generate_key.export + self.person.serialized_key ||= User.generate_key.export self.person.email ||= email self.person.save! end @@ -269,9 +282,6 @@ class User self.groups.all.collect{|x| x.id} end protected - def generate_key - OpenSSL::PKey::RSA::generate 1024 - end def self.generate_key OpenSSL::PKey::RSA::generate 1024 diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb index 732367ffadf2f2b3933936bbed30dd13ff3a2a1d..0ae5ce446a3bb0d7199e1600681926775a2dd4a1 100644 --- a/app/uploaders/image_uploader.rb +++ b/app/uploaders/image_uploader.rb @@ -16,7 +16,7 @@ class ImageUploader < CarrierWave::Uploader::Base end version :thumb_small do - process :resize_to_fill => [30,30] + process :resize_to_fill => [50,50] end version :thumb_medium do @@ -24,7 +24,7 @@ class ImageUploader < CarrierWave::Uploader::Base end version :thumb_large do - process :resize_to_fill => [300,300] + process :resize_to_fill => [200,200] end version :scaled_full do diff --git a/app/views/albums/index.html.haml b/app/views/albums/index.html.haml index 47d2f68a953c18aa657c30a487e02fa46c24ad2b..2be320629c695a3c84b2db50f9ae51e33c22298c 100644 --- a/app/views/albums/index.html.haml +++ b/app/views/albums/index.html.haml @@ -1,3 +1,9 @@ +- content_for :head do + :javascript + $(document).ready(function(){ + $("#add_album_button").fancybox(); + }); + .back= link_to "⇧ home", root_path %h1.big_text Albums diff --git a/app/views/albums/show.html.haml b/app/views/albums/show.html.haml index f67fb5d33876d4e60f28dba81a353114d61114f1..18e042ad9a4bca6c463e73c1d132d0cf78d9d4da 100644 --- a/app/views/albums/show.html.haml +++ b/app/views/albums/show.html.haml @@ -1,8 +1,5 @@ - content_for :head do - :javascript - $(document).ready(function(){ - reset_photo_fancybox(); - }); + = javascript_include_tag 'photos', 'jquery.html5_upload' .album_id{:id => @album.id, :style => "display:hidden;"} .back= link_to '⇧ albums', albums_path diff --git a/app/views/groups/edit.html.haml b/app/views/groups/edit.html.haml index d6e227b5f69367d336f2edfcc5932bc60e6f72b2..2f87b23f1c529b95b372ecbc3dec3093d2392e54 100644 --- a/app/views/groups/edit.html.haml +++ b/app/views/groups/edit.html.haml @@ -2,22 +2,25 @@ = javascript_include_tag 'jquery-ui-1.8.4.custom.min.js' = javascript_include_tag 'group-edit.js' +.back + = link_to "⇧ #{@group.name}", @group -%h1.big_text - .back - = link_to "⇧ #{@group.name}", @group +%h1{:class => 'big_text', :id => 'group_title'} = "Editing Groups" -%ul +%ul#group_list - for group in @groups - %li.group + %li{:class => 'group'} = group.name - %ul - stuff + %ul{:id => group.id} + dummy person for dropping onto -for person in group.people - %li.person + %li{:class => 'person', :id => person.id, :from_group_id => group.id} + = image_tag(person.profile.image_url(:thumb_small),:size => "30x30") unless person.profile.image_url.nil? = person.real_name - +%p + %br + = link_to 'Update Groups', '#', :class => 'button', :id => "move_friends_link" #content_bottom .back diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 328ab1650da400af7f15ee6451adbabc56d8a1ec..cd3579319adf086f44c249e553f099c11d19283c 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -23,8 +23,6 @@ = csrf_meta_tag = yield(:head) - = javascript_include_tag 'jquery.html5_upload' - %body - flash.each do |name, msg| = content_tag :div, msg, :id => "flash_#{name}" diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 76fc3acef8c4fb6535409110b5878b99fc226175..0fc75352437f6dbe78faca60f88c71631ec913de 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -5,7 +5,7 @@ %h1 = @person.real_name - - unless @person.id == current_user.person.id + - if @person != current_user.person && current_user.friends.include?(@person) .right = link_to 'remove friend', @person, :confirm => 'Are you sure?', :method => :delete, :class => "button" @@ -13,17 +13,15 @@ -unless @posts.first.nil? %li %i= "last seen: #{how_long_ago(@posts.first)}" - %li - %i= "friends since: #{how_long_ago(@person)}" - %li - ="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" + - if @person != current_user.person && current_user.friends.include?(@person) + %li + %i= "friends since: #{how_long_ago(@person)}" + %li + = form_tag move_friend_path + = select :to, :to, @groups_dropdown_array, :selected_value => @groups_with_person.first.id + = hidden_field_tag :from, :from, :value => @groups_with_person.first.id + = hidden_field_tag :friend_id, :friend_id, :value => @person.id + = submit_tag "save" %li url: = @person.url diff --git a/app/views/photos/_new_photo.haml b/app/views/photos/_new_photo.haml index 5bc6d68822def319a08755e7a7c68a8cb5fbf7cf..32fd2a3e880556e78fd16d6289ef04ade7b4a993 100644 --- a/app/views/photos/_new_photo.haml +++ b/app/views/photos/_new_photo.haml @@ -1,33 +1,3 @@ -:javascript - $(function() { - $("#photo_image").html5_upload({ - // WE INSERT ALBUM_ID PARAM HERE - url: "/photos?album_id=#{@album.id}", - sendBoundary: window.FormData || $.browser.mozilla, - setName: function(text) { - $("#progress_report_name").text(text); - }, - onFinish: function(event, total){ - $("#add_photo_button").html( "Add Photos" ); - $("#add_photo_loader").fadeOut(400); - - $("#photo_title_status").text("Done!"); - $("#progress_report").html("Good job me!"); - - $("#add_photo_button").addClass("uploading_complete"); - }, - onStart: function(event, total){ - $("#add_photo_button").html( "Uploading Photos" ); - $("#add_photo_loader").fadeIn(400); - - $("form").fadeOut(0); - $("#progress_report").fadeIn(0); - $("#photo_title_status").text("Uploading..."); - return true; - } - }); - }); - %h1 %span{:id=>"photo_title_status"} Add photos to diff --git a/app/views/photos/_photo.haml b/app/views/photos/_photo.haml index caeae5c99276c3a408ecf38897c449b882e9b4b6..d44c056ba931ef4bca02c2e992400babf71960db 100644 --- a/app/views/photos/_photo.haml +++ b/app/views/photos/_photo.haml @@ -1,20 +1,20 @@ %li.message{:id => post.id} + = person_image_tag(post.person) - %span.from - = link_to post.person.real_name, post.person - %b - posted a new photo to - = link_to post.album.name, object_path(post.album) + .content + %span.from + = link_to post.person.real_name, post.person + %b + posted a new photo to + = link_to post.album.name, object_path(post.album) - %br - - = render "albums/album", :post => post.album, :current_user => current_user - - = link_to (image_tag post.url(:thumb_medium)), object_path(post) - - %div.time - = link_to(how_long_ago(post), photo_path(post)) - \-- - = link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments" - = render "comments/comments", :post => post + %br + = render "albums/album", :post => post.album, :current_user => current_user + = link_to (image_tag post.url(:thumb_medium)), object_path(post) + + .info + = link_to(how_long_ago(post), photo_path(post)) + \-- + = link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments" + = render "comments/comments", :post => post diff --git a/app/views/shared/_group_nav.haml b/app/views/shared/_group_nav.haml index 2d959b70befe2614b027c28c46afabc36e515e14..88995f9b55cdd3d73ac68a6c40355f859dd6fc7f 100644 --- a/app/views/shared/_group_nav.haml +++ b/app/views/shared/_group_nav.haml @@ -4,7 +4,8 @@ = link_to "All Groups", root_url - for group in @groups %li{:id => group.id, :class => ("selected" if current_group?(group))} - = link_for_group group + %span.group_name + = link_for_group group %span{:class => '⚙'} = link_to "⚙", "#", :class => "edit_group_button" diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index 7217d3ec84d6766c2fd7c544cd554154172bf2ed..5c8f041c0da662d371c3f73a385bc391ed62c71b 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -7,7 +7,7 @@ = link_to post.person.real_name, post.person = auto_link sanitize post.message - %div.info + .info = link_to(how_long_ago(post), object_path(post)) \-- = link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments" diff --git a/config/routes.rb b/config/routes.rb index 30865c3c7c2924b231176362ce87455e985d639f..b9fa375e27d8a0d5071c24992ec0bcc9d70553a0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,8 @@ 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' + match 'groups/move_friends', :to => 'groups#move_friends', :as => 'move_friends' + match 'groups/move_friend', :to => 'groups#move_friend', :as => 'move_friend' #public routes # match 'webfinger', :to => 'publics#webfinger' diff --git a/lib/diaspora/parser.rb b/lib/diaspora/parser.rb index 650c4a4e49b280ebbe3a711fb5ec59ccf3820c1a..51523724def9eb43129a4fc58b708ea99a2af1df 100644 --- a/lib/diaspora/parser.rb +++ b/lib/diaspora/parser.rb @@ -6,10 +6,10 @@ module Diaspora Person.first(:id => id) end - def self.get_or_create_person_object_from_xml(xml) + def self.parse_or_find_person_from_xml(xml) doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks } - person_xml = doc.xpath("//request/person").to_s - person_id = doc.xpath("//request/person/_id").text.to_s + person_xml = doc.xpath("//person").to_s + person_id = doc.xpath("//person/_id").text.to_s person = Person.first(:_id => person_id) person ? person : Person.from_xml( person_xml) end @@ -36,6 +36,5 @@ module Diaspora raise e end end - end end diff --git a/public/javascripts/group-edit.js b/public/javascripts/group-edit.js index e92cadb75078f876d4629f7d1312a1d79b0070e4..94ca47cfd6aad946f41f13d2edd66d8ced9b1c99 100644 --- a/public/javascripts/group-edit.js +++ b/public/javascripts/group-edit.js @@ -1,3 +1,10 @@ +$('#move_friends_link').live( 'click', + function(){ + $.post('/groups/move_friends', + {'moves' : $('#group_list').data()}, + function(){ $('#group_title').html("Groups edited successfully!");}); + }); + $(function() { $("li .person").draggable({ revert: true @@ -7,8 +14,14 @@ $(function() { drop: function(event, ui) { $(this).closest("ul").append(ui.draggable) //$("<li class='person ui-draggable'></li>").text(ui.draggable.text()).appendTo(this).draggable(); + var move = {}; + move[ 'friend_id' ] = ui.draggable[0].id + move[ 'to' ] = $(this)[0].id; + move[ 'from' ] = ui.draggable[0].getAttribute('from_group_id'); + $('#group_list').data( ui.draggable[0].id, move); } }); + }); diff --git a/public/javascripts/photos.js b/public/javascripts/photos.js new file mode 100644 index 0000000000000000000000000000000000000000..3980c008e1e19f7374fff825fe10bfad495d7295 --- /dev/null +++ b/public/javascripts/photos.js @@ -0,0 +1,51 @@ +$(document).ready(function(){ + reset_photo_fancybox(); + + $("#add_photo_button").fancybox({ + 'onClosed' : function(){ + if($("#add_photo_button").hasClass("uploading_complete")){ + $("#add_photo_button").removeClass("uploading_complete"); + reset_photo_fancybox(); + } + } + }); + + $(".image_thumb img").load( function() { + $(this).fadeIn("slow"); + }); + +});//end document ready + +function reset_photo_fancybox(){ + album_id = $(".album_id")[0].id; + ajax = $.get("/photos/new?album_id=" + album_id, function(){ + $("#new_photo_pane").html(ajax.responseText) + }); +} + +$("#photo_image").html5_upload({ + // WE INSERT ALBUM_ID PARAM HERE + url: "/photos?album_id="+$(".album_id")[0].id, + sendBoundary: window.FormData || $.browser.mozilla, + setName: function(text) { + $("#progress_report_name").text(text); + }, + onFinish: function(event, total){ + $("#add_photo_button").html( "Add Photos" ); + $("#add_photo_loader").fadeOut(400); + + $("#photo_title_status").text("Done!"); + $("#progress_report").html("Good job me!"); + + $("#add_photo_button").addClass("uploading_complete"); + }, + onStart: function(event, total){ + $("#add_photo_button").html( "Uploading Photos" ); + $("#add_photo_loader").fadeIn(400); + + $("form.new_photo").fadeOut(0); + $("#progress_report").fadeIn(0); + $("#photo_title_status").text("Uploading..."); + return true; + } +}); diff --git a/public/javascripts/view.js b/public/javascripts/view.js index c50439768f74faf3c1ed85efe8dcbadad3ccf9fb..782a1bdadd5c0e3b19f3ec2c1b6513efeb83e5dd 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -8,8 +8,6 @@ $(document).ready(function(){ $('#flash_notice, #flash_error, #flash_alert').delay(2500).slideUp(130); - - $("div.image_cycle").cycle({ fx: 'fade', random: 1, @@ -18,42 +16,64 @@ $(document).ready(function(){ }); //buttons////// - - - $("#add_album_button").fancybox(); $("#add_group_button").fancybox(); $("#add_request_button").fancybox({ 'titleShow': false }); - $("#add_photo_button").fancybox({ - 'onClosed' : function(){ - if($("#add_photo_button").hasClass("uploading_complete")){ - $("#add_photo_button").removeClass("uploading_complete"); - reset_photo_fancybox(); - } - } - }); - - //pane_toggler_button("photo"); $("input[type='submit']").addClass("button"); - $(".image_thumb img").load( function() { - $(this).fadeIn("slow"); - }); - $(".image_cycle img").load( function() { $(this).fadeIn("slow"); }); + $(".edit_group_button").click(function() { + + var element = $(this).closest("li").children(".group_name").children("a"); + var oldHTML = element.html(); + + var link = element.attr("href"); + + element.toggleClass("editing"); + + if( element.hasClass("editing") ) { + + element.attr("contentEditable", true); + element.focus(); + + + + //remove newline action + $(element).keypress(function(e) { + if (e.which == 13) { + e.preventDefault(); + element.attr("contentEditable", false); + element.toggleClass("editing"); + element.blur(); + + //save changes + $.ajax({ + type: "PUT", + url: link, + data: {"group" : {"name" : element.text() }} + }); + } + }); + + //update all other group links + $(element).keyup(function(e) { + $("a[href='"+link+"']").not(element).text(element.text()); + }); + + } else { + element.attr("contentEditable", false); + } + + }); + });//end document ready -function reset_photo_fancybox(){ - album_id = $(".album_id")[0].id; - ajax = $.get("/photos/new?album_id=" + album_id, function(){ - $("#new_photo_pane").html(ajax.responseText) - }); -} + function pane_toggler_button( name ) { diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 18c040055e66b02538b6eeaf451e301c0ae10bdc..f1b9f794588ea6ff0619966f0d35fb665deedf62 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -11,12 +11,10 @@ body { margin: 0; } a { - color: #018790; color: #556270; text-decoration: none; } a:hover { color: white; - background-color: #018790; background-color: #556270; } .avatar { @@ -381,9 +379,12 @@ label { /* cycle it! */ .album { position: relative; - height: 300px; - width: 300px; + height: 200px; + width: 200px; display: inline-block; } + .album img { + width: 200px; + height: 200px; } .album .name { position: absolute; z-index: 6; @@ -473,6 +474,8 @@ h1.big_text { color: #999999; } #group_nav ul > li a:hover { background: none; } + #group_nav ul > li a.editable:hover { + background: yellow; } #group_nav ul .⚙ { margin-left: 4px; } #group_nav ul .⚙ a { @@ -569,3 +572,7 @@ h1.big_text { #global_search form label { font-size: 12px; margin-top: -3px; } + +.editing, .editing:hover { + background-color: yellow; + border: 1px #666666 solid; } diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 6c5c0c1178a26fa99230e86163e7bd726cb189ea..552049c8ec05a77e66d8be17b68d669f9bfd57fe 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -10,14 +10,12 @@ body :padding 2em :margin 0 a - :color #018790 :color #556270 :text :decoration none &:hover :color #fff :background - :color #018790 :color #556270 .avatar @@ -480,10 +478,14 @@ label /* cycle it! */ .album :position relative - :height 300px - :width 300px + :height 200px + :width 200px :display inline-block + img + :width 200px + :height 200px + .name :position absolute :z-index 6 @@ -601,6 +603,8 @@ h1.big_text :color #999 &:hover :background none + &.editable:hover + :background yellow .⚙ :margin @@ -738,4 +742,7 @@ h1.big_text :margin :top -3px - +.editing, .editing:hover + :background + :color yellow + :border 1px #666 solid diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 36773fd98bf58274520544ac6e3847f59a408627..590739e6a4273d6fc41c0bf11ad7870314664594 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -6,7 +6,7 @@ describe GroupsController do @user = Factory.create(:user) @user.group(:name => "lame-os") @person = Factory.create(:person) - request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user, :authenticate => @user) + sign_in :user, @user end it "on index sets a variable containing all a user's friends when a user is signed in" do diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 0bca73e18bbc9034a41c740e9dcb6ec89f0a4016..bc5348052b724750868b20855da3ba8386252f6a 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -4,7 +4,6 @@ describe PeopleController do render_views before do @user = Factory.create(:user) - request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user, :authenticate => @user) sign_in :user, @user @user.group(:name => "lame-os") diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index dfe1e461b730b5c380afe90def9478eb54d5a33f..cc6bd85b5f31a66dd45eca4ce446cfb733c4eaf5 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -6,7 +6,7 @@ describe PublicsController do before do @user = Factory.create(:user) @user.person.save - request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user, :authenticate => @user) + sign_in :user, @user end describe 'receive endpoint' do diff --git a/spec/controllers/sockets_controller_spec.rb b/spec/controllers/sockets_controller_spec.rb index 23a02d61e22c2103149bf8abf216c285b8ee12aa..26318dad6356343007c8be72026604c6417a10d3 100644 --- a/spec/controllers/sockets_controller_spec.rb +++ b/spec/controllers/sockets_controller_spec.rb @@ -6,15 +6,11 @@ class SocketsController end end -describe 'SocketsController' do +describe SocketsController do render_views before do @user = Factory.create(:user) - SocketsController.unstub!(:new) @controller = SocketsController.new - @controller.request = mock_model(Request, :env => - {'warden' => mock_model(Warden, :authenticate? => @user, :authenticate! => @user, :authenticate => @user)}) - stub_sockets_controller end it 'should unstub the websockets' do diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb index d57ccc8ce94b87b3f94f5ae56cc40cb63376b228..5197080dc3b58f877606e937562d085f3d973160 100644 --- a/spec/lib/diaspora_parser_spec.rb +++ b/spec/lib/diaspora_parser_spec.rb @@ -18,7 +18,7 @@ describe Diaspora::Parser do @xml = Factory.build(:status_message).to_diaspora_xml end - it 'should be able to correctly handle comments' do + it 'should be able to correctly handle comments with person in db' do person = Factory.create(:person, :email => "test@testing.com") post = Factory.create(:status_message, :person => @user.person) comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!") @@ -29,6 +29,23 @@ describe Diaspora::Parser do comment.person.should == person comment.post.should == post end + + it 'should be able to correctly handle person on a comment with person not in db' do + commenter = Factory.create(:user) + commenter_group = commenter.group :name => "bruisers" + friend_users(@user, @group, commenter, commenter_group) + post = @user.post :status_message, :message => "hello", :to => @group.id + comment = commenter.comment "Fool!", :on => post + + xml = comment.to_diaspora_xml + commenter.delete + commenter.person.delete + + parsed_person = Diaspora::Parser::parse_or_find_person_from_xml(xml) + parsed_person.save.should be true + parsed_person.email.should == commenter.person.email + parsed_person.profile.should_not be_nil + end it 'should marshal retractions' do person = Factory.create(:person) diff --git a/spec/lib/salmon_salmon_spec.rb b/spec/lib/salmon_salmon_spec.rb index 273762a41af8e56ba885f44285779eef9b83185d..49ffa483da4eb73271cf7ed54b113427a3b03b1e 100644 --- a/spec/lib/salmon_salmon_spec.rb +++ b/spec/lib/salmon_salmon_spec.rb @@ -22,8 +22,8 @@ describe Salmon do x.magic_sig.signable_string.should == z.magic_sig.signable_string - x.verified_for_key?(OpenSSL::PKey::RSA.new(@user.export_key)).should be true - z.verified_for_key?(OpenSSL::PKey::RSA.new(@user.export_key)).should be true + x.verified_for_key?(OpenSSL::PKey::RSA.new(@user.exported_key)).should be true + z.verified_for_key?(OpenSSL::PKey::RSA.new(@user.exported_key)).should be true end diff --git a/spec/models/comments_spec.rb b/spec/models/comments_spec.rb index a9066f6d04745e93865b87283d2f87592e1c3835..95d2c977c122b1c67289a99c73311fa0516a6d38 100644 --- a/spec/models/comments_spec.rb +++ b/spec/models/comments_spec.rb @@ -4,7 +4,10 @@ describe Comment do describe "user" do before do @user = Factory.create :user - @user.person.save + @group = @user.group(:name => "Doofuses") + + @user2 = Factory.create(:user) + @group2 = @user2.group(:name => "Lame-faces") end it "should be able to comment on his own status" do status = Factory.create(:status_message, :person => @user.person) @@ -31,10 +34,7 @@ describe Comment do describe 'comment propagation' do before do - @group = @user.group(:name => "Doofuses") - @user2 = Factory.create(:user) - @group2 = @user2.group(:name => "Lame-faces") request = @user.send_friend_request_to(@user2.receive_url, @group.id) reversed_request = @user2.accept_friend_request( request.id, @group2.id ) @@ -79,5 +79,16 @@ describe Comment do @user.receive(comment.to_diaspora_xml) end end + describe 'serialization' do + it 'should serialize the commenter' do + commenter = Factory.create(:user) + commenter_group = commenter.group :name => "bruisers" + friend_users(@user, @group, commenter, commenter_group) + post = @user.post :status_message, :message => "hello", :to => @group.id + comment = commenter.comment "Fool!", :on => post + comment.person.should_not == @user.person + comment.to_diaspora_xml.include?(commenter.person.id.to_s).should be true + end + end end end diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index bd2afb6ddb1d73ef90fd6b1812d3d1e5bc17ab5b..74ddfb8824b9ad0f4225358699275acbc21e3a92 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -8,6 +8,10 @@ describe User do @user2 = Factory.create(:user) @group2 = @user2.group(:name => 'losers') + + @user3 = Factory.create(:user) + @group3 = @user3.group(:name => 'heroes') + friend_users(@user, @group, @user2, @group2) end @@ -39,8 +43,7 @@ describe User do describe 'post refs' do before do - @user3 = Factory.create(:user) - @group3 = @user3.group(:name => 'heroes') + end it "should add the post to that user's posts when a user posts it" do @@ -130,4 +133,36 @@ describe User do Post.count.should be 1 end end + + describe 'comments' do + it 'should correctly marshal a stranger for the downstream user' do + + friend_users(@user, @group, @user3, @group3) + post = @user.post :status_message, :message => "hello", :to => @group.id + + @user2.receive post.to_diaspora_xml + @user3.receive post.to_diaspora_xml + + comment = @user2.comment('tada',:on => post) + @user.receive comment.to_diaspora_xml + @user.reload + + commenter_id = @user2.person.id + + @user2.person.delete + @user2.delete + comment_id = comment.id + + comment.delete + @user3.receive comment.to_diaspora_xml + @user3.reload + + new_comment = Comment.find_by_id(comment_id) + new_comment.should_not be_nil + new_comment.person.should_not be_nil + new_comment.person.profile.should_not be_nil + + @user3.visible_person_by_id(commenter_id).should_not be_nil + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 548c7867de5dafd0720801f688d5a6f8572d6ec8..ff5cb46f33ccd14f2856b63dbd5730a4b4260251 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -21,29 +21,27 @@ RSpec.configure do |config| config.before(:suite) do DatabaseCleaner.clean_with(:truncation) stub_signature_verification + end config.before(:each) do DatabaseCleaner.start - stub_sockets_controller + stub_sockets end config.after(:each) do DatabaseCleaner.clean end end - def stub_sockets_controller - mock_sockets_controller = mock('sockets mock') - mock_sockets_controller.stub!(:incoming).and_return(true) - mock_sockets_controller.stub!(:new_subscriber).and_return(true) - mock_sockets_controller.stub!(:outgoing).and_return(true) - mock_sockets_controller.stub!(:delete_subscriber).and_return(true) - SocketsController.stub!(:new).and_return(mock_sockets_controller) + def stub_sockets + Diaspora::WebSocket.stub!(:push_to_user).and_return(true) + Diaspora::WebSocket.stub!(:subscribe).and_return(true) + Diaspora::WebSocket.stub!(:unsubscribe).and_return(true) end def stub_signature_verification (get_models.map{|model| model.camelize.constantize} - [User]).each do |model| - model.any_instance.stubs(:signature_valid?).returns(true) + model.any_instance.stubs(:verify_signature).returns(true) end end diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index 47433b80f022cbe685b96d7b2df26c0f904fe598..9432ac07b81dc98bbbb236d7079cf3b7fdf33ce8 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -33,7 +33,7 @@ describe 'user encryption' do it 'should send over a public key' do message_queue.stub!(:add_post_request) request = @user.send_friend_request_to("http://example.com/", @group.id) - request.to_diaspora_xml.include?( @user.export_key).should be true + request.to_diaspora_xml.include?( @user.exported_key).should be true end it 'should receive and marshal a public key from a request' do @@ -41,7 +41,7 @@ describe 'user encryption' do remote_user.encryption_key.nil?.should== false #should move this to friend request, but i found it here id = remote_user.person.id - original_key = remote_user.export_key + original_key = remote_user.exported_key request = remote_user.send_friend_request_to( @user.receive_url, remote_user.group(:name => "temp").id) @@ -52,10 +52,10 @@ describe 'user encryption' do remote_user.destroy person_count = Person.all.count - proc {@user.receive xml}.should_not raise_error /Signature was not valid/ + proc {@user.receive xml}.should_not raise_error /ignature was not valid/ Person.all.count.should == person_count + 1 new_person = Person.first(:id => id) - new_person.export_key.should == original_key + new_person.exported_key.should == original_key end end @@ -125,7 +125,7 @@ describe 'user encryption' do xml = message.to_diaspora_xml message.destroy Post.count.should be 0 - proc {@user.receive xml}.should raise_error /Signature was not valid/ + proc {@user.receive xml}.should raise_error /ignature was not valid/ Post.count.should be 0 end