FIX: Don't fail silently when updating a record.

This commit is contained in:
Guo Xiang Tan 2017-11-29 08:01:13 +08:00
parent 44ee388070
commit bb0b7b61d7

View File

@ -65,10 +65,11 @@ class GroupUser < ActiveRecord::Base
def grant_trust_level
return if group.grant_trust_level.nil?
if (user.group_locked_trust_level || 0) < group.grant_trust_level
user.group_locked_trust_level = group.grant_trust_level
user.save
user.update!(group_locked_trust_level: group.grant_trust_level)
end
TrustLevelGranter.grant(group.grant_trust_level, user)
end
@ -84,14 +85,10 @@ class GroupUser < ActiveRecord::Base
if highest_level.nil?
# If the user no longer has a group with a trust level,
# unlock them, start at 0 and consider promotions.
user.group_locked_trust_level = nil
user.save
user.update!(group_locked_trust_level: nil)
Promotion.recalculate(user)
else
user.group_locked_trust_level = highest_level
user.save
user.update!(group_locked_trust_level: highest_level)
user.change_trust_level!(highest_level)
end
end