query the set url only through #pod_uri in the app

This commit is contained in:
Jonne Haß 2012-09-20 17:58:42 +02:00
parent 2a4db54db9
commit 89c1fd5f7f
16 changed files with 40 additions and 21 deletions

View file

@ -21,7 +21,7 @@ module ApplicationHelper
end end
def raw_bookmarklet( height = 250, width = 620) def raw_bookmarklet( height = 250, width = 620)
"javascript:(function(){f='#{AppConfig.environment.url}bookmarklet?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'&notes='+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)+'&notes='+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 end
def magic_bookmarklet_link def magic_bookmarklet_link

View file

@ -99,9 +99,7 @@ class Photo < ActiveRecord::Base
def update_remote_path def update_remote_path
unless self.unprocessed_image.url.match(/^https?:\/\//) unless self.unprocessed_image.url.match(/^https?:\/\//)
pod_url = AppConfig.environment.url.get.dup remote_path = "#{AppConfig.pod_uri.to_s.chomp("/")}#{self.unprocessed_image.url}"
pod_url.chop! if pod_url[-1,1] == '/'
remote_path = "#{pod_url}#{self.unprocessed_image.url}"
else else
remote_path = self.unprocessed_image.url remote_path = self.unprocessed_image.url
end end

View file

@ -185,8 +185,6 @@ class Profile < ActiveRecord::Base
end end
def absolutify_local_url url def absolutify_local_url url
pod_url = AppConfig.environment.url.get "#{AppConfig.pod_uri.to_s.chomp("/")}#{url}"
pod_url.chop! if pod_url[-1,1] == '/'
"#{pod_url}#{url}"
end end
end end

View file

@ -23,7 +23,7 @@ class Services::Facebook < Service
end end
def create_open_graph_params(post) 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 end
def create_post_params(post) def create_post_params(post)

View file

@ -395,7 +395,7 @@ class User < ActiveRecord::Base
end end
def set_person(person) 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}" person.diaspora_handle = "#{self.username}#{User.diaspora_id_host}"
self.person = person self.person = person
end end

View file

@ -15,7 +15,7 @@ class OEmbedPresenter
def as_json(opts={}) def as_json(opts={})
{ {
:provider_name => "Diaspora", :provider_name => "Diaspora",
:provider_url => AppConfig.environment.url, :provider_url => AppConfig.pod_uri.to_s,
:type => 'rich', :type => 'rich',
:version => '1.0', :version => '1.0',
:title => post_title, :title => post_title,

View file

@ -28,7 +28,7 @@
<table cellspacing="0" cellpadding="0" border="0" align="center" width="100%" style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:14px;color:#333;"> <table cellspacing="0" cellpadding="0" border="0" align="center" width="100%" style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:14px;color:#333;">
<tr> <tr>
<td style="text-align:center;padding:30px;"> <td style="text-align:center;padding:30px;">
<img src="<%=AppConfig.environment.url %>assets/branding/logo_caps.png" alt="DIASPORA*" width="95px" height="14px"/> <img src="<%=AppConfig.pod_uri.to_s %>assets/branding/logo_caps.png" alt="DIASPORA*" width="95px" height="14px"/>
</td> </td>
</tr> </tr>
</table> </table>

View file

@ -5,6 +5,6 @@
<Link rel='lrdd' <Link rel='lrdd'
type='application/xrd+xml' type='application/xrd+xml'
template='<%= AppConfig.environment.url %>webfinger?q={uri}' /> template='<%= AppConfig.pod_uri.to_s %>webfinger?q={uri}' />
</XRD> </XRD>

View file

@ -74,7 +74,7 @@
= t('aspects.index.donate') = t('aspects.index.donate')
.content .content
- if AppConfig.settings.paypal_hosted_button_id.present? - 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 %br
= render 'shared/donatepod' = render 'shared/donatepod'
- else - else

View file

@ -8,7 +8,7 @@ atom_feed({'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
:id => "#{@user.public_url}.atom", :id => "#{@user.public_url}.atom",
:root_url => "#{@user.public_url}"}) do |feed| :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.title "#{@user.name}'s Public Feed"
feed.subtitle "Updates from #{@user.name} on Diaspora" feed.subtitle "Updates from #{@user.name} on Diaspora"
feed.logo "#{@user.image_url(:thumb_small)}" feed.logo "#{@user.image_url(:thumb_small)}"

View file

@ -70,7 +70,7 @@ namespace :db do
require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment') require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')
Person.where(:url => 'example.org').all.each{|person| Person.where(:url => 'example.org').all.each{|person|
if person.owner if person.owner
person.url = AppConfig.environment.url person.url = AppConfig.pod_uri.to_s
person.diaspora_handle = person.owner.diaspora_handle person.diaspora_handle = person.owner.diaspora_handle
person.save person.save
end end

View file

@ -28,7 +28,7 @@ FactoryGirl.define do
factory :person do factory :person do
sequence(:diaspora_handle) { |n| "bob-person-#{n}#{r_str}@example.net" } 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 serialized_public_key OpenSSL::PKey::RSA.generate(1024).public_key.export
after(:build) do |person| after(:build) do |person|
person.profile = FactoryGirl.build(:profile, :person => person) unless person.profile.first_name.present? person.profile = FactoryGirl.build(:profile, :person => person) unless person.profile.first_name.present?

View file

@ -10,11 +10,36 @@ describe Configuration::Methods do
end end
describe "#pod_uri" do 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 it "properly parses the pod url" do
@settings.environment.url = "http://example.org/" @settings.environment.url = "http://example.org/"
@settings.pod_uri.scheme.should == "http" @settings.pod_uri.scheme.should == "http"
@settings.pod_uri.host.should == "example.org" @settings.pod_uri.host.should == "example.org"
end 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 end
describe "#bare_pod_uri" do describe "#bare_pod_uri" do

View file

@ -132,11 +132,9 @@ describe Person do
end end
it 'does not include www if it is set in app config' do it 'does not include www if it is set in app config' do
old_url = AppConfig.environment.url.get AppConfig.stub(:pod_uri).and_return(Addressable::URI.parse('https://www.foobar.com/'))
AppConfig.environment.url = 'https://www.foobar.com/'
new_person = User.build(:username => "foo123", :email => "foo123@example.com", :password => "password", :password_confirmation => "password").person new_person = User.build(:username => "foo123", :email => "foo123@example.com", :password => "password", :password_confirmation => "password").person
new_person.diaspora_handle.should == "foo123@foobar.com" new_person.diaspora_handle.should == "foo123@foobar.com"
AppConfig.environment.url = old_url
end end
end end

View file

@ -116,7 +116,7 @@ describe Profile do
before do before do
@profile = FactoryGirl.build(:profile) @profile = FactoryGirl.build(:profile)
@profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg" @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 end
it 'ignores an empty string' do it 'ignores an empty string' do

View file

@ -1,7 +1,7 @@
class User class User
include Rails.application.routes.url_helpers include Rails.application.routes.url_helpers
def default_url_options def default_url_options
{:host => AppConfig.environment.url} {:host => AppConfig.pod_uri.host}
end end
alias_method :share_with_original, :share_with alias_method :share_with_original, :share_with