"Fossies" - the Fresh Open Source Software Archive

Member "discourse-2.8.3/db/fixtures/006_badges.rb" (14 Apr 2022, 12285 Bytes) of package /linux/www/discourse-2.8.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 # frozen_string_literal: true
    2 
    3 require 'badge_queries'
    4 
    5 BadgeGrouping.seed do |g|
    6   g.id = BadgeGrouping::GettingStarted
    7   g.name = "Getting Started"
    8   g.default_position = 10
    9 end
   10 
   11 BadgeGrouping.seed do |g|
   12   g.id = BadgeGrouping::Community
   13   g.name = "Community"
   14   g.default_position = 11
   15 end
   16 
   17 BadgeGrouping.seed do |g|
   18   g.id = BadgeGrouping::Posting
   19   g.name = "Posting"
   20   g.default_position = 12
   21 end
   22 
   23 BadgeGrouping.seed do |g|
   24   g.id = BadgeGrouping::TrustLevel
   25   g.name = "Trust Level"
   26   g.default_position = 13
   27 end
   28 
   29 BadgeGrouping.seed do |g|
   30   g.id = BadgeGrouping::Other
   31   g.name = "Other"
   32   g.default_position = 14
   33 end
   34 
   35 # BUGFIX
   36 DB.exec <<-SQL.squish
   37   UPDATE badges
   38      SET badge_grouping_id = -1
   39    WHERE NOT EXISTS (
   40             SELECT 1
   41               FROM badge_groupings g
   42              WHERE g.id = badge_grouping_id
   43          ) OR (id < 100 AND badge_grouping_id = #{BadgeGrouping::Other})
   44 SQL
   45 
   46 [
   47   [Badge::BasicUser, "Basic User", BadgeType::Bronze],
   48   [Badge::Member,    "Member",     BadgeType::Bronze],
   49   [Badge::Regular,   "Regular",    BadgeType::Silver],
   50   [Badge::Leader,    "Leader",     BadgeType::Gold],
   51 ].each do |id, name, type|
   52   Badge.seed do |b|
   53     b.id = id
   54     b.name = name
   55     b.badge_type_id = type
   56     b.query = BadgeQueries.trust_level(id)
   57     b.default_badge_grouping_id = BadgeGrouping::TrustLevel
   58     b.trigger = Badge::Trigger::TrustLevelChange
   59     # allow title for tl3 and above
   60     b.default_allow_title = id > Badge::Member
   61     b.default_icon = "fa-user"
   62     b.system = true
   63   end
   64 end
   65 
   66 Badge.seed do |b|
   67   b.id = Badge::Reader
   68   b.name = "Reader"
   69   b.badge_type_id = BadgeType::Bronze
   70   b.multiple_grant = false
   71   b.target_posts = false
   72   b.show_posts = false
   73   b.query = BadgeQueries::Reader
   74   b.default_badge_grouping_id = BadgeGrouping::GettingStarted
   75   b.auto_revoke = false
   76   b.system = true
   77 end
   78 
   79 Badge.seed do |b|
   80   b.id = Badge::ReadGuidelines
   81   b.name = "Read Guidelines"
   82   b.badge_type_id = BadgeType::Bronze
   83   b.multiple_grant = false
   84   b.target_posts = false
   85   b.show_posts = false
   86   b.query = BadgeQueries::ReadGuidelines
   87   b.default_badge_grouping_id = BadgeGrouping::GettingStarted
   88   b.trigger = Badge::Trigger::UserChange
   89   b.system = true
   90 end
   91 
   92 Badge.seed do |b|
   93   b.id = Badge::FirstLink
   94   b.name = "First Link"
   95   b.badge_type_id = BadgeType::Bronze
   96   b.multiple_grant = false
   97   b.target_posts = true
   98   b.show_posts = true
   99   b.query = BadgeQueries::FirstLink
  100   b.default_badge_grouping_id = BadgeGrouping::GettingStarted
  101   b.trigger = Badge::Trigger::PostRevision
  102   b.system = true
  103 end
  104 
  105 Badge.seed do |b|
  106   b.id = Badge::FirstQuote
  107   b.name = "First Quote"
  108   b.badge_type_id = BadgeType::Bronze
  109   b.multiple_grant = false
  110   b.target_posts = true
  111   b.show_posts = true
  112   b.query = BadgeQueries::FirstQuote
  113   b.default_badge_grouping_id = BadgeGrouping::GettingStarted
  114   b.trigger = Badge::Trigger::PostRevision
  115   b.system = true
  116 end
  117 
  118 Badge.seed do |b|
  119   b.id = Badge::FirstLike
  120   b.name = "First Like"
  121   b.badge_type_id = BadgeType::Bronze
  122   b.multiple_grant = false
  123   b.target_posts = true
  124   b.show_posts = true
  125   b.query = BadgeQueries::FirstLike
  126   b.default_badge_grouping_id = BadgeGrouping::GettingStarted
  127   b.trigger = Badge::Trigger::PostAction
  128   b.system = true
  129 end
  130 
  131 Badge.seed do |b|
  132   b.id = Badge::FirstFlag
  133   b.name = "First Flag"
  134   b.badge_type_id = BadgeType::Bronze
  135   b.multiple_grant = false
  136   b.target_posts = true
  137   b.show_posts = false
  138   b.query = BadgeQueries::FirstFlag
  139   b.default_badge_grouping_id = BadgeGrouping::GettingStarted
  140   b.trigger = Badge::Trigger::PostAction
  141   b.auto_revoke = false
  142   b.system = true
  143 end
  144 
  145 [
  146   [Badge::Promoter, "Promoter", BadgeType::Bronze, 1, 0],
  147   [Badge::Campaigner, "Campaigner", BadgeType::Silver, 3, 1],
  148   [Badge::Champion, "Champion", BadgeType::Gold, 5, 2],
  149 ].each do |id, name, type, count, trust_level|
  150   Badge.seed do |b|
  151     b.id = id
  152     b.name = name
  153     b.default_icon = "fa-user-plus"
  154     b.badge_type_id = type
  155     b.multiple_grant = false
  156     b.target_posts = false
  157     b.show_posts = false
  158     b.query = BadgeQueries.invite_badge(count, trust_level)
  159     b.default_badge_grouping_id = BadgeGrouping::Community
  160     # daily is good enough
  161     b.trigger = Badge::Trigger::None
  162     b.auto_revoke = true
  163     b.system = true
  164   end
  165 end
  166 
  167 Badge.seed do |b|
  168   b.id = Badge::FirstShare
  169   b.name = "First Share"
  170   b.badge_type_id = BadgeType::Bronze
  171   b.multiple_grant = false
  172   b.target_posts = true
  173   b.show_posts = true
  174   b.query = BadgeQueries::FirstShare
  175   b.default_badge_grouping_id = BadgeGrouping::GettingStarted
  176   # don't trigger for now, its too expensive
  177   b.trigger = Badge::Trigger::None
  178   b.system = true
  179 end
  180 
  181 [
  182  [Badge::NiceShare, "Nice Share", BadgeType::Bronze, 25],
  183  [Badge::GoodShare, "Good Share", BadgeType::Silver, 300],
  184  [Badge::GreatShare, "Great Share", BadgeType::Gold, 1000],
  185 ].each do |id, name, level, count|
  186   Badge.seed do |b|
  187     b.id = id
  188     b.name = name
  189     b.badge_type_id = level
  190     b.multiple_grant = true
  191     b.target_posts = true
  192     b.show_posts = true
  193     b.query = BadgeQueries.sharing_badge(count)
  194     b.default_badge_grouping_id = BadgeGrouping::Community
  195     # don't trigger for now, its too expensive
  196     b.trigger = Badge::Trigger::None
  197     b.system = true
  198   end
  199 end
  200 
  201 Badge.seed do |b|
  202   b.id = Badge::Welcome
  203   b.name = "Welcome"
  204   b.badge_type_id = BadgeType::Bronze
  205   b.multiple_grant = false
  206   b.target_posts = true
  207   b.show_posts = true
  208   b.query = BadgeQueries::Welcome
  209   b.default_badge_grouping_id = BadgeGrouping::Community
  210   b.trigger = Badge::Trigger::PostAction
  211   b.system = true
  212 end
  213 
  214 Badge.seed do |b|
  215   b.id = Badge::Autobiographer
  216   b.name = "Autobiographer"
  217   b.badge_type_id = BadgeType::Bronze
  218   b.multiple_grant = false
  219   b.query = BadgeQueries::Autobiographer
  220   b.default_badge_grouping_id = BadgeGrouping::GettingStarted
  221   b.trigger = Badge::Trigger::UserChange
  222   b.system = true
  223 end
  224 
  225 Badge.seed do |b|
  226   b.id = Badge::Editor
  227   b.name = "Editor"
  228   b.badge_type_id = BadgeType::Bronze
  229   b.multiple_grant = false
  230   b.query = BadgeQueries::Editor
  231   b.default_badge_grouping_id = BadgeGrouping::GettingStarted
  232   b.trigger = Badge::Trigger::PostRevision
  233   b.system = true
  234 end
  235 
  236 Badge.seed do |b|
  237   b.id = Badge::WikiEditor
  238   b.name = "Wiki Editor"
  239   b.badge_type_id = BadgeType::Bronze
  240   b.multiple_grant = false
  241   b.target_posts = true
  242   b.query = BadgeQueries::WikiEditor
  243   b.default_badge_grouping_id = BadgeGrouping::GettingStarted
  244   b.trigger = Badge::Trigger::PostRevision
  245   b.system = true
  246 end
  247 
  248 [
  249   [Badge::NicePost,   "Nice Post",   BadgeType::Bronze, false],
  250   [Badge::GoodPost,   "Good Post",   BadgeType::Silver, false],
  251   [Badge::GreatPost,  "Great Post",  BadgeType::Gold,   false],
  252   [Badge::NiceTopic,  "Nice Topic",  BadgeType::Bronze, true],
  253   [Badge::GoodTopic,  "Good Topic",  BadgeType::Silver, true],
  254   [Badge::GreatTopic, "Great Topic", BadgeType::Gold,   true],
  255 ].each do |id, name, type, topic|
  256   Badge.seed do |b|
  257     b.id = id
  258     b.name = name
  259     b.badge_type_id = type
  260     b.multiple_grant = true
  261     b.target_posts = true
  262     b.show_posts = true
  263     b.query = BadgeQueries.like_badge(Badge.like_badge_counts[id], topic)
  264     b.default_badge_grouping_id = BadgeGrouping::Posting
  265     b.trigger = Badge::Trigger::PostAction
  266     b.system = true
  267   end
  268 end
  269 
  270 Badge.seed do |b|
  271   b.id = Badge::Anniversary
  272   b.name = "Anniversary"
  273   b.default_icon = "far-clock"
  274   b.badge_type_id = BadgeType::Silver
  275   b.default_badge_grouping_id = BadgeGrouping::Community
  276   b.query = nil
  277   b.trigger = Badge::Trigger::None
  278   b.auto_revoke = false
  279   b.system = true
  280   b.multiple_grant = true
  281 end
  282 
  283 [
  284  [Badge::PopularLink, "Popular Link", BadgeType::Bronze, 50],
  285  [Badge::HotLink,     "Hot Link",     BadgeType::Silver, 300],
  286  [Badge::FamousLink,  "Famous Link",  BadgeType::Gold,   1000],
  287 ].each do |id, name, level, count|
  288   Badge.seed do |b|
  289     b.id = id
  290     b.name = name
  291     b.badge_type_id = level
  292     b.multiple_grant = true
  293     b.target_posts = true
  294     b.show_posts = true
  295     b.query = BadgeQueries.linking_badge(count)
  296     b.default_badge_grouping_id = BadgeGrouping::Posting
  297     # don't trigger for now, its too expensive
  298     b.trigger = Badge::Trigger::None
  299     b.system = true
  300   end
  301 end
  302 
  303 [
  304   [Badge::Appreciated, "Appreciated", BadgeType::Bronze, 1, 20],
  305   [Badge::Respected,   "Respected",   BadgeType::Silver, 2, 100],
  306   [Badge::Admired,     "Admired",     BadgeType::Gold,   5, 300],
  307 ].each do |id, name, level, like_count, post_count|
  308   Badge.seed do |b|
  309     b.id = id
  310     b.name = name
  311     b.default_icon = "fa-heart"
  312     b.badge_type_id = level
  313     b.query = BadgeQueries.liked_posts(post_count, like_count)
  314     b.default_badge_grouping_id = BadgeGrouping::Community
  315     b.trigger = Badge::Trigger::None
  316     b.auto_revoke = false
  317     b.system = true
  318   end
  319 end
  320 
  321 [
  322   [Badge::ThankYou,   "Thank You",  BadgeType::Bronze, 20, 10],
  323   [Badge::GivesBack,  "Gives Back", BadgeType::Silver, 100, 100],
  324   [Badge::Empathetic, "Empathetic", BadgeType::Gold,   500, 1000]
  325 ].each do |id, name, level, count, ratio|
  326   Badge.seed do |b|
  327     b.id = id
  328     b.name = name
  329     b.default_icon = "fa-heart"
  330     b.badge_type_id = level
  331     b.query = BadgeQueries.liked_back(count, ratio)
  332     b.default_badge_grouping_id = BadgeGrouping::Community
  333     b.trigger = Badge::Trigger::None
  334     b.auto_revoke = false
  335     b.system = true
  336   end
  337 end
  338 
  339 [
  340   [Badge::OutOfLove,   "Out of Love",   BadgeType::Bronze, 1],
  341   [Badge::HigherLove,  "Higher Love",   BadgeType::Silver, 5],
  342   [Badge::CrazyInLove, "Crazy in Love", BadgeType::Gold,   20],
  343 ].each do |id, name, level, count|
  344   Badge.seed do |b|
  345     b.id = id
  346     b.name = name
  347     b.default_icon = "fa-heart"
  348     b.badge_type_id = level
  349     b.query = BadgeQueries.like_rate_limit(count)
  350     b.default_badge_grouping_id = BadgeGrouping::Community
  351     b.trigger = Badge::Trigger::None
  352     b.auto_revoke = false
  353     b.system = true
  354   end
  355 end
  356 
  357 Badge.seed do |b|
  358   b.id = Badge::FirstMention
  359   b.name = "First Mention"
  360   b.badge_type_id = BadgeType::Bronze
  361   b.multiple_grant = false
  362   b.target_posts = true
  363   b.show_posts = true
  364   b.query = BadgeQueries::FirstMention
  365   b.default_badge_grouping_id = BadgeGrouping::GettingStarted
  366   b.trigger = Badge::Trigger::PostRevision
  367   b.system = true
  368 end
  369 
  370 Badge.seed do |b|
  371   b.id = Badge::FirstEmoji
  372   b.name = "First Emoji"
  373   b.badge_type_id = BadgeType::Bronze
  374   b.multiple_grant = false
  375   b.target_posts = true
  376   b.show_posts = true
  377   b.query = nil
  378   b.default_badge_grouping_id = BadgeGrouping::GettingStarted
  379   b.trigger = Badge::Trigger::None
  380   b.system = true
  381 end
  382 
  383 Badge.seed do |b|
  384   b.id = Badge::FirstOnebox
  385   b.name = "First Onebox"
  386   b.badge_type_id = BadgeType::Bronze
  387   b.multiple_grant = false
  388   b.target_posts = true
  389   b.show_posts = true
  390   b.query = nil
  391   b.default_badge_grouping_id = BadgeGrouping::GettingStarted
  392   b.trigger = Badge::Trigger::None
  393   b.system = true
  394 end
  395 
  396 Badge.seed do |b|
  397   b.id = Badge::FirstReplyByEmail
  398   b.name = "First Reply By Email"
  399   b.badge_type_id = BadgeType::Bronze
  400   b.multiple_grant = false
  401   b.target_posts = true
  402   b.show_posts = true
  403   b.query = nil
  404   b.default_badge_grouping_id = BadgeGrouping::GettingStarted
  405   b.trigger = Badge::Trigger::None
  406   b.system = true
  407 end
  408 
  409 Badge.seed do |b|
  410   b.id = Badge::NewUserOfTheMonth
  411   b.name = "New User of the Month"
  412   b.badge_type_id = BadgeType::Bronze
  413   b.multiple_grant = false
  414   b.target_posts = false
  415   b.show_posts = false
  416   b.query = nil
  417   b.default_badge_grouping_id = BadgeGrouping::GettingStarted
  418   b.trigger = Badge::Trigger::None
  419   b.system = true
  420 end
  421 
  422 [
  423   [Badge::Enthusiast, "Enthusiast", BadgeType::Bronze, 10],
  424   [Badge::Aficionado, "Aficionado", BadgeType::Silver, 100],
  425   [Badge::Devotee,    "Devotee",    BadgeType::Gold,   365],
  426 ].each do |id, name, level, days|
  427   Badge.seed do |b|
  428     b.id = id
  429     b.name = name
  430     b.default_icon = "far-eye"
  431     b.badge_type_id = level
  432     b.query = BadgeQueries.consecutive_visits(days)
  433     b.default_badge_grouping_id = BadgeGrouping::Community
  434     b.trigger = Badge::Trigger::None
  435     b.auto_revoke = false
  436     b.system = true
  437   end
  438 end
  439 
  440 Badge.where("NOT system AND id < 100").each do |badge|
  441   new_id = [Badge.maximum(:id) + 1, 100].max
  442   old_id = badge.id
  443   badge.update_columns(id: new_id)
  444   UserBadge.where(badge_id: old_id).update_all(badge_id: new_id)
  445 end