mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Restore trust level when leaving group (#17954)
If a user was granted a trust level, joined a group that granted a trust level and left the group, the trust level was reset. This commit tries to restore the last known trust level before joining the group by looking into staff logs. This commit also migrates old :change_trust_level user history records to use previous_value and new_value fields.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class MoveTlUserHistoryToPreviousAndNewValue < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
execute <<~SQL
|
||||
UPDATE user_histories
|
||||
SET previous_value = old_tl,
|
||||
new_value = new_tl,
|
||||
details = NULL
|
||||
FROM (
|
||||
SELECT id user_history_id,
|
||||
(REGEXP_MATCHES(details, 'old trust level: (\d+)', 'i'))[1] old_tl,
|
||||
(REGEXP_MATCHES(details, 'new trust level: (\d+)', 'i'))[1] new_tl
|
||||
FROM user_histories
|
||||
WHERE action = 2
|
||||
) trust_levels
|
||||
WHERE user_histories.id = trust_levels.user_history_id
|
||||
SQL
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user