mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
FIX: update flair group of all members if primary group setting changed. (#14762)
Previously, if we enable the `primary_group` setting on a group then the `flair_group_id` of its' members are not affected.
This commit is contained in:
parent
c62242c6b3
commit
deee715a2c
@ -979,23 +979,26 @@ class Group < ActiveRecord::Base
|
|||||||
/*where*/
|
/*where*/
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
builder = DB.build(sql)
|
[:primary_group_id, :flair_group_id].each do |column|
|
||||||
builder.where(<<~SQL, id: id)
|
builder = DB.build(sql)
|
||||||
id IN (
|
builder.where(<<~SQL, id: id)
|
||||||
SELECT user_id
|
id IN (
|
||||||
FROM group_users
|
SELECT user_id
|
||||||
WHERE group_id = :id
|
FROM group_users
|
||||||
)
|
WHERE group_id = :id
|
||||||
SQL
|
)
|
||||||
|
SQL
|
||||||
|
|
||||||
if primary_group
|
if primary_group
|
||||||
builder.set("primary_group_id = :id")
|
builder.set("#{column} = :id")
|
||||||
else
|
builder.where("#{column} IS NULL") if column == :flair_group_id
|
||||||
builder.set("primary_group_id = NULL")
|
else
|
||||||
builder.where("primary_group_id = :id")
|
builder.set("#{column} = NULL")
|
||||||
|
builder.where("#{column} = :id")
|
||||||
|
end
|
||||||
|
|
||||||
|
builder.exec
|
||||||
end
|
end
|
||||||
|
|
||||||
builder.exec
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -198,12 +198,19 @@ describe Group do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#primary_group=' do
|
describe '#primary_group=' do
|
||||||
it "updates all members' #primary_group" do
|
before do
|
||||||
group.add(user)
|
group.add(user)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "updates all members' #primary_group" do
|
||||||
expect { group.update(primary_group: true) }.to change { user.reload.primary_group }.from(nil).to(group)
|
expect { group.update(primary_group: true) }.to change { user.reload.primary_group }.from(nil).to(group)
|
||||||
expect { group.update(primary_group: false) }.to change { user.reload.primary_group }.from(group).to(nil)
|
expect { group.update(primary_group: false) }.to change { user.reload.primary_group }.from(group).to(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "updates all members' #flair_group" do
|
||||||
|
expect { group.update(primary_group: true) }.to change { user.reload.flair_group }.from(nil).to(group)
|
||||||
|
expect { group.update(primary_group: false) }.to change { user.reload.flair_group }.from(group).to(nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#title=' do
|
describe '#title=' do
|
||||||
|
Loading…
Reference in New Issue
Block a user