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
f6b52cd6
Commit
f6b52cd6
authored
Jun 22, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dashboard_folders' of github.com:grafana/grafana into dashboard_folders
parents
a82b25eb
46c5625b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
9 deletions
+66
-9
pkg/services/sqlstore/dashboard.go
+4
-4
pkg/services/sqlstore/dashboard_test.go
+62
-5
No files found.
pkg/services/sqlstore/dashboard.go
View file @
f6b52cd6
...
...
@@ -204,12 +204,12 @@ func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSear
allowedDashboardsSubQuery
:=
` AND (dashboard.has_acl = 0 OR dashboard.id in (
SELECT distinct d.id AS DashboardId
FROM dashboard AS d
LEFT JOIN dashboard AS df ON d.parent_id = df.
id
LEFT JOIN dashboard_acl as dfa on d.parent_id = dfa.dashboard_id or d.id = dfa.dashboard
_id
LEFT JOIN user_group_member as ugm on ugm.user_group_id = dfa.user_group_id
LEFT JOIN dashboard_acl as da on d.parent_id = da.dashboard_id or d.id = da.dashboard_
id
LEFT JOIN user_group_member as ugm on ugm.user_group_id = da.user_group
_id
LEFT JOIN org_user ou on ou.role = da.role
WHERE
d.has_acl = 1 and
(d
fa.user_id = ? or ugm.user_id = ?
)
(d
a.user_id = ? or ugm.user_id = ? or ou.id is not null
)
and d.org_id = ?
))`
...
...
pkg/services/sqlstore/dashboard_test.go
View file @
f6b52cd6
...
...
@@ -297,10 +297,10 @@ func TestDashboardDataAccess(t *testing.T) {
})
})
Convey
(
"Given one dashboard folder with two dashboard and one dashboard in the root folder"
,
func
()
{
Convey
(
"Given one dashboard folder with two dashboard
s
and one dashboard in the root folder"
,
func
()
{
folder
:=
insertTestDashboard
(
"1 test dash folder"
,
1
,
0
,
true
,
"prod"
,
"webapp"
)
dashInRoot
:=
insertTestDashboard
(
"test dash 67"
,
1
,
0
,
false
,
"prod"
,
"webapp"
)
insertTestDashboard
(
"test dash 23"
,
1
,
folder
.
Id
,
false
,
"prod"
,
"webapp"
)
childDash
:=
insertTestDashboard
(
"test dash 23"
,
1
,
folder
.
Id
,
false
,
"prod"
,
"webapp"
)
insertTestDashboard
(
"test dash 45"
,
1
,
folder
.
Id
,
false
,
"prod"
)
currentUser
:=
createUser
(
"viewer"
,
"Viewer"
,
false
)
...
...
@@ -360,6 +360,54 @@ func TestDashboardDataAccess(t *testing.T) {
})
})
})
Convey
(
"and acl is set for dashboard child and folder has all permissions removed"
,
func
()
{
var
otherUser
int64
=
999
aclId
:=
updateTestDashboardWithAcl
(
folder
.
Id
,
otherUser
,
m
.
PERMISSION_EDIT
)
removeAcl
(
aclId
)
updateTestDashboardWithAcl
(
childDash
.
Id
,
otherUser
,
m
.
PERMISSION_EDIT
)
Convey
(
"should not return folder or child"
,
func
()
{
query
:=
&
search
.
FindPersistedDashboardsQuery
{
SignedInUser
:
&
m
.
SignedInUser
{
UserId
:
currentUser
.
Id
,
OrgId
:
1
},
OrgId
:
1
,
DashboardIds
:
[]
int64
{
folder
.
Id
,
childDash
.
Id
,
dashInRoot
.
Id
}}
err
:=
SearchDashboards
(
query
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
1
)
So
(
query
.
Result
[
0
]
.
Id
,
ShouldEqual
,
dashInRoot
.
Id
)
})
Convey
(
"when the user is given permission to child"
,
func
()
{
updateTestDashboardWithAcl
(
childDash
.
Id
,
currentUser
.
Id
,
m
.
PERMISSION_EDIT
)
Convey
(
"should be able to search for child dashboard but not folder"
,
func
()
{
query
:=
&
search
.
FindPersistedDashboardsQuery
{
SignedInUser
:
&
m
.
SignedInUser
{
UserId
:
currentUser
.
Id
,
OrgId
:
1
},
OrgId
:
1
,
DashboardIds
:
[]
int64
{
folder
.
Id
,
childDash
.
Id
,
dashInRoot
.
Id
}}
err
:=
SearchDashboards
(
query
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
2
)
So
(
query
.
Result
[
0
]
.
Id
,
ShouldEqual
,
childDash
.
Id
)
So
(
query
.
Result
[
1
]
.
Id
,
ShouldEqual
,
dashInRoot
.
Id
)
})
})
Convey
(
"when the user is an admin"
,
func
()
{
Convey
(
"should be able to search for child dash and folder"
,
func
()
{
query
:=
&
search
.
FindPersistedDashboardsQuery
{
SignedInUser
:
&
m
.
SignedInUser
{
UserId
:
currentUser
.
Id
,
OrgId
:
1
,
OrgRole
:
m
.
ROLE_ADMIN
,
},
OrgId
:
1
,
DashboardIds
:
[]
int64
{
folder
.
Id
,
dashInRoot
.
Id
,
childDash
.
Id
},
}
err
:=
SearchDashboards
(
query
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
3
)
So
(
query
.
Result
[
0
]
.
Id
,
ShouldEqual
,
folder
.
Id
)
So
(
query
.
Result
[
1
]
.
Id
,
ShouldEqual
,
childDash
.
Id
)
So
(
query
.
Result
[
2
]
.
Id
,
ShouldEqual
,
dashInRoot
.
Id
)
})
})
})
})
})
}
...
...
@@ -379,12 +427,21 @@ func createUser(name string, role string, isAdmin bool) m.User {
return
currentUserCmd
.
Result
}
func
updateTestDashboardWithAcl
(
dashId
int64
,
userId
int64
,
permissions
m
.
PermissionType
)
{
err
:=
SetDashboardAcl
(
&
m
.
SetDashboardAclCommand
{
func
updateTestDashboardWithAcl
(
dashId
int64
,
userId
int64
,
permissions
m
.
PermissionType
)
int64
{
cmd
:=
&
m
.
SetDashboardAclCommand
{
OrgId
:
1
,
UserId
:
userId
,
DashboardId
:
dashId
,
Permission
:
permissions
,
})
}
err
:=
SetDashboardAcl
(
cmd
)
So
(
err
,
ShouldBeNil
)
return
cmd
.
Result
.
Id
}
func
removeAcl
(
aclId
int64
)
{
err
:=
RemoveDashboardAcl
(
&
m
.
RemoveDashboardAclCommand
{
AclId
:
aclId
,
OrgId
:
1
})
So
(
err
,
ShouldBeNil
)
}
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