diff --git a/app/models/badge.rb b/app/models/badge.rb index 41a2d7922af..96c577f47d7 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -21,6 +21,10 @@ class Badge < ActiveRecord::Base GreatShare = 23 OneYearAnniversary = 24 + Promoter = 25 + Campaigner = 26 + Champion = 27 + # other consts AutobiographerMinBioLength = 10 @@ -189,6 +193,22 @@ SQL HAVING COUNT(p.id) > 0 SQL + def self.invite_badge(count,trust_level) +" + SELECT u.id user_id, current_timestamp granted_at + FROM users u + WHERE u.id IN ( + SELECT invited_by_id + FROM invites i + JOIN users u2 ON u2.id = i.user_id + WHERE i.deleted_at IS NULL AND u2.active AND u2.trust_level >= #{trust_level.to_i} AND not u2.blocked + GROUP BY invited_by_id + HAVING COUNT(*) > #{count.to_i} + ) AND u.active AND NOT u.blocked AND u.id > 0 AND + (:backfill OR u.id IN (:user_ids) ) +" + end + def self.like_badge(count, is_topic) # we can do better with dates, but its hard work " diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 12c2dd5d186..7300d658b75 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -2521,6 +2521,15 @@ en: first_flag: name: First Flag description: Flagged a post + promoter: + name: Promoter + description: Invited a user + campaigner: + name: Campaigner + description: Invited 3 members + champion: + name: Champion + description: Invited 10 members first_share: name: First Share description: Shared a post diff --git a/db/fixtures/006_badges.rb b/db/fixtures/006_badges.rb index 93d11a65f49..e169cfd9dc9 100644 --- a/db/fixtures/006_badges.rb +++ b/db/fixtures/006_badges.rb @@ -140,6 +140,29 @@ Badge.seed do |b| b.system = true end + +[ + [Badge::Promoter,"Promoter",BadgeType::Bronze,1,0], + [Badge::Campaigner,"Campaigner",BadgeType::Silver,3,2], + [Badge::Champion,"Champion",BadgeType::Gold,10,2], +].each do |id, name, type, count, trust_level| + Badge.seed do |b| + b.id = id + b.default_name = name + b.default_icon = "fa-user-plus" + b.badge_type_id = type + b.multiple_grant = false + b.target_posts = false + b.show_posts = false + b.query = Badge::Queries.invite_badge(count,trust_level) + b.default_badge_grouping_id = BadgeGrouping::Community + # daily is good enough + b.trigger = Badge::Trigger::None + b.auto_revoke = true + b.system = true + end +end + Badge.seed do |b| b.id = Badge::FirstShare b.default_name = "First Share"