diff --git a/db/fixtures/006_badges.rb b/db/fixtures/006_badges.rb index 1642abe64a4..a9647d9492b 100644 --- a/db/fixtures/006_badges.rb +++ b/db/fixtures/006_badges.rb @@ -66,6 +66,7 @@ end Badge.seed do |b| b.id = Badge::Reader b.name = "Reader" + b.default_icon = "book-reader" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = false @@ -79,6 +80,7 @@ end Badge.seed do |b| b.id = Badge::ReadGuidelines b.name = "Read Guidelines" + b.default_icon = "file-alt" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = false @@ -92,6 +94,7 @@ end Badge.seed do |b| b.id = Badge::FirstLink b.name = "First Link" + b.default_icon = "link" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -105,6 +108,7 @@ end Badge.seed do |b| b.id = Badge::FirstQuote b.name = "First Quote" + b.default_icon = "quote-right" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -118,6 +122,7 @@ end Badge.seed do |b| b.id = Badge::FirstLike b.name = "First Like" + b.default_icon = "heart" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -131,6 +136,7 @@ end Badge.seed do |b| b.id = Badge::FirstFlag b.name = "First Flag" + b.default_icon = "flag" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -167,6 +173,7 @@ end Badge.seed do |b| b.id = Badge::FirstShare b.name = "First Share" + b.default_icon = "share-alt" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -186,6 +193,7 @@ end Badge.seed do |b| b.id = id b.name = name + b.default_icon = "share-alt" b.badge_type_id = level b.multiple_grant = true b.target_posts = true @@ -201,6 +209,7 @@ end Badge.seed do |b| b.id = Badge::Welcome b.name = "Welcome" + b.default_icon = "heart" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -214,6 +223,7 @@ end Badge.seed do |b| b.id = Badge::Autobiographer b.name = "Autobiographer" + b.default_icon = "user-edit" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.query = BadgeQueries::Autobiographer @@ -225,6 +235,7 @@ end Badge.seed do |b| b.id = Badge::Editor b.name = "Editor" + b.default_icon = "pen" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.query = BadgeQueries::Editor @@ -236,6 +247,7 @@ end Badge.seed do |b| b.id = Badge::WikiEditor b.name = "Wiki Editor" + b.default_icon = "far-edit" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -249,6 +261,23 @@ end [Badge::NicePost, "Nice Post", BadgeType::Bronze, false], [Badge::GoodPost, "Good Post", BadgeType::Silver, false], [Badge::GreatPost, "Great Post", BadgeType::Gold, false], +].each do |id, name, type, topic| + Badge.seed do |b| + b.id = id + b.name = name + b.default_icon = "reply" + b.badge_type_id = type + b.multiple_grant = true + b.target_posts = true + b.show_posts = true + b.query = BadgeQueries.like_badge(Badge.like_badge_counts[id], topic) + b.default_badge_grouping_id = BadgeGrouping::Posting + b.trigger = Badge::Trigger::PostAction + b.system = true + end +end + +[ [Badge::NiceTopic, "Nice Topic", BadgeType::Bronze, true], [Badge::GoodTopic, "Good Topic", BadgeType::Silver, true], [Badge::GreatTopic, "Great Topic", BadgeType::Gold, true], @@ -256,6 +285,7 @@ end Badge.seed do |b| b.id = id b.name = name + b.default_icon = "file-signature" b.badge_type_id = type b.multiple_grant = true b.target_posts = true @@ -270,7 +300,7 @@ end Badge.seed do |b| b.id = Badge::Anniversary b.name = "Anniversary" - b.default_icon = "far-clock" + b.default_icon = "birthday-cake" b.badge_type_id = BadgeType::Silver b.default_badge_grouping_id = BadgeGrouping::Community b.query = nil @@ -288,6 +318,7 @@ end Badge.seed do |b| b.id = id b.name = name + b.default_icon = "link" b.badge_type_id = level b.multiple_grant = true b.target_posts = true @@ -357,6 +388,7 @@ end Badge.seed do |b| b.id = Badge::FirstMention b.name = "First Mention" + b.default_icon = "at" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -370,6 +402,7 @@ end Badge.seed do |b| b.id = Badge::FirstEmoji b.name = "First Emoji" + b.default_icon = "smile" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -383,6 +416,7 @@ end Badge.seed do |b| b.id = Badge::FirstOnebox b.name = "First Onebox" + b.default_icon = "cube" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -396,6 +430,7 @@ end Badge.seed do |b| b.id = Badge::FirstReplyByEmail b.name = "First Reply By Email" + b.default_icon = "envelope" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = true @@ -409,6 +444,7 @@ end Badge.seed do |b| b.id = Badge::NewUserOfTheMonth b.name = "New User of the Month" + b.default_icon = "medal" b.badge_type_id = BadgeType::Bronze b.multiple_grant = false b.target_posts = false diff --git a/db/migrate/20230227050147_update_badge_icons.rb b/db/migrate/20230227050147_update_badge_icons.rb new file mode 100644 index 00000000000..06a289dd78a --- /dev/null +++ b/db/migrate/20230227050147_update_badge_icons.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +class UpdateBadgeIcons < ActiveRecord::Migration[7.0] + def change + icon_id_replacement = [ + ["book-reader", [Badge::Reader], "fa-certificate"], + ["file-alt", [Badge::ReadGuidelines], "fa-certificate"], + [ + "link", + [Badge::FirstLink, Badge::PopularLink, Badge::HotLink, Badge::FamousLink], + "fa-certificate", + ], + ["quote-right", [Badge::FirstQuote], "fa-certificate"], + ["heart", [Badge::FirstLike, Badge::Welcome], "fa-certificate"], + ["flag", [Badge::FirstFlag], "fa-certificate"], + [ + "share-alt", + [Badge::FirstShare, Badge::NiceShare, Badge::GoodShare, Badge::GreatShare], + "fa-certificate", + ], + ["user-edit", [Badge::Autobiographer], "fa-certificate"], + ["pen", [Badge::Editor], "fa-certificate"], + ["far-edit", [Badge::WikiEditor], "fa-certificate"], + ["reply", [Badge::NicePost, Badge::GoodPost, Badge::GreatPost], "fa-certificate"], + ["file-signature", [Badge::NiceTopic, Badge::GoodTopic, Badge::GreatTopic], "fa-certificate"], + ["at", [Badge::FirstMention], "fa-certificate"], + ["smile", [Badge::FirstEmoji], "fa-certificate"], + ["cube", [Badge::FirstOnebox], "fa-certificate"], + ["envelope", [Badge::FirstReplyByEmail], "fa-certificate"], + ["medal", [Badge::NewUserOfTheMonth], "fa-certificate"], + ["birthday-cake", [Badge::Anniversary], "far-clock"], + ] + + icon_id_replacement.each do |new_icon, badge_ids, old_icon| + execute "UPDATE badges SET icon = '#{new_icon}' WHERE id IN (#{badge_ids.join(",")}) AND icon = '#{old_icon}'" + end + end +end diff --git a/plugins/discourse-narrative-bot/db/fixtures/002_badges.rb b/plugins/discourse-narrative-bot/db/fixtures/002_badges.rb index a6c4b2dc282..5d32fa512b1 100644 --- a/plugins/discourse-narrative-bot/db/fixtures/002_badges.rb +++ b/plugins/discourse-narrative-bot/db/fixtures/002_badges.rb @@ -12,7 +12,11 @@ new_user_narrative_badge = Badge.find_by(name: DiscourseNarrativeBot::NewUserNar unless new_user_narrative_badge new_user_narrative_badge = - Badge.create!(name: DiscourseNarrativeBot::NewUserNarrative::BADGE_NAME, badge_type_id: 3) + Badge.create!( + name: DiscourseNarrativeBot::NewUserNarrative::BADGE_NAME, + badge_type_id: 3, + icon: "stamp", + ) end advanced_user_narrative_badge = @@ -20,7 +24,11 @@ advanced_user_narrative_badge = unless advanced_user_narrative_badge advanced_user_narrative_badge = - Badge.create!(name: DiscourseNarrativeBot::AdvancedUserNarrative::BADGE_NAME, badge_type_id: 2) + Badge.create!( + name: DiscourseNarrativeBot::AdvancedUserNarrative::BADGE_NAME, + badge_type_id: 2, + icon: "stamp", + ) end badge_grouping = BadgeGrouping.find(1) @@ -29,5 +37,10 @@ badge_grouping = BadgeGrouping.find(1) [new_user_narrative_badge, I18n.t("badges.certified.description")], [advanced_user_narrative_badge, I18n.t("badges.licensed.description")], ].each do |badge, description| - badge.update!(badge_grouping: badge_grouping, description: description, system: true) + badge.update!( + badge_grouping: badge_grouping, + description: description, + system: true, + icon: "stamp", + ) end diff --git a/plugins/discourse-narrative-bot/db/migrate/20230227050146_update_narrative_badge_icons.rb b/plugins/discourse-narrative-bot/db/migrate/20230227050146_update_narrative_badge_icons.rb new file mode 100644 index 00000000000..5695cc65fb1 --- /dev/null +++ b/plugins/discourse-narrative-bot/db/migrate/20230227050146_update_narrative_badge_icons.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class UpdateNarrativeBadgeIcons < ActiveRecord::Migration[7.0] + def change + execute <<~SQL + UPDATE badges + SET icon = 'stamp' + WHERE + name IN ('#{DiscourseNarrativeBot::NewUserNarrative::BADGE_NAME}', '#{DiscourseNarrativeBot::AdvancedUserNarrative::BADGE_NAME}') + AND icon = 'fa-certificate' + SQL + end +end