FIX: Unable to invite groups that are not public visible into pms.
https://meta.discourse.org/t/inviting-groups-broken-in-head/73346/6
This commit is contained in:
parent
470b1a5bc1
commit
d320f4840d
|
@ -719,9 +719,15 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if groups || params[:include_groups] == "true"
|
include_groups = params[:include_groups] == "true"
|
||||||
to_render[:groups] = Group.search_groups(term, groups: groups)
|
|
||||||
.map { |m| { name: m.name, full_name: m.full_name } }
|
if include_groups || groups
|
||||||
|
groups = Group.search_groups(term, groups: groups)
|
||||||
|
groups = groups.where(visibility_level: Group.visibility_levels[:public]) if include_groups
|
||||||
|
|
||||||
|
to_render[:groups] = groups.map do |m|
|
||||||
|
{ name: m.name, full_name: m.full_name }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: to_render
|
render json: to_render
|
||||||
|
|
|
@ -370,11 +370,7 @@ class Group < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.search_groups(name, groups: nil)
|
def self.search_groups(name, groups: nil)
|
||||||
query = groups || Group
|
(groups || Group).where(
|
||||||
|
|
||||||
query
|
|
||||||
.where(visibility_level: visibility_levels[:public])
|
|
||||||
.where(
|
|
||||||
"name ILIKE :term_like OR full_name ILIKE :term_like", term_like: "%#{name}%"
|
"name ILIKE :term_like OR full_name ILIKE :term_like", term_like: "%#{name}%"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -167,14 +167,45 @@ RSpec.describe UsersController do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'groups' do
|
context 'groups' do
|
||||||
let!(:mentionable_group) { Fabricate(:group, mentionable_level: 99, messageable_level: 0) }
|
let!(:mentionable_group) do
|
||||||
let!(:messageable_group) { Fabricate(:group, mentionable_level: 0, messageable_level: 99) }
|
Fabricate(:group,
|
||||||
|
mentionable_level: 99,
|
||||||
|
messageable_level: 0,
|
||||||
|
visibility_level: 0
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
let!(:mentionable_group_2) do
|
||||||
|
Fabricate(:group,
|
||||||
|
mentionable_level: 99,
|
||||||
|
messageable_level: 0,
|
||||||
|
visibility_level: 1
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
let!(:messageable_group) do
|
||||||
|
Fabricate(:group,
|
||||||
|
mentionable_level: 0,
|
||||||
|
messageable_level: 99
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
describe 'when signed in' do
|
describe 'when signed in' do
|
||||||
before do
|
before do
|
||||||
sign_in(user)
|
sign_in(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "only returns visible groups" do
|
||||||
|
get "/u/search/users.json", params: { include_groups: "true" }
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
|
|
||||||
|
groups = JSON.parse(response.body)["groups"]
|
||||||
|
|
||||||
|
expect(groups.map { |group| group['name'] })
|
||||||
|
.to_not include(mentionable_group_2.name)
|
||||||
|
end
|
||||||
|
|
||||||
it "doesn't search for groups" do
|
it "doesn't search for groups" do
|
||||||
get "/u/search/users.json", params: {
|
get "/u/search/users.json", params: {
|
||||||
include_mentionable_groups: 'false',
|
include_mentionable_groups: 'false',
|
||||||
|
@ -202,7 +233,11 @@ RSpec.describe UsersController do
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
expect(JSON.parse(response.body)["groups"].first['name']).to eq(mentionable_group.name)
|
|
||||||
|
groups = JSON.parse(response.body)["groups"]
|
||||||
|
|
||||||
|
expect(groups.map { |group| group['name'] })
|
||||||
|
.to eq([mentionable_group.name, mentionable_group_2.name])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue