Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
12a6de74
Commit
12a6de74
authored
Feb 12, 2018
by
Marcus Efraimsson
Committed by
Torkel Ödegaard
Feb 12, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: always make sure dashboard exist in dashboard acl http api (#10856)
parent
1b795c0c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
0 deletions
+57
-0
pkg/api/dashboard_acl.go
+15
-0
pkg/api/dashboard_acl_test.go
+42
-0
No files found.
pkg/api/dashboard_acl.go
View file @
12a6de74
...
...
@@ -13,6 +13,11 @@ import (
func
GetDashboardAclList
(
c
*
middleware
.
Context
)
Response
{
dashId
:=
c
.
ParamsInt64
(
":dashboardId"
)
_
,
rsp
:=
getDashboardHelper
(
c
.
OrgId
,
""
,
dashId
,
""
)
if
rsp
!=
nil
{
return
rsp
}
guardian
:=
guardian
.
NewDashboardGuardian
(
dashId
,
c
.
OrgId
,
c
.
SignedInUser
)
if
canAdmin
,
err
:=
guardian
.
CanAdmin
();
err
!=
nil
||
!
canAdmin
{
...
...
@@ -36,6 +41,11 @@ func GetDashboardAclList(c *middleware.Context) Response {
func
UpdateDashboardAcl
(
c
*
middleware
.
Context
,
apiCmd
dtos
.
UpdateDashboardAclCommand
)
Response
{
dashId
:=
c
.
ParamsInt64
(
":dashboardId"
)
_
,
rsp
:=
getDashboardHelper
(
c
.
OrgId
,
""
,
dashId
,
""
)
if
rsp
!=
nil
{
return
rsp
}
guardian
:=
guardian
.
NewDashboardGuardian
(
dashId
,
c
.
OrgId
,
c
.
SignedInUser
)
if
canAdmin
,
err
:=
guardian
.
CanAdmin
();
err
!=
nil
||
!
canAdmin
{
return
dashboardGuardianResponse
(
err
)
...
...
@@ -79,6 +89,11 @@ func DeleteDashboardAcl(c *middleware.Context) Response {
dashId
:=
c
.
ParamsInt64
(
":dashboardId"
)
aclId
:=
c
.
ParamsInt64
(
":aclId"
)
_
,
rsp
:=
getDashboardHelper
(
c
.
OrgId
,
""
,
dashId
,
""
)
if
rsp
!=
nil
{
return
rsp
}
guardian
:=
guardian
.
NewDashboardGuardian
(
dashId
,
c
.
OrgId
,
c
.
SignedInUser
)
if
canAdmin
,
err
:=
guardian
.
CanAdmin
();
err
!=
nil
||
!
canAdmin
{
return
dashboardGuardianResponse
(
err
)
...
...
pkg/api/dashboard_acl_test.go
View file @
12a6de74
...
...
@@ -23,6 +23,14 @@ func TestDashboardAclApiEndpoint(t *testing.T) {
}
dtoRes
:=
transformDashboardAclsToDTOs
(
mockResult
)
getDashboardQueryResult
:=
m
.
NewDashboard
(
"Dash"
)
var
getDashboardNotFoundError
error
bus
.
AddHandler
(
"test"
,
func
(
query
*
m
.
GetDashboardQuery
)
error
{
query
.
Result
=
getDashboardQueryResult
return
getDashboardNotFoundError
})
bus
.
AddHandler
(
"test"
,
func
(
query
*
m
.
GetDashboardAclInfoListQuery
)
error
{
query
.
Result
=
dtoRes
return
nil
...
...
@@ -60,6 +68,40 @@ func TestDashboardAclApiEndpoint(t *testing.T) {
So
(
respJSON
.
GetIndex
(
0
)
.
Get
(
"permission"
)
.
MustInt
(),
ShouldEqual
,
m
.
PERMISSION_VIEW
)
})
})
loggedInUserScenarioWithRole
(
"When calling GET on"
,
"GET"
,
"/api/dashboards/id/2/acl"
,
"/api/dashboards/id/:dashboardId/acl"
,
m
.
ROLE_ADMIN
,
func
(
sc
*
scenarioContext
)
{
getDashboardNotFoundError
=
m
.
ErrDashboardNotFound
sc
.
handlerFunc
=
GetDashboardAclList
sc
.
fakeReqWithParams
(
"GET"
,
sc
.
url
,
map
[
string
]
string
{})
.
exec
()
Convey
(
"Should not be able to access ACL"
,
func
()
{
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
404
)
})
})
Convey
(
"Should not be able to update permissions for non-existing dashboard"
,
func
()
{
cmd
:=
dtos
.
UpdateDashboardAclCommand
{
Items
:
[]
dtos
.
DashboardAclUpdateItem
{
{
UserId
:
1000
,
Permission
:
m
.
PERMISSION_ADMIN
},
},
}
postAclScenario
(
"When calling POST on"
,
"/api/dashboards/id/1/acl"
,
"/api/dashboards/id/:dashboardId/acl"
,
m
.
ROLE_ADMIN
,
cmd
,
func
(
sc
*
scenarioContext
)
{
getDashboardNotFoundError
=
m
.
ErrDashboardNotFound
CallPostAcl
(
sc
)
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
404
)
})
})
loggedInUserScenarioWithRole
(
"When calling DELETE on"
,
"DELETE"
,
"/api/dashboards/id/2/acl/6"
,
"/api/dashboards/id/:dashboardId/acl/:aclId"
,
m
.
ROLE_ADMIN
,
func
(
sc
*
scenarioContext
)
{
getDashboardNotFoundError
=
m
.
ErrDashboardNotFound
sc
.
handlerFunc
=
DeleteDashboardAcl
sc
.
fakeReqWithParams
(
"DELETE"
,
sc
.
url
,
map
[
string
]
string
{})
.
exec
()
Convey
(
"Should not be able to delete non-existing dashboard"
,
func
()
{
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
404
)
})
})
})
Convey
(
"When user is org editor and has admin permission in the ACL"
,
func
()
{
...
...
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