FEATURE: Reader badge

Read a every post in a topic that if 50 posts or longer
This commit is contained in:
Sam 2014-07-15 15:16:41 +10:00
parent 1b03feacf8
commit 4c25fedf70
5 changed files with 37 additions and 1 deletions

View File

@ -13,6 +13,7 @@ class Badge < ActiveRecord::Base
FirstLink = 14
FirstQuote = 15
ReadFaq = 16
Reader = 17
# other consts
AutobiographerMinBioLength = 10
@ -20,6 +21,23 @@ class Badge < ActiveRecord::Base
module Queries
Reader = <<SQL
SELECT id user_id, current_timestamp granted_at
FROM users
WHERE id IN
(
SELECT pt.user_id
FROM post_timings pt
JOIN badge_posts b ON b.post_number = pt.post_number AND
b.topic_id = pt.topic_id
JOIN topics t ON t.id = pt.topic_id
LEFT JOIN user_badges ub ON ub.badge_id = 17 AND ub.user_id = pt.user_id
WHERE ub.id IS NULL AND t.posts_count > 50
GROUP BY pt.user_id, pt.topic_id, t.posts_count
HAVING count(*) = t.posts_count
)
SQL
ReadFaq = <<SQL
SELECT user_id, read_faq granted_at
FROM user_stats

View File

@ -77,7 +77,7 @@ class BadgeGranter
WHERE ub.badge_id = :id AND q.user_id IS NULL
)"
Badge.exec_sql(sql, id: badge.id)
Badge.exec_sql(sql, id: badge.id) if badge.auto_revoke
sql = "INSERT INTO user_badges(badge_id, user_id, granted_at, granted_by_id, post_id)
SELECT :id, q.user_id, q.granted_at, -1, #{post_id_field}

View File

@ -2003,3 +2003,6 @@ en:
read_faq:
name: Read Faq
description: Read the community guidelines
reader:
name: Reader
description: Read every post in a topic with more than 50 posts

View File

@ -18,6 +18,16 @@ trust_level_badges.each do |spec|
end
end
Badge.seed do |b|
b.id = Badge::Reader
b.name = "Reader"
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = false
b.query = Badge::Queries::Reader
b.auto_revoke = false
end
Badge.seed do |b|
b.id = Badge::ReadFaq
b.name = "Read Faq"

View File

@ -0,0 +1,5 @@
class AddAutoRevokeToBadges < ActiveRecord::Migration
def change
add_column :badges, :auto_revoke, :boolean, default: true, null: false
end
end