Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
fc937197
Commit
fc937197
authored
Aug 24, 2021
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use linear version of User#membership_groups
Changelog: performance
parent
72f0f338
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
7 deletions
+34
-7
app/models/user.rb
app/models/user.rb
+5
-1
config/feature_flags/development/linear_user_membership_groups.yml
...ature_flags/development/linear_user_membership_groups.yml
+8
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+21
-6
No files found.
app/models/user.rb
View file @
fc937197
...
...
@@ -996,7 +996,11 @@ class User < ApplicationRecord
# Returns the groups a user is a member of, either directly or through a parent group
def
membership_groups
Gitlab
::
ObjectHierarchy
.
new
(
groups
).
base_and_descendants
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
...
...
config/feature_flags/development/linear_user_membership_groups.yml
0 → 100644
View file @
fc937197
---
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
spec/models/user_spec.rb
View file @
fc937197
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment