From 5bcc3acbbb3d9202a1737d233843b16dc7ffa26f Mon Sep 17 00:00:00 2001 From: MrZYX Date: Sat, 26 Feb 2011 13:37:10 +0100 Subject: [PATCH 1/4] save the correct url on redirect in http_multi job; be tolerant about messed up urls in the db --- app/models/jobs/http_multi.rb | 12 +++++++++++- app/models/person.rb | 17 +++++++++++++++-- config/locale_settings.yml | 27 ++++++++------------------- spec/models/jobs/http_multi_spec.rb | 2 +- spec/models/person_spec.rb | 14 ++++++++++++-- 5 files changed, 47 insertions(+), 25 deletions(-) diff --git a/app/models/jobs/http_multi.rb b/app/models/jobs/http_multi.rb index 26359d70e..814645c1e 100644 --- a/app/models/jobs/http_multi.rb +++ b/app/models/jobs/http_multi.rb @@ -1,3 +1,9 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'uri' + module Job class HttpMulti < Base @queue = :http @@ -24,7 +30,11 @@ module Job request.on_complete do |response| if response.code >= 300 && response.code < 400 if response.headers_hash['Location'] == response.request.url.sub('http://', 'https://') - person.url = response.headers_hash['Location'] + location = URI.parse(response.headers_hash['Location']) + newuri = "#{location.scheme}://#{location.host}" + newuri += ":#{location.port}" unless ["80", "443"].include?(location.port.to_s) + newuri += "/" + person.url = newuri person.save end end diff --git a/app/models/person.rb b/app/models/person.rb index 510361a59..3be94302a 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -2,6 +2,7 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. +require 'uri' require File.join(Rails.root, 'lib/hcard') class Person < ActiveRecord::Base @@ -93,13 +94,25 @@ class Person < ActiveRecord::Base def owns?(post) self == post.person end + + def url + begin + uri = URI.parse(@attributes['url']) + url = "#{uri.scheme}://#{uri.host}" + url += ":#{uri.port}" unless ["80", "443"].include?(uri.port.to_s) + url += "/" + rescue Exception => e + url = @attributes['url'] + end + url + end def receive_url - "#{self.url}receive/users/#{self.guid}/" + "#{url}receive/users/#{self.guid}/" end def public_url - "#{self.url}public/#{self.owner.username}" + "#{url}public/#{self.owner.username}" end def public_key_hash diff --git a/config/locale_settings.yml b/config/locale_settings.yml index 63af26001..2bc3842c3 100644 --- a/config/locale_settings.yml +++ b/config/locale_settings.yml @@ -34,22 +34,11 @@ available: tr: 'Türk' zh: '中文' fallbacks: - en-GB: - - :en - en-US: - - :en - en_shaw: - - :en - - :en-GB - - :en-US - sv: - - :sv-SE - he: - - :he-IL - es-CL: - - :es - gl: - - :gl-ES - zh: - - :zh-CN - - :zh-TW + en-GB: [:en] + en-US: [:en] + en_shaw: [:en, :en-GB, :en-US] + sv: [:sv-SE] + he: [:he-IL] + es-CL: [:es] + gl: [:gl-ES] + zh: [:zh-CN, :zh-TW] diff --git a/spec/models/jobs/http_multi_spec.rb b/spec/models/jobs/http_multi_spec.rb index 509c9a800..be04806be 100644 --- a/spec/models/jobs/http_multi_spec.rb +++ b/spec/models/jobs/http_multi_spec.rb @@ -72,6 +72,6 @@ describe Job::HttpMulti do Job::HttpMulti.perform(bob.id, @post_xml, [person.id]) person.reload - person.url.should =~ /https:\/\/remote.net\// + person.url.should == "https://remote.net/" end end diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 319c5eb72..67c53dc35 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -20,11 +20,21 @@ describe Person do end describe "vaild url" do - it 'should allow for https urls' do + it 'should allow for https urls' do person = Factory.create(:person, :url => "https://example.com") person.should be_valid - end end + + it 'should always return the correct receive url' do + person = Factory.create(:person, :url => "https://example.com/a/bit/messed/up") + person.receive_url.should == "https://example.com/receive/users/#{person.guid}/" + end + + it 'should allow ports in the url' do + person = Factory.create(:person, :url => "https://example.com:3000/") + person.url.should == "https://example.com:3000/" + end + end describe '#diaspora_handle' do From b47714f8814c3d20bfbd5dcb0887f980413e618a Mon Sep 17 00:00:00 2001 From: MrZYX Date: Sat, 26 Feb 2011 14:31:54 +0100 Subject: [PATCH 2/4] updated locales --- config/locale_settings.yml | 27 +++++++++---- config/locales/diaspora/da.yml | 70 +++++++++++++++++----------------- config/locales/diaspora/fr.yml | 4 +- config/locales/diaspora/nl.yml | 8 ++-- 4 files changed, 60 insertions(+), 49 deletions(-) diff --git a/config/locale_settings.yml b/config/locale_settings.yml index 2bc3842c3..63af26001 100644 --- a/config/locale_settings.yml +++ b/config/locale_settings.yml @@ -34,11 +34,22 @@ available: tr: 'Türk' zh: '中文' fallbacks: - en-GB: [:en] - en-US: [:en] - en_shaw: [:en, :en-GB, :en-US] - sv: [:sv-SE] - he: [:he-IL] - es-CL: [:es] - gl: [:gl-ES] - zh: [:zh-CN, :zh-TW] + en-GB: + - :en + en-US: + - :en + en_shaw: + - :en + - :en-GB + - :en-US + sv: + - :sv-SE + he: + - :he-IL + es-CL: + - :es + gl: + - :gl-ES + zh: + - :zh-CN + - :zh-TW diff --git a/config/locales/diaspora/da.yml b/config/locales/diaspora/da.yml index 91f75bb9d..70e91e212 100644 --- a/config/locales/diaspora/da.yml +++ b/config/locales/diaspora/da.yml @@ -21,23 +21,23 @@ da: contact: attributes: person_id: - taken: "must be unique among this user's contacts." + taken: "skal være unik for denne brugers kontakter." person: attributes: diaspora_handle: - taken: "is already taken." + taken: "er allerede taget." request: attributes: from_id: - taken: "is a duplicate of a pre-existing request." + taken: "er en kopi af en allerede eksisterende forespørgsel." user: attributes: email: - taken: "is already taken." + taken: "er allerede taget." person: - invalid: "is invalid." + invalid: "er ugyldig." username: - taken: "is already taken." + taken: "er allerede taget." ago: "%{time} siden" application: helper: @@ -49,9 +49,9 @@ da: are_you_sure: "Er du sikker?" aspect_memberships: destroy: - failure: "Failed to remove person from aspect" - no_membership: "Could not find the selected person in that aspect" - success: "Successfully removed person from aspect" + failure: "Kunne ikke fjerne person fra aspekt" + no_membership: "Kunne ikke finde den valgte person i det aspekt" + success: "Personen er fjernet fra aspektet" aspects: add_to_aspect: failure: "Kunne ikke tilføje kontakten til aspektet." @@ -59,9 +59,9 @@ da: aspect_contacts: done_editing: "afslut redigering" aspect_stream: - activity: "activity" - post_time: "post time" - sort_by: "sort by:" + activity: "aktivitet" + post_time: "post tid" + sort_by: "sorter efter:" contacts_not_visible: "Kontakter i dette aspekt vil ikke være i stand til at se hinanden." contacts_visible: "Kontakter i dette aspekt vil være i stand til at se hinanden." create: @@ -121,17 +121,17 @@ da: commenting: "Kommentering ..." contacts: create: - failure: "Failed to create contact" + failure: "Kunne ikke oprette kontakt" destroy: - failure: "Failed to disconnect from %{name}" - success: "Successfully disconnected from %{name}" + failure: "Det lykkedes ikke at afbryde forbindelse til %{name}" + success: "Forbindelse til %{name} er nu afbrudt " few: "%{count} kontaktpersoner" one: "Én kontaktperson" other: "%{count} kontaktpersoner" share_with_pane: - accepts: "Once %{name} accepts, you'll start seeing each other's posts on Diaspora" - add_new_aspect: "add to new aspect" - share_with: "Start sharing with %{name}" + accepts: "Når %{name} acceptere, vil i kunne se hinandens indlæg på Diaspora" + add_new_aspect: "tilføj til nyt aspekt" + share_with: "Begynd at dele med %{name}" zero: "Ingen kontaktpersoner" date: formats: @@ -177,7 +177,7 @@ da: if_they_accept_info: "hvis de accepterer, vil de blive tilføjet til det aspekt du inviterede dem til." invite_someone_to_join: "Invitér en person til Diaspora!" personal_message: "Personlig besked" - resend: "Resend" + resend: "Send igen" send_an_invitation: "Send en invitation" send_invitation: "Send invitation" to: "Til" @@ -208,7 +208,7 @@ da: no_new_notifications: "Ingen nye notifikationer" notifications: also_commented: "kommenterede også på din kontakts" - also_commented_deleted: "commented on a deleted post" + also_commented_deleted: "kommenterede på en slettet post" comment_on_post: "kommenterede et af dine" deleted: "slettet" index: @@ -331,21 +331,21 @@ da: profile: "Profil" profiles: edit: - allow_search: "Allow for people to search for you within Diaspora" - edit_profile: "Edit profile" - first_name: "First name" - info_available_to: "This info will be available to whomever you connect with on Diaspora." - last_name: "Last name" - update_profile: "Update Profile" - your_bio: "Your bio" - your_birthday: "Your birthday" - your_gender: "Your gender" - your_name: "Your name" - your_photo: "Your photo" - your_profile: "Your profile" + allow_search: "Tillad folk at søge på dig indeni Diaspora" + edit_profile: "Rediger profil" + first_name: "Fornavn" + info_available_to: "Denne information vil være tilgenelig for alle du forbinder til på Diaspora." + last_name: "Efternavn" + update_profile: "Opdater profil" + your_bio: "Din bio" + your_birthday: "Din fødselsdag" + your_gender: "Dit køn" + your_name: "Dit navn" + your_photo: "Dit foto" + your_profile: "Din profil" update: - failed: "Failed to update profile" - updated: "Profile updated" + failed: "Kunne ikke opdatere profil" + updated: "Profil opdateret" registrations: closed: "Der er lukket for tilmeldinger på dette Diaspora server." create: @@ -480,7 +480,7 @@ da: your_email: "Din e-mail" your_handle: "Dit diaspora handle" getting_started: - connect_on_diaspora: "Connect on Diaspora" + connect_on_diaspora: "Forbind på Diaspora" connect_services: "Tilslut dine eksisterende tjenester" edit_profile: "Redigér din profil" finished: "Færdig!" diff --git a/config/locales/diaspora/fr.yml b/config/locales/diaspora/fr.yml index b4ab98034..da161d023 100644 --- a/config/locales/diaspora/fr.yml +++ b/config/locales/diaspora/fr.yml @@ -207,7 +207,7 @@ fr: next: "suivant" no_new_notifications: "aucune nouvelle notification" notifications: - also_commented: "a/ont également commenté ce" + also_commented: "a/ont également commenté" also_commented_deleted: "a commenté un message supprimé" comment_on_post: "a/ont commenté votre" deleted: "supprimé" @@ -222,7 +222,7 @@ fr: also_commented: commented: "a également commenté le message de %{post_author} :" sign_in: "Connectez-vous pour le voir." - subject: "%{name} a également commenté sur le message de votre contact." + subject: "%{name} a également commenté le message de votre %{post_author}." comment_on_post: commented: "a commenté votre message:" sign_in: "Connectez-vous pour le voir." diff --git a/config/locales/diaspora/nl.yml b/config/locales/diaspora/nl.yml index 990585590..7903b2432 100644 --- a/config/locales/diaspora/nl.yml +++ b/config/locales/diaspora/nl.yml @@ -207,8 +207,8 @@ nl: next: "volgende" no_new_notifications: "Geen nieuwe notificaties" notifications: - also_commented: "heeft ook gereageerd op jouw contact zijn of haar" - also_commented_deleted: "commented on a deleted post" + also_commented: "heeft ook gereageerd %{post_author}'s" + also_commented_deleted: "reageerde op een verwijderde post" comment_on_post: "reageerde op jouw" deleted: "verwijderde" index: @@ -222,7 +222,7 @@ nl: also_commented: commented: "heeft ook op %{post_author}'s post gereageerd:" sign_in: "Log in om het te zien." - subject: "%{name} heeft ook gereageerd op de post van jou contact." + subject: "%{name} heeft ook gereageerd %{post_author}'s post." comment_on_post: commented: "heeft gereageerd op jou post:" sign_in: "Log in om het te zien." @@ -438,7 +438,7 @@ nl: all: "al" all_contacts: "alle contacten" make_public: "maak openbaar" - mention_helper_text: "om iemand te noemen, druk op '@' en typ zijn of haar naam" + mention_helper_text: "om iemand te noemen, typ '@' gevolgd door zijn of haar naam" post_a_message_to: "Plaats een bericht aan %{aspect}" posting: "Plaatsen..." share: "Delen" From 1adcc4cc99549b26a7ce757de8ddbdc255c53b60 Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Sat, 26 Feb 2011 06:16:34 -0800 Subject: [PATCH 3/4] fix jasmine specs --- spec/javascripts/contact-list-spec.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/spec/javascripts/contact-list-spec.js b/spec/javascripts/contact-list-spec.js index a49ac7636..afeb52a6d 100644 --- a/spec/javascripts/contact-list-spec.js +++ b/spec/javascripts/contact-list-spec.js @@ -7,15 +7,13 @@ describe("Contact List", function() { describe("disconnectUser", function() { it("does an ajax call to person delete with the passed in id", function(){ var id = '3'; - spyOn($,'ajax').andCallThrough(); + spyOn($,'ajax'); List.disconnectUser(id); - expect($.ajax).toHaveBeenCalledWith({ - url: "/contacts/" + id, - type: "DELETE", - success: function(){ - $('.contact_list li[data-guid='+id+']').fadeOut(200); - } - }); + expect($.ajax).toHaveBeenCalled(); + var option_hash = $.ajax.mostRecentCall.args[0]; + expect(option_hash.url).toEqual("/contacts/" + id); + expect(option_hash.type).toEqual("DELETE"); + expect(option_hash.success).toBeDefined(); }); }); }); From 0fc5f1c04395b3c720177cdb0b67d98ee7d840dc Mon Sep 17 00:00:00 2001 From: MrZYX Date: Sat, 26 Feb 2011 16:41:49 +0100 Subject: [PATCH 4/4] log the 'received comment but no corresponding post' case --- lib/postzord/receiver.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/postzord/receiver.rb b/lib/postzord/receiver.rb index db0af10e0..bfc56ab11 100644 --- a/lib/postzord/receiver.rb +++ b/lib/postzord/receiver.rb @@ -70,6 +70,11 @@ module Postzord @object.sender_handle = @sender.diaspora_handle end + # abort if we haven't received the post to a comment + if @object.is_a?(Comment) && @object.post.nil? + Rails.logger.info("event=receive status=abort reason='received a comment but no corresponding post' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type=#{@object.class})") + return false + end if (@author.diaspora_handle != xml_author) Rails.logger.info("event=receive status=abort reason='author in xml does not match retrieved person' payload_type=#{@object.class} recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}")