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
af23428c
Commit
af23428c
authored
May 13, 2021
by
Mario Celi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow reporters to read project statistics
- Change policies - Update specs - Update docs Changelog: changed
parent
d4d77888
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
9 deletions
+32
-9
app/policies/project_policy.rb
app/policies/project_policy.rb
+1
-1
doc/user/permissions.md
doc/user/permissions.md
+1
-1
spec/requests/api/graphql/project_query_spec.rb
spec/requests/api/graphql/project_query_spec.rb
+23
-0
spec/requests/api/project_statistics_spec.rb
spec/requests/api/project_statistics_spec.rb
+5
-5
spec/support/shared_contexts/policies/project_policy_shared_context.rb
...shared_contexts/policies/project_policy_shared_context.rb
+2
-2
No files found.
app/policies/project_policy.rb
View file @
af23428c
...
@@ -238,6 +238,7 @@ class ProjectPolicy < BasePolicy
...
@@ -238,6 +238,7 @@ class ProjectPolicy < BasePolicy
enable
:admin_issue_board
enable
:admin_issue_board
enable
:download_code
enable
:download_code
enable
:read_statistics
enable
:read_statistics
enable
:daily_statistics
enable
:download_wiki_code
enable
:download_wiki_code
enable
:create_snippet
enable
:create_snippet
enable
:update_issue
enable
:update_issue
...
@@ -347,7 +348,6 @@ class ProjectPolicy < BasePolicy
...
@@ -347,7 +348,6 @@ class ProjectPolicy < BasePolicy
enable
:update_deployment
enable
:update_deployment
enable
:create_release
enable
:create_release
enable
:update_release
enable
:update_release
enable
:daily_statistics
enable
:create_metrics_dashboard_annotation
enable
:create_metrics_dashboard_annotation
enable
:delete_metrics_dashboard_annotation
enable
:delete_metrics_dashboard_annotation
enable
:update_metrics_dashboard_annotation
enable
:update_metrics_dashboard_annotation
...
...
doc/user/permissions.md
View file @
af23428c
...
@@ -103,6 +103,7 @@ The following table lists project permissions available for each role:
...
@@ -103,6 +103,7 @@ The following table lists project permissions available for each role:
| Move
[
test case
](
../ci/test_cases/index.md
)
| | ✓ | ✓ | ✓ | ✓ |
| Move
[
test case
](
../ci/test_cases/index.md
)
| | ✓ | ✓ | ✓ | ✓ |
| Reopen
[
test case
](
../ci/test_cases/index.md
)
| | ✓ | ✓ | ✓ | ✓ |
| Reopen
[
test case
](
../ci/test_cases/index.md
)
| | ✓ | ✓ | ✓ | ✓ |
| Pull
[
packages
](
packages/index.md
)
| | ✓ | ✓ | ✓ | ✓ |
| Pull
[
packages
](
packages/index.md
)
| | ✓ | ✓ | ✓ | ✓ |
| View project statistics | | ✓ | ✓ | ✓ | ✓ |
| Publish
[
packages
](
packages/index.md
)
| | | ✓ | ✓ | ✓ |
| Publish
[
packages
](
packages/index.md
)
| | | ✓ | ✓ | ✓ |
| Create/edit/delete a Cleanup policy | | | ✓ | ✓ | ✓ |
| Create/edit/delete a Cleanup policy | | | ✓ | ✓ | ✓ |
| Upload
[
Design Management
](
project/issues/design_management.md
)
files | | | ✓ | ✓ | ✓ |
| Upload
[
Design Management
](
project/issues/design_management.md
)
files | | | ✓ | ✓ | ✓ |
...
@@ -119,7 +120,6 @@ The following table lists project permissions available for each role:
...
@@ -119,7 +120,6 @@ The following table lists project permissions available for each role:
| Lock merge request threads | | | ✓ | ✓ | ✓ |
| Lock merge request threads | | | ✓ | ✓ | ✓ |
| Approve merge requests (
*9*
) | | | ✓ | ✓ | ✓ |
| Approve merge requests (
*9*
) | | | ✓ | ✓ | ✓ |
| Manage/Accept merge requests | | | ✓ | ✓ | ✓ |
| Manage/Accept merge requests | | | ✓ | ✓ | ✓ |
| View project statistics | | | ✓ | ✓ | ✓ |
| Create new environments | | | ✓ | ✓ | ✓ |
| Create new environments | | | ✓ | ✓ | ✓ |
| Stop environments | | | ✓ | ✓ | ✓ |
| Stop environments | | | ✓ | ✓ | ✓ |
| Enable Review Apps | | | ✓ | ✓ | ✓ |
| Enable Review Apps | | | ✓ | ✓ | ✓ |
...
...
spec/requests/api/graphql/project_query_spec.rb
View file @
af23428c
...
@@ -119,6 +119,29 @@ RSpec.describe 'getting project information' do
...
@@ -119,6 +119,29 @@ RSpec.describe 'getting project information' do
end
end
end
end
context
'when the user has reporter access to the project'
do
let
(
:statistics_query
)
do
<<~
GRAPHQL
{
project(fullPath: "
#{
project
.
full_path
}
") {
statistics { wikiSize }
}
}
GRAPHQL
end
before
do
project
.
add_reporter
(
current_user
)
create
(
:project_statistics
,
project:
project
,
wiki_size:
100
)
end
it
'allows fetching project statistics'
do
post_graphql
(
statistics_query
,
current_user:
current_user
)
expect
(
graphql_data
.
dig
(
'project'
,
'statistics'
)).
to
include
(
'wikiSize'
=>
100.0
)
end
end
context
'when the user does not have access to the project'
do
context
'when the user does not have access to the project'
do
it
'returns an empty field'
do
it
'returns an empty field'
do
post_graphql
(
query
,
current_user:
current_user
)
post_graphql
(
query
,
current_user:
current_user
)
...
...
spec/requests/api/project_statistics_spec.rb
View file @
af23428c
...
@@ -3,11 +3,11 @@
...
@@ -3,11 +3,11 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
API
::
ProjectStatistics
do
RSpec
.
describe
API
::
ProjectStatistics
do
let_it_be
(
:
develop
er
)
{
create
(
:user
)
}
let_it_be
(
:
report
er
)
{
create
(
:user
)
}
let_it_be
(
:public_project
)
{
create
(
:project
,
:public
)
}
let_it_be
(
:public_project
)
{
create
(
:project
,
:public
)
}
before
do
before
do
public_project
.
add_
developer
(
develop
er
)
public_project
.
add_
reporter
(
report
er
)
end
end
describe
'GET /projects/:id/statistics'
do
describe
'GET /projects/:id/statistics'
do
...
@@ -19,7 +19,7 @@ RSpec.describe API::ProjectStatistics do
...
@@ -19,7 +19,7 @@ RSpec.describe API::ProjectStatistics do
let_it_be
(
:fetch_statistics_other_project
)
{
create
(
:project_daily_statistic
,
project:
create
(
:project
),
fetch_count:
29
,
date:
29
.
days
.
ago
)
}
let_it_be
(
:fetch_statistics_other_project
)
{
create
(
:project_daily_statistic
,
project:
create
(
:project
),
fetch_count:
29
,
date:
29
.
days
.
ago
)
}
it
'returns the fetch statistics of the last 30 days'
do
it
'returns the fetch statistics of the last 30 days'
do
get
api
(
"/projects/
#{
public_project
.
id
}
/statistics"
,
develop
er
)
get
api
(
"/projects/
#{
public_project
.
id
}
/statistics"
,
report
er
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
fetches
=
json_response
[
'fetches'
]
fetches
=
json_response
[
'fetches'
]
...
@@ -32,7 +32,7 @@ RSpec.describe API::ProjectStatistics do
...
@@ -32,7 +32,7 @@ RSpec.describe API::ProjectStatistics do
it
'excludes the fetch statistics older than 30 days'
do
it
'excludes the fetch statistics older than 30 days'
do
create
(
:project_daily_statistic
,
fetch_count:
31
,
project:
public_project
,
date:
30
.
days
.
ago
)
create
(
:project_daily_statistic
,
fetch_count:
31
,
project:
public_project
,
date:
30
.
days
.
ago
)
get
api
(
"/projects/
#{
public_project
.
id
}
/statistics"
,
develop
er
)
get
api
(
"/projects/
#{
public_project
.
id
}
/statistics"
,
report
er
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
fetches
=
json_response
[
'fetches'
]
fetches
=
json_response
[
'fetches'
]
...
@@ -41,7 +41,7 @@ RSpec.describe API::ProjectStatistics do
...
@@ -41,7 +41,7 @@ RSpec.describe API::ProjectStatistics do
expect
(
fetches
[
'days'
].
last
).
to
eq
({
'count'
=>
fetch_statistics1
.
fetch_count
,
'date'
=>
fetch_statistics1
.
date
.
to_s
})
expect
(
fetches
[
'days'
].
last
).
to
eq
({
'count'
=>
fetch_statistics1
.
fetch_count
,
'date'
=>
fetch_statistics1
.
date
.
to_s
})
end
end
it
'responds with 403 when the user is not a
develop
er of the repository'
do
it
'responds with 403 when the user is not a
report
er of the repository'
do
guest
=
create
(
:user
)
guest
=
create
(
:user
)
public_project
.
add_guest
(
guest
)
public_project
.
add_guest
(
guest
)
...
...
spec/support/shared_contexts/policies/project_policy_shared_context.rb
View file @
af23428c
...
@@ -26,7 +26,7 @@ RSpec.shared_context 'ProjectPolicy context' do
...
@@ -26,7 +26,7 @@ RSpec.shared_context 'ProjectPolicy context' do
let
(
:base_reporter_permissions
)
do
let
(
:base_reporter_permissions
)
do
%i[
%i[
admin_issue admin_issue_link admin_label admin_issue_board_list create_snippet
admin_issue admin_issue_link admin_label admin_issue_board_list create_snippet
download_code download_wiki_code fork_project metrics_dashboard
d
aily_statistics d
ownload_code download_wiki_code fork_project metrics_dashboard
read_build read_commit_status read_confidential_issues
read_build read_commit_status read_confidential_issues
read_container_image read_deployment read_environment read_merge_request
read_container_image read_deployment read_environment read_merge_request
read_metrics_dashboard_annotation read_pipeline read_prometheus
read_metrics_dashboard_annotation read_pipeline read_prometheus
...
@@ -44,7 +44,7 @@ RSpec.shared_context 'ProjectPolicy context' do
...
@@ -44,7 +44,7 @@ RSpec.shared_context 'ProjectPolicy context' do
create_commit_status create_container_image create_deployment
create_commit_status create_container_image create_deployment
create_environment create_merge_request_from
create_environment create_merge_request_from
create_metrics_dashboard_annotation create_pipeline create_release
create_metrics_dashboard_annotation create_pipeline create_release
create_wiki d
aily_statistics d
elete_metrics_dashboard_annotation
create_wiki delete_metrics_dashboard_annotation
destroy_container_image push_code read_pod_logs read_terraform_state
destroy_container_image push_code read_pod_logs read_terraform_state
resolve_note update_build update_commit_status update_container_image
resolve_note update_build update_commit_status update_container_image
update_deployment update_environment update_merge_request
update_deployment update_environment update_merge_request
...
...
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