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
b1af4f67
Commit
b1af4f67
authored
Jan 18, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
4bb2cb2b
41ae26d9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
1 deletion
+80
-1
app/models/group.rb
app/models/group.rb
+4
-0
changelogs/unreleased/api-nested-group-permission.yml
changelogs/unreleased/api-nested-group-permission.yml
+5
-0
lib/api/entities.rb
lib/api/entities.rb
+1
-1
spec/models/group_spec.rb
spec/models/group_spec.rb
+36
-0
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+34
-0
No files found.
app/models/group.rb
View file @
b1af4f67
...
...
@@ -382,6 +382,10 @@ class Group < Namespace
end
end
def
highest_group_member
(
user
)
GroupMember
.
where
(
source_id:
self_and_ancestors_ids
,
user_id:
user
.
id
).
order
(
:access_level
).
last
end
def
hashed_storage?
(
_feature
)
false
end
...
...
changelogs/unreleased/api-nested-group-permission.yml
0 → 100644
View file @
b1af4f67
---
title
:
Return the maximum group access level in the projects API
merge_request
:
24403
author
:
type
:
changed
lib/api/entities.rb
View file @
b1af4f67
...
...
@@ -992,7 +992,7 @@ module API
if
options
[
:group_members
]
options
[
:group_members
].
find
{
|
member
|
member
.
source_id
==
project
.
namespace_id
}
else
project
.
group
.
group_member
(
options
[
:current_user
])
project
.
group
.
highest_
group_member
(
options
[
:current_user
])
end
end
end
...
...
spec/models/group_spec.rb
View file @
b1af4f67
...
...
@@ -722,6 +722,42 @@ describe Group do
end
end
describe
'#highest_group_member'
,
:nested_groups
do
let
(
:nested_group
)
{
create
(
:group
,
parent:
group
)
}
let
(
:nested_group_2
)
{
create
(
:group
,
parent:
nested_group
)
}
let
(
:user
)
{
create
(
:user
)
}
subject
(
:highest_group_member
)
{
nested_group_2
.
highest_group_member
(
user
)
}
context
'when the user is not a member of any group in the hierarchy'
do
it
'returns nil'
do
expect
(
highest_group_member
).
to
be_nil
end
end
context
'when the user is only a member of one group in the hierarchy'
do
before
do
nested_group
.
add_developer
(
user
)
end
it
'returns that group member'
do
expect
(
highest_group_member
.
access_level
).
to
eq
(
Gitlab
::
Access
::
DEVELOPER
)
end
end
context
'when the user is a member of several groups in the hierarchy'
do
before
do
group
.
add_owner
(
user
)
nested_group
.
add_developer
(
user
)
nested_group_2
.
add_maintainer
(
user
)
end
it
'returns the group member with the highest access level'
do
expect
(
highest_group_member
.
access_level
).
to
eq
(
Gitlab
::
Access
::
OWNER
)
end
end
end
describe
'#has_parent?'
do
context
'when the group has a parent'
do
it
'should be truthy'
do
...
...
spec/requests/api/projects_spec.rb
View file @
b1af4f67
...
...
@@ -1197,6 +1197,40 @@ describe API::Projects do
.
to
eq
(
Gitlab
::
Access
::
OWNER
)
end
end
context
'nested group project'
,
:nested_groups
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:nested_group
)
{
create
(
:group
,
parent:
group
)
}
let
(
:project2
)
{
create
(
:project
,
group:
nested_group
)
}
before
do
project2
.
group
.
parent
.
add_owner
(
user
)
end
it
'sets group access and return 200'
do
get
api
(
"/projects/
#{
project2
.
id
}
"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'permissions'
][
'project_access'
]).
to
be_nil
expect
(
json_response
[
'permissions'
][
'group_access'
][
'access_level'
])
.
to
eq
(
Gitlab
::
Access
::
OWNER
)
end
context
'with various access levels across nested groups'
do
before
do
project2
.
group
.
add_maintainer
(
user
)
end
it
'sets the maximum group access and return 200'
do
get
api
(
"/projects/
#{
project2
.
id
}
"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'permissions'
][
'project_access'
]).
to
be_nil
expect
(
json_response
[
'permissions'
][
'group_access'
][
'access_level'
])
.
to
eq
(
Gitlab
::
Access
::
OWNER
)
end
end
end
end
end
end
...
...
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