From 89c1fd5f7f8243b62b1ac11baf73f280fcb7d663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Thu, 20 Sep 2012 17:58:42 +0200 Subject: [PATCH] query the set url only through #pod_uri in the app --- app/helpers/application_helper.rb | 2 +- app/models/photo.rb | 4 +--- app/models/profile.rb | 4 +--- app/models/services/facebook.rb | 2 +- app/models/user.rb | 2 +- app/presenters/o_embed_presenter.rb | 2 +- app/views/layouts/notifier.html.erb | 2 +- app/views/publics/host_meta.erb | 2 +- app/views/shared/_right_sections.html.haml | 2 +- app/views/users/public.atom.builder | 2 +- lib/tasks/db.rake | 2 +- spec/factories.rb | 2 +- spec/lib/configuration/methods_spec.rb | 25 ++++++++++++++++++++++ spec/models/person_spec.rb | 4 +--- spec/models/profile_spec.rb | 2 +- spec/support/user_methods.rb | 2 +- 16 files changed, 40 insertions(+), 21 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d554c5a15..9095dddf4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -21,7 +21,7 @@ module ApplicationHelper end def raw_bookmarklet( height = 250, width = 620) - "javascript:(function(){f='#{AppConfig.environment.url}bookmarklet?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'¬es='+encodeURIComponent(''+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text))+'&v=1&';a=function(){if(!window.open(f+'noui=1&jump=doclose','diasporav1','location=yes,links=no,scrollbars=no,toolbar=no,width=#{width},height=#{height}'))location.href=f+'jump=yes'};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()" + "javascript:(function(){f='#{AppConfig.pod_uri.to_s}bookmarklet?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'¬es='+encodeURIComponent(''+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text))+'&v=1&';a=function(){if(!window.open(f+'noui=1&jump=doclose','diasporav1','location=yes,links=no,scrollbars=no,toolbar=no,width=#{width},height=#{height}'))location.href=f+'jump=yes'};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()" end def magic_bookmarklet_link diff --git a/app/models/photo.rb b/app/models/photo.rb index 5e80ea1ba..ce666b5d1 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -99,9 +99,7 @@ class Photo < ActiveRecord::Base def update_remote_path unless self.unprocessed_image.url.match(/^https?:\/\//) - pod_url = AppConfig.environment.url.get.dup - pod_url.chop! if pod_url[-1,1] == '/' - remote_path = "#{pod_url}#{self.unprocessed_image.url}" + remote_path = "#{AppConfig.pod_uri.to_s.chomp("/")}#{self.unprocessed_image.url}" else remote_path = self.unprocessed_image.url end diff --git a/app/models/profile.rb b/app/models/profile.rb index 331dde95b..5a8073d3b 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -185,8 +185,6 @@ class Profile < ActiveRecord::Base end def absolutify_local_url url - pod_url = AppConfig.environment.url.get - pod_url.chop! if pod_url[-1,1] == '/' - "#{pod_url}#{url}" + "#{AppConfig.pod_uri.to_s.chomp("/")}#{url}" end end diff --git a/app/models/services/facebook.rb b/app/models/services/facebook.rb index 1e23bf61e..39d2b1086 100644 --- a/app/models/services/facebook.rb +++ b/app/models/services/facebook.rb @@ -23,7 +23,7 @@ class Services::Facebook < Service end def create_open_graph_params(post) - {:post => "#{AppConfig.environment.url}#{short_post_path(post)}", :access_token => self.access_token} + {:post => "#{AppConfig.pod_uri.to_s}#{short_post_path(post)}", :access_token => self.access_token} end def create_post_params(post) diff --git a/app/models/user.rb b/app/models/user.rb index 7677245f6..f37457d07 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -395,7 +395,7 @@ class User < ActiveRecord::Base end def set_person(person) - person.url = AppConfig.environment.url + person.url = AppConfig.pod_uri.to_s person.diaspora_handle = "#{self.username}#{User.diaspora_id_host}" self.person = person end diff --git a/app/presenters/o_embed_presenter.rb b/app/presenters/o_embed_presenter.rb index 73e1cbb35..c8baf4752 100644 --- a/app/presenters/o_embed_presenter.rb +++ b/app/presenters/o_embed_presenter.rb @@ -15,7 +15,7 @@ class OEmbedPresenter def as_json(opts={}) { :provider_name => "Diaspora", - :provider_url => AppConfig.environment.url, + :provider_url => AppConfig.pod_uri.to_s, :type => 'rich', :version => '1.0', :title => post_title, diff --git a/app/views/layouts/notifier.html.erb b/app/views/layouts/notifier.html.erb index a55c90bd3..ddc0a59f6 100644 --- a/app/views/layouts/notifier.html.erb +++ b/app/views/layouts/notifier.html.erb @@ -28,7 +28,7 @@
- DIASPORA* + DIASPORA*
diff --git a/app/views/publics/host_meta.erb b/app/views/publics/host_meta.erb index 0fcde3b96..f5efcab11 100644 --- a/app/views/publics/host_meta.erb +++ b/app/views/publics/host_meta.erb @@ -5,6 +5,6 @@ + template='<%= AppConfig.pod_uri.to_s %>webfinger?q={uri}' /> diff --git a/app/views/shared/_right_sections.html.haml b/app/views/shared/_right_sections.html.haml index 6a0861c48..565e15dcd 100644 --- a/app/views/shared/_right_sections.html.haml +++ b/app/views/shared/_right_sections.html.haml @@ -74,7 +74,7 @@ = t('aspects.index.donate') .content - if AppConfig.settings.paypal_hosted_button_id.present? - = t('aspects.index.keep_pod_running', :pod => URI.parse(AppConfig.environment.url).host) + = t('aspects.index.keep_pod_running', :pod => AppConfig.pod_uri.host) %br = render 'shared/donatepod' - else diff --git a/app/views/users/public.atom.builder b/app/views/users/public.atom.builder index b29ea1140..3c5fb21a7 100644 --- a/app/views/users/public.atom.builder +++ b/app/views/users/public.atom.builder @@ -8,7 +8,7 @@ atom_feed({'xmlns:thr' => 'http://purl.org/syndication/thread/1.0', :id => "#{@user.public_url}.atom", :root_url => "#{@user.public_url}"}) do |feed| - feed.tag! :generator, 'Diaspora', :uri => "#{AppConfig.environment.url}" + feed.tag! :generator, 'Diaspora', :uri => "#{AppConfig.pod_uri.to_s}" feed.title "#{@user.name}'s Public Feed" feed.subtitle "Updates from #{@user.name} on Diaspora" feed.logo "#{@user.image_url(:thumb_small)}" diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index f87ecfae6..d91a6123b 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -70,7 +70,7 @@ namespace :db do require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment') Person.where(:url => 'example.org').all.each{|person| if person.owner - person.url = AppConfig.environment.url + person.url = AppConfig.pod_uri.to_s person.diaspora_handle = person.owner.diaspora_handle person.save end diff --git a/spec/factories.rb b/spec/factories.rb index 5062653cb..d814ae7aa 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -28,7 +28,7 @@ FactoryGirl.define do factory :person do sequence(:diaspora_handle) { |n| "bob-person-#{n}#{r_str}@example.net" } - sequence(:url) { |n| AppConfig.environment.url.get } + url AppConfig.pod_uri.to_s serialized_public_key OpenSSL::PKey::RSA.generate(1024).public_key.export after(:build) do |person| person.profile = FactoryGirl.build(:profile, :person => person) unless person.profile.first_name.present? diff --git a/spec/lib/configuration/methods_spec.rb b/spec/lib/configuration/methods_spec.rb index 352664d42..1ec0b7520 100644 --- a/spec/lib/configuration/methods_spec.rb +++ b/spec/lib/configuration/methods_spec.rb @@ -10,11 +10,36 @@ describe Configuration::Methods do end describe "#pod_uri" do + before do + @settings.environment.url = nil + @settings.instance_variable_set(:@pod_uri, nil) + end + it "properly parses the pod url" do @settings.environment.url = "http://example.org/" @settings.pod_uri.scheme.should == "http" @settings.pod_uri.host.should == "example.org" end + + it "adds a trailing slash if there isn't one" do + @settings.environment.url = "http://example.org" + @settings.pod_uri.to_s.should == "http://example.org/" + end + + it "does not add an extra trailing slash" do + @settings.environment.url = "http://example.org/" + @settings.pod_uri.to_s.should == "http://example.org/" + end + + it "adds http:// on the front if it's missing" do + @settings.environment.url = "example.org/" + @settings.pod_uri.to_s.should == "http://example.org/" + end + + it "does not add a prefix if there already is https:// on the front" do + @settings.environment.url = "https://example.org/" + @settings.pod_uri.to_s.should == "https://example.org/" + end end describe "#bare_pod_uri" do diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 7ce861cb3..c5104ae54 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -132,11 +132,9 @@ describe Person do end it 'does not include www if it is set in app config' do - old_url = AppConfig.environment.url.get - AppConfig.environment.url = 'https://www.foobar.com/' + AppConfig.stub(:pod_uri).and_return(Addressable::URI.parse('https://www.foobar.com/')) new_person = User.build(:username => "foo123", :email => "foo123@example.com", :password => "password", :password_confirmation => "password").person new_person.diaspora_handle.should == "foo123@foobar.com" - AppConfig.environment.url = old_url end end diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index fabc6815f..4d152589d 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -116,7 +116,7 @@ describe Profile do before do @profile = FactoryGirl.build(:profile) @profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg" - @pod_url = (AppConfig.environment.url.get[-1,1] == '/' ? AppConfig.environment.url.chop : AppConfig.environment.url) + @pod_url = AppConfig.pod_uri.to_s.chomp("/") end it 'ignores an empty string' do diff --git a/spec/support/user_methods.rb b/spec/support/user_methods.rb index e2a7038cd..6d167f342 100644 --- a/spec/support/user_methods.rb +++ b/spec/support/user_methods.rb @@ -1,7 +1,7 @@ class User include Rails.application.routes.url_helpers def default_url_options - {:host => AppConfig.environment.url} + {:host => AppConfig.pod_uri.host} end alias_method :share_with_original, :share_with