FEATURE: new badges

- Pay it forward renamed to first like
- First flag
- First share
This commit is contained in:
Sam 2014-07-09 12:17:39 +10:00
parent 0317e503b3
commit e32e96dabb
4 changed files with 69 additions and 9 deletions

View file

@ -7,14 +7,47 @@ class Badge < ActiveRecord::Base
GreatPost = 8 GreatPost = 8
Autobiographer = 9 Autobiographer = 9
Editor = 10 Editor = 10
PayingItForward = 11 FirstLike = 11
FirstShare = 12
FirstFlag = 13
# other consts # other consts
AutobiographerMinBioLength = 10 AutobiographerMinBioLength = 10
module Queries module Queries
PayingItForward = <<SQL
FirstShare = <<SQL
SELECT views.user_id, p2.id post_id, i2.created_at granted_at
FROM
(
SELECT i.user_id, MIN(i.id) i_id
FROM incoming_links i
JOIN topics t on t.id = i.topic_id
JOIN posts p on p.topic_id = t.id AND p.post_number = i.post_number
WHERE i.user_id IS NOT NULL AND
p.deleted_at IS NULL AND
t.deleted_at IS NULL AND
t.visible
GROUP BY i.user_id
) as views
JOIN incoming_links i2 ON i2.id = views.i_id
JOIN posts p2 on p2.topic_id = i2.topic_id AND p2.post_number = i2.post_number
SQL
FirstFlag = <<SQL
SELECT pa.user_id, min(pa.created_at) granted_at
FROM post_actions pa
JOIN posts p on p.id = pa.post_id
JOIN topics t on t.id = p.topic_id
WHERE p.deleted_at IS NULL AND
t.deleted_at IS NULL AND
t.visible AND
post_action_type_id IN (#{PostActionType.flag_types.values.join(",")})
GROUP BY pa.user_id
SQL
FirstLike = <<SQL
SELECT pa.user_id, min(post_id) post_id, min(pa.created_at) granted_at SELECT pa.user_id, min(post_id) post_id, min(pa.created_at) granted_at
FROM post_actions pa FROM post_actions pa
JOIN posts p on p.id = pa.post_id JOIN posts p on p.id = pa.post_id

View file

@ -1976,6 +1976,12 @@ en:
great_post: great_post:
name: Great Post name: Great Post
description: Received 50 likes on a post. This badge can be granted multiple times. description: Received 50 likes on a post. This badge can be granted multiple times.
paying_it_forward: first_like:
name: Paying It Forward name: First Like
description: Liked a post description: Liked a post
first_flag:
name: First Flag
description: Flagged a post
first_share:
name: First Share
description: Shared a post

View file

@ -12,16 +12,37 @@ trust_level_badges.each do |spec|
b.name = spec[:name] b.name = spec[:name]
b.badge_type_id = spec[:type] b.badge_type_id = spec[:type]
b.query = Badge::Queries.trust_level(spec[:id]) b.query = Badge::Queries.trust_level(spec[:id])
# allow title for leader and elder
b.allow_title = spec[:id] > 2
end end
end end
Badge.seed do |b| Badge.seed do |b|
b.id = Badge::PayingItForward b.id = Badge::FirstLike
b.name = "Paying It Forward" b.name = "First Like"
b.badge_type_id = BadgeType::Bronze b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false b.multiple_grant = false
b.target_posts = true b.target_posts = true
b.query = Badge::Queries::PayingItForward b.query = Badge::Queries::FirstLike
end
Badge.seed do |b|
b.id = Badge::FirstFlag
b.name = "First Flag"
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = false
b.query = Badge::Queries::FirstFlag
end
Badge.seed do |b|
b.id = Badge::FirstShare
b.name = "First Share"
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.query = Badge::Queries::FirstShare
end end
Badge.seed do |b| Badge.seed do |b|

View file

@ -20,7 +20,7 @@ describe BadgeGranter do
UserBadge.destroy_all UserBadge.destroy_all
BadgeGranter.backfill(Badge.find(Badge::Welcome)) BadgeGranter.backfill(Badge.find(Badge::Welcome))
BadgeGranter.backfill(Badge.find(Badge::PayingItForward)) BadgeGranter.backfill(Badge.find(Badge::FirstLike))
b = UserBadge.find_by(user_id: post.user_id) b = UserBadge.find_by(user_id: post.user_id)
b.post_id.should == post.id b.post_id.should == post.id
@ -28,7 +28,7 @@ describe BadgeGranter do
b = UserBadge.find_by(user_id: user2.id) b = UserBadge.find_by(user_id: user2.id)
b.post_id.should == post.id b.post_id.should == post.id
b.badge_id = Badge::PayingItForward b.badge_id = Badge::FirstLike
end end
it 'should grant missing badges' do it 'should grant missing badges' do