FIX: Remove groups when promotion is recalculated. (#31058)

The group has `grant_trust_level` setting which automatically updates
the trust level when the user is added to the group.

Similarly, when the user is removed from the group, the trust level is
recalculated.

There was a bug that when the trust level was downgraded, the user was
not removed from automatic groups like for example `trust_level_3`.
This commit is contained in:
Krzysztof Kotlarek
2025-01-30 14:24:18 +11:00
committed by GitHub
parent 7a0762771e
commit d75a0b1165
2 changed files with 8 additions and 0 deletions

View File

@ -298,10 +298,16 @@ RSpec.describe GroupUser do
group_user = Fabricate(:group_user, group: group, user: user)
expect(user.reload.trust_level).to eq(4)
expect(user.groups.where(automatic: true).map(&:name)).to eq(
%w[trust_level_0 trust_level_1 trust_level_2 trust_level_3 trust_level_4],
)
group_user.destroy!
# keep in mind that we do not restore tl3, cause reqs can be lost
expect(user.reload.trust_level).to eq(2)
expect(user.groups.where(automatic: true).map(&:name)).to eq(
%w[trust_level_0 trust_level_1 trust_level_2],
)
end
it "protects user trust level if all requirements are met" do