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:
Bianca Nenciu
2022-08-29 13:00:48 +03:00
committed by GitHub
parent c4bb15441d
commit 0d8ecab362
7 changed files with 90 additions and 44 deletions

View File

@@ -121,21 +121,12 @@ class Promotion
end
# Figure out what a user's trust level should be from scratch
def self.recalculate(user, performed_by = nil)
# First, use the manual locked level
unless user.manual_locked_trust_level.nil?
return user.update!(
trust_level: user.manual_locked_trust_level
)
end
# Then consider the group locked level
user_group_granted_trust_level = user.group_granted_trust_level
if user_group_granted_trust_level.present?
return user.update(
trust_level: user_group_granted_trust_level
)
def self.recalculate(user, performed_by = nil, use_previous_trust_level: false)
granted_trust_level = TrustLevel.calculate(
user, use_previous_trust_level: use_previous_trust_level
)
if granted_trust_level.present?
return user.update(trust_level: granted_trust_level)
end
user.update_column(:trust_level, TrustLevel[0])