UX: show complete URL path if website domain is same as instance domain

This commit is contained in:
Arpit Jalan 2015-08-10 13:37:53 +05:30
parent 7a5fbae060
commit 267d8be1f5
5 changed files with 44 additions and 12 deletions

View File

@ -14,12 +14,6 @@ export default ObjectController.extend(CanCheckEmails, {
collapsedInfo: Em.computed.not('indexStream'), collapsedInfo: Em.computed.not('indexStream'),
websiteName: function() {
var website = this.get('model.website');
if (Em.isEmpty(website)) { return; }
return website.split("/")[2];
}.property('model.website'),
linkWebsite: Em.computed.not('model.isBasic'), linkWebsite: Em.computed.not('model.isBasic'),
removeNoFollow: function() { removeNoFollow: function() {

View File

@ -56,7 +56,7 @@ const User = RestModel.extend({
/** /**
This user's profile background(in CSS). This user's profile background(in CSS).
@property websiteName @property profileBackground
@type {String} @type {String}
**/ **/
profileBackground: function() { profileBackground: function() {

View File

@ -63,12 +63,12 @@
{{/if}} {{/if}}
<h3> <h3>
{{#if model.location}}{{fa-icon "map-marker"}} {{model.location}}{{/if}} {{#if model.location}}{{fa-icon "map-marker"}} {{model.location}}{{/if}}
{{#if websiteName}} {{#if model.website_name}}
{{fa-icon "globe"}} {{fa-icon "globe"}}
{{#if linkWebsite}} {{#if linkWebsite}}
<a href={{model.website}} rel={{unless removeNoFollow 'nofollow'}} target="_blank">{{websiteName}}</a> <a href={{model.website}} rel={{unless removeNoFollow 'nofollow'}} target="_blank">{{model.website_name}}</a>
{{else}} {{else}}
<span title={{model.website}}>{{websiteName}}</span> <span title={{model.website}}>{{model.website_name}}</span>
{{/if}} {{/if}}
{{/if}} {{/if}}
</h3> </h3>

View File

@ -40,6 +40,7 @@ class UserSerializer < BasicUserSerializer
:bio_cooked, :bio_cooked,
:created_at, :created_at,
:website, :website,
:website_name,
:profile_background, :profile_background,
:card_background, :card_background,
:location, :location,
@ -133,6 +134,26 @@ class UserSerializer < BasicUserSerializer
object.user_profile.website object.user_profile.website
end 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
end
def include_website_name
website.present?
end
def card_image_badge_id def card_image_badge_id
object.user_profile.card_image_badge.try(:id) object.user_profile.card_image_badge.try(:id)
end end

View File

@ -66,11 +66,28 @@ describe UserSerializer do
context "with filled out website" do context "with filled out website" do
before do before do
user.user_profile.website = 'http://example.com' user.user_profile.website = 'http://example.com/user'
end end
it "has a website" do it "has a website" do
expect(json[:website]).to eq 'http://example.com' 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'
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'
end
it "returns complete website path when website domain is parent of instance domain" do
Discourse.stubs(:current_hostname).returns('forums.example.com')
expect(json[:website_name]).to eq 'example.com/user'
end
end end
end end