mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
UX: Show website path in website name for all domains
Query parameters are still truncated in website name
This commit is contained in:
parent
030fb71f60
commit
c6f6b17f71
2 changed files with 27 additions and 22 deletions
|
@ -144,19 +144,9 @@ class UserSerializer < BasicUserSerializer
|
|||
end
|
||||
|
||||
def website_name
|
||||
website_host = URI(website.to_s).host rescue nil
|
||||
discourse_host = Discourse.current_hostname
|
||||
return if website_host.nil?
|
||||
if website_host == discourse_host
|
||||
# example.com == example.com
|
||||
website_host + URI(website.to_s).path
|
||||
elsif (website_host.split('.').length == discourse_host.split('.').length) && discourse_host.split('.').length > 2
|
||||
# www.example.com == forum.example.com
|
||||
website_host.split('.')[1..-1].join('.') == discourse_host.split('.')[1..-1].join('.') ? website_host + URI(website.to_s).path : website_host
|
||||
else
|
||||
# example.com == forum.example.com
|
||||
discourse_host.ends_with?("." << website_host) ? website_host + URI(website.to_s).path : website_host
|
||||
end
|
||||
uri = URI(website.to_s) rescue nil
|
||||
return if uri.nil? || uri.host.nil?
|
||||
uri.host + uri.path
|
||||
end
|
||||
|
||||
def include_website_name
|
||||
|
|
|
@ -96,22 +96,37 @@ describe UserSerializer do
|
|||
expect(json[:website]).to eq 'http://example.com/user'
|
||||
end
|
||||
|
||||
context "has a website name" do
|
||||
it "returns website host name when instance domain is not same as website domain" do
|
||||
Discourse.stubs(:current_hostname).returns('discourse.org')
|
||||
expect(json[:website_name]).to eq 'example.com'
|
||||
it "returns complete website name with path" do
|
||||
expect(json[:website_name]).to eq 'example.com/user'
|
||||
end
|
||||
|
||||
context "when website includes query parameters" do
|
||||
before do
|
||||
user.user_profile.website = 'http://example.com/user?ref=payme'
|
||||
end
|
||||
|
||||
it "returns complete website path when instance domain is same as website domain" do
|
||||
Discourse.stubs(:current_hostname).returns('example.com')
|
||||
expect(json[:website_name]).to eq 'example.com/user'
|
||||
it "has a website with query params" do
|
||||
expect(json[:website]).to eq 'http://example.com/user?ref=payme'
|
||||
end
|
||||
|
||||
it "returns complete website path when website domain is parent of instance domain" do
|
||||
Discourse.stubs(:current_hostname).returns('forums.example.com')
|
||||
it "has a website name without query params" do
|
||||
expect(json[:website_name]).to eq 'example.com/user'
|
||||
end
|
||||
end
|
||||
|
||||
context "when website is not a valid url" do
|
||||
before do
|
||||
user.user_profile.website = 'invalid-url'
|
||||
end
|
||||
|
||||
it "has a website with the invalid url" do
|
||||
expect(json[:website]).to eq 'invalid-url'
|
||||
end
|
||||
|
||||
it "has a nil website name" do
|
||||
expect(json[:website_name]).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with filled out bio" do
|
||||
|
|
Loading…
Reference in a new issue