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
95bbb475
Commit
95bbb475
authored
May 13, 2021
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add repository diskPath parameter to GraphQL API
If user has admin porject permissions it will see the disk path
parent
4b9a92b0
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
65 additions
and
0 deletions
+65
-0
app/graphql/types/repository_type.rb
app/graphql/types/repository_type.rb
+4
-0
app/policies/project_policy.rb
app/policies/project_policy.rb
+1
-0
changelogs/unreleased/29861-hashed-storage-add-disk-path-to-rest-api.yml
...leased/29861-hashed-storage-add-disk-path-to-rest-api.yml
+5
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+1
-0
spec/graphql/types/repository_type_spec.rb
spec/graphql/types/repository_type_spec.rb
+2
-0
spec/policies/project_policy_spec.rb
spec/policies/project_policy_spec.rb
+28
-0
spec/requests/api/graphql/project/repository_spec.rb
spec/requests/api/graphql/project/repository_spec.rb
+24
-0
No files found.
app/graphql/types/repository_type.rb
View file @
95bbb475
...
...
@@ -19,5 +19,9 @@ module Types
field
:branch_names
,
[
GraphQL
::
STRING_TYPE
],
null:
true
,
calls_gitaly:
true
,
complexity:
170
,
description:
'Names of branches available in this repository that match the search pattern.'
,
resolver:
Resolvers
::
RepositoryBranchNamesResolver
field
:disk_path
,
GraphQL
::
STRING_TYPE
,
description:
'Shows a disk path of the repository.'
,
null:
true
,
authorize: :read_storage_disk_path
end
end
app/policies/project_policy.rb
View file @
95bbb475
...
...
@@ -171,6 +171,7 @@ class ProjectPolicy < BasePolicy
rule
{
guest
|
admin
}.
enable
:read_project_for_iids
rule
{
admin
}.
enable
:update_max_artifacts_size
rule
{
admin
}.
enable
:read_storage_disk_path
rule
{
can?
(
:read_all_resources
)
}.
enable
:read_confidential_issues
rule
{
guest
}.
enable
:guest_access
...
...
changelogs/unreleased/29861-hashed-storage-add-disk-path-to-rest-api.yml
0 → 100644
View file @
95bbb475
---
title
:
Add repository diskPath parameter to GraphQL API
merge_request
:
61725
author
:
type
:
added
doc/api/graphql/reference/index.md
View file @
95bbb475
...
...
@@ -11826,6 +11826,7 @@ Represents the source code attached to a release in a particular format.
| Name | Type | Description |
| ---- | ---- | ----------- |
|
<a
id=
"repositorydiskpath"
></a>
`diskPath`
|
[
`String`
](
#string
)
| Shows a disk path of the repository. |
|
<a
id=
"repositoryempty"
></a>
`empty`
|
[
`Boolean!`
](
#boolean
)
| Indicates repository has no visible content. |
|
<a
id=
"repositoryexists"
></a>
`exists`
|
[
`Boolean!`
](
#boolean
)
| Indicates a corresponding Git repository exists on disk. |
|
<a
id=
"repositoryrootref"
></a>
`rootRef`
|
[
`String`
](
#string
)
| Default branch of the repository. |
...
...
spec/graphql/types/repository_type_spec.rb
View file @
95bbb475
...
...
@@ -16,4 +16,6 @@ RSpec.describe GitlabSchema.types['Repository'] do
specify
{
expect
(
described_class
).
to
have_graphql_field
(
:blobs
)
}
specify
{
expect
(
described_class
).
to
have_graphql_field
(
:branch_names
,
calls_gitaly?:
true
,
complexity:
170
)
}
specify
{
expect
(
described_class
).
to
have_graphql_field
(
:disk_path
)
}
end
spec/policies/project_policy_spec.rb
View file @
95bbb475
...
...
@@ -393,6 +393,34 @@ RSpec.describe ProjectPolicy do
end
end
describe
'read_storage_disk_path'
do
context
'when no user'
do
let
(
:current_user
)
{
anonymous
}
it
{
expect_disallowed
(
:read_storage_disk_path
)
}
end
context
'admin'
do
let
(
:current_user
)
{
admin
}
context
'when admin mode is enabled'
,
:enable_admin_mode
do
it
{
expect_allowed
(
:read_storage_disk_path
)
}
end
context
'when admin mode is disabled'
do
it
{
expect_disallowed
(
:read_storage_disk_path
)
}
end
end
%w(guest reporter developer maintainer owner)
.
each
do
|
role
|
context
role
do
let
(
:current_user
)
{
send
(
role
)
}
it
{
expect_disallowed
(
:read_storage_disk_path
)
}
end
end
end
context
'alert bot'
do
let
(
:current_user
)
{
User
.
alert_bot
}
...
...
spec/requests/api/graphql/project/repository_spec.rb
View file @
95bbb475
...
...
@@ -36,6 +36,30 @@ RSpec.describe 'getting a repository in a project' do
end
end
context
'as a non-admin'
do
let
(
:current_user
)
{
create
(
:user
)
}
before
do
project
.
add_role
(
current_user
,
:developer
)
end
it
'does not return diskPath'
do
post_graphql
(
query
,
current_user:
current_user
)
expect
(
graphql_data
[
'project'
][
'repository'
]).
not_to
be_nil
expect
(
graphql_data
[
'project'
][
'repository'
][
'diskPath'
]).
to
be_nil
end
end
context
'as an admin'
do
it
'returns diskPath'
do
post_graphql
(
query
,
current_user:
create
(
:admin
))
expect
(
graphql_data
[
'project'
][
'repository'
]).
not_to
be_nil
expect
(
graphql_data
[
'project'
][
'repository'
][
'diskPath'
]).
to
eq
project
.
disk_path
end
end
context
'when the repository is only accessible to members'
do
let
(
:project
)
do
create
(
:project
,
:public
,
:repository
,
repository_access_level:
ProjectFeature
::
PRIVATE
)
...
...
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