Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Leamas <leamas.alec@gmail.com>2010-12-10 14:54:02 +0300
committerAlec Leamas <leamas.elac@nospam.net>2010-12-10 16:29:19 +0300
commiteacee54846818bb159302aababcc0e89af58bb55 (patch)
tree4a49e176d58f13aeeee0666b2070a19eb4abb898
parent416a36ea9a035dc5cf897ad471eb26fb6b518405 (diff)
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.
-rw-r--r--app/mailers/notifier.rb12
-rw-r--r--app/models/user.rb4
-rw-r--r--app/views/devise/sessions/new.haml8
-rw-r--r--app/views/devise/sessions/new.mobile.haml4
-rw-r--r--app/views/publics/host_meta.erb4
-rw-r--r--config/initializers/_load_app_config.rb23
-rw-r--r--config/initializers/mailer_config.rb2
-rw-r--r--spec/config/config_spec.rb2
-rw-r--r--spec/models/person_spec.rb4
9 files changed, 38 insertions, 25 deletions
diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb
index 525feb412..c836fb581 100644
--- a/app/mailers/notifier.rb
+++ b/app/mailers/notifier.rb
@@ -1,7 +1,7 @@
class Notifier < ActionMailer::Base
-
+
default :from => APP_CONFIG[:smtp_sender_address]
-
+
ATTACHMENT = File.read("#{Rails.root}/public/images/diaspora_white_on_grey.png")
def self.admin(string, recipients, opts = {})
@@ -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)
@@ -40,10 +40,10 @@ class Notifier < ActionMailer::Base
log_mail(recipient_id, sender_id, 'request_accepted')
- attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT
+ 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
diff --git a/app/models/user.rb b/app/models/user.rb
index d992fc0eb..c09d9ef3b 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -357,13 +357,13 @@ 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]
self.serialized_private_key ||= User.generate_key
self.person.serialized_public_key = OpenSSL::PKey::RSA.new(self.serialized_private_key).public_key
-
+
self
end
diff --git a/app/views/devise/sessions/new.haml b/app/views/devise/sessions/new.haml
index 7ef5c2f10..52849eb66 100644
--- a/app/views/devise/sessions/new.haml
+++ b/app/views/devise/sessions/new.haml
@@ -4,7 +4,7 @@
.span-10.append-1.last
.floating
- %h3
+ %h3
= t('.login')
= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
#user
@@ -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')
@@ -22,7 +22,7 @@
/ = f.check_box :remember_me
/ = f.label :remember_me , t('.remember_me')
= f.submit t('.sign_in')
-
+
%p
= render :partial => "devise/shared/links"
%p
@@ -39,5 +39,5 @@
%span.brandon DIASPORA*
= t('.modern_browsers')
= image_tag('modern_browsers.png')
-
+
diff --git a/app/views/devise/sessions/new.mobile.haml b/app/views/devise/sessions/new.mobile.haml
index 41fb9038a..486372005 100644
--- a/app/views/devise/sessions/new.mobile.haml
+++ b/app/views/devise/sessions/new.mobile.haml
@@ -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')
@@ -26,4 +26,4 @@
= t('.alpha_software')
%h3
- = t('.bugs_and_feedback_mobile') \ No newline at end of file
+ = t('.bugs_and_feedback_mobile')
diff --git a/app/views/publics/host_meta.erb b/app/views/publics/host_meta.erb
index 8ad35f36f..e8e1d59d3 100644
--- a/app/views/publics/host_meta.erb
+++ b/app/views/publics/host_meta.erb
@@ -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>
diff --git a/config/initializers/_load_app_config.rb b/config/initializers/_load_app_config.rb
index 33897ab69..8b4eda713 100644
--- a/config/initializers/_load_app_config.rb
+++ b/config/initializers/_load_app_config.rb
@@ -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
diff --git a/config/initializers/mailer_config.rb b/config/initializers/mailer_config.rb
index 25cd82ce5..c91a99f3d 100644
--- a/config/initializers/mailer_config.rb
+++ b/config/initializers/mailer_config.rb
@@ -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"
diff --git a/spec/config/config_spec.rb b/spec/config/config_spec.rb
index de5c1f755..b84758a07 100644
--- a/spec/config/config_spec.rb
+++ b/spec/config/config_spec.rb
@@ -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
diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb
index 841cbed70..9f422055a 100644
--- a/spec/models/person_spec.rb
+++ b/spec/models/person_spec.rb
@@ -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