FIX: Generate Onebox for posts of type moderator_action. (#6466)

This commit is contained in:
Bianca Nenciu 2018-10-10 13:39:03 +03:00 committed by Régis Hanol
parent 3d8b063c83
commit 4e0533a20b
2 changed files with 15 additions and 5 deletions

View File

@ -26,6 +26,10 @@ module Oneboxer
@force_get_hosts ||= ['http://us.battle.net']
end
def self.allowed_post_types
@allowed_post_types ||= [Post.types[:regular], Post.types[:moderator_action]]
end
def self.preview(url, options = nil)
options ||= {}
invalidate(url) if options[:invalidate_oneboxes]
@ -197,7 +201,7 @@ module Oneboxer
topic.posts.where(post_number: post_number).first :
topic.ordered_posts.first
return if !post || post.hidden || post.post_type != Post.types[:regular]
return if !post || post.hidden || !allowed_post_types.include?(post.post_type)
if post_number > 1 && current_topic&.id == topic.id
excerpt = post.excerpt(SiteSetting.post_onebox_maxlength)

View File

@ -35,10 +35,11 @@ describe Oneboxer do
replier = Fabricate(:user)
public_post = Fabricate(:post, raw: "This post has an emoji :+1:")
public_topic = public_post.topic
public_reply = Fabricate(:post, topic: public_topic, post_number: 2, user: replier)
public_hidden = Fabricate(:post, topic: public_topic, post_number: 3, hidden: true)
public_post = Fabricate(:post, raw: "This post has an emoji :+1:")
public_topic = public_post.topic
public_reply = Fabricate(:post, topic: public_topic, post_number: 2, user: replier)
public_hidden = Fabricate(:post, topic: public_topic, post_number: 3, hidden: true)
public_moderator_action = Fabricate(:post, topic: public_topic, post_number: 4, user: staff, post_type: Post.types[:moderator_action])
user = public_post.user
public_category = public_topic.category
@ -57,6 +58,11 @@ describe Oneboxer do
expect(onebox).to include(%{data-post="2"})
expect(onebox).to include(PrettyText.avatar_img(replier.avatar_template, "tiny"))
onebox = preview(public_moderator_action.url, user, public_category)
expect(onebox).to include(public_moderator_action.excerpt)
expect(onebox).to include(%{data-post="4"})
expect(onebox).to include(PrettyText.avatar_img(staff.avatar_template, "tiny"))
onebox = preview(public_reply.url, user, public_category, public_topic)
expect(onebox).not_to include(public_topic.title)
expect(onebox).to include(replier.avatar_template.sub("{size}", "40"))