mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Reader badge
Read a every post in a topic that if 50 posts or longer
This commit is contained in:
parent
1b03feacf8
commit
4c25fedf70
@ -13,6 +13,7 @@ class Badge < ActiveRecord::Base
|
|||||||
FirstLink = 14
|
FirstLink = 14
|
||||||
FirstQuote = 15
|
FirstQuote = 15
|
||||||
ReadFaq = 16
|
ReadFaq = 16
|
||||||
|
Reader = 17
|
||||||
|
|
||||||
# other consts
|
# other consts
|
||||||
AutobiographerMinBioLength = 10
|
AutobiographerMinBioLength = 10
|
||||||
@ -20,6 +21,23 @@ class Badge < ActiveRecord::Base
|
|||||||
|
|
||||||
module Queries
|
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
|
ReadFaq = <<SQL
|
||||||
SELECT user_id, read_faq granted_at
|
SELECT user_id, read_faq granted_at
|
||||||
FROM user_stats
|
FROM user_stats
|
||||||
|
@ -77,7 +77,7 @@ class BadgeGranter
|
|||||||
WHERE ub.badge_id = :id AND q.user_id IS NULL
|
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)
|
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}
|
SELECT :id, q.user_id, q.granted_at, -1, #{post_id_field}
|
||||||
|
@ -2003,3 +2003,6 @@ en:
|
|||||||
read_faq:
|
read_faq:
|
||||||
name: Read Faq
|
name: Read Faq
|
||||||
description: Read the community guidelines
|
description: Read the community guidelines
|
||||||
|
reader:
|
||||||
|
name: Reader
|
||||||
|
description: Read every post in a topic with more than 50 posts
|
||||||
|
@ -18,6 +18,16 @@ trust_level_badges.each do |spec|
|
|||||||
end
|
end
|
||||||
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|
|
Badge.seed do |b|
|
||||||
b.id = Badge::ReadFaq
|
b.id = Badge::ReadFaq
|
||||||
b.name = "Read Faq"
|
b.name = "Read Faq"
|
||||||
|
5
db/migrate/20140715051412_add_auto_revoke_to_badges.rb
Normal file
5
db/migrate/20140715051412_add_auto_revoke_to_badges.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class AddAutoRevokeToBadges < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :badges, :auto_revoke, :boolean, default: true, null: false
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user