From b09e76a0ceae15d44312c8d35b6686bc55c0bd37 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Tue, 17 Jan 2012 17:34:42 -0800 Subject: [PATCH] introduce base_pod_uri, so we can support domains that use www and [bare] with webfinger --- app/helpers/application_helper.rb | 4 ++++ app/models/app_config.rb | 4 ++++ app/models/user.rb | 8 ++++++-- app/views/invitations/edit.html.haml | 2 +- app/views/publics/host_meta.erb | 2 +- app/views/registrations/new.html.haml | 2 +- app/views/registrations/new.mobile.haml | 2 +- spec/factories.rb | 2 +- spec/models/app_config_spec.rb | 8 ++++++++ spec/models/person_spec.rb | 8 ++++++++ spec/models/user_spec.rb | 2 +- 11 files changed, 36 insertions(+), 8 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 21752935c..d0f12da91 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -32,6 +32,10 @@ module ApplicationHelper without_close_html + link_to(image_tag('deletelabel.png'), "#", :class => 'close') end + def diaspora_id_host + User.diaspora_id_host + end + def jquery_include_tag javascript_include_tag('//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js') + content_tag(:script) do diff --git a/app/models/app_config.rb b/app/models/app_config.rb index 12e266bac..40866429a 100644 --- a/app/models/app_config.rb +++ b/app/models/app_config.rb @@ -103,6 +103,10 @@ HELP end end + def self.bare_pod_uri + self[:pod_uri].authority.gsub('www.', '') + end + def self.normalize_admins self[:admins] ||= [] self[:admins].collect! { |username| username.downcase } diff --git a/app/models/user.rb b/app/models/user.rb index 7c91f29bd..49e681187 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -377,10 +377,14 @@ class User < ActiveRecord::Base def set_person(person) person.url = AppConfig[:pod_url] - person.diaspora_handle = "#{self.username}@#{AppConfig[:pod_uri].authority}" + person.diaspora_handle = "#{self.username}#{User.diaspora_id_host}" self.person = person end + def self.diaspora_id_host + "@#{AppConfig.bare_pod_uri}" + end + def seed_aspects self.aspects.create(:name => I18n.t('aspects.seed.family')) self.aspects.create(:name => I18n.t('aspects.seed.friends')) @@ -476,7 +480,7 @@ class User < ActiveRecord::Base end def no_person_with_same_username - diaspora_id = "#{self.username}@#{AppConfig[:pod_uri].host}" + diaspora_id = "#{self.username}#{User.diaspora_id_host}" if self.username_changed? && Person.exists?(:diaspora_handle => diaspora_id) errors[:base] << 'That username has already been taken' end diff --git a/app/views/invitations/edit.html.haml b/app/views/invitations/edit.html.haml index ca4047ff3..e208b613f 100644 --- a/app/views/invitations/edit.html.haml +++ b/app/views/invitations/edit.html.haml @@ -27,7 +27,7 @@ = t('username') = f.text_field :username, :title => t('registrations.new.enter_username') %span.host_uri - = "@#{AppConfig[:pod_uri].host}" + = diaspora_id_host .clearfix %b = t('email') diff --git a/app/views/publics/host_meta.erb b/app/views/publics/host_meta.erb index fa8cd9879..bc7b16d4c 100644 --- a/app/views/publics/host_meta.erb +++ b/app/views/publics/host_meta.erb @@ -1,7 +1,7 @@ - <%= AppConfig[:pod_uri].authority %> + <%= AppConfig[:pod_bare_domain] %> Resource Descriptor diff --git a/app/views/registrations/new.html.haml b/app/views/registrations/new.html.haml index 012aa79be..b4a27188e 100644 --- a/app/views/registrations/new.html.haml +++ b/app/views/registrations/new.html.haml @@ -28,7 +28,7 @@ = t('username') = f.text_field :username, :title => t('registrations.new.enter_username') %span.host_uri - = "@#{AppConfig[:pod_uri].host}" + = diaspora_id_host .clearfix %b = t('email') diff --git a/app/views/registrations/new.mobile.haml b/app/views/registrations/new.mobile.haml index 17f0d5f5a..60b23c1f4 100644 --- a/app/views/registrations/new.mobile.haml +++ b/app/views/registrations/new.mobile.haml @@ -16,7 +16,7 @@ .centered = f.text_field :username %span.host_uri - = "@#{AppConfig[:pod_uri].host}" + = diaspora_id_host .row .row = f.label :email, t('email') diff --git a/spec/factories.rb b/spec/factories.rb index 284d1e67a..1a64e2b1c 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -66,7 +66,7 @@ Factory.define :user do |u| user.person = Factory.build(:person, :profile => Factory.build(:profile), :owner_id => user.id, :serialized_public_key => user.encryption_key.public_key.export, - :diaspora_handle => "#{user.username}@#{AppConfig[:pod_url].gsub(/(https?:|www\.)\/\//, '').chop!}") + :diaspora_handle => "#{user.username}#{User.diaspora_id_host}") end u.after_create do |user| user.person.save diff --git a/spec/models/app_config_spec.rb b/spec/models/app_config_spec.rb index 7ba7180ba..56e03df95 100644 --- a/spec/models/app_config_spec.rb +++ b/spec/models/app_config_spec.rb @@ -142,6 +142,14 @@ describe AppConfig do AppConfig.normalize_pod_url AppConfig[:pod_url].should == "https://example.org/" end + + end + + describe '.bare_pod_uri' do + it 'is AppConfig[:pod_uri].authority stripping www.' do + AppConfig[:pod_url] = "https://www.example.org/" + AppConfig.bare_pod_uri.should == 'example.org' + end end describe ".pod_uri" do diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index f37f80c51..dc3c835b8 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -132,6 +132,14 @@ describe Person do new_person = User.build(:username => "foo123", :email => "foo123@example.com", :password => "password", :password_confirmation => "password").person new_person.diaspora_handle.should == "foo123@#{AppConfig[:pod_uri].authority}" end + + it 'does not include www if it is set in app config' do + old_url = AppConfig[:pod_url] + AppConfig[:pod_url] = '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[:pod_url] = old_url + end end context 'remote people' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index c2b513d19..a18974173 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -111,7 +111,7 @@ describe User do end it 'requires uniqueness also amount Person objects with diaspora handle' do - p = Factory(:person, :diaspora_handle => "jimmy@#{AppConfig[:pod_uri].host}") + p = Factory(:person, :diaspora_handle => "jimmy#{User.diaspora_id_host}") alice.username = 'jimmy' alice.should_not be_valid