FIX: use `update_attribute` method to trigger callbacks. (#13930)

Group flair is not removed while removing a user from the group since the `before_save` callback methods are not triggered while using the `update_columns` method.
This commit is contained in:
Vinoth Kannan 2021-08-04 11:54:46 +05:30 committed by GitHub
parent fc5194e515
commit 1da0aa838f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -690,7 +690,7 @@ class Group < ActiveRecord::Base
has_webhooks = WebHook.active_web_hooks(:group_user)
payload = WebHook.generate_payload(:group_user, group_user, WebHookGroupUserSerializer) if has_webhooks
group_user.destroy
user.update_columns(primary_group_id: nil) if user.primary_group_id == self.id
user.update_attribute(:primary_group_id, nil) if user.primary_group_id == self.id
DiscourseEvent.trigger(:user_removed_from_group, user, self)
WebHook.enqueue_hooks(:group_user, :user_removed_from_group,
id: group_user.id,

View File

@ -315,7 +315,7 @@ describe Group do
end
it "Correctly handles removal of primary group" do
group = Fabricate(:group)
group = Fabricate(:group, flair_icon: "icon")
user = Fabricate(:user)
group.add(user)
group.save
@ -330,6 +330,7 @@ describe Group do
user.reload
expect(user.primary_group).to eq nil
expect(user.flair_group_id).to eq nil
end
it "Can update moderator/staff/admin groups correctly" do