FIX: Allow integer group_ids for create invite api (#21494)

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.
This commit is contained in:
Blake Erickson 2023-05-11 11:39:33 -06:00 committed by GitHub
parent ce5430adc1
commit bd6e487df0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -686,7 +686,7 @@ class Group < ActiveRecord::Base
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

View File

@ -579,6 +579,23 @@ RSpec.describe Group do
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