mirror of
https://github.com/discourse/discourse.git
synced 2025-03-24 11:25:45 +08:00
parent
95e0aa059c
commit
018cb7f36b
@ -212,6 +212,16 @@ aside.onebox {
|
||||
}
|
||||
}
|
||||
|
||||
&.user-onebox {
|
||||
.fa {
|
||||
margin-right: 5px;
|
||||
}
|
||||
.full-name,
|
||||
.location {
|
||||
margin-right: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3684,3 +3684,5 @@ en:
|
||||
|
||||
search_logs:
|
||||
graph_title: "Search Count"
|
||||
|
||||
joined: "Joined"
|
||||
|
@ -14,7 +14,7 @@ module Onebox
|
||||
|
||||
route = Discourse.route_for(url)
|
||||
|
||||
!!(route[:controller] =~ /topics|uploads/)
|
||||
!!(route[:controller] =~ /topics|uploads|users/)
|
||||
rescue ActionController::RoutingError
|
||||
false
|
||||
end
|
||||
@ -27,6 +27,7 @@ module Onebox
|
||||
case route[:controller]
|
||||
when "uploads" then upload_html(path)
|
||||
when "topics" then topic_html(route)
|
||||
when "users" then user_html(route)
|
||||
end
|
||||
end
|
||||
|
||||
@ -82,6 +83,33 @@ module Onebox
|
||||
end
|
||||
end
|
||||
|
||||
def user_html(route)
|
||||
link = "<a href='#{@url}'>#{@url}</a>"
|
||||
username = route[:username] || ''
|
||||
user = User.find_by(username_lower: username.downcase)
|
||||
|
||||
if user
|
||||
args = {
|
||||
user_id: user.id,
|
||||
username: user.username,
|
||||
avatar: PrettyText.avatar_img(user.avatar_template, "extra_large"),
|
||||
name: user.name,
|
||||
bio: user.user_profile.bio_excerpt(230),
|
||||
location: user.user_profile.location,
|
||||
joined: I18n.t('joined'),
|
||||
created_at: user.created_at.strftime(I18n.t('datetime_formats.formats.date_only')),
|
||||
website: user.user_profile.website,
|
||||
website_name: UserSerializer.new(user).website_name,
|
||||
original_url: @url
|
||||
}
|
||||
|
||||
template = File.read("#{Rails.root}/lib/onebox/templates/discourse_user_onebox.hbs")
|
||||
Mustache.render(template, args)
|
||||
else
|
||||
return link
|
||||
end
|
||||
end
|
||||
|
||||
def can_see_post?(post, source_topic)
|
||||
return false if post.nil? || post.hidden || post.trashed? || post.topic.nil?
|
||||
Guardian.new.can_see_post?(post) || same_category?(post.topic.category, source_topic)
|
||||
|
24
lib/onebox/templates/discourse_user_onebox.hbs
Normal file
24
lib/onebox/templates/discourse_user_onebox.hbs
Normal file
@ -0,0 +1,24 @@
|
||||
<aside class="onebox">
|
||||
<article class="onebox-body user-onebox">
|
||||
{{{avatar}}}
|
||||
<h3><a href="{{original_url}}">{{{username}}}</a></h3>
|
||||
<div>
|
||||
{{#name}}
|
||||
<span class="full-name">{{name}}</span>
|
||||
{{/name}}
|
||||
{{#location}}
|
||||
<span class="location"><i class="fa fa-map-marker d-icon d-icon-map-marker"></i>{{{location}}}</span>
|
||||
{{/location}}
|
||||
{{#website}}
|
||||
<span>
|
||||
<i class="fa fa-globe d-icon d-icon-globe"></i><a href="{{website}}">{{{website_name}}}</a>
|
||||
</span>
|
||||
{{/website}}
|
||||
</div>
|
||||
{{#bio}}
|
||||
<p>{{{bio}}}</p>
|
||||
{{/bio}}
|
||||
<span>{{joined}} {{created_at}}</span>
|
||||
</article>
|
||||
<div style="clear: both"></div>
|
||||
</aside>
|
@ -77,6 +77,23 @@ describe Onebox::Engine::DiscourseLocalOnebox do
|
||||
end
|
||||
end
|
||||
|
||||
context "for a link to a user profile" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
it "returns a link if user isn't found" do
|
||||
url = "#{Discourse.base_url}/u/none"
|
||||
expect(Onebox.preview(url).to_s).to eq(build_link(url))
|
||||
end
|
||||
|
||||
it "returns some onebox goodness if user exists" do
|
||||
html = Onebox.preview("#{Discourse.base_url}/u/#{user.username}").to_s
|
||||
expect(html).to include(user.username)
|
||||
expect(html).to include(user.name)
|
||||
expect(html).to include(user.created_at.strftime("%B %-d, %Y"))
|
||||
expect(html).to include('<aside class="onebox">')
|
||||
end
|
||||
end
|
||||
|
||||
context "for a link to an internal audio or video file" do
|
||||
|
||||
let(:sha) { Digest::SHA1.hexdigest("discourse") }
|
||||
|
Loading…
x
Reference in New Issue
Block a user