mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 03:06:53 +08:00
FIX: Do not award badges for links in restricted categories. (#6492)
This commit is contained in:
@ -189,8 +189,7 @@ SQL
|
|||||||
<<-SQL
|
<<-SQL
|
||||||
SELECT tl.user_id, post_id, current_timestamp granted_at
|
SELECT tl.user_id, post_id, current_timestamp granted_at
|
||||||
FROM topic_links tl
|
FROM topic_links tl
|
||||||
JOIN posts p ON p.id = post_id AND p.deleted_at IS NULL
|
JOIN badge_posts p ON p.id = post_id
|
||||||
JOIN topics t ON t.id = p.topic_id AND t.deleted_at IS NULL AND t.archetype <> 'private_message'
|
|
||||||
WHERE NOT tl.internal
|
WHERE NOT tl.internal
|
||||||
AND tl.clicks >= #{count}
|
AND tl.clicks >= #{count}
|
||||||
GROUP BY tl.user_id, tl.post_id
|
GROUP BY tl.user_id, tl.post_id
|
||||||
|
@ -97,4 +97,37 @@ describe Badge do
|
|||||||
expect(Badge.display_name('Not In Translations')).to eq('Not In Translations')
|
expect(Badge.display_name('Not In Translations')).to eq('Not In Translations')
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
Reference in New Issue
Block a user