mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:21:18 +08:00
FIX: Badge and user title interaction fixes (#8282)
* Fix user title logic when badge name customized * Fix an issue where a user's title was not considered a badge granted title when the user used a badge for their title and the badge name was customized. this affected the effectiveness of revoke_ungranted_titles! which only operates on badge_granted_titles. * When a user's title is set now it is considered a badge_granted_title if the badge name OR the badge custom name from TranslationOverride is the same as the title * When a user's badge is revoked we now also revoke their title if the user's title matches the badge name OR the badge custom name from TranslationOverride * Add a user history log when the title is revoked to remove confusion about why titles are revoked * Add granted_title_badge_id to user_profile, now when we set badge_granted_title on a user profile when updating a user's title based on a badge, we also remember which badge matched the title * When badge name (or custom text) changes update titles of users in a background job * When the name of a badge changes, or in the case of system badges when their custom translation text changes, then we need to update the title of all corresponding users who have a badge_granted_title and matching granted_title_badge_id. In the case of system badges we need to first get the proper badge ID based on the translation key e.g. badges.regular.name * Add migration to backfill all granted_title_badge_ids for both normal badge name titles and titles using custom badge text.
This commit is contained in:
@ -59,6 +59,15 @@ class Admin::SiteTextsController < Admin::AdminController
|
||||
|
||||
if translation_override.errors.empty?
|
||||
StaffActionLogger.new(current_user).log_site_text_change(id, value, old_value)
|
||||
system_badge_id = Badge.find_system_badge_id_from_translation_key(id)
|
||||
if system_badge_id.present?
|
||||
Jobs.enqueue(
|
||||
:bulk_user_title_update,
|
||||
new_title: value,
|
||||
granted_badge_id: system_badge_id,
|
||||
action: Jobs::BulkUserTitleUpdate::UPDATE_ACTION
|
||||
)
|
||||
end
|
||||
render_serialized(site_text, SiteTextSerializer, root: 'site_text', rest_serializer: true)
|
||||
else
|
||||
render json: failed_json.merge(
|
||||
@ -69,10 +78,19 @@ class Admin::SiteTextsController < Admin::AdminController
|
||||
|
||||
def revert
|
||||
site_text = find_site_text
|
||||
old_text = I18n.t(site_text[:id])
|
||||
TranslationOverride.revert!(I18n.locale, site_text[:id])
|
||||
id = site_text[:id]
|
||||
old_text = I18n.t(id)
|
||||
TranslationOverride.revert!(I18n.locale, id)
|
||||
site_text = find_site_text
|
||||
StaffActionLogger.new(current_user).log_site_text_change(site_text[:id], site_text[:value], old_text)
|
||||
StaffActionLogger.new(current_user).log_site_text_change(id, site_text[:value], old_text)
|
||||
system_badge_id = Badge.find_system_badge_id_from_translation_key(id)
|
||||
if system_badge_id.present?
|
||||
Jobs.enqueue(
|
||||
:bulk_user_title_update,
|
||||
granted_badge_id: system_badge_id,
|
||||
action: Jobs::BulkUserTitleUpdate::RESET_ACTION
|
||||
)
|
||||
end
|
||||
render_serialized(site_text, SiteTextSerializer, root: 'site_text', rest_serializer: true)
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user