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
bd4c2847
Commit
bd4c2847
authored
Jun 28, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename members_count to members_count_with_descendants and expose only to group admins
parent
7db27689
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
39 additions
and
20 deletions
+39
-20
doc/api/namespaces.md
doc/api/namespaces.md
+6
-6
lib/api/entities.rb
lib/api/entities.rb
+6
-2
lib/api/namespaces.rb
lib/api/namespaces.rb
+1
-1
spec/requests/api/namespaces_spec.rb
spec/requests/api/namespaces_spec.rb
+24
-5
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+1
-3
spec/requests/api/v3/projects_spec.rb
spec/requests/api/v3/projects_spec.rb
+1
-3
No files found.
doc/api/namespaces.md
View file @
bd4c2847
...
@@ -30,9 +30,7 @@ Example response:
...
@@ -30,9 +30,7 @@ Example response:
"id"
:
1
,
"id"
:
1
,
"path"
:
"user1"
,
"path"
:
"user1"
,
"kind"
:
"user"
,
"kind"
:
"user"
,
"full_path"
:
"user1"
,
"full_path"
:
"user1"
"parent_id"
:
"null"
,
"members_count"
:
"null"
},
},
{
{
"id"
:
2
,
"id"
:
2
,
...
@@ -40,7 +38,7 @@ Example response:
...
@@ -40,7 +38,7 @@ Example response:
"kind"
:
"group"
,
"kind"
:
"group"
,
"full_path"
:
"group1"
,
"full_path"
:
"group1"
,
"parent_id"
:
"null"
,
"parent_id"
:
"null"
,
"members_count"
:
2
"members_count
_with_descendants
"
:
2
},
},
{
{
...
@@ -49,11 +47,13 @@ Example response:
...
@@ -49,11 +47,13 @@ Example response:
"kind"
:
"group"
,
"kind"
:
"group"
,
"full_path"
:
"foo/bar"
,
"full_path"
:
"foo/bar"
,
"parent_id"
:
"9"
,
"parent_id"
:
"9"
,
"members_count"
:
5
"members_count
_with_descendants
"
:
5
}
}
]
]
```
```
**Note**
:
`members_count_with_descendants`
are presented only for group masters/owners.
## Search for namespace
## Search for namespace
Get all namespaces that match a string in their name or path.
Get all namespaces that match a string in their name or path.
...
@@ -82,7 +82,7 @@ Example response:
...
@@ -82,7 +82,7 @@ Example response:
"kind"
:
"group"
,
"kind"
:
"group"
,
"full_path"
:
"twitter"
,
"full_path"
:
"twitter"
,
"parent_id"
:
"null"
,
"parent_id"
:
"null"
,
"members_count"
:
2
"members_count
_with_descendants
"
:
2
}
}
]
]
```
```
lib/api/entities.rb
View file @
bd4c2847
...
@@ -446,8 +446,12 @@ module API
...
@@ -446,8 +446,12 @@ module API
class
Namespace
<
Grape
::
Entity
class
Namespace
<
Grape
::
Entity
expose
:id
,
:name
,
:path
,
:kind
,
:full_path
,
:parent_id
expose
:id
,
:name
,
:path
,
:kind
,
:full_path
,
:parent_id
expose
:members_count
do
|
namespace
,
_
|
expose
:members_count_with_descendants
,
if:
->
(
namespace
,
opts
)
{
expose_members_count_with_descendants?
(
namespace
,
opts
)
}
do
|
namespace
,
_
|
namespace
.
users_with_descendants
.
count
if
namespace
.
kind
==
'group'
namespace
.
users_with_descendants
.
count
end
def
expose_members_count_with_descendants?
(
namespace
,
opts
)
namespace
.
kind
==
'group'
&&
Ability
.
allowed?
(
opts
[
:current_user
],
:admin_group
,
namespace
)
end
end
end
end
...
...
lib/api/namespaces.rb
View file @
bd4c2847
...
@@ -17,7 +17,7 @@ module API
...
@@ -17,7 +17,7 @@ module API
namespaces
=
namespaces
.
search
(
params
[
:search
])
if
params
[
:search
].
present?
namespaces
=
namespaces
.
search
(
params
[
:search
])
if
params
[
:search
].
present?
present
paginate
(
namespaces
),
with:
Entities
::
Namespace
present
paginate
(
namespaces
),
with:
Entities
::
Namespace
,
current_user:
current_user
end
end
end
end
end
end
...
...
spec/requests/api/namespaces_spec.rb
View file @
bd4c2847
...
@@ -18,9 +18,15 @@ describe API::Namespaces do
...
@@ -18,9 +18,15 @@ describe API::Namespaces do
it
"returns correct attributes"
do
it
"returns correct attributes"
do
get
api
(
"/namespaces"
,
admin
)
get
api
(
"/namespaces"
,
admin
)
group_kind_json_response
=
json_response
.
find
{
|
resource
|
resource
[
'kind'
]
==
'group'
}
user_kind_json_response
=
json_response
.
find
{
|
resource
|
resource
[
'kind'
]
==
'user'
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
.
first
).
to
include
(
'id'
,
'name'
,
'path'
,
'full_path'
,
'parent_id'
,
'members_count'
)
expect
(
group_kind_json_response
.
keys
).
to
contain_exactly
(
'id'
,
'kind'
,
'name'
,
'path'
,
'full_path'
,
'parent_id'
,
'members_count_with_descendants'
)
expect
(
user_kind_json_response
.
keys
).
to
contain_exactly
(
'id'
,
'kind'
,
'name'
,
'path'
,
'full_path'
,
'parent_id'
)
end
end
it
"admin: returns an array of all namespaces"
do
it
"admin: returns an array of all namespaces"
do
...
@@ -45,12 +51,25 @@ describe API::Namespaces do
...
@@ -45,12 +51,25 @@ describe API::Namespaces do
end
end
context
"when authenticated as a regular user"
do
context
"when authenticated as a regular user"
do
it
"returns correct attributes"
do
it
"returns members_count_with_descendants if user can admin group"
do
group1
.
add_owner
(
user
)
get
api
(
"/namespaces"
,
user
)
get
api
(
"/namespaces"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
owned_group_response
=
json_response
.
find
{
|
resource
|
resource
[
'id'
]
==
group1
.
id
}
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
.
first
).
to
include
(
'id'
,
'name'
,
'path'
,
'full_path'
,
'parent_id'
,
'members_count'
)
expect
(
owned_group_response
.
keys
).
to
contain_exactly
(
'id'
,
'kind'
,
'name'
,
'path'
,
'full_path'
,
'parent_id'
,
'members_count_with_descendants'
)
end
it
"does not returns members_count_with_descendants if user cannot admin group"
do
group1
.
add_guest
(
user
)
get
api
(
"/namespaces"
,
user
)
guest_group_response
=
json_response
.
find
{
|
resource
|
resource
[
'id'
]
==
group1
.
id
}
expect
(
guest_group_response
.
keys
).
to
contain_exactly
(
'id'
,
'kind'
,
'name'
,
'path'
,
'full_path'
,
'parent_id'
)
end
end
it
"user: returns an array of namespaces"
do
it
"user: returns an array of namespaces"
do
...
...
spec/requests/api/projects_spec.rb
View file @
bd4c2847
...
@@ -698,9 +698,7 @@ describe API::Projects do
...
@@ -698,9 +698,7 @@ describe API::Projects do
'name'
=>
user
.
namespace
.
name
,
'name'
=>
user
.
namespace
.
name
,
'path'
=>
user
.
namespace
.
path
,
'path'
=>
user
.
namespace
.
path
,
'kind'
=>
user
.
namespace
.
kind
,
'kind'
=>
user
.
namespace
.
kind
,
'full_path'
=>
user
.
namespace
.
full_path
,
'full_path'
=>
user
.
namespace
.
full_path
'parent_id'
=>
nil
,
'members_count'
=>
nil
})
})
end
end
...
...
spec/requests/api/v3/projects_spec.rb
View file @
bd4c2847
...
@@ -734,9 +734,7 @@ describe API::V3::Projects do
...
@@ -734,9 +734,7 @@ describe API::V3::Projects do
'name'
=>
user
.
namespace
.
name
,
'name'
=>
user
.
namespace
.
name
,
'path'
=>
user
.
namespace
.
path
,
'path'
=>
user
.
namespace
.
path
,
'kind'
=>
user
.
namespace
.
kind
,
'kind'
=>
user
.
namespace
.
kind
,
'full_path'
=>
user
.
namespace
.
full_path
,
'full_path'
=>
user
.
namespace
.
full_path
'parent_id'
=>
nil
,
'members_count'
=>
nil
})
})
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