Replace APP_CONFIG[:terse_pod_url] with uri object.

Adds a new APP_CONFIG[:pod_uri] item, an uri object parsed from
pod_url. Replace all occurrences of APP_CONFIG[:terse_pod_url] with
APP_CONFIG[:pod_uri].host. Closes http://bugs.joindiaspora.com/issues/684,
using the well-defined semantics of the uri object.

The pod_url is normalized using module URI's functions, always with a
trailing /.

The diaspora-handle will always reflect the pod_url with this patch
i. e., a pod_url like www.dpod.se will give the handle xx@www.dpod.se;
previous code stripped the www. prefix. If this is a problem, it
should be addressed by another setting, since one cannot presume that
www.domain.tld resolves to the same address as domain.tld.
This commit is contained in:
Alec Leamas 2010-12-10 12:54:02 +01:00 committed by Alec Leamas
parent 416a36ea9a
commit eacee54846
9 changed files with 38 additions and 25 deletions

View file

@ -18,7 +18,7 @@ class Notifier < ActionMailer::Base
@string = string.html_safe
attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT
mail(:to => @recipient.email,
:subject => I18n.t('notifier.single_admin.subject'), :host => APP_CONFIG[:terse_pod_url])
:subject => I18n.t('notifier.single_admin.subject'), :host => APP_CONFIG[:pod_uri].host)
end
def new_request(recipient_id, sender_id)
@ -30,7 +30,7 @@ class Notifier < ActionMailer::Base
attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT
mail(:to => "\"#{@receiver.name}\" <#{@receiver.email}>",
:subject => I18n.t('notifier.new_request.subject', :from => @sender.name), :host => APP_CONFIG[:terse_pod_url])
:subject => I18n.t('notifier.new_request.subject', :from => @sender.name), :host => APP_CONFIG[:pod_uri].host)
end
def request_accepted(recipient_id, sender_id, aspect_id)
@ -43,7 +43,7 @@ class Notifier < ActionMailer::Base
attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT
mail(:to => "\"#{@receiver.name}\" <#{@receiver.email}>",
:subject => I18n.t('notifier.request_accepted.subject', :name => @sender.name), :host => APP_CONFIG[:terse_pod_url])
:subject => I18n.t('notifier.request_accepted.subject', :name => @sender.name), :host => APP_CONFIG[:pod_uri].host)
end
private

View file

@ -357,7 +357,7 @@ class User
opts[:person][:profile] ||= Profile.new
self.person = Person.new(opts[:person])
self.person.diaspora_handle = "#{opts[:username]}@#{APP_CONFIG[:terse_pod_url]}"
self.person.diaspora_handle = "#{opts[:username]}@#{APP_CONFIG[:pod_uri].host}"
self.person.url = APP_CONFIG[:pod_url]

View file

@ -12,7 +12,7 @@
= f.label :username , t('username')
= f.text_field :username
%p.user_network
="@#{APP_CONFIG[:terse_pod_url]}"
="@#{APP_CONFIG[:pod_uri].host}/"
%p
= f.label :password , t('password')

View file

@ -11,7 +11,7 @@
= f.label :username , t('username')
= f.text_field :username
%p.user_network
="@#{APP_CONFIG[:terse_pod_url]}"
="@#{APP_CONFIG[:pod_uri].host}/"
%p
= f.label :password , t('password')

View file

@ -1,9 +1,9 @@
<?xml version='1.0' encoding='UTF-8'?>
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'
xmlns:hm='http://host-meta.net/xrd/1.0'>
<hm:Host><%= APP_CONFIG[:terse_pod_url] %></hm:Host>
<hm:Host><%= APP_CONFIG[:pod_uri].host %></hm:Host>
<Link rel='lrdd'
template='<%= APP_CONFIG[:pod_url] %>webfinger?q={uri}'>
template='<%= APP_CONFIG[:pod_uri].host %>/webfinger?q={uri}'>
<Title>Resource Descriptor</Title>
</Link>
</XRD>

View file

@ -1,6 +1,15 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
#
# Sets up APP_CONFIG. Unless stated below, each entry is a the string in
# the file app_config.yml, as applicable for current environment.
#
# Specific items
# * pod_url: As in app_config.yml, normalized with a trailing /.
# * pod_uri: An uri object derived from pod_url.
require 'uri'
def load_config_yaml filename
YAML.load(File.read(filename))
@ -20,10 +29,14 @@ else
APP_CONFIG = all_envs['default'].symbolize_keys
end
APP_CONFIG[:terse_pod_url] = APP_CONFIG[:pod_url].gsub(/(https?:|www\.)\/\//, '')
APP_CONFIG[:terse_pod_url].chop! if APP_CONFIG[:terse_pod_url][-1, 1] == '/'
begin
APP_CONFIG[:pod_uri] = URI.parse( APP_CONFIG[:pod_url])
rescue
puts "WARNING: pod url " + APP_CONFIG[:pod_url] + " is not a legal URI"
end
APP_CONFIG[:pod_url].chop! if APP_CONFIG[:pod_url][-1, 1] == '/'
APP_CONFIG[:pod_url] = APP_CONFIG[:pod_url] + '/'
APP_CONFIG[:pod_url] = APP_CONFIG[:pod_uri].normalize.to_s
puts "WARNING: Please modify your app_config.yml to have a proper pod_url!" if APP_CONFIG[:terse_pod_url] == "example.org" && Rails.env != "test"
if APP_CONFIG[:pod_uri].host == "example.org" && Rails.env != "test"
puts "WARNING: Please modify your app_config.yml to have a proper pod_url!"
end

View file

@ -3,7 +3,7 @@
# the COPYRIGHT file.
Diaspora::Application.configure do
config.action_mailer.default_url_options = {:host => APP_CONFIG[:terse_pod_url]}
config.action_mailer.default_url_options = {:host => APP_CONFIG[:pod_uri].host}
unless Rails.env == 'test' || APP_CONFIG[:mailer_on] != true
config.action_mailer.delivery_method = :smtp
if APP_CONFIG[:smtp_authentication] == "none"

View file

@ -12,6 +12,6 @@ describe 'making sure the config is parsed as should' do
describe 'terse_pod_url'
it 'should be correctly parsed' do
APP_CONFIG[:terse_pod_url].should == 'example.org'
APP_CONFIG[:pod_uri].host.should == 'example.org'
end
end

View file

@ -38,13 +38,13 @@ describe Person do
context 'local people' do
it 'uses the pod config url to set the diaspora_handle' do
new_user = Factory.create(:user)
new_user.person.diaspora_handle.should == new_user.username + "@" + APP_CONFIG[:terse_pod_url]
new_user.person.diaspora_handle.should == new_user.username + "@" + APP_CONFIG[:pod_uri].host
end
end
context 'remote people' do
it 'stores the diaspora_handle in the database' do
@person.diaspora_handle.include?(APP_CONFIG[:terse_pod_url]).should be false
@person.diaspora_handle.include?(APP_CONFIG[:pod_uri].host).should be false
end
end