From 112088ace374a260e535282b14962308cc931fae Mon Sep 17 00:00:00 2001 From: "livefromthemoon@gmail.com" Date: Sat, 30 Oct 2010 17:21:16 +0200 Subject: [PATCH 01/22] add support for markdown emphasis in status messages --- app/helpers/status_messages_helper.rb | 34 +++++++++++++++--- spec/helpers/status_messages_helper_spec.rb | 40 +++++++++++++++++++++ 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/app/helpers/status_messages_helper.rb b/app/helpers/status_messages_helper.rb index 2e010715a..39ba258d3 100644 --- a/app/helpers/status_messages_helper.rb +++ b/app/helpers/status_messages_helper.rb @@ -18,14 +18,38 @@ module StatusMessagesHelper # next line is important due to XSS! (h is rail's make_html_safe-function) message = h(message).html_safe - message.gsub!(/( |^)(www\.[^ ]+\.[^ ])/, '\1http://\2') - message.gsub!(/( |^)http:\/\/www\.youtube\.com\/watch[^ ]*v=([A-Za-z0-9_]+)(&[^ ]*|)/, '\1youtube.com::\2') - message.gsub!(/(https|http|ftp):\/\/([^ ]+)/, '\2') - - while youtube = message.match(/youtube\.com::([A-Za-z0-9_]+)/) + + message.gsub!(/( |^)(www\.[^ ]+\.[^ ])/) do |m| + res = "#{$1}http://#{$2}" + res.gsub!(/^(\*|_)$/) { |m| "\\#{$1}" } + res + end + message.gsub!(/( |^)http:\/\/www\.youtube\.com\/watch[^ ]*v=([A-Za-z0-9_]+)(&[^ ]*|)/) do |m| + res = "#{$1}youtube.com::#{$2}" + res.gsub!(/(\*|_)/) { |m| "\\#{$1}" } + res + end + message.gsub!(/(https|http|ftp):\/\/([^ ]+)/) do |m| + res = %{#{$2}} + res.gsub!(/(\*|_)/) { |m| "\\#{$1}" } + res + end + + # markdown + message.gsub!(/([^\\]|^)\*\*(([^*]|([^*]\*[^*]))*[^\\])\*\*/, '\1\2') + message.gsub!(/([^\\]|^)__(([^_]|([^_]_[^_]))*[^\\])__/, '\1\2') + message.gsub!(/([^\\]|^)\*([^*]*[^\\])\*/, '\1\2') + message.gsub!(/([^\\]|^)_([^_]*[^\\])_/, '\1\2') + message.gsub!(/([^\\]|^)\*/, '\1') + message.gsub!(/([^\\]|^)_/, '\1') + message.gsub!("\\*", "*") + message.gsub!("\\_", "_") + + while youtube = message.match(/youtube\.com::([A-Za-z0-9_\\]+)/) videoid = youtube[1] message.gsub!('youtube.com::'+videoid, 'Youtube: ' + youtube_title(videoid) + '') end + return message end diff --git a/spec/helpers/status_messages_helper_spec.rb b/spec/helpers/status_messages_helper_spec.rb index 0aee3826a..9f89a1eb5 100644 --- a/spec/helpers/status_messages_helper_spec.rb +++ b/spec/helpers/status_messages_helper_spec.rb @@ -68,5 +68,45 @@ describe StatusMessagesHelper do make_links(url).should == ""+url+"" end + describe "markdown" do + describe "weak emphasis" do + it "should be recognized (1/2)" do + message = "*some text* some text *some text* some text" + make_links(message).should == "some text some text some text some text" + end + + it "should be recognized (2/2)" do + message = "_some text_ some text _some text_ some text" + make_links(message).should == "some text some text some text some text" + end + end + + describe "strong emphasis" do + it "should be recognized (1/2)" do + message = "**some text** some text **some text** some text" + make_links(message).should == "some text some text some text some text" + end + + it "should be recognized (2/2)" do + message = "__some text__ some text __some text__ some text" + make_links(message).should == "some text some text some text some text" + end + end + + describe "imbricated weak and strong emphasis" do + it "should be rendered correctly" do + message = "__this is _some_ text__" + make_links(message).should == "this is some text" + message = "*this is **some** text*" + make_links(message).should == "this is some text" + end + end + + it "should allow escaping" do + message = '*some text* \\*some text* \\**some text* _some text_ \\_some text_ \\__some text_' + make_links(message).should == "some text *some text *some text some text _some text _some text" + end + end + end From ebf9dd464f47593013e74a2363c2db7a5d3d0696 Mon Sep 17 00:00:00 2001 From: "livefromthemoon@gmail.com" Date: Sat, 30 Oct 2010 18:02:43 +0200 Subject: [PATCH 02/22] Better support for imbricated markdown emphasis --- app/helpers/status_messages_helper.rb | 4 ++-- spec/helpers/status_messages_helper_spec.rb | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/helpers/status_messages_helper.rb b/app/helpers/status_messages_helper.rb index 39ba258d3..80a20d00b 100644 --- a/app/helpers/status_messages_helper.rb +++ b/app/helpers/status_messages_helper.rb @@ -36,8 +36,8 @@ module StatusMessagesHelper end # markdown - message.gsub!(/([^\\]|^)\*\*(([^*]|([^*]\*[^*]))*[^\\])\*\*/, '\1\2') - message.gsub!(/([^\\]|^)__(([^_]|([^_]_[^_]))*[^\\])__/, '\1\2') + message.gsub!(/([^\\]|^)\*\*(([^*]|([^*]\*[^*]))*[^*\\])\*\*/, '\1\2') + message.gsub!(/([^\\]|^)__(([^_]|([^_]_[^_]))*[^_\\])__/, '\1\2') message.gsub!(/([^\\]|^)\*([^*]*[^\\])\*/, '\1\2') message.gsub!(/([^\\]|^)_([^_]*[^\\])_/, '\1\2') message.gsub!(/([^\\]|^)\*/, '\1') diff --git a/spec/helpers/status_messages_helper_spec.rb b/spec/helpers/status_messages_helper_spec.rb index 9f89a1eb5..0f699781b 100644 --- a/spec/helpers/status_messages_helper_spec.rb +++ b/spec/helpers/status_messages_helper_spec.rb @@ -99,6 +99,8 @@ describe StatusMessagesHelper do make_links(message).should == "this is some text" message = "*this is **some** text*" make_links(message).should == "this is some text" + message = "___some text___" + make_links(message).should == "some text" end end From bcb17aae166f0cdf7380cbe4c18cecf000ace594 Mon Sep 17 00:00:00 2001 From: "livefromthemoon@gmail.com" Date: Sat, 30 Oct 2010 19:24:46 +0200 Subject: [PATCH 03/22] Add support for markdown links --- app/helpers/status_messages_helper.rb | 16 +++++++++++----- spec/helpers/status_messages_helper_spec.rb | 12 ++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/helpers/status_messages_helper.rb b/app/helpers/status_messages_helper.rb index 80a20d00b..b999f1a49 100644 --- a/app/helpers/status_messages_helper.rb +++ b/app/helpers/status_messages_helper.rb @@ -19,6 +19,9 @@ module StatusMessagesHelper # next line is important due to XSS! (h is rail's make_html_safe-function) message = h(message).html_safe + message.gsub!(/\[([^\[]+)\]\(([^ ]+) \"(([^&]|(&[^q])|(&q[^u])|(&qu[^o])|(&quo[^t])|("[^;]))+)\"\)/, '\1') + message.gsub!(/\[([^\[]+)\]\(([^ ]+)\)/, '\1') + message.gsub!(/( |^)(www\.[^ ]+\.[^ ])/) do |m| res = "#{$1}http://#{$2}" res.gsub!(/^(\*|_)$/) { |m| "\\#{$1}" } @@ -29,13 +32,16 @@ module StatusMessagesHelper res.gsub!(/(\*|_)/) { |m| "\\#{$1}" } res end - message.gsub!(/(https|http|ftp):\/\/([^ ]+)/) do |m| - res = %{#{$2}} - res.gsub!(/(\*|_)/) { |m| "\\#{$1}" } - res + message.gsub!(/(#{$3}} + res.gsub!(/(\*|_)/) { |m| "\\#{$1}" } + res + end end - # markdown message.gsub!(/([^\\]|^)\*\*(([^*]|([^*]\*[^*]))*[^*\\])\*\*/, '\1\2') message.gsub!(/([^\\]|^)__(([^_]|([^_]_[^_]))*[^_\\])__/, '\1\2') message.gsub!(/([^\\]|^)\*([^*]*[^\\])\*/, '\1\2') diff --git a/spec/helpers/status_messages_helper_spec.rb b/spec/helpers/status_messages_helper_spec.rb index 0f699781b..61ae88be0 100644 --- a/spec/helpers/status_messages_helper_spec.rb +++ b/spec/helpers/status_messages_helper_spec.rb @@ -104,6 +104,18 @@ describe StatusMessagesHelper do end end + describe "links" do + it "should be recognized without title attribute" do + message = "[link text](http://someurl.com) [link text](http://someurl.com)" + make_links(message).should == 'link text link text' + end + + it "should be recognized with title attribute" do + message = '[link text](http://someurl.com "some title") [link text](http://someurl.com "some title")' + make_links(message).should == 'link text link text' + end + end + it "should allow escaping" do message = '*some text* \\*some text* \\**some text* _some text_ \\_some text_ \\__some text_' make_links(message).should == "some text *some text *some text some text _some text _some text" From b19cdf2e252e166b1ae566dc9f2c67a9175e191d Mon Sep 17 00:00:00 2001 From: Derrick Camerino Date: Sun, 31 Oct 2010 03:10:12 -0700 Subject: [PATCH 04/22] fixing N socketing bug --- lib/diaspora/user/receiving.rb | 9 ++++----- spec/models/user/receive_spec.rb | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/diaspora/user/receiving.rb b/lib/diaspora/user/receiving.rb index a651b4793..25ccad7fb 100644 --- a/lib/diaspora/user/receiving.rb +++ b/lib/diaspora/user/receiving.rb @@ -20,7 +20,6 @@ module Diaspora Rails.logger.debug("Receiving object for #{self.real_name}:\n#{object.inspect}") Rails.logger.debug("From: #{object.person.inspect}") if object.person - if object.is_a?(Comment) || object.is_a?(Post) e = EMWebfinger.new(object.diaspora_handle) @@ -34,7 +33,7 @@ module Diaspora raise "Not friends with that person" unless self.contact_for(salmon_author) - if object.is_a?(Comment) + if object.is_a?(Comment) receive_comment object, xml else receive_post object, xml @@ -137,11 +136,11 @@ module Diaspora self.save aspects = self.aspects_with_person(post.person) - aspects.each{ |aspect| + aspects.each do |aspect| aspect.posts << post aspect.save - post.socket_to_uid(id, :aspect_ids => [aspect.id]) if (post.respond_to?(:socket_to_uid) && !self.owns?(post)) - } + end + post.socket_to_uid(id, :aspect_ids => aspects.map(&:id)) if (post.respond_to?(:socket_to_uid) && !self.owns?(post)) end end end diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 04500d40d..6e959c508 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -19,6 +19,14 @@ describe User do friend_users(user, aspect, user2, aspect2) end + it 'should stream only one message to the everyone aspect when a multi-aspected friend posts' do + user.add_person_to_aspect(user2.person.id, user.aspect(:name => "villains").id) + status = user2.post(:status_message, :message => "Users do things", :to => aspect2.id) + xml = status.to_diaspora_xml + Diaspora::WebSocket.should_receive(:queue_to_user).exactly(:once) + user.receive xml, user2.person + end + it 'should be able to parse and store a status message from xml' do status_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id @@ -113,11 +121,11 @@ describe User do post_in_db.comments.should == [] user2.receive_salmon(@xml) post_in_db.reload - + post_in_db.comments.include?(@comment).should be true post_in_db.comments.first.person.should == local_person end - + it 'should correctly marshal a stranger for the downstream user' do remote_person = user3.person remote_person.delete @@ -127,13 +135,13 @@ describe User do Person.should_receive(:by_account_identifier).twice.and_return{ |handle| if handle == user.person.diaspora_handle; user.person.save user.person; else; remote_person.save; remote_person; end } - + user2.reload.raw_visible_posts.size.should == 1 post_in_db = user2.raw_visible_posts.first post_in_db.comments.should == [] user2.receive_salmon(@xml) post_in_db.reload - + post_in_db.comments.include?(@comment).should be true post_in_db.comments.first.person.should == remote_person end From 1a03dd799ae797b360da1f62ef5f7475cb2f5125 Mon Sep 17 00:00:00 2001 From: Derrick Camerino Date: Sun, 31 Oct 2010 23:25:05 -0700 Subject: [PATCH 05/22] showing aspect labels when posting status messages --- app/models/user.rb | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index f15f0e2ae..b06f63775 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -22,11 +22,11 @@ class User key :invites, Integer, :default => 5 key :invitation_token, String key :invitation_sent_at, DateTime - key :inviter_ids, Array, :typecast => 'ObjectId' - key :friend_ids, Array, :typecast => 'ObjectId' - key :pending_request_ids, Array, :typecast => 'ObjectId' - key :visible_post_ids, Array, :typecast => 'ObjectId' - key :visible_person_ids, Array, :typecast => 'ObjectId' + key :inviter_ids, Array, :typecast => 'ObjectId' + key :friend_ids, Array, :typecast => 'ObjectId' + key :pending_request_ids, Array, :typecast => 'ObjectId' + key :visible_post_ids, Array, :typecast => 'ObjectId' + key :visible_person_ids, Array, :typecast => 'ObjectId' key :invite_messages, Hash @@ -39,7 +39,7 @@ class User validates_presence_of :username validates_uniqueness_of :username, :case_sensitive => false - validates_format_of :username, :with => /\A[A-Za-z0-9_.]+\z/ + validates_format_of :username, :with => /\A[A-Za-z0-9_.]+\z/ validates_presence_of :person, :unless => proc {|user| user.invitation_token.present?} validates_inclusion_of :language, :in => AVAILABLE_LANGUAGE_CODES validates_associated :person @@ -95,11 +95,11 @@ class User def move_friend(opts = {}) return true if opts[:to] == opts[:from] - if opts[:friend_id] && opts[:to] && opts[:from] + if opts[:friend_id] && opts[:to] && opts[:from] from_aspect = self.aspects.first(:_id => opts[:from]) posts_to_move = from_aspect.posts.find_all_by_person_id(opts[:friend_id]) if add_person_to_aspect(opts[:friend_id], opts[:to], :posts => posts_to_move) - delete_person_from_aspect(opts[:friend_id], opts[:from], :posts => posts_to_move) + delete_person_from_aspect(opts[:friend_id], opts[:from], :posts => posts_to_move) return true end end @@ -113,7 +113,7 @@ class User raise 'Can not add person who is already in the aspect' if aspect.people.include?(contact) contact.aspects << aspect opts[:posts] ||= self.raw_visible_posts.all(:person_id => person_id) - + aspect.posts += opts[:posts] contact.save aspect.save @@ -142,9 +142,9 @@ class User aspect_ids = validate_aspect_permissions(aspect_ids) post = build_post(class_name, options) - post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid) push_to_aspects(post, aspect_ids) - + post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid) + if options[:public] == true self.services.each do |service| self.send("post_to_#{service.provider}".to_sym, service, post.message) @@ -318,14 +318,14 @@ class User raise "Must invite to your aspect" else u = User.find_by_email(opts[:email]) - if u.nil? + if u.nil? elsif friends.include?(u.person) - raise "You are already friends with this person" + raise "You are already friends with this person" elsif not u.invited? self.send_friend_request_to(u.person, aspect_object) return elsif u.invited? && u.inviters.include?(self) - raise "You already invited this person" + raise "You already invited this person" end end request = Request.instantiate( From 2b890e6ef249f3c6f3284862724b1fe4f964f872 Mon Sep 17 00:00:00 2001 From: "livefromthemoon@gmail.com" Date: Mon, 1 Nov 2010 21:31:12 +0100 Subject: [PATCH 06/22] Added 'lang' attribute in the html tag --- app/views/layouts/application.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index c8c0448cc..b84f336bf 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -3,7 +3,7 @@ -# the COPYRIGHT file. !!! -%html +%html{:lang => I18n.locale.to_s} %head %title = "#{current_user.real_name} | diaspora" if current_user From 938d146405ca453fc3faaac1b9010e4c888e7fed Mon Sep 17 00:00:00 2001 From: Hexagon Date: Tue, 2 Nov 2010 00:05:56 +0100 Subject: [PATCH 07/22] Common translations are used without the namespace --- app/helpers/application_helper.rb | 2 +- app/views/albums/edit.html.haml | 4 +- app/views/albums/show.html.haml | 2 +- app/views/comments/_comment.html.haml | 2 +- app/views/invitations/_new.haml | 2 +- app/views/invitations/new.html.haml | 2 +- app/views/people/edit.html.haml | 12 ++-- app/views/people/show.html.haml | 2 +- app/views/photos/_photo.haml | 2 +- app/views/photos/edit.html.haml | 2 +- app/views/registrations/edit.html.haml | 2 +- app/views/services/index.html.haml | 10 +-- app/views/shared/_publisher.haml | 2 +- .../status_messages/_status_message.html.haml | 2 +- app/views/status_messages/show.html.haml | 2 +- app/views/users/edit.html.haml | 18 ++--- config/locales/diaspora/en.yml | 65 ++++++------------- 17 files changed, 53 insertions(+), 80 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d89b0b1ee..0060f0156 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -34,7 +34,7 @@ module ApplicationHelper end def how_long_ago(obj) - "#{time_ago_in_words(obj.created_at)} #{t('.ago')}" + "#{time_ago_in_words(obj.created_at)} #{t('ago')}" end def person_url(person) diff --git a/app/views/albums/edit.html.haml b/app/views/albums/edit.html.haml index ccc5854fd..81da980e0 100644 --- a/app/views/albums/edit.html.haml +++ b/app/views/albums/edit.html.haml @@ -16,10 +16,10 @@ .photo_edit_block= image_tag photo.url(:thumb_medium) .submit_block - = link_to t('.cancel'), root_path + = link_to t('cancel'), root_path or = album.submit t('.update_album') .button.delete - = link_to t('.delete_album'), @album, :confirm => t('.are_you_sure'), :method => :delete + = link_to t('.delete_album'), @album, :confirm => t('are_you_sure'), :method => :delete diff --git a/app/views/albums/show.html.haml b/app/views/albums/show.html.haml index f997d91af..267b43bc1 100644 --- a/app/views/albums/show.html.haml +++ b/app/views/albums/show.html.haml @@ -42,5 +42,5 @@ .album_id{:id => @album_id, :style => "display:hidden;"} -unless current_user.person.id == @person.id - %h4= "#{t('.by')} #{@person.real_name}" + %h4= "#{t('by')} #{@person.real_name}" diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml index 54612d7e4..9dcff29ba 100644 --- a/app/views/comments/_comment.html.haml +++ b/app/views/comments/_comment.html.haml @@ -9,4 +9,4 @@ = link_to post.person.real_name, post.person = post.text %div.time - = "#{time_ago_in_words(post.updated_at)} #{t('.ago')}" + = "#{time_ago_in_words(post.updated_at)} #{t('ago')}" diff --git a/app/views/invitations/_new.haml b/app/views/invitations/_new.haml index b05792dd1..b63184327 100644 --- a/app/views/invitations/_new.haml +++ b/app/views/invitations/_new.haml @@ -7,7 +7,7 @@ = t('.if_they_accept_info') = form_for User.new, :url => invitation_path(User) do |invite| %p - = invite.label :email , t('.email') + = invite.label :email , t('email') = invite.text_field :email = t('.to') - unless @aspect.is_a? Aspect diff --git a/app/views/invitations/new.html.haml b/app/views/invitations/new.html.haml index 1b226aa80..b22e1f0c2 100644 --- a/app/views/invitations/new.html.haml +++ b/app/views/invitations/new.html.haml @@ -3,7 +3,7 @@ = form_for User.new, :url => invitation_path(User) do |f| = devise_error_messages! %p - = f.label :email , t('.email') + = f.label :email , t('email') = f.text_field :email %p= f.submit t('.send_an_invitation') /= link_to "Home", after_sign_in_path_for(resource_name) diff --git a/app/views/people/edit.html.haml b/app/views/people/edit.html.haml index 082a31c2a..d3b8b135d 100644 --- a/app/views/people/edit.html.haml +++ b/app/views/people/edit.html.haml @@ -5,11 +5,11 @@ #section_header %h2 - = t('.settings') + = t('settings') %ul#settings_nav - %li=link_to t('.profile'), edit_person_path(current_user.person) - %li=link_to t('.account'), edit_user_path(current_user) - %li=link_to t('.services'), services_path + %li=link_to t('profile'), edit_person_path(current_user.person) + %li=link_to t('account'), edit_user_path(current_user) + %li=link_to t('services'), services_path .span-19.prepend-5.last = form_for @person, :html => { :multipart => true } do |person| @@ -45,6 +45,6 @@ = render 'people/profile_photo_upload', :form => profile .submit_block - = link_to t('.cancel'), edit_user_path(current_user) - = t('.or') + = link_to t('cancel'), edit_user_path(current_user) + = t('or') = person.submit t('.update_profile') diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 0dd95e752..fd8bedee1 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -28,7 +28,7 @@ %li= link_to aspect.name, aspect - if @person != current_user.person && @contact - = link_to t('.remove_friend'), @person, :confirm => t('.are_you_sure'), :method => :delete, :class => "button" + = link_to t('.remove_friend'), @person, :confirm => t('are_you_sure'), :method => :delete, :class => "button" - if @person == current_user.person %b diff --git a/app/views/photos/_photo.haml b/app/views/photos/_photo.haml index 9e878b510..a122614aa 100644 --- a/app/views/photos/_photo.haml +++ b/app/views/photos/_photo.haml @@ -20,7 +20,7 @@ - if current_user.owns?(post) .right - = link_to t('.delete'), photo_path(post), :confirm => t('.are_you_sure'), :method => :delete, :remote => true, :class => "delete" + = link_to t('delete'), photo_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete" - if !post.album_id.nil? =t('.posted_a_new_photo_to') diff --git a/app/views/photos/edit.html.haml b/app/views/photos/edit.html.haml index 08e6dae0a..dcdebab1c 100644 --- a/app/views/photos/edit.html.haml +++ b/app/views/photos/edit.html.haml @@ -19,5 +19,5 @@ = link_to "⇧ #{@album.name}", album_path(@album) -if current_user.owns? @album .button.right - = link_to t('.delete_photo'), @photo, :confirm => t('.are_you_sure'), :method => :delete + = link_to t('.delete_photo'), @photo, :confirm => t('are_you_sure'), :method => :delete diff --git a/app/views/registrations/edit.html.haml b/app/views/registrations/edit.html.haml index 5da950379..9cadd779f 100644 --- a/app/views/registrations/edit.html.haml +++ b/app/views/registrations/edit.html.haml @@ -24,5 +24,5 @@ = f.submit t('.update') %h3 t('.cancel_my_account') %p - Unhappy? #{link_to t('.cancel_my_account'), registration_path(resource_name), :confirm => t('.are_you_sure'), :method => :delete}. + Unhappy? #{link_to t('.cancel_my_account'), registration_path(resource_name), :confirm => t('are_you_sure'), :method => :delete}. = link_to t('.back'), :back diff --git a/app/views/services/index.html.haml b/app/views/services/index.html.haml index bf1546172..5d5a3b772 100644 --- a/app/views/services/index.html.haml +++ b/app/views/services/index.html.haml @@ -4,15 +4,15 @@ #section_header %h2 - = t('.settings') + = t('settings') %ul#settings_nav - %li=link_to t('.profile'), edit_person_path(current_user.person) - %li=link_to t('.account'), edit_user_path(current_user) - %li=link_to t('.services'), services_path + %li=link_to t('profile'), edit_person_path(current_user.person) + %li=link_to t('account'), edit_user_path(current_user) + %li=link_to t('services'), services_path .span-19.prepend-5.last %h2 - = t('.services') + = t('services') %ul - for service in @services diff --git a/app/views/shared/_publisher.haml b/app/views/shared/_publisher.haml index 5f36f3c84..94f7737d7 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.haml @@ -48,7 +48,7 @@ = status.submit t('.share'), :title => "Share with #{aspect}" #publisher_photo_upload - = t('.or') + = t('or') = render 'photos/new_photo', :aspect_id => (aspect == :all ? aspect : aspect.id), :album_id => nil diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index 7e065b475..f78f4d405 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -21,7 +21,7 @@ - if current_user.owns?(post) .right = render "shared/reshare", :post => post, :current_user => current_user - = link_to t('.delete'), status_message_path(post), :confirm => t('.are_you_sure'), :method => :delete, :remote => true, :class => "delete" + = link_to t('delete'), status_message_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete" = make_links(post.message) diff --git a/app/views/status_messages/show.html.haml b/app/views/status_messages/show.html.haml index 0672ca1e8..8ab8d3a35 100644 --- a/app/views/status_messages/show.html.haml +++ b/app/views/status_messages/show.html.haml @@ -13,7 +13,7 @@ - if current_user.owns? @status_message %p - = link_to t('.destroy'), @status_message, :confirm => t('.are_you_sure'), :method => :delete + = link_to t('.destroy'), @status_message, :confirm => t('are_you_sure'), :method => :delete .span-9.last #stream.show diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 7aa2bbcda..634729a83 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -14,15 +14,15 @@ #section_header %h2 - = t('.settings') + = t('settings') %ul#settings_nav - %li=link_to t('.profile'), edit_person_path(current_user.person) - %li=link_to t('.account'), edit_user_path(current_user) - %li=link_to t('.services'), services_path + %li=link_to t('profile'), edit_person_path(current_user.person) + %li=link_to t('account'), edit_user_path(current_user) + %li=link_to t('services'), services_path .span-19.prepend-5.last %h2 - = t('.account') + = t('account') = link_to t('.invite_friends'), new_user_invitation_path(current_user) @@ -39,12 +39,12 @@ = f.label :password, t('.new_password') = f.password_field :password %p - = f.label :password_confirmation, t('.password_confirmation') + = f.label :password_confirmation, t('password_confirmation') = f.password_field :password_confirmation .submit_block - = link_to t('.cancel'), edit_user_path(current_user) - = t('.or') + = link_to t('cancel'), edit_user_path(current_user) + = t('or') = f.submit t('.change_password') %h3 @@ -70,5 +70,5 @@ %h3 = t('.close_account') = link_to t('.close_account'), current_user, - :confirm => t('.are_you_sure'), :method => :delete, + :confirm => t('are_you_sure'), :method => :delete, :class => "button" diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 250315b6a..3a9de1b7c 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -6,6 +6,23 @@ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. en: + + settings: "Settings" + profile: "Profile" + account: "Account" + services: "Services" + cancel: "Cancel" + delete: "Delete" + or: "or" + by: "by" + ago: "ago" + username: "Username" + email: "Email" + home: "Home" + password: "Password" + password_confirmation: "Password confirmation" + are_you_sure: "Are you sure?" + activemodel: errors: models: @@ -26,9 +43,6 @@ en: helper: unknown_person: "unknown person" new_requests: "new requests" - dashboards: - helper: - home: "home" error_messages: helper: invalid_fields: "Invalid Fields" @@ -54,7 +68,6 @@ en: manage_aspects: "Manage Aspects" publisher: share: "Share" - or: "or" post_a_message_to: "Post a message to %{aspect}" make_public: "make public" aspect_friends: @@ -66,6 +79,8 @@ en: invitations_left: '(%{count} left)' reshare: reshare: 'Reshare' + author_info: + view_profile: 'View profile' albums: album: you: "you" @@ -76,17 +91,13 @@ en: edit_album: "Edit Album" albums: "albums" updated: "updated" - by: "by" edit: album_name: "Album name" editing: "Editing" updated: "updated" update_album: "Update album" - are_you_sure: "Are you sure?" delete_album: "Delete Album" - cancel: "Cancel" index: - home: "home" new_album: "New Album" create: success: "You've created an album called %{name}." @@ -138,19 +149,11 @@ en: edit: editing_profile: "Editing profile" invite_friends: "Invite friends" - are_you_sure: "Are you sure?" export_data: "Export Data" close_account: "Close Account" change_language: "Change Language" change_password: "Change Password" new_password: "New Password" - password_confirmation: "Password confirmation" - settings: "Settings" - profile: "Profile" - account: "Account" - services: "Services" - cancel: "Cancel" - or: "or" destroy: "Account successfully closed." getting_started: signup_steps: "Complete your sign-up by doing these things:" @@ -158,10 +161,7 @@ en: albums: "Albums" you_dont_have_any_photos: "You don't have any photos! Go to the" page_to_upload_some: "page to upload some." - or: "or" comments: - comment: - ago: "ago" new_comment: comment: "Comment" photos: @@ -171,17 +171,13 @@ en: next: "next" edit_photo: "Edit Photo" delete_photo: "Delete Photo" - are_you_sure: "Are you sure?" comments: "comments" edit: editing: "Editing" - are_you_sure: "Are you sure?" delete_photo: "Delete Photo" photo: show_comments: "show comments" posted_a_new_photo_to: "posted a new photo to" - delete: "Delete" - are_you_sure: "Are you sure?" new: new_photo: "New Photo" back_to_list: "Back to List" @@ -201,10 +197,6 @@ en: sign_up_for_diaspora: "Sign up for Diaspora" upload_existing_account: "Upload an existing Diaspora account" upload: "Upload" - username: "Username" - email: "Email" - password: "Password" - password_confirmation: "Password confirmation" create: success: "You've joined Diaspora!" invitations: @@ -216,7 +208,6 @@ en: invitation_token_invalid: 'The invitation token provided is not valid!' updated: 'Your password was set successfully. You are now signed in.' new: - email: 'Email' invite_someone_to_join: 'Invite someone to join Diaspora!' if_they_accept_info: 'if they accept, they will be added to the aspect you invited them' to: 'To' @@ -229,13 +220,9 @@ en: oh_yeah: "oh yeah!" status_message: show_comments: "show comments" - delete: "Delete" - are_you_sure: "Are you sure?" - ago: "ago" show: status_message: "Status Message" comments: "comments" - are_you_sure: "Are you sure?" destroy: "Destroy" view_all: "View All" message: "Message" @@ -260,13 +247,11 @@ en: last_seen: "last seen: %{how_long_ago}" friends_since: "friends since: %{how_long_ago}" save: "save" - are_you_sure: "Are you sure?" remove_friend: "remove friend" no_posts: "no posts to display!" add_friend: "add friend" edit_my_profile: "Edit my profile" edit: - settings: "Settings" info_available_to: "This info will be available to whomever you connect with on Diaspora." your_profile: "Your profile" your_name: "Your name" @@ -277,12 +262,7 @@ en: your_bio: "Your bio" fill_me_out: "Fill me out" your_photo: "Your photo" - profile: "Profile" - account: "Account" - services: "Services" - cancel: "Cancel" update_profile: "Update Profile" - home: "Home" diaspora_username: "DIASPORA USERNAME" info: "Info" picture: "Picture" @@ -290,7 +270,6 @@ en: albums: "Albums" you_dont_have_any_photos: "You don't have any photos! Go to the" page_to_upload_some: "page to upload some." - or: "or" requests: new_request: add_a_new_friend_to: "Add a new friend to" @@ -310,9 +289,3 @@ en: already_friends: "You are already friends with %{destination_url}!" success: "A friend request was sent to %{destination_url}." horribly_wrong: "Something went horribly wrong." - services: - index: - settings: "Settings" - profile: "Profile" - account: "Account" - services: "Services" From aab74cf1ff7416f6cd213909c2d3781182770a0e Mon Sep 17 00:00:00 2001 From: "livefromthemoon@gmail.com" Date: Tue, 2 Nov 2010 03:55:14 +0100 Subject: [PATCH 08/22] Added markdown support for status messages --- app/helpers/application_helper.rb | 84 ++++++++++ app/helpers/status_messages_helper.rb | 37 ----- .../status_messages/_status_message.html.haml | 2 +- app/views/status_messages/show.html.haml | 2 +- spec/helpers/application_helper_spec.rb | 151 ++++++++++++++++++ spec/helpers/status_messages_helper_spec.rb | 72 --------- 6 files changed, 237 insertions(+), 111 deletions(-) delete mode 100644 spec/helpers/status_messages_helper_spec.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d89b0b1ee..420170cb0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3,6 +3,8 @@ # the COPYRIGHT file. module ApplicationHelper + @@youtube_title_cache = Hash.new("no-title") + def current_aspect?(aspect) !@aspect.is_a?(Symbol) && @aspect.id == aspect.id end @@ -85,4 +87,86 @@ module ApplicationHelper "#{photos_path}?person_id=#{person_id}" end + + def markdownify(message, options = {}) + message = h(message).html_safe + + [:autolinks, :youtube, :emphasis, :links].each do |k| + if !options.has_key?(k) + options[k] = true + end + end + + if options[:links] + message.gsub!(/\[([^\[]+)\]\(([^ ]+) \"(([^&]|(&[^q])|(&q[^u])|(&qu[^o])|(&quo[^t])|("[^;]))+)\"\)/) do |m| + escape = (options[:emphasis]) ? "\\" : "" + res = "#{$1}" + res + end + message.gsub!(/\[([^\[]+)\]\(([^ ]+)\)/) do |m| + escape = (options[:emphasis]) ? "\\" : "" + res = "#{$1}" + res + end + end + + if options[:youtube] + message.gsub!(/( |^)(http:\/\/)?www\.youtube\.com\/watch[^ ]*v=([A-Za-z0-9_]+)(&[^ ]*|)/) do |m| + res = "#{$1}youtube.com::#{$3}" + res.gsub!(/(\*|_)/) { |m| "\\#{$1}" } if options[:emphasis] + res + end + end + + if options[:autolinks] + message.gsub!(/( |^)(www\.[^ ]+\.[^ ])/, '\1http://\2') + message.gsub!(/(#{$3}} + res.gsub!(/(\*|_)/) { |m| "\\#{$1}" } if options[:emphasis] + res + end + end + end + + if options[:emphasis] + message.gsub!(/([^\\]|^)\*\*(([^*]|([^*]\*[^*]))*[^*\\])\*\*/, '\1\2') + message.gsub!(/([^\\]|^)__(([^_]|([^_]_[^_]))*[^_\\])__/, '\1\2') + message.gsub!(/([^\\]|^)\*([^*]*[^\\])\*/, '\1\2') + message.gsub!(/([^\\]|^)_([^_]*[^\\])_/, '\1\2') + message.gsub!(/([^\\]|^)\*/, '\1') + message.gsub!(/([^\\]|^)_/, '\1') + message.gsub!("\\*", "*") + message.gsub!("\\_", "_") + end + + if options[:youtube] + while youtube = message.match(/youtube\.com::([A-Za-z0-9_\\]+)/) + videoid = youtube[1] + message.gsub!('youtube.com::'+videoid, 'Youtube: ' + youtube_title(videoid) + '') + end + end + + return message + end + + def youtube_title(id) + unless @@youtube_title_cache[id] == 'no-title' + return @@youtube_title_cache[id] + end + + ret = 'Unknown Video Title' #TODO add translation + http = Net::HTTP.new('gdata.youtube.com', 80) + path = '/feeds/api/videos/'+id+'?v=2' + resp, data = http.get(path, nil) + title = data.match(/(.*)<\/title>/) + unless title.nil? + ret = title.to_s[7..-9] + end + + @@youtube_title_cache[id] = ret; + return ret + end end diff --git a/app/helpers/status_messages_helper.rb b/app/helpers/status_messages_helper.rb index 2e010715a..2dfbd31cc 100644 --- a/app/helpers/status_messages_helper.rb +++ b/app/helpers/status_messages_helper.rb @@ -3,8 +3,6 @@ # the COPYRIGHT file. module StatusMessagesHelper - @@youtube_title_cache = Hash.new("no-title") - def my_latest_message unless @latest_status_message.nil? return @latest_status_message.message @@ -12,39 +10,4 @@ module StatusMessagesHelper return I18n.t('status_messages.helper.no_message_to_display') end end - - def make_links(message) - # If there should be some kind of bb-style markup, email/diaspora highlighting, it could go here. - - # next line is important due to XSS! (h is rail's make_html_safe-function) - message = h(message).html_safe - message.gsub!(/( |^)(www\.[^ ]+\.[^ ])/, '\1http://\2') - message.gsub!(/( |^)http:\/\/www\.youtube\.com\/watch[^ ]*v=([A-Za-z0-9_]+)(&[^ ]*|)/, '\1youtube.com::\2') - message.gsub!(/(https|http|ftp):\/\/([^ ]+)/, '<a target="_blank" href="\1://\2">\2</a>') - - while youtube = message.match(/youtube\.com::([A-Za-z0-9_]+)/) - videoid = youtube[1] - message.gsub!('youtube.com::'+videoid, '<a onclick="openVideo(\'youtube.com\', \'' + videoid + '\', this)" href="#video">Youtube: ' + youtube_title(videoid) + '</a>') - end - return message - end - - def youtube_title(id) - unless @@youtube_title_cache[id] == 'no-title' - return @@youtube_title_cache[id] - end - - ret = 'Unknown Video Title' #TODO add translation - http = Net::HTTP.new('gdata.youtube.com', 80) - path = '/feeds/api/videos/'+id+'?v=2' - resp, data = http.get(path, nil) - title = data.match(/<title>(.*)<\/title>/) - unless title.nil? - ret = title.to_s[7..-9] - end - - @@youtube_title_cache[id] = ret; - return ret - end - end diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index 7e065b475..c009520cc 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -23,7 +23,7 @@ = render "shared/reshare", :post => post, :current_user => current_user = link_to t('.delete'), status_message_path(post), :confirm => t('.are_you_sure'), :method => :delete, :remote => true, :class => "delete" - = make_links(post.message) + = markdownify(post.message) .info %span.time= link_to(how_long_ago(post), object_path(post)) diff --git a/app/views/status_messages/show.html.haml b/app/views/status_messages/show.html.haml index 0672ca1e8..246ca0e1b 100644 --- a/app/views/status_messages/show.html.haml +++ b/app/views/status_messages/show.html.haml @@ -7,7 +7,7 @@ .span-14.append-1.last %h1.show_text - = make_links(@status_message.message) + = markdownify(@status_message.message) = how_long_ago(@status_message) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 0ba2bb28a..9e7cb7f4c 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -18,4 +18,155 @@ describe ApplicationHelper do person_url(@user).should == "/users/#{@user.id}" end + describe "markdownify" do + describe "autolinks" do + it "should not allow basic XSS/HTML" do + markdownify("<script>alert('XSS is evil')</script>").should == "<script>alert('XSS is evil')</script>" + end + + it "should recognize basic http links (1/3)" do + proto="http" + url="bugs.joindiaspora.com/issues/332" + markdownify(proto+"://"+url).should == "<a target=\"_blank\" href=\""+proto+"://"+url+"\">"+url+"</a>" + end + + it "should recognize basic http links (2/3)" do + proto="http" + url="webmail.example.com?~()!*/" + markdownify(proto+"://"+url).should == "<a target=\"_blank\" href=\""+proto+"://"+url+"\">"+url+"</a>" + end + + it "should recognize basic http links (3/3)" do + proto="http" + url="127.0.0.1:3000/users/sign_in" + markdownify(proto+"://"+url).should == "<a target=\"_blank\" href=\""+proto+"://"+url+"\">"+url+"</a>" + end + + it "should recognize secure https links" do + proto="https" + url="127.0.0.1:3000/users/sign_in" + markdownify(proto+"://"+url).should == "<a target=\"_blank\" href=\""+proto+"://"+url+"\">"+url+"</a>" + end + + it "should recognize youtube links" do + proto="http" + videoid = "0x__dDWdf23" + url="www.youtube.com/watch?v="+videoid+"&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1" + title = "UP & down & UP & down &" + mock_http = mock("http") + Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http) + mock_http.should_receive(:get).with('/feeds/api/videos/'+videoid+'?v=2', nil).and_return([nil, 'Foobar <title>'+title+' hallo welt dsd']) + res = markdownify(proto+'://'+url) + res.should == "Youtube: "+title+"" + end + + it "should recognize a bunch of different links" do + message = "http:// Hello World, this is for www.joindiaspora.com and not for http://www.google.com though their Youtube service is neat, take http://www.youtube.com/watch?v=foobar or www.youtube.com/watch?foo=bar&v=BARFOO&whatever=related It is a good idea we finally have youtube, so enjoy this video http://www.youtube.com/watch?v=rickrolld" + mock_http = mock("http") + Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http) + mock_http.should_receive(:get).with('/feeds/api/videos/foobar?v=2', nil).and_return([nil, 'Foobar F 007 - the bar is not enough hallo welt dsd']) + mock_http.should_receive(:get).with('/feeds/api/videos/BARFOO?v=2', nil).and_return([nil, 'Foobar BAR is the new FOO hallo welt dsd']) + mock_http.should_receive(:get).with('/feeds/api/videos/rickrolld?v=2', nil).and_return([nil, 'Foobar Never gonne give you up hallo welt dsd']) + res = markdownify(message) + res.should == "http:// Hello World, this is for www.joindiaspora.com and not for www.google.com though their Youtube service is neat, take Youtube: F 007 - the bar is not enough or Youtube: BAR is the new FOO It is a good idea we finally have youtube, so enjoy this video Youtube: Never gonne give you up" + end + + it "should recognize basic ftp links" do + proto="ftp" + url="ftp.uni-kl.de/CCC/26C3/mp4/26c3-3540-en-a_hackers_utopia.mp4" + # I did not watch that one, but the title sounds nice :P + markdownify(proto+"://"+url).should == ""+url+"" + end + + it "should recognize www links" do + url="www.joindiaspora.com" + markdownify(url).should == ""+url+"" + end + end + + describe "weak emphasis" do + it "should be recognized (1/2)" do + message = "*some text* some text *some text* some text" + markdownify(message).should == "some text some text some text some text" + end + + it "should be recognized (2/2)" do + message = "_some text_ some text _some text_ some text" + markdownify(message).should == "some text some text some text some text" + end + end + + describe "strong emphasis" do + it "should be recognized (1/2)" do + message = "**some text** some text **some text** some text" + markdownify(message).should == "some text some text some text some text" + end + + it "should be recognized (2/2)" do + message = "__some text__ some text __some text__ some text" + markdownify(message).should == "some text some text some text some text" + end + end + + describe "nested weak and strong emphasis" do + it "should be rendered correctly" do + message = "__this is _some_ text__" + markdownify(message).should == "this is some text" + message = "*this is **some** text*" + markdownify(message).should == "this is some text" + message = "___some text___" + markdownify(message).should == "some text" + end + end + + describe "links" do + it "should be recognized without title attribute" do + message = "[link text](http://someurl.com) [link text](http://someurl.com)" + markdownify(message).should == 'link text link text' + end + + it "should be recognized with title attribute" do + message = '[link text](http://someurl.com "some title") [link text](http://someurl.com "some title")' + markdownify(message).should == 'link text link text' + end + end + + describe "nested emphasis and links tags" do + it "should be rendered correctly" do + message = '[**some *link* text**](someurl.com "some title")' + markdownify(message).should == 'some link text' + end + end + + it "should allow escaping" do + message = '*some text* \\*some text* \\**some text* _some text_ \\_some text_ \\__some text_' + markdownify(message).should == "some text *some text *some text some text _some text _some text" + end + + describe "options" do + before do + @message = "http://url.com www.url.com www.youtube.com/watch?foo=bar&v=BARFOO&whatever=related *emphasis* __emphasis__ [link](www.url.com) [link](url.com \"title\")" + end + + it "should allow to render only autolinks" do + res = markdownify(@message, :youtube => false, :emphasis => false, :links => false) + res.should == "url.com www.url.com www.youtube.com/watch?foo=bar&v=BARFOO&whatever=related *emphasis* __emphasis__ [link](www.url.com) [link](url.com "title")" + end + + it "should allow to render only youtube autolinks" do + res = markdownify(@message, :autolinks => false, :emphasis => false, :links => false) + res.should == "http://url.com www.url.com Youtube: BAR is the new FOO *emphasis* __emphasis__ [link](www.url.com) [link](url.com "title")" + end + + it "should allow to render only emphasis tags" do + res = markdownify(@message, :autolinks => false, :youtube => false, :links => false) + res.should == "http://url.com www.url.com www.youtube.com/watch?foo=bar&v=BARFOO&whatever=related emphasis emphasis [link](www.url.com) [link](url.com "title")" + end + + it "should allo to render only links tags" do + res = markdownify(@message, :autolinks => false, :youtube => false, :emphasis => false) + res.should == "http://url.com www.url.com www.youtube.com/watch?foo=bar&v=BARFOO&whatever=related *emphasis* __emphasis__ link link" + end + end + end end diff --git a/spec/helpers/status_messages_helper_spec.rb b/spec/helpers/status_messages_helper_spec.rb deleted file mode 100644 index 0aee3826a..000000000 --- a/spec/helpers/status_messages_helper_spec.rb +++ /dev/null @@ -1,72 +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' - -describe StatusMessagesHelper do - it "should not allow basic XSS/HTML" do - make_links("").should == "<script>alert('XSS is evil')</script>" - end - - it "should recognize basic http links (1/3)" do - proto="http" - url="bugs.joindiaspora.com/issues/332" - make_links(proto+"://"+url).should == ""+url+"" - end - - it "should recognize basic http links (2/3)" do - proto="http" - url="webmail.example.com?~()!*/" - make_links(proto+"://"+url).should == ""+url+"" - end - - it "should recognize basic http links (3/3)" do - proto="http" - url="127.0.0.1:3000/users/sign_in" - make_links(proto+"://"+url).should == ""+url+"" - end - - it "should recognize secure https links" do - proto="https" - url="127.0.0.1:3000/users/sign_in" - make_links(proto+"://"+url).should == ""+url+"" - end - - it "should recognize youtube links" do - proto="http" - videoid = "0x__dDWdf23" - url="www.youtube.com/watch?v="+videoid+"&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1" - title = "UP & down & UP & down &" - mock_http = mock("http") - Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http) - mock_http.should_receive(:get).with('/feeds/api/videos/'+videoid+'?v=2', nil).and_return([nil, 'Foobar '+title+' hallo welt dsd']) - res = make_links(proto+'://'+url) - res.should == "Youtube: "+title+"" - end - - it "should recognize a bunch of different links" do - message = "http:// Hello World, this is for www.joindiaspora.com and not for http://www.google.com though their Youtube service is neat, take http://www.youtube.com/watch?v=foobar or www.youtube.com/watch?foo=bar&v=BARFOO&whatever=related It is a good idea we finally have youtube, so enjoy this video http://www.youtube.com/watch?v=rickrolld" - mock_http = mock("http") - Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http) - mock_http.should_receive(:get).with('/feeds/api/videos/foobar?v=2', nil).and_return([nil, 'Foobar F 007 - the bar is not enough hallo welt dsd']) - mock_http.should_receive(:get).with('/feeds/api/videos/BARFOO?v=2', nil).and_return([nil, 'Foobar BAR is the new FOO hallo welt dsd']) - mock_http.should_receive(:get).with('/feeds/api/videos/rickrolld?v=2', nil).and_return([nil, 'Foobar Never gonne give you up hallo welt dsd']) - res = make_links(message) - res.should == "http:// Hello World, this is for www.joindiaspora.com and not for www.google.com though their Youtube service is neat, take Youtube: F 007 - the bar is not enough or Youtube: BAR is the new FOO It is a good idea we finally have youtube, so enjoy this video Youtube: Never gonne give you up" - end - - it "should recognize basic ftp links" do - proto="ftp" - url="ftp.uni-kl.de/CCC/26C3/mp4/26c3-3540-en-a_hackers_utopia.mp4" - # I did not watch that one, but the title sounds nice :P - make_links(proto+"://"+url).should == ""+url+"" - end - - it "should recognize www links" do - url="www.joindiaspora.com" - make_links(url).should == ""+url+"" - end - - -end From 9e1c6174bf9a87dd6f3f0b6968b5d2dcb3e5e529 Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 2 Nov 2010 10:06:41 -0700 Subject: [PATCH 09/22] IZ MS remove two unused methods from diaspora_parser --- lib/diaspora/parser.rb | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lib/diaspora/parser.rb b/lib/diaspora/parser.rb index 2d002a2c9..acdd27afd 100644 --- a/lib/diaspora/parser.rb +++ b/lib/diaspora/parser.rb @@ -4,22 +4,7 @@ module Diaspora module Parser - def self.owner_id_from_xml(xml) - doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks } - id = doc.xpath("//person_id").text.to_s - Person.first(:id => id) - end - - def self.parse_or_find_person_from_xml(xml) - doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks } - 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 - def self.from_xml(xml) - doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks } return unless body = doc.xpath("/XML/post").children.first From 67219248b0c33c203e668b113931babcdc577393 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 2 Nov 2010 10:32:34 -0700 Subject: [PATCH 10/22] unscope i18n calls --- app/views/devise/sessions/new.html.haml | 4 ++-- app/views/registrations/new.html.haml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/devise/sessions/new.html.haml b/app/views/devise/sessions/new.html.haml index 15c29ec4f..595fba52d 100644 --- a/app/views/devise/sessions/new.html.haml +++ b/app/views/devise/sessions/new.html.haml @@ -5,13 +5,13 @@ = form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| #user %p.username - = f.label :username , t('.username') + = f.label :username , t('username') = f.text_field :username %p.user_network ="@#{APP_CONFIG[:terse_pod_url]}" %p - = f.label :password , t('.password') + = f.label :password , t('password') = f.password_field :password /%p /- if devise_mapping.rememberable? diff --git a/app/views/registrations/new.html.haml b/app/views/registrations/new.html.haml index 8dae3824a..41423e55e 100644 --- a/app/views/registrations/new.html.haml +++ b/app/views/registrations/new.html.haml @@ -5,16 +5,16 @@ = image_tag "http://needcoffee.cachefly.net/needcoffee/uploads/2009/02/predator-arnold-schwarzenegger.jpg" = form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %p - = f.label :username , t('.username') + = f.label :username , t('username') = f.text_field :username %p - = f.label :email , t('.email') + = f.label :email , t('email') = f.text_field :email %p - = f.label :password , t('.password') + = f.label :password , t('password') = f.password_field :password %p - = f.label :password_confirmation , t('.password_confirmation') + = f.label :password_confirmation , t('password_confirmation') = f.password_field :password_confirmation = f.submit t('.sign_up') From 0b8425cbde194693a3068734f3c78d27ffbbfb71 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 2 Nov 2010 11:02:08 -0700 Subject: [PATCH 11/22] user.aspect is gone --- spec/models/user/receive_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 86f0246a3..eef2c08f0 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -20,7 +20,7 @@ describe User do end it 'should stream only one message to the everyone aspect when a multi-aspected friend posts' do - user.add_person_to_aspect(user2.person.id, user.aspect(:name => "villains").id) + user.add_person_to_aspect(user2.person.id, user.aspects.create(:name => "villains").id) status = user2.post(:status_message, :message => "Users do things", :to => aspect2.id) xml = status.to_diaspora_xml Diaspora::WebSocket.should_receive(:queue_to_user).exactly(:once) From a3ce5f1cd7e1680be4207c6221e7de00cf6d4d54 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Tue, 2 Nov 2010 11:17:47 -0700 Subject: [PATCH 12/22] REMOVED IMPORTER --- app/controllers/users_controller.rb | 23 +-- app/models/contact.rb | 3 +- app/views/registrations/new.html.haml | 21 --- config/routes.rb | 1 - lib/diaspora/importer.rb | 222 ---------------------- spec/lib/diaspora/importer_spec.rb | 254 -------------------------- spec/lib/verify_spec.rb | 126 ------------- 7 files changed, 2 insertions(+), 648 deletions(-) delete mode 100644 lib/diaspora/importer.rb delete mode 100644 spec/lib/diaspora/importer_spec.rb delete mode 100644 spec/lib/verify_spec.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b5e11f86a..a96438dc2 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,11 +5,9 @@ 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 @@ -101,23 +99,4 @@ class UsersController < ApplicationController User.invite!(:email => params[:email]) end - - def import - xml = params[:upload][:file].read - - 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] = "Something went wrong: #{e.message}" - end - - redirect_to new_user_registration_path - #redirect_to user_session_path - end - - - end diff --git a/app/models/contact.rb b/app/models/contact.rb index 9ae223579..5aef55292 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -4,8 +4,7 @@ class Contact include MongoMapper::Document - attr_accessor :aspect_names #this is only used in the importer - + belongs_to :user validates_presence_of :user diff --git a/app/views/registrations/new.html.haml b/app/views/registrations/new.html.haml index 41423e55e..f6cd28981 100644 --- a/app/views/registrations/new.html.haml +++ b/app/views/registrations/new.html.haml @@ -19,24 +19,3 @@ = f.submit t('.sign_up') - - .floating - %h3 - = t('.upload_existing_account') - - = 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 t('.upload') - diff --git a/config/routes.rb b/config/routes.rb index 8604abaad..3bd37a018 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,6 @@ Diaspora::Application.routes.draw do match 'public/:username', :to => 'users#public' match 'getting_started', :to => 'users#getting_started', :as => 'getting_started' 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/importer.rb b/lib/diaspora/importer.rb deleted file mode 100644 index 57dd11ae9..000000000 --- a/lib/diaspora/importer.rb +++ /dev/null @@ -1,222 +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, contacts, opts = {}) - filter = verify_and_clean(user, person, people, aspects, posts, contacts) - - #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 = - user.visible_person_ids = people.collect{ |x| x.id } - - - 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 - - contacts.each do |contact| - contact.user = user - - user.friends << contact - contact.save! - end - - - puts user.persisted? - - puts user.inspect - user.save(:validate => false) - - - end - - def assign_aspect_ids(contacts, aspects) - a_hash = {} - aspects.each{|x| a_hash[x.name]=x.id} - - contacts.each do |contact| - contact.aspect_names.each do |x| - contact.aspect_ids << a_hash[x] - end - contact.aspect_names = nil - end - - - end - - ### verification (to be module) ################ - - def verify_and_clean(user, person, people, aspects, posts, contacts) - verify_user(user) - verify_person_for_user(user, person) - filters = filter_posts(posts, person) - clean_aspects(aspects, filters[:whitelist]) - filters[:all_person_ids] = people.collect{ |x| x.id.to_id } - - raise "incorrect number of contacts" unless verify_contacts(contacts, filters[:all_person_ids]) - assign_aspect_ids(contacts, aspects) - filters[:people] = filter_people(people) - filters - end - - def verify_contacts(contacts, person_ids) - return false if contacts.count != person_ids.count - contacts.all?{|x| person_ids.include?(x.person_id)} - 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) - contacts = parse_contacts(doc) - people = parse_people(doc) - posts = parse_posts(doc) - - user - commit(user, person, aspects, people, posts, contacts, 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 } - 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_contacts(doc) - contacts = [] - contact_doc = doc.xpath('/export/contacts/contact') - - contact_doc.each do |x| - contact = Contact.new - contact.person_id = x.xpath("person_id").text.to_id - contact.aspect_names = x.xpath('aspects/aspect/name').collect{ |x| x.text} - contacts << contact - end - contacts - 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/spec/lib/diaspora/importer_spec.rb b/spec/lib/diaspora/importer_spec.rb deleted file mode 100644 index f855f8bd0..000000000 --- a/spec/lib/diaspora/importer_spec.rb +++ /dev/null @@ -1,254 +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 - def setup_for_exporting - # Five users on pod - @user1 = make_user - @user2 = make_user - @user3 = make_user - @user4 = make_user - @user5 = make_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.aspects.create(:name => "Dudes") - @aspect2 = @user1.aspects.create(:name => "Girls") - @aspect3 = @user1.aspects.create(:name => "Bros") - @aspect4 = @user1.aspects.create(:name => "People") - @aspect5 = @user2.aspects.create(:name => "Abe Lincolns") - @aspect6 = @user3.aspects.create(:name => "Cats") - @aspect7 = @user4.aspects.create(:name => "Dogs") - @aspect8 = @user5.aspects.create(:name => "Hamsters") - @aspect9 = @user5.aspects.create(:name => "Gophers") - - @aspect10 = @user1.aspects.create(:name => "Work") - @aspect11 = @user1.aspects.create(: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 - - before(:all) do - DatabaseCleaner.clean - UserFixer.load_user_fixtures - setup_for_exporting - # 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 - end - - it 'should gut check this test' do - setup_for_exporting - @user1.friends.count.should be 4 - - @user1.contact_for(@user2.person).should_not be_nil - @user1.contact_for(@user3.person).should_not be_nil - @user1.contact_for(@user4.person).should_not be_nil - @user1.contact_for(@user5.person).should_not be_nil - - # User is generated with two pre-populated aspects - @user1.aspects.count.should be 6 - @user1.aspects.find_by_name("Dudes").people.find_by_person_id(@user2.person.id).should_not be_nil - @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 - @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 - end - - describe '#parse_contacts' do - let(:contacts) { @importer.parse_contacts(@doc) } - - it 'should return an array' do - contacts.count.should == 4 - end - - it 'should should have post ids' do - contacts.all?{|x| x.aspect_names.count > 0}.should be true - end - - it 'should should have a person id' do - contacts.all?{|x| x.person_id.nil? || x.person_id == ""}.should be false - 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) - @username =@user1.username - # Remove user1 from the server - @user1.aspects.each( &:delete ) - @user1.friends.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 needs love - the test passes when the validations are set to false when saving the user in the importer" - - User.delete_all - Person.delete_all - Post.delete_all - StatusMessage.delete_all - Aspect.delete_all - Contact.delete_all - - User.count.should == 0 - Person.count.should == 0 - - @importer.execute(@xml, - :email => "bob@bob.com", - :password => "bobbybob", - :password => "bobbybob", - :diaspora_handle => "#{@username}@#{APP_CONFIG[:terse_pod_url]}") - - User.count.should == 1 - n = User.first - Post.count.should == 4 - n.aspects.count.should == 6 - Person.count.should be == 5 - Contact.count.should be == 4 - - # need to check this - #User.first.person.diaspora_handle.should == User.first.diaspora_handle - User.first.diaspora_handle.should == "#{@username}@#{APP_CONFIG[:terse_pod_url]}" - - - 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 9dca1cb78..000000000 --- a/spec/lib/verify_spec.rb +++ /dev/null @@ -1,126 +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) { make_user } - let!(:user2) { make_user } - let!(:user3) { make_user } - - let(:aspect1) { user1.aspects.create(:name => "Work") } - let(:aspect2) { user2.aspects.create(:name => "Family") } - let(:aspect3) { user3.aspects.create(: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 = make_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 'verify contacts' do - let(:contact1) {Contact.new(:user => user1, :person => user2.person, :aspects => [aspect1])} - let(:contact2) {Contact.new(:user => user1, :person => user3.person, :aspects => [aspect2])} - let(:contact3) {Contact.new(:user => user1, :person => user3.person, :aspects => [aspect3])} - let(:less_contacts) {[contact1]} - let(:same_contacts) {[contact1, contact2]} - let(:more_contacts) {[contact1, contact2, contact3]} - - let(:person_ids) {[user2.person.id, user3.person.id]} - - - it 'should be false if the number of the number of contacts is not equal to the number of imported people' do - importer.verify_contacts(less_contacts, person_ids).should be false - importer.verify_contacts(same_contacts, person_ids).should be true - importer.verify_contacts(more_contacts, person_ids).should be false - 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 From bbd8cadc14c5de8364b32f81ba08e235f4a93b57 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 2 Nov 2010 11:19:34 -0700 Subject: [PATCH 13/22] Retaining specs and line from robustdj's patch --- config/locales/diaspora/en.yml | 1 + spec/controllers/albums_controller_spec.rb | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 3a9de1b7c..582cc170a 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -101,6 +101,7 @@ en: new_album: "New Album" create: success: "You've created an album called %{name}." + failure: "Failed to create album." update: success: "Album %{name} successfully edited." failure: "Failed to edit album %{name}." diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 21e750685..78a4b4290 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -22,6 +22,19 @@ describe AlbumsController do params = {"album" => {"name" => "Sunsets","to" => @aspect.id.to_s}} post :create, params end + + context 'with invalid params' do + it 'should render a flash error message when album name is blank' do + params = {"album" => {"name" => "", "to" => "all"}} + post :create, params + flash[:error].should == "Failed to create album." + end + it 'should redirect back to album page for that given aspect' do + params = {"album" => {"name" => "", "to" => "all"}} + post :create, params + response.should redirect_to albums_path(:aspect => "all") + end + end end describe "#update" do @@ -29,7 +42,7 @@ describe AlbumsController do put :update, :id => @album.id, :album => { :name => "new_name"} @album.reload.name.should eql("new_name") end - + it "doesn't overwrite random attributes" do new_user = make_user params = {:name => "Bruisers", :person_id => new_user.person.id} From 7fdd0475ae672086bff09b6dfd319c68b0600005 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 2 Nov 2010 11:26:54 -0700 Subject: [PATCH 14/22] robustdj's specs now green --- app/controllers/albums_controller.rb | 9 +++++++-- app/models/user.rb | 15 ++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index a74143363..1474b5c0f 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -17,8 +17,13 @@ class AlbumsController < ApplicationController aspect = params[:album][:to] @album = current_user.post(:album, params[:album]) - flash[:notice] = I18n.t 'albums.create.success', :name => @album.name - redirect_to :action => :show, :id => @album.id, :aspect => aspect + if @album.persisted? + flash[:notice] = I18n.t 'albums.create.success', :name => @album.name + redirect_to :action => :show, :id => @album.id, :aspect => aspect + else + flash[:error] = I18n.t 'albums.create.failure' + redirect_to albums_path(:aspect => aspect) + end end def new diff --git a/app/models/user.rb b/app/models/user.rb index bb465e78a..6a028a015 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -146,15 +146,16 @@ class User post = build_post(class_name, options) - post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid) - push_to_aspects(post, aspect_ids) - - if options[:public] == true - self.services.each do |service| - self.send("post_to_#{service.provider}".to_sym, service, post.message) + if post.persisted? + post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid) + push_to_aspects(post, aspect_ids) + + if options[:public] == true + self.services.each do |service| + self.send("post_to_#{service.provider}".to_sym, service, post.message) + end end end - post end From fdd326481261761cf1aa8193ad71dc6bd0bdd18b Mon Sep 17 00:00:00 2001 From: danielvincent Date: Tue, 2 Nov 2010 12:00:27 -0700 Subject: [PATCH 15/22] proxy buffering enabled and gzip compression for files other than text/html in nginx.conf --- config/sprinkle/conf/nginx.conf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/sprinkle/conf/nginx.conf b/config/sprinkle/conf/nginx.conf index 68eff1606..724645292 100644 --- a/config/sprinkle/conf/nginx.conf +++ b/config/sprinkle/conf/nginx.conf @@ -27,8 +27,9 @@ http { gzip_comp_level 2; gzip_proxied any; gzip_buffers 16 8k; - #gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; - # gzip_disable "MSIE [1-6]\.(?!.*SV1)"; + gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; + gzip_disable "MSIE [1-6]\.(?!.*SV1)"; + upstream thin_cluster { server unix:/tmp/thin.0.sock; server unix:/tmp/thin.1.sock; @@ -46,7 +47,6 @@ http { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; - proxy_buffering off; if (-f $request_filename/index.html) { rewrite (.*) $1/index.html break; From b1c9961a72dbbe77454cc273b7d9db6bd0ff9b28 Mon Sep 17 00:00:00 2001 From: MrZYX Date: Sat, 30 Oct 2010 17:33:50 +0200 Subject: [PATCH 16/22] updated german locale so no keys are missing (informal) also added parts for german from the rails i18n project still some parts missing, unclear or not translatable look at #FIXME's even added translation that is missing in en.yml :P thanks to michiwend for help --- config/locales/devise/devise.de.yml | 25 +- config/locales/diaspora/de.yml | 413 ++++++++++++++++++++++------ 2 files changed, 352 insertions(+), 86 deletions(-) diff --git a/config/locales/devise/devise.de.yml b/config/locales/devise/devise.de.yml index 543ab1935..ebbb2baa1 100644 --- a/config/locales/devise/devise.de.yml +++ b/config/locales/devise/devise.de.yml @@ -19,6 +19,11 @@ de: timeout: "Deine Sitzung ist abgelaufen, bitte melde dich erneut an um fortzufahren." inactive: "Dein Konto wurde noch nicht aktiviert." sessions: + new: + login: 'Login' + username: 'Benutzername' + password: 'Passwort' + sign_in: 'Anmelden' signed_in: "Erfolgreich angemeldet." signed_out: "Erfolgreich abgemeldet." passwords: @@ -34,7 +39,21 @@ de: unlocks: send_instructions: "Du wirst in ein paar Minuten eine E-Mail erhalten, die beschreibt, wie du dein Konto entsperren kannst." unlocked: "Dein Konto wurde erfolgreich entsperrt. Du bist nun angemeldet." + invitations: + send_instructions: 'Deine Einladung wurde versandt.' + invitation_token_invalid: 'Das Einladungstoken ist ungültig!' #FIXME: translate token? + updated: 'Dein Passwort wurde erfolgreich gesetzt. Du bist nun angemeldet.' mailer: - confirmation_instructions: "Instruktionen zur Bestätigung" - reset_password_instructions: "Instruktionen zum Zurücksetzen des Passworts" - unlock_instructions: "Instruktionen zum Entsperren" + confirmation_instructions: + subject: "Instruktionen zur Bestätigung" + reset_password_instructions: + subject: "Instruktionen zum Zurücksetzen des Passworts" + unlock_instructions: + subject: "Instruktionen zum Entsperren" + invitation: + subject: 'Ein Freund möchte dich bei Diaspora einladen!' + shared: + links: + sign_in: 'Anmelden' + sign_up: 'Registrieren' + forgot_your_password: 'Passwort vergessen?' diff --git a/config/locales/diaspora/de.yml b/config/locales/diaspora/de.yml index 1f7c028ae..93a6d9729 100644 --- a/config/locales/diaspora/de.yml +++ b/config/locales/diaspora/de.yml @@ -2,35 +2,55 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -# Localization file for German. Add more files in this directory for other locales. -# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. +# Localization file for German +# +# This file has parts from rails-i18n project at +# http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale de: + activemodel: + errors: + models: + user: + attributes: + person: + invalid: "ist ungültig" + username: + taken: "ist bereits benutzt" + email: + taken: "ist bereits benutzt" + person: + attributes: + diaspora_handle: + taken: "ist bereits benutzt" hello: "Hallo Welt" application: helper: unknown_person: "unbekannte Person" - new_requests: "neue Anfrage" + new_requests: "neue Anfragen" dashboards: helper: - home: "Startseite" + home: "start" error_messages: helper: invalid_fields: "Ungültige Felder" - correct_the_following_errors_and_try_again: "Korrigiere die folgenden Fehler und probiere es erneut." - people: + correct_the_following_errors_and_try_again: "Korrigiere die folgenden Fehler und versuche es erneut." + people: #FIXME: seems unused helper: - results_for: " Resultate für %{params}" - people_on_pod_are_aware_of: " people on pod are aware of" + results_for: " Ergebnisse für %{params}" + people_on_pod_are_aware_of: " Leute auf dem Pod sind aufmerksam auf" layouts: application: + view_profile: "Profil anzeigen" edit_profile: "Profil bearbeiten" + account_settings: "Konto Einstellungen" + search: "Suche" logout: "Abmelden" shared: aspect_nav: all_aspects: "Alle Aspekte" manage: "Verwalten" - manage_your_aspects: "Aspekte verwalten" + manage_your_aspects: "Deine Aspekte verwalten" sub_header: all_aspects: "Alle Aspekte" manage_aspects: "Aspekte verwalten" @@ -38,11 +58,14 @@ de: share: "Teilen" aspect_friends: add_friends: "Freunde hinzufügen" + photos: "Fotos" + author_info: + view_profile: "Profil anzeigen" albums: album: - you: "dir" + you: "Du" new_album: - create: "erstellen" + create: "Hinzufügen" add_a_new_album: "Album hinzufügen" show: edit_album: "Album bearbeiten" @@ -50,158 +73,382 @@ de: updated: "aktualisiert" by: "von" edit: - editing: "Bearbeite" - updated: "geändert" + album_name: "Album Name" + editing: "Bearbeiten" + updated: "aktualisiert" + update_album: "Album aktualisieren" are_you_sure: "Bist du sicher?" delete_album: "Album löschen" cancel: "Abbrechen" index: - home: "Startseite" + home: "Start" new_album: "Neues Album" create: success: "Du hast das Album %{name} erstellt." update: - success: "Album %{name} erfolgreich geändert." - failure: "%{name} wurde nicht geändert." + success: "Album %{name} erfolgreich bearbeitet." + failure: "Bearbeiten des Album %{name} fehlgeschlagen." destroy: success: "Album %{name} gelöscht." helper: friends_albums: "Alben von Freunden" your_albums: "Deine Alben" aspects: - index: - photos: "Fotos" - show: - photos: "Fotos" + no_friends_message: + nobody: "Wir wissen du hast Freunde, hole sie an Bord!" + nobody_in_aspect: "Dein Aspekt %{aspect_name} ist leer." + add_friend: "Freund hinzufügen" + add_friend_to: "Jemanden zum Aspekt %{aspect_name} hinzufügen" + invite: "Jemanden zu Diaspora einladen!" + no_posts_message: + start_talking: "Niemand hat bisher etwas gesagt. Beginne die Konversation!" manage: - add_a_new_aspect: "Neuen Aspekt erstellen" - add_a_new_friend: "Freund hinzufügen" - show: "Anzeigen" + add_a_new_aspect: "Neuen Aspekt hinzufügen" + add_a_new_friend: "Neuen Freund hinzufügen" + show: "Zeigen" update_aspects: "Aspekte aktualisieren" requests: "Anfragen" ignore_remove: "Ignorieren/Entfernen" new_aspect: - add_a_new_aspect: "Neuen Aspekt erstellen" + add_a_new_aspect: "Neuen Aspekt hinzufügen" + name: "Name" create: "Erstellen" create: - success: "Klicke auf das Plus auf der linken Seite um Diaspora mitzuteilen wer deinen neuen Aspekt sehen kann." + success: "Klicke auf das Plus auf der linken Seite um Diaspora zu sagen wer deinen neuen Aspekt sehen kann." + failure: "Erstellen des Aspekt fehlgeschlagen." destroy: - success: "%{name} wurde erfolgreich gelöscht." + success: "%{name} wurde erfolgreich entfernt." update: - success: "Dein Aspekt, %{name}, wurde erfolgreich geändert." - move_friends: - failure: "Ändern des Aspekts für deinen Freund %{real_name} fehlgeschlagen." - success: "Aspekt erfolgreich geändert." + success: "Dein Aspekt %{name} wurde erfolgreich bearbeitet." move_friend: - error: "didn't work %{inspect}" - notice: "Du zeigst deinem Freund jetzt einen anderen Aspekt von dir." + failure: "hat nicht funktioniert %{inspect}" + success: "Person zu neuem Aspekt verschoben" + add_to_aspect: + failure: "Hinzufügen des Freundes zum Aspekt fehlgeschlagen." + success: "Freund erfolgreich zum Aspekt hinzugefügt." helper: remove: "entfernen" aspect_not_empty: "Aspekt ist nicht leer" users: edit: editing_profile: "Profil bearbeiten" - profile: + invite_friends: "Feunde einladen" + are_you_sure: "Bist du sicher?" + export_data: "Daten exportieren" + close_account: "Konto schließen" + change_language: "Sprache ändern" + change_password: "Passwort ändern" + new_password: "Neues Passwort" + password_confirmation: "Passwort bestätigen" + settings: "Einstellungen" + profile: "Profil" + account: "Konto" + services: "Dienste" cancel: "Abbrechen" - update_profile: "Profil aktualisieren" - home: "Startseite" - diaspora_username: "Diaspora Benutzername" - info: "Info" - picture: "Bild" - editing_profile: "Profil bearbeiten" - albums: "Alben" - you_dont_have_any_photos: "Du hast keine Fotos! Gehe auf die" - page_to_upload_some: "Seite um welche hochzuladen." + destroy: "Account erfolgreich geschlossen." + getting_started: + 'step_1': + albums: "Alben" + you_dont_have_any_photos: "Du hast keine Fotos! Gehe zur" + page_to_upload_some: "Seite um welche hochzuladen." + or: "oder" comments: comment: - # this won't work in german at all. Needs more thorough I18n - ago: "ago" + ago: "her" #FIXME: need something like %{time} ago to translate it to something like Vor %{time} new_comment: - comment: "Kommentar" + comment: "Kommentieren" photos: show: prev: "zurück" full_size: "volle Größe" - next: "vor" + next: "weiter" edit_photo: "Foto bearbeiten" delete_photo: "Foto löschen" are_you_sure: "Bist du sicher?" comments: "Kommentare" edit: - editing: "Bearbeite" + editing: "Bearbeiten" are_you_sure: "Bist du sicher?" delete_photo: "Foto löschen" photo: - show_comments: "Kommentare anzeigen" - posted_a_new_photo_to: "neues Foto veröffentlicht bei" + show_comments: "Kommentare zeigen" + posted_a_new_photo_to: "Hinzugefügt:" + delete: "Löschen" + are_you_sure: "Bist du sicher?" new: - new_photo: "Foto erstellen" - back_to_list: "Zurück zur Liste" - post_it: "Hochladen" + new_photo: "Neues Foto" + back_to_list: "Zurück zu Liste" + post_it: "Poste es!" create: - runtime_error: "Hochladen eines Fotos fehlgeschlagen. Bist du sicher, dass dein Sicherheitsgurt befestigt ist?" - integrity_error: "Hochladen eines Fotos fehlgeschlagen. Bist du sicher, dass das ein Bild war?" - type_error: "Hochladen eines Fotos fehlgeschlagen. Bist du sicher, dass ein Bild hinzugefügt wurde?" + runtime_error: "Der Server wollte das Foto nicht bearbeiten, bist du darauf zu sehen?" + integrity_error: "Hochladen des Fotos fehlgeschlagen. Bist du sicher das es ein Foto war?" + type_error: "Hochladen des Foto fehlgeschlagen. Du solltest hier nur FOTOS hochladen..." update: notice: "Foto erfolgreich aktualisiert." - error: "Ändern des Fotos fehlgeschlagen." + error: "Bearbeiten des Fotos fehlgeschlagen." destroy: notice: "Foto gelöscht." registrations: new: - sign_up: "Anmelden" + sign_up: "Registrieren" + sign_up_for_diaspora: "Ein Diaspora Konto anlegen" + upload_existing_account: "Ein existierendes Konto hochladen" + upload: "Hochladen" + username: "Benutzername" + email: "E-Mail" + password: "Passwort" + password_confirmation: "Passwort bestätigen" create: - success: "Du bist Diaspora beigetreten!" + success: "Willkommen bei Diaspora!" + invitations: + create: + sent: 'Deine Einladung wurde verschickt.' + no_more: 'Du hast keine Einladungen mehr.' + already_sent: 'Du hast diese Person bereits eingeladen.' + already_friends: 'Du bist bereits mit dieser Person befreundet' + invitation_token_invalid: 'Das Einladungstoken ist ungültig!' + updated: 'Dein Passwort wurde erfolgreich gespeichert. Du bist jetzt angemeldet.' + status_messages: - new_status_message: - tell_me_something_good: "Erzähl' mir was schönes!" - oh_yeah: "Oh, super!" + new_status_message: #FIXME: seems unused + tell_me_something_good: "Was gibt es neues?" + oh_yeah: "oh yeah!" status_message: - show_comments: "Kommentare anzeigen" + show_comments: "Kommentare zeigen" delete: "Löschen" are_you_sure: "Bist du sicher?" show: - status_message: "Statusmeldung" + status_message: "Status Nachricht" comments: "Kommentare" are_you_sure: "Bist du sicher?" - destroy: "Löschen" - view_all: "Alle anzeigen" + destroy: "Zerstören" + view_all: "Alle zeigen" message: "Nachricht" - owner: "Eigentümer" + owner: "Besitzer" helper: no_message_to_display: "Keine Nachricht zum anzeigen." people: person: add_friend: "Freund hinzufügen" - pending_request: "Anfrage ausstehend" + pending_request: "Ausstehende Anfrage" index: add_friend: "Freund hinzufügen" - real_name: "Echter Name" - diaspora_handle: "diaspora handle" - thats_you: "das bist du!" - friend_request_pending: "Ausstehende Freundschaftsanfrage" - you_have_a_friend_request_from_this_person: "Du hast eine Freundschaftsanfrage von dieser Person" + real_name: "Realer Name" + diaspora_handle: "Diaspora Adresse" + thats_you: "Das bist du!" + friend_request_pending: "Ausstehende Freundes-Anfrage" + you_have_a_friend_request_from_this_person: "Du hast eine Freundes-Anfrage von dieser Person" new: new_person: "Neue Person" back_to_list: "Zurück zur Liste" show: - last_seen: "zuletzt gesehen: %{how_long_ago}" + last_seen: "Zuletzt gesehen vor: %{how_long_ago}" #FIXME: appends ago friends_since: "Freunde seit: %{how_long_ago}" save: "speichern" are_you_sure: "Bist du sicher?" remove_friend: "Freund entfernen" + no_posts: "Keine Posts zum anzeigen!" + add_friend: "Freund hinzufügen" + edit: + settings: "Einstellungen" + your_profile: "Dein Profil" + your_name: "Dein Name" + first_name: "Vorname" + last_name: "Nachname" + your_gender: "Dein Geschlecht" + your_birthday: "Dein Geburtstag" + your_bio: "Deine Info" + fill_me_out: "Füll mich aus" + your_photo: "Dein Foto" + profile: "Profil" + account: "Konto" + services: "Dienste" + cancel: "Abbrechen" + update_profile: "Profil aktualisieren" + home: "Start" + diaspora_username: "DIASPORA ADRESSE" + info: "Info" + picture: "Bild" + editing_profile: "Profil bearbeiten" + albums: "Alben" + you_dont_have_any_photos: "Du hast keine Fotos! Gehe zur" + page_to_upload_some: "Seite um welche hochzuladen." + or: "oder" requests: new_request: - add_a_new_friend_to: "Add a new friend to" - enter_a_diaspora_username: "Gebe einen Diaspora Benutzernamen ein:" - your_diaspora_username_is: "Dein Diaspora Benutzername ist: %{diaspora_handle}" - friends_username: "Freundes Benutzername" + add_a_new_friend_to: "Neuen Freund hinzufügen zu" + enter_a_diaspora_username: "Gib eine Diaspora Adresse ein:" + your_diaspora_username_is: "Deine Diaspora Adresse ist: %{diaspora_handle}" + friends_username: "Freunde's Benutzername" + create_request: "Anfrage erstellen" destroy: - success: "Ihr seid jetzt Freunde." - error: "Bitte wähle einen Aspekt aus!" - ignore: "Freundschaftsanfrage ignorieren." + success: "Ihr seit jetzt Freunde." + error: "Bitte wähle einen Aspekt!" + ignore: "Freundes-Anfrage ignoriert." create: - error: "Kein Diaspora-Seed in dieser E-Mail gefunden!" + error: "Keinen Diaspora Seed mit dieser E-Mail gefunden!" #FIXME: wtf? + invalid_identity: "Diese Diaspora Adresse ist nicht richtig formatiert" + error_server: "Problem mit dem anderen Server. Vielleicht existiert er nicht?" + yourself: "Du kannst dich nicht mit dir selbst befreunden!" already_friends: "Du bist bereits mit %{destination_url} befreundet!" - success: "Eine Freundschaftsanfrage wurde an %{destination_url} gesendet." - horribly_wrong: "Etwas ging tierisch schief." + success: "Eine Freundes-Anfrage wurde an %{destination_url} geschickt." + horribly_wrong: "Irgendwas ist furchtbar schief gelaufen." + services: + index: + settings: "Einstellungen" + profile: "Profil" + account: "Konto" + services: "Dienste" + +# The following is from the rails-i18n project at http://github.com/svenfuchs/rails-i18n + +# German translations for Ruby on Rails +# by Clemens Kofler (clemens@railway.at) + + date: + formats: + default: "%d.%m.%Y" + short: "%e. %b" + long: "%e. %B %Y" + only_day: "%e" + + day_names: [Sonntag, Montag, Dienstag, Mittwoch, Donnerstag, Freitag, Samstag] + abbr_day_names: [So, Mo, Di, Mi, Do, Fr, Sa] + month_names: [~, Januar, Februar, März, April, Mai, Juni, Juli, August, September, Oktober, November, Dezember] + abbr_month_names: [~, Jan, Feb, Mär, Apr, Mai, Jun, Jul, Aug, Sep, Okt, Nov, Dez] + order: [ :day, :month, :year ] + + time: + formats: + default: "%A, %d. %B %Y, %H:%M Uhr" + short: "%d. %B, %H:%M Uhr" + long: "%A, %d. %B %Y, %H:%M Uhr" + time: "%H:%M" + + am: "vormittags" + pm: "nachmittags" + + datetime: + distance_in_words: + half_a_minute: 'eine halbe Minute' + less_than_x_seconds: + one: 'weniger als eine Sekunde' + other: 'weniger als %{count} Sekunden' + x_seconds: + one: 'eine Sekunde' + other: '%{count} Sekunden' + less_than_x_minutes: + one: 'weniger als eine Minute' + other: 'weniger als %{count} Minuten' + x_minutes: + one: 'eine Minute' + other: '%{count} Minuten' + about_x_hours: + one: 'etwa eine Stunde' + other: 'etwa %{count} Stunden' + x_days: + one: 'ein Tag' + other: '%{count} Tage' + about_x_months: + one: 'etwa ein Monat' + other: 'etwa %{count} Monate' + x_months: + one: 'ein Monat' + other: '%{count} Monate' + almost_x_years: + one: 'fast ein Jahr' + other: 'fast %{count} Jahre' + about_x_years: + one: 'etwa ein Jahr' + other: 'etwa %{count} Jahre' + over_x_years: + one: 'mehr als ein Jahr' + other: 'mehr als %{count} Jahre' + prompts: + second: "Sekunden" + minute: "Minuten" + hour: "Stunden" + day: "Tag" + month: "Monat" + year: "Jahr" + + number: + format: + precision: 2 + separator: ',' + delimiter: '.' + currency: + format: + unit: '€' + format: '%n%u' + separator: "," + delimiter: "" + precision: 2 + percentage: + format: + delimiter: "" + precision: + format: + delimiter: "" + human: + format: + delimiter: "" + precision: 1 + storage_units: + # Storage units output formatting. + # %u is the storage unit, %n is the number (default: 2 MB) + format: "%n %u" + units: + byte: + one: "Byte" + other: "Bytes" + kb: "KB" + mb: "MB" + gb: "GB" + tb: "TB" + + support: + array: + words_connector: ", " + two_words_connector: " und " + last_word_connector: " und " + select: + prompt: "Bitte wählen:" + + activemodel: + errors: + template: + header: + one: "Konnte %{model} nicht speichern: ein Fehler." + other: "Konnte %{model} nicht speichern: %{count} Fehler." + body: "Bitte überprüfen Sie die folgenden Felder:" + + activerecord: + errors: + template: + header: + one: "Konnte %{model} nicht speichern: ein Fehler." + other: "Konnte %{model} nicht speichern: %{count} Fehler." + body: "Bitte überprüfen Sie die folgenden Felder:" + + messages: + inclusion: "ist kein gültiger Wert" + exclusion: "ist nicht verfügbar" + invalid: "ist nicht gültig" + confirmation: "stimmt nicht mit der Bestätigung überein" + accepted: "muss akzeptiert werden" + empty: "muss ausgefüllt werden" + blank: "muss ausgefüllt werden" + too_long: "ist zu lang (nicht mehr als %{count} Zeichen)" + too_short: "ist zu kurz (nicht weniger als %{count} Zeichen)" + wrong_length: "hat die falsche Länge (muss genau %{count} Zeichen haben)" + taken: "ist bereits vergeben" + not_a_number: "ist keine Zahl" + greater_than: "muss größer als %{count} sein" + greater_than_or_equal_to: "muss größer oder gleich %{count} sein" + equal_to: "muss genau %{count} sein" + less_than: "muss kleiner als %{count} sein" + less_than_or_equal_to: "muss kleiner oder gleich %{count} sein" + odd: "muss ungerade sein" + even: "muss gerade sein" + record_invalid: "Gültigkeitsprüfung ist fehlgeschlagen: %{errors}" From 7cd6e3a86875c5b6e0389c7a5a2a81c75fd7fcd7 Mon Sep 17 00:00:00 2001 From: MrZYX Date: Mon, 1 Nov 2010 19:52:53 +0100 Subject: [PATCH 17/22] updated german locale (informal) with keys from pull request 465 again with help of michiwend --- config/locales/diaspora/de.yml | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/config/locales/diaspora/de.yml b/config/locales/diaspora/de.yml index 93a6d9729..796f303a8 100644 --- a/config/locales/diaspora/de.yml +++ b/config/locales/diaspora/de.yml @@ -7,6 +7,7 @@ # This file has parts from rails-i18n project at # http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale + de: activemodel: errors: @@ -56,11 +57,18 @@ de: manage_aspects: "Aspekte verwalten" publisher: share: "Teilen" + or: "oder" + post_a_message_to: "Sende eine Nachricht an %{aspect}" + make_public: "öffentlich machen" aspect_friends: add_friends: "Freunde hinzufügen" photos: "Fotos" - author_info: - view_profile: "Profil anzeigen" + invitations: + invites: 'Einladungen' + invite_a_friend: 'Freund einladen' + invitations_left: '(%{count} übrig)' + reshare: + reshare: 'Erneut senden an' albums: album: you: "Du" @@ -134,7 +142,7 @@ de: editing_profile: "Profil bearbeiten" invite_friends: "Feunde einladen" are_you_sure: "Bist du sicher?" - export_data: "Daten exportieren" + export_data: "Konto exportieren" close_account: "Konto schließen" change_language: "Sprache ändern" change_password: "Passwort ändern" @@ -145,8 +153,10 @@ de: account: "Konto" services: "Dienste" cancel: "Abbrechen" - destroy: "Account erfolgreich geschlossen." + or: "oder" + destroy: "Konto erfolgreich geschlossen." getting_started: + signup_steps: "Vervollständige deine Registrierung indem du folgende Dinge tust:" 'step_1': albums: "Alben" you_dont_have_any_photos: "Du hast keine Fotos! Gehe zur" @@ -208,6 +218,14 @@ de: already_friends: 'Du bist bereits mit dieser Person befreundet' invitation_token_invalid: 'Das Einladungstoken ist ungültig!' updated: 'Dein Passwort wurde erfolgreich gespeichert. Du bist jetzt angemeldet.' + new: + email: 'E-Mail' + invite_someone_to_join: 'Lade jemanden zu Diaspora ein!' + if_they_accept_info: 'Wenn sie akzeptieren findest du sie im Aspekt in den du sie eingeladen hast' + to: 'An' + message: 'Nachricht:' + send_an_invitation: 'Eine Einladung senden' + send_invitation: 'Einladung senden' status_messages: new_status_message: #FIXME: seems unused @@ -217,6 +235,7 @@ de: show_comments: "Kommentare zeigen" delete: "Löschen" are_you_sure: "Bist du sicher?" + ago: "her" #FIXME: need something like %{time} ago to translate it to something like Vor %{time} show: status_message: "Status Nachricht" comments: "Kommentare" @@ -249,8 +268,10 @@ de: remove_friend: "Freund entfernen" no_posts: "Keine Posts zum anzeigen!" add_friend: "Freund hinzufügen" + edit_my_profile: "Mein Profil bearbeiten" edit: settings: "Einstellungen" + info_available_to: "Diese Infos werden für alle verfügbar sein mit denen du bei Diaspora verbunden bist." your_profile: "Dein Profil" your_name: "Dein Name" first_name: "Vorname" From 80b8e5e42dafff5be0cebb570dfe899c96f1f5c3 Mon Sep 17 00:00:00 2001 From: MrZYX Date: Tue, 2 Nov 2010 16:50:55 +0100 Subject: [PATCH 18/22] updated german locale (informal) to reflect latest changes --- config/locales/diaspora/de.yml | 69 ++++++++++------------------------ 1 file changed, 20 insertions(+), 49 deletions(-) diff --git a/config/locales/diaspora/de.yml b/config/locales/diaspora/de.yml index 796f303a8..5e257644c 100644 --- a/config/locales/diaspora/de.yml +++ b/config/locales/diaspora/de.yml @@ -7,8 +7,23 @@ # This file has parts from rails-i18n project at # http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale - de: + settings: "Einstellungen" + profile: "Profil" + account: "Konto" + services: "Dienste" + cancel: "Abbrechen" + delete: "Löschen" + or: "oder" + by: "von" + ago: "her" + username: "Benutzername" + email: "E-Mail" + home: "Start" + password: "Passwort" + password_confirmation: "Passwort bestätigen" + are_you_sure: "Bist du sicher?" + activemodel: errors: models: @@ -29,9 +44,6 @@ de: helper: unknown_person: "unbekannte Person" new_requests: "neue Anfragen" - dashboards: - helper: - home: "start" error_messages: helper: invalid_fields: "Ungültige Felder" @@ -57,7 +69,6 @@ de: manage_aspects: "Aspekte verwalten" publisher: share: "Teilen" - or: "oder" post_a_message_to: "Sende eine Nachricht an %{aspect}" make_public: "öffentlich machen" aspect_friends: @@ -69,6 +80,8 @@ de: invitations_left: '(%{count} übrig)' reshare: reshare: 'Erneut senden an' + author_info: + view_profile: 'View profile' albums: album: you: "Du" @@ -79,17 +92,13 @@ de: edit_album: "Album bearbeiten" albums: "Alben" updated: "aktualisiert" - by: "von" edit: - album_name: "Album Name" + album_name: "Name des Albums" editing: "Bearbeiten" updated: "aktualisiert" update_album: "Album aktualisieren" - are_you_sure: "Bist du sicher?" delete_album: "Album löschen" - cancel: "Abbrechen" index: - home: "Start" new_album: "Neues Album" create: success: "Du hast das Album %{name} erstellt." @@ -141,19 +150,11 @@ de: edit: editing_profile: "Profil bearbeiten" invite_friends: "Feunde einladen" - are_you_sure: "Bist du sicher?" export_data: "Konto exportieren" close_account: "Konto schließen" change_language: "Sprache ändern" change_password: "Passwort ändern" new_password: "Neues Passwort" - password_confirmation: "Passwort bestätigen" - settings: "Einstellungen" - profile: "Profil" - account: "Konto" - services: "Dienste" - cancel: "Abbrechen" - or: "oder" destroy: "Konto erfolgreich geschlossen." getting_started: signup_steps: "Vervollständige deine Registrierung indem du folgende Dinge tust:" @@ -161,10 +162,7 @@ de: albums: "Alben" you_dont_have_any_photos: "Du hast keine Fotos! Gehe zur" page_to_upload_some: "Seite um welche hochzuladen." - or: "oder" comments: - comment: - ago: "her" #FIXME: need something like %{time} ago to translate it to something like Vor %{time} new_comment: comment: "Kommentieren" photos: @@ -174,17 +172,13 @@ de: next: "weiter" edit_photo: "Foto bearbeiten" delete_photo: "Foto löschen" - are_you_sure: "Bist du sicher?" comments: "Kommentare" edit: editing: "Bearbeiten" - are_you_sure: "Bist du sicher?" delete_photo: "Foto löschen" photo: show_comments: "Kommentare zeigen" posted_a_new_photo_to: "Hinzugefügt:" - delete: "Löschen" - are_you_sure: "Bist du sicher?" new: new_photo: "Neues Foto" back_to_list: "Zurück zu Liste" @@ -204,10 +198,6 @@ de: sign_up_for_diaspora: "Ein Diaspora Konto anlegen" upload_existing_account: "Ein existierendes Konto hochladen" upload: "Hochladen" - username: "Benutzername" - email: "E-Mail" - password: "Passwort" - password_confirmation: "Passwort bestätigen" create: success: "Willkommen bei Diaspora!" invitations: @@ -219,7 +209,6 @@ de: invitation_token_invalid: 'Das Einladungstoken ist ungültig!' updated: 'Dein Passwort wurde erfolgreich gespeichert. Du bist jetzt angemeldet.' new: - email: 'E-Mail' invite_someone_to_join: 'Lade jemanden zu Diaspora ein!' if_they_accept_info: 'Wenn sie akzeptieren findest du sie im Aspekt in den du sie eingeladen hast' to: 'An' @@ -233,13 +222,9 @@ de: oh_yeah: "oh yeah!" status_message: show_comments: "Kommentare zeigen" - delete: "Löschen" - are_you_sure: "Bist du sicher?" - ago: "her" #FIXME: need something like %{time} ago to translate it to something like Vor %{time} show: status_message: "Status Nachricht" comments: "Kommentare" - are_you_sure: "Bist du sicher?" destroy: "Zerstören" view_all: "Alle zeigen" message: "Nachricht" @@ -264,13 +249,11 @@ de: last_seen: "Zuletzt gesehen vor: %{how_long_ago}" #FIXME: appends ago friends_since: "Freunde seit: %{how_long_ago}" save: "speichern" - are_you_sure: "Bist du sicher?" remove_friend: "Freund entfernen" no_posts: "Keine Posts zum anzeigen!" add_friend: "Freund hinzufügen" edit_my_profile: "Mein Profil bearbeiten" edit: - settings: "Einstellungen" info_available_to: "Diese Infos werden für alle verfügbar sein mit denen du bei Diaspora verbunden bist." your_profile: "Dein Profil" your_name: "Dein Name" @@ -281,12 +264,7 @@ de: your_bio: "Deine Info" fill_me_out: "Füll mich aus" your_photo: "Dein Foto" - profile: "Profil" - account: "Konto" - services: "Dienste" - cancel: "Abbrechen" update_profile: "Profil aktualisieren" - home: "Start" diaspora_username: "DIASPORA ADRESSE" info: "Info" picture: "Bild" @@ -294,13 +272,12 @@ de: albums: "Alben" you_dont_have_any_photos: "Du hast keine Fotos! Gehe zur" page_to_upload_some: "Seite um welche hochzuladen." - or: "oder" requests: new_request: add_a_new_friend_to: "Neuen Freund hinzufügen zu" enter_a_diaspora_username: "Gib eine Diaspora Adresse ein:" your_diaspora_username_is: "Deine Diaspora Adresse ist: %{diaspora_handle}" - friends_username: "Freunde's Benutzername" + friends_username: "Diaspora Addresse deines Freundes" create_request: "Anfrage erstellen" destroy: success: "Ihr seit jetzt Freunde." @@ -314,12 +291,6 @@ de: already_friends: "Du bist bereits mit %{destination_url} befreundet!" success: "Eine Freundes-Anfrage wurde an %{destination_url} geschickt." horribly_wrong: "Irgendwas ist furchtbar schief gelaufen." - services: - index: - settings: "Einstellungen" - profile: "Profil" - account: "Konto" - services: "Dienste" # The following is from the rails-i18n project at http://github.com/svenfuchs/rails-i18n From ff21c827e41e242b03e7bf59d0320b45ad610f68 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 2 Nov 2010 12:14:12 -0700 Subject: [PATCH 19/22] Revert "Merge remote branch 'ed0h/336-markdown-for-status-messages'" This reverts commit 2b128d88ec690a1569220ff1a5a5968ff095c850, reversing changes made to 8778bdab3b5dacdff98efb91abf051167ac0644a. --- app/helpers/status_messages_helper.rb | 40 ++------------- spec/helpers/status_messages_helper_spec.rb | 54 --------------------- 2 files changed, 5 insertions(+), 89 deletions(-) diff --git a/app/helpers/status_messages_helper.rb b/app/helpers/status_messages_helper.rb index b999f1a49..2e010715a 100644 --- a/app/helpers/status_messages_helper.rb +++ b/app/helpers/status_messages_helper.rb @@ -18,44 +18,14 @@ module StatusMessagesHelper # next line is important due to XSS! (h is rail's make_html_safe-function) message = h(message).html_safe - - message.gsub!(/\[([^\[]+)\]\(([^ ]+) \"(([^&]|(&[^q])|(&q[^u])|(&qu[^o])|(&quo[^t])|("[^;]))+)\"\)/, '\1') - message.gsub!(/\[([^\[]+)\]\(([^ ]+)\)/, '\1') - - message.gsub!(/( |^)(www\.[^ ]+\.[^ ])/) do |m| - res = "#{$1}http://#{$2}" - res.gsub!(/^(\*|_)$/) { |m| "\\#{$1}" } - res - end - message.gsub!(/( |^)http:\/\/www\.youtube\.com\/watch[^ ]*v=([A-Za-z0-9_]+)(&[^ ]*|)/) do |m| - res = "#{$1}youtube.com::#{$2}" - res.gsub!(/(\*|_)/) { |m| "\\#{$1}" } - res - end - message.gsub!(/(#{$3}} - res.gsub!(/(\*|_)/) { |m| "\\#{$1}" } - res - end - end - - message.gsub!(/([^\\]|^)\*\*(([^*]|([^*]\*[^*]))*[^*\\])\*\*/, '\1\2') - message.gsub!(/([^\\]|^)__(([^_]|([^_]_[^_]))*[^_\\])__/, '\1\2') - message.gsub!(/([^\\]|^)\*([^*]*[^\\])\*/, '\1\2') - message.gsub!(/([^\\]|^)_([^_]*[^\\])_/, '\1\2') - message.gsub!(/([^\\]|^)\*/, '\1') - message.gsub!(/([^\\]|^)_/, '\1') - message.gsub!("\\*", "*") - message.gsub!("\\_", "_") - - while youtube = message.match(/youtube\.com::([A-Za-z0-9_\\]+)/) + message.gsub!(/( |^)(www\.[^ ]+\.[^ ])/, '\1http://\2') + message.gsub!(/( |^)http:\/\/www\.youtube\.com\/watch[^ ]*v=([A-Za-z0-9_]+)(&[^ ]*|)/, '\1youtube.com::\2') + message.gsub!(/(https|http|ftp):\/\/([^ ]+)/, '\2') + + while youtube = message.match(/youtube\.com::([A-Za-z0-9_]+)/) videoid = youtube[1] message.gsub!('youtube.com::'+videoid, 'Youtube: ' + youtube_title(videoid) + '') end - return message end diff --git a/spec/helpers/status_messages_helper_spec.rb b/spec/helpers/status_messages_helper_spec.rb index 61ae88be0..0aee3826a 100644 --- a/spec/helpers/status_messages_helper_spec.rb +++ b/spec/helpers/status_messages_helper_spec.rb @@ -68,59 +68,5 @@ describe StatusMessagesHelper do make_links(url).should == ""+url+"" end - describe "markdown" do - describe "weak emphasis" do - it "should be recognized (1/2)" do - message = "*some text* some text *some text* some text" - make_links(message).should == "some text some text some text some text" - end - - it "should be recognized (2/2)" do - message = "_some text_ some text _some text_ some text" - make_links(message).should == "some text some text some text some text" - end - end - - describe "strong emphasis" do - it "should be recognized (1/2)" do - message = "**some text** some text **some text** some text" - make_links(message).should == "some text some text some text some text" - end - - it "should be recognized (2/2)" do - message = "__some text__ some text __some text__ some text" - make_links(message).should == "some text some text some text some text" - end - end - - describe "imbricated weak and strong emphasis" do - it "should be rendered correctly" do - message = "__this is _some_ text__" - make_links(message).should == "this is some text" - message = "*this is **some** text*" - make_links(message).should == "this is some text" - message = "___some text___" - make_links(message).should == "some text" - end - end - - describe "links" do - it "should be recognized without title attribute" do - message = "[link text](http://someurl.com) [link text](http://someurl.com)" - make_links(message).should == 'link text link text' - end - - it "should be recognized with title attribute" do - message = '[link text](http://someurl.com "some title") [link text](http://someurl.com "some title")' - make_links(message).should == 'link text link text' - end - end - - it "should allow escaping" do - message = '*some text* \\*some text* \\**some text* _some text_ \\_some text_ \\__some text_' - make_links(message).should == "some text *some text *some text some text _some text _some text" - end - end - end From bfcb2a9e18fb5d69b0ff5831368a7565f9351ea1 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 2 Nov 2010 12:37:32 -0700 Subject: [PATCH 20/22] Remove random href --- app/views/layouts/application.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index d98973343..5fc9f3b51 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -43,7 +43,7 @@ %header .container{:style => "position:relative;"} - #diaspora_text{:href => root_path} + #diaspora_text = link_to "DIASPORA", (current_user ? root_path : new_user_session_path) %span.sub_text PREVIEW From 19bbf8ce4d89b3bf5a4de28acde9d79fed292308 Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 2 Nov 2010 12:38:30 -0700 Subject: [PATCH 21/22] IZ MS; fixed post update. Posts which implement the mutable? method now can be updated via receive --- app/models/album.rb | 4 ++ app/models/photo.rb | 4 ++ app/models/post.rb | 4 ++ lib/diaspora/parser.rb | 9 +---- lib/diaspora/user/receiving.rb | 65 +++++++++++++++++++++++--------- spec/models/album_spec.rb | 5 +++ spec/models/photo_spec.rb | 4 ++ spec/models/post_spec.rb | 7 ++++ spec/models/user/receive_spec.rb | 30 +++++++++++++++ 9 files changed, 107 insertions(+), 25 deletions(-) diff --git a/app/models/album.rb b/app/models/album.rb index fbc64b2cf..9be93701c 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -32,6 +32,10 @@ class Album < Post p_photo ? p_photo : self.photos.sort(:created_at.desc).last end + def mutable? + true + end + protected def destroy_photos self.photos.each{|p| p.destroy} diff --git a/app/models/photo.rb b/app/models/photo.rb index bce9d469d..e9790cd9f 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -74,5 +74,9 @@ class Photo < Post def thumb_hash {:thumb_url => url(:thumb_medium), :id => id, :album_id => album_id} end + + def mutable? + true + end end diff --git a/app/models/post.rb b/app/models/post.rb index 298d25b5f..842af2b2e 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -50,6 +50,10 @@ class Post } end + def mutable? + false + end + protected def destroy_comments comments.each{|c| c.destroy} diff --git a/lib/diaspora/parser.rb b/lib/diaspora/parser.rb index acdd27afd..da3344d84 100644 --- a/lib/diaspora/parser.rb +++ b/lib/diaspora/parser.rb @@ -10,14 +10,7 @@ module Diaspora begin new_object = body.name.camelize.constantize.from_xml body.to_s - - if new_object.is_a? Post - existing_object = new_object.class.find_by_id(new_object.id) - existing_object ? (return existing_object) : (return new_object) - end - - new_object - + return new_object rescue NameError => e if e.message.include? 'wrong constant name' Rails.logger.info "Not a real type: #{object.to_s}" diff --git a/lib/diaspora/user/receiving.rb b/lib/diaspora/user/receiving.rb index 9e9da020c..b3c6729a7 100644 --- a/lib/diaspora/user/receiving.rb +++ b/lib/diaspora/user/receiving.rb @@ -45,13 +45,13 @@ module Diaspora raise "Not friends with that person" unless self.contact_for(salmon_author) if object.is_a?(Comment) - receive_comment object, xml + receive_comment object elsif object.is_a?(Retraction) - receive_retraction object, xml + receive_retraction object elsif object.is_a?(Profile) receive_profile object, person else - receive_post object, xml + receive_post object end end } @@ -60,7 +60,7 @@ module Diaspora end end - def receive_retraction retraction, xml + def receive_retraction retraction if retraction.type == 'Person' unless retraction.person.id.to_s == retraction.post_id.to_s raise "#{retraction.diaspora_handle} trying to unfriend #{retraction.post_id} from #{self.id}" @@ -91,7 +91,7 @@ module Diaspora person.save end - def receive_comment comment, xml + def receive_comment comment raise "In receive for #{self.real_name}, signature was not valid on: #{comment.inspect}" unless comment.post.person == self.person || comment.verify_post_creator_signature self.visible_people = self.visible_people | [comment.person] self.save @@ -105,20 +105,51 @@ module Diaspora comment.socket_to_uid(id) if (comment.respond_to?(:socket_to_uid) && !self.owns?(comment)) end - def receive_post post, xml - Rails.logger.debug("Saving post: #{post}") - post.user_refs += 1 - post.save + def exsists_on_pod?(post) + post.class.find_by_id(post.id) + end - self.raw_visible_posts << post - self.save + def receive_post post + #exsists locally, but you dont know about it + #does not exsist locally, and you dont know about it + + #exsists_locally? + #you know about it, and it is mutable + #you know about it, and it is not mutable + # + on_pod = exsists_on_pod?(post) + if on_pod + known_post = find_visible_post_by_id(post.id) + if known_post + if known_post.mutable? + known_post.update_attributes(post.to_mongo) + else + Rails.logger.info("#{post.diaspora_handle} is trying to update an immutable object #{known_post.inspect}") + end + elsif on_pod == post + update_user_refs_and_add_to_aspects(on_pod) + end - aspects = self.aspects_with_person(post.person) - aspects.each{ |aspect| - aspect.posts << post - aspect.save - post.socket_to_uid(id, :aspect_ids => [aspect.id]) if (post.respond_to?(:socket_to_uid) && !self.owns?(post)) - } + else + update_user_refs_and_add_to_aspects(post) + end + end + + + def update_user_refs_and_add_to_aspects(post) + Rails.logger.debug("Saving post: #{post}") + post.user_refs += 1 + post.save + + self.raw_visible_posts << post + self.save + + aspects = self.aspects_with_person(post.person) + aspects.each do |aspect| + aspect.posts << post + aspect.save + post.socket_to_uid(id, :aspect_ids => [aspect.id]) if (post.respond_to?(:socket_to_uid) && !self.owns?(post)) + end end end end diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index d8226c2dc..6c3890611 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -23,6 +23,11 @@ describe Album do album.associations[:photos].type.should == :many end + it 'should be mutable' do + post = user.post :album, :name => "hello", :to => aspect.id + post.mutable?.should == true + end + context 'when an album has two attached images' do before do 2.times do diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index f5d07fc55..b048e9c16 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -31,6 +31,10 @@ describe Photo do end end + it 'should be mutable' do + @photo.mutable?.should == true + end + it 'has a constructor' do image = File.open(@fixture_name) photo = Photo.instantiate( diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 587751b0c..e4ca64938 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -29,5 +29,12 @@ describe Post do xml.include?(@user.person.diaspora_handle).should be true end end + + describe '#mutable?' do + it 'should be false by default' do + post = @user.post :status_message, :message => "hello", :to => @aspect.id + post.mutable?.should == false + end + end end diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 7d504f1d3..6f309b6fd 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -41,6 +41,36 @@ describe User do user.aspects.size.should == num_aspects end + context 'update posts' do + let(:status) {user.post(:status_message, :message => "Original", :to => aspect.id)} + let(:album) {user.post(:album, :name => "Original", :to => aspect.id)} + + it 'does not update posts not marked as mutable' do + user2.receive_salmon(user.salmon(status).xml_for(user2.person)) + status.message = 'foo' + xml = user.salmon(status).xml_for(user2.person) + + status.reload.message.should == 'Original' + + user2.receive_salmon(xml) + + status.reload.message.should == 'Original' + end + + it 'updates posts marked as mutable' do + user2.receive_salmon(user.salmon(album).xml_for(user2.person)) + album.name = 'foo' + xml = user.salmon(album).xml_for(user2.person) + + album.reload.name.should == 'Original' + + user2.receive_salmon(xml) + + album.reload.name.should == 'foo' + end + + end + describe 'post refs' do before do @status_message = user2.post :status_message, :message => "hi", :to =>aspect2.id From dc6a01e7e4b3644dd6d1107c8953e4de5b76edf8 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 2 Nov 2010 12:37:32 -0700 Subject: [PATCH 22/22] Remove random href, thanks to Hexagon --- app/views/layouts/application.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index d98973343..5fc9f3b51 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -43,7 +43,7 @@ %header .container{:style => "position:relative;"} - #diaspora_text{:href => root_path} + #diaspora_text = link_to "DIASPORA", (current_user ? root_path : new_user_session_path) %span.sub_text PREVIEW