FEATURE: Add new badges and rename existing badges
This commit is contained in:
parent
d6c8089ca3
commit
882dd61e11
|
@ -27,11 +27,21 @@ en:
|
||||||
|
|
||||||
badges:
|
badges:
|
||||||
solved_1:
|
solved_1:
|
||||||
name: "Helpdesk"
|
name: "Solved!"
|
||||||
description: "First Accepted Answer on a Topic"
|
description: "Have a reply marked as a Solution"
|
||||||
|
long_description: "This badge is granted for having a reply marked as a Solution to a topic. :white_check_mark: Nice job. :+1:"
|
||||||
solved_2:
|
solved_2:
|
||||||
name: "Tech Support"
|
name: "Guidance Counsellor"
|
||||||
description: "10 Accepted answers"
|
description: "Have 10 replies marked as Solutions"
|
||||||
|
long_description: "This badge is granted for having 10 of your replies marked as Solutions to topics. :white_check_mark: You are a true asset to your fellow community members."
|
||||||
|
solved_3:
|
||||||
|
name: "Know-it-All"
|
||||||
|
description: "Have 50 replies marked as Solutions"
|
||||||
|
long_description: "This badge is granted for having 50 of your replies marked as Solutions to topics. :white_check_mark: You really know your stuff. :clap:"
|
||||||
|
solved_4:
|
||||||
|
name: "Solution Institution"
|
||||||
|
description: "Have 150 replies marked as Solutions"
|
||||||
|
long_description: "This badge is granted for having 150 of your replies marked as Solutions to topics. :white_check_mark: Excellent work. :slightly_smiling_face: You are officially a Solution Institution. :brain:"
|
||||||
|
|
||||||
discourse_automation:
|
discourse_automation:
|
||||||
triggerables:
|
triggerables:
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
return unless badge_grouping = BadgeGrouping.find_by(name: "Community")
|
first_solution_query = <<~SQL
|
||||||
|
|
||||||
first_solution_query = <<-SQL
|
|
||||||
SELECT post_id, user_id, created_at AS granted_at
|
SELECT post_id, user_id, created_at AS granted_at
|
||||||
FROM (
|
FROM (
|
||||||
SELECT p.id AS post_id, p.user_id, pcf.created_at,
|
SELECT p.id AS post_id, p.user_id, pcf.created_at,
|
||||||
|
@ -19,9 +17,9 @@ SQL
|
||||||
|
|
||||||
Badge.seed(:name) do |badge|
|
Badge.seed(:name) do |badge|
|
||||||
badge.name = "Solved 1"
|
badge.name = "Solved 1"
|
||||||
badge.icon = "check-square"
|
badge.default_icon = "check-square"
|
||||||
badge.badge_type_id = 3
|
badge.badge_type_id = BadgeType::Bronze
|
||||||
badge.badge_grouping = badge_grouping
|
badge.default_badge_grouping_id = BadgeGrouping::Community
|
||||||
badge.query = first_solution_query
|
badge.query = first_solution_query
|
||||||
badge.listable = true
|
badge.listable = true
|
||||||
badge.target_posts = true
|
badge.target_posts = true
|
||||||
|
@ -32,7 +30,8 @@ Badge.seed(:name) do |badge|
|
||||||
badge.system = true
|
badge.system = true
|
||||||
end
|
end
|
||||||
|
|
||||||
solved_10_query = <<-SQL
|
def solved_query_with_count(min_count)
|
||||||
|
<<~SQL
|
||||||
SELECT p.user_id, MAX(pcf.created_at) AS granted_at
|
SELECT p.user_id, MAX(pcf.created_at) AS granted_at
|
||||||
FROM post_custom_fields pcf
|
FROM post_custom_fields pcf
|
||||||
JOIN badge_posts p ON pcf.post_id = p.id
|
JOIN badge_posts p ON pcf.post_id = p.id
|
||||||
|
@ -41,21 +40,28 @@ solved_10_query = <<-SQL
|
||||||
AND p.user_id <> t.user_id -- ignore topics solved by OP
|
AND p.user_id <> t.user_id -- ignore topics solved by OP
|
||||||
AND (:backfill OR p.id IN (:post_ids))
|
AND (:backfill OR p.id IN (:post_ids))
|
||||||
GROUP BY p.user_id
|
GROUP BY p.user_id
|
||||||
HAVING COUNT(*) >= 10
|
HAVING COUNT(*) >= #{min_count}
|
||||||
SQL
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
Badge.seed(:name) do |badge|
|
[
|
||||||
badge.name = "Solved 2"
|
["Solved 2", BadgeType::Silver, 10],
|
||||||
badge.icon = "check-square"
|
["Solved 3", BadgeType::Gold, 50],
|
||||||
badge.badge_type_id = 2
|
["Solved 4", BadgeType::Gold, 150],
|
||||||
badge.badge_grouping = badge_grouping
|
].each do |name, level, count|
|
||||||
badge.query = solved_10_query
|
Badge.seed(:name) do |badge|
|
||||||
|
badge.name = name
|
||||||
|
badge.default_icon = "check-square"
|
||||||
|
badge.badge_type_id = level
|
||||||
|
badge.default_badge_grouping_id = BadgeGrouping::Community
|
||||||
|
badge.query = solved_query_with_count(count)
|
||||||
badge.listable = true
|
badge.listable = true
|
||||||
badge.allow_title = true
|
badge.default_allow_title = true
|
||||||
badge.target_posts = false
|
badge.target_posts = false
|
||||||
badge.enabled = false
|
badge.enabled = false
|
||||||
badge.trigger = Badge::Trigger::PostRevision
|
badge.trigger = Badge::Trigger::PostRevision
|
||||||
badge.auto_revoke = true
|
badge.auto_revoke = true
|
||||||
badge.show_posts = false
|
badge.show_posts = false
|
||||||
badge.system = true
|
badge.system = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue