FIX: show primary user group options to members in account prefs (#27664)

The user serializer groups method previously relied on the members_visible_groups to determine groups that the user should be able to see, however this setting was intended for visibility of group members (which is entirely different).

The result of this could be seen when choosing a primary group from user preferences -> account, due to the serializer the group name was not visible when members_visible_groups was set to owners.
This commit is contained in:
David Battersby 2024-07-05 19:43:50 +04:00 committed by GitHub
parent 4f87f0d7ef
commit 640dccd224
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View File

@ -90,7 +90,7 @@ class UserSerializer < UserCardSerializer
end
def groups
object.groups.order(:id).visible_groups(scope.user).members_visible_groups(scope.user)
object.groups.order(:id).visible_groups(scope.user)
end
def group_users

View File

@ -495,4 +495,26 @@ RSpec.describe UserSerializer do
expect(serializer.as_json[:display_sidebar_tags]).to eq(nil)
end
end
context "with groups" do
fab!(:group) do
Fabricate(
:group,
visibility_level: Group.visibility_levels[:public],
members_visibility_level: Group.visibility_levels[:owners],
)
end
let(:serializer) { UserSerializer.new(user, scope: Guardian.new, root: false) }
before do
group.add(user)
group.save!
end
it "should show group even when members list is not visible" do
json = serializer.as_json
expect(json[:groups].length).to eq(1)
expect(json[:groups].first[:id]).to eq(group.id)
end
end
end