Skip to content

Commit

Permalink
FIX: Allow integer group_ids for create invite api (discourse#21494)
Browse files Browse the repository at this point in the history
This fixes a bug in the create invite API where if you passed in an
integer for the group_ids field it would fail to add the user to the
specified group.
  • Loading branch information
oblakeerickson authored May 11, 2023
1 parent ce5430a commit bd6e487
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def self.lookup_group(name)

def self.lookup_groups(group_ids: [], group_names: [])
if group_ids.present?
group_ids = group_ids.split(",") if group_ids.is_a?(String)
group_ids = group_ids.to_s.split(",") if !group_ids.is_a?(Array)
group_ids.map!(&:to_i)
groups = Group.where(id: group_ids) if group_ids.present?
end
Expand Down
17 changes: 17 additions & 0 deletions spec/models/group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,23 @@ def real_staff
expect(group.id).to eq Group[group.name.to_sym].id
end

it "allows you to lookup a group by integer id" do
group = Fabricate(:group)
expect(group.id).to eq Group.lookup_groups(group_ids: group.id).first.id
end

it "allows you to lookup groups by comma separated string" do
group1 = Fabricate(:group)
group2 = Fabricate(:group)
expect([group1, group2]).to eq Group.lookup_groups(group_ids: "#{group1.id},#{group2.id}")
end

it "allows you to lookup groups by array" do
group1 = Fabricate(:group)
group2 = Fabricate(:group)
expect([group1, group2]).to eq Group.lookup_groups(group_ids: [group1.id, group2.id])
end

it "can find desired groups correctly" do
expect(Group.desired_trust_level_groups(2).sort).to eq [10, 11, 12]
end
Expand Down

0 comments on commit bd6e487

Please sign in to comment.