FIX: Do not award badges for links in restricted categories. (#6492)

This commit is contained in:
Bianca Nenciu 2018-10-16 02:38:59 +03:00 committed by Sam
parent 2c8c1bf188
commit c68a456baa
2 changed files with 34 additions and 2 deletions

View File

@ -189,8 +189,7 @@ SQL
<<-SQL
SELECT tl.user_id, post_id, current_timestamp granted_at
FROM topic_links tl
JOIN posts p ON p.id = post_id AND p.deleted_at IS NULL
JOIN topics t ON t.id = p.topic_id AND t.deleted_at IS NULL AND t.archetype <> 'private_message'
JOIN badge_posts p ON p.id = post_id
WHERE NOT tl.internal
AND tl.clicks >= #{count}
GROUP BY tl.user_id, tl.post_id

View File

@ -97,4 +97,37 @@ describe Badge do
expect(Badge.display_name('Not In Translations')).to eq('Not In Translations')
end
end
context "PopularLink badge" do
before do
badge = Badge.find(Badge::PopularLink)
badge.query = BadgeQueries.linking_badge(2)
badge.save!
end
it "is awarded" do
post = create_post(raw: "https://www.discourse.org/")
TopicLinkClick.create_from(url: "https://www.discourse.org/", post_id: post.id, topic_id: post.topic.id, ip: "192.168.0.100")
BadgeGranter.backfill(Badge.find(Badge::PopularLink))
expect(UserBadge.where(user_id: post.user.id, badge_id: Badge::PopularLink).count).to eq(0)
TopicLinkClick.create_from(url: "https://www.discourse.org/", post_id: post.id, topic_id: post.topic.id, ip: "192.168.0.101")
BadgeGranter.backfill(Badge.find(Badge::PopularLink))
expect(UserBadge.where(user_id: post.user.id, badge_id: Badge::PopularLink).count).to eq(1)
end
it "is not awarded for links in a restricted category" do
category = Fabricate(:category)
post = create_post(raw: "https://www.discourse.org/", category: category)
category.set_permissions({})
category.save!
TopicLinkClick.create_from(url: "https://www.discourse.org/", post_id: post.id, topic_id: post.topic.id, ip: "192.168.0.100")
TopicLinkClick.create_from(url: "https://www.discourse.org/", post_id: post.id, topic_id: post.topic.id, ip: "192.168.0.101")
BadgeGranter.backfill(Badge.find(Badge::PopularLink))
expect(UserBadge.where(user_id: post.user.id, badge_id: Badge::PopularLink).count).to eq(0)
end
end
end