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
28cdd8aa
Commit
28cdd8aa
authored
Nov 07, 2019
by
Ryan Cobb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add can_edit to metric dashboard endpoint
parent
359c524e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
8 deletions
+25
-8
app/controllers/concerns/metrics_dashboard.rb
app/controllers/concerns/metrics_dashboard.rb
+11
-3
spec/controllers/concerns/metrics_dashboard_spec.rb
spec/controllers/concerns/metrics_dashboard_spec.rb
+14
-5
No files found.
app/controllers/concerns/metrics_dashboard.rb
View file @
28cdd8aa
...
...
@@ -35,15 +35,23 @@ module MetricsDashboard
def
all_dashboards
dashboards
=
dashboard_finder
.
find_all_paths
(
project_for_dashboard
)
dashboards
.
map
do
|
dashboard
|
dashboard
[
:edit_path
]
=
edit_path
(
dashboard
)
dashboard
[
:can_edit
]
=
can_edit?
(
dashboard
)
dashboard
[
:project_blob_path
]
=
project_blob_path
(
dashboard
)
dashboard
end
end
def
edit_path
(
dashboard
)
def
can_edit?
(
dashboard
)
return
false
unless
project_for_dashboard
return
false
if
dashboard
[
:system_dashboard
]
return
false
unless
can_collaborate_with_project?
(
project_for_dashboard
,
ref:
project_for_dashboard
.
default_branch
)
true
end
def
project_blob_path
(
dashboard
)
return
unless
project_for_dashboard
return
if
dashboard
[
:system_dashboard
]
return
unless
can_collaborate_with_project?
(
project_for_dashboard
,
ref:
project_for_dashboard
.
default_branch
)
Gitlab
::
Routing
.
url_helpers
.
project_blob_path
(
project_for_dashboard
,
File
.
join
(
project_for_dashboard
.
default_branch
,
dashboard
[
:path
]))
end
...
...
spec/controllers/concerns/metrics_dashboard_spec.rb
View file @
28cdd8aa
...
...
@@ -67,10 +67,18 @@ describe MetricsDashboard do
end
context
'in all_dashboard list'
do
let
(
:system_dashboard
)
{
json_response
[
'all_dashboards'
][
0
]
}
let
(
:project_dashboard
)
{
json_response
[
'all_dashboards'
][
1
]
}
it
'includes project_blob_path only for project dashboards'
do
expect
(
system_dashboard
[
'project_blob_path'
]).
to
be_nil
expect
(
project_dashboard
[
'project_blob_path'
]).
to
eq
(
"/
#{
project
.
namespace
.
path
}
/
#{
project
.
name
}
/blob/master/.gitlab/dashboards/test.yml"
)
end
context
'when a user can collaborate on project'
do
it
'
includes edit_path only
for project dashboards'
do
expect
(
json_response
[
'all_dashboards'
][
0
][
'edit_path'
]).
to
be_nil
expect
(
json_response
[
'all_dashboards'
][
1
][
'edit_path'
]).
to
eq
(
"/
#{
project
.
namespace
.
path
}
/
#{
project
.
name
}
/blob/master/.gitlab/dashboards/test.yml"
)
it
'
sets can_edit to true
for project dashboards'
do
expect
(
system_dashboard
[
'can_edit'
]).
to
eq
(
false
)
expect
(
project_dashboard
[
'can_edit'
]).
to
eq
(
true
)
end
end
...
...
@@ -79,8 +87,9 @@ describe MetricsDashboard do
allow
(
controller
).
to
receive
(
:can_collaborate_with_project?
).
and_return
(
false
)
end
it
'does not include edit_path for project dashboards'
do
expect
(
json_response
[
'all_dashboards'
][
1
][
'edit_path'
]).
to
be_nil
it
'sets can_edit to false for project dashboards'
do
expect
(
system_dashboard
[
'can_edit'
]).
to
eq
(
false
)
expect
(
project_dashboard
[
'can_edit'
]).
to
eq
(
false
)
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