Skip to content

Commit 267d8be

Browse files
committed
UX: show complete URL path if website domain is same as instance domain
1 parent 7a5fbae commit 267d8be

File tree

5 files changed

+44
-12
lines changed

5 files changed

+44
-12
lines changed

app/assets/javascripts/discourse/controllers/user.js.es6

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ export default ObjectController.extend(CanCheckEmails, {
1414

1515
collapsedInfo: Em.computed.not('indexStream'),
1616

17-
websiteName: function() {
18-
var website = this.get('model.website');
19-
if (Em.isEmpty(website)) { return; }
20-
return website.split("/")[2];
21-
}.property('model.website'),
22-
2317
linkWebsite: Em.computed.not('model.isBasic'),
2418

2519
removeNoFollow: function() {

app/assets/javascripts/discourse/models/user.js.es6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const User = RestModel.extend({
5656
/**
5757
This user's profile background(in CSS).
5858
59-
@property websiteName
59+
@property profileBackground
6060
@type {String}
6161
**/
6262
profileBackground: function() {

app/assets/javascripts/discourse/templates/user/user.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@
6363
{{/if}}
6464
<h3>
6565
{{#if model.location}}{{fa-icon "map-marker"}} {{model.location}}{{/if}}
66-
{{#if websiteName}}
66+
{{#if model.website_name}}
6767
{{fa-icon "globe"}}
6868
{{#if linkWebsite}}
69-
<a href={{model.website}} rel={{unless removeNoFollow 'nofollow'}} target="_blank">{{websiteName}}</a>
69+
<a href={{model.website}} rel={{unless removeNoFollow 'nofollow'}} target="_blank">{{model.website_name}}</a>
7070
{{else}}
71-
<span title={{model.website}}>{{websiteName}}</span>
71+
<span title={{model.website}}>{{model.website_name}}</span>
7272
{{/if}}
7373
{{/if}}
7474
</h3>

app/serializers/user_serializer.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def self.untrusted_attributes(*attrs)
4040
:bio_cooked,
4141
:created_at,
4242
:website,
43+
:website_name,
4344
:profile_background,
4445
:card_background,
4546
:location,
@@ -133,6 +134,26 @@ def website
133134
object.user_profile.website
134135
end
135136

137+
def website_name
138+
website_host = URI(website.to_s).host rescue nil
139+
discourse_host = Discourse.current_hostname
140+
return if website_host.nil?
141+
if website_host == discourse_host
142+
# example.com == example.com
143+
website_host + URI(website.to_s).path
144+
elsif (website_host.split('.').length == discourse_host.split('.').length) && discourse_host.split('.').length > 2
145+
# www.example.com == forum.example.com
146+
website_host.split('.')[1..-1].join('.') == discourse_host.split('.')[1..-1].join('.') ? website_host + URI(website.to_s).path : website_host
147+
else
148+
# example.com == forum.example.com
149+
discourse_host.ends_with?("." << website_host) ? website_host + URI(website.to_s).path : website_host
150+
end
151+
end
152+
153+
def include_website_name
154+
website.present?
155+
end
156+
136157
def card_image_badge_id
137158
object.user_profile.card_image_badge.try(:id)
138159
end

spec/serializers/user_serializer_spec.rb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,28 @@
6666

6767
context "with filled out website" do
6868
before do
69-
user.user_profile.website = 'http://example.com'
69+
user.user_profile.website = 'http://example.com/user'
7070
end
7171

7272
it "has a website" do
73-
expect(json[:website]).to eq 'http://example.com'
73+
expect(json[:website]).to eq 'http://example.com/user'
74+
end
75+
76+
context "has a website name" do
77+
it "returns website host name when instance domain is not same as website domain" do
78+
Discourse.stubs(:current_hostname).returns('discourse.org')
79+
expect(json[:website_name]).to eq 'example.com'
80+
end
81+
82+
it "returns complete website path when instance domain is same as website domain" do
83+
Discourse.stubs(:current_hostname).returns('example.com')
84+
expect(json[:website_name]).to eq 'example.com/user'
85+
end
86+
87+
it "returns complete website path when website domain is parent of instance domain" do
88+
Discourse.stubs(:current_hostname).returns('forums.example.com')
89+
expect(json[:website_name]).to eq 'example.com/user'
90+
end
7491
end
7592
end
7693

0 commit comments

Comments
 (0)