Commit df21240f authored by Stan Hu's avatar Stan Hu

Merge branch '339195-fj-linear-membership-groups' into 'master'

Use linear version of User#membership_groups

See merge request gitlab-org/gitlab!68842
parents 8f4b7c72 fc937197
......@@ -1000,8 +1000,12 @@ class User < ApplicationRecord
# Returns the groups a user is a member of, either directly or through a parent group
def membership_groups
if Feature.enabled?(:linear_user_membership_groups, self, default_enabled: :yaml)
groups.self_and_descendants
else
Gitlab::ObjectHierarchy.new(groups).base_and_descendants
end
end
# Returns a relation of groups the user has access to, including their parent
# and child groups (recursively).
......
---
name: linear_user_membership_groups
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68842
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/339432
milestone: '14.3'
type: development
group: group::access
default_enabled: false
......@@ -3389,17 +3389,32 @@ RSpec.describe User do
end
describe '#membership_groups' do
let!(:user) { create(:user) }
let!(:parent_group) { create(:group) }
let!(:child_group) { create(:group, parent: parent_group) }
let_it_be(:user) { create(:user) }
before do
parent_group.add_user(user, Gitlab::Access::MAINTAINER)
let_it_be(:parent_group) do
create(:group).tap do |g|
g.add_user(user, Gitlab::Access::MAINTAINER)
end
end
let_it_be(:child_group) { create(:group, parent: parent_group) }
let_it_be(:other_group) { create(:group) }
subject { user.membership_groups }
it { is_expected.to contain_exactly parent_group, child_group }
shared_examples 'returns groups where the user is a member' do
specify { is_expected.to contain_exactly(parent_group, child_group) }
end
it_behaves_like 'returns groups where the user is a member'
context 'when feature flag :linear_user_membership_groups is disabled' do
before do
stub_feature_flags(linear_user_membership_groups: false)
end
it_behaves_like 'returns groups where the user is a member'
end
end
describe '#authorizations_for_projects' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment