Commit 7e2e57c3 by Daniel Lee

dashfolders: fixes #10671. Allow Editors default access to Root.

Editors should be able to create dashboards in root and should be
able to create folders. They cannot administrate permissions though
and these dashboards and folders will get the default permissions.
parent 2409d129
...@@ -126,14 +126,10 @@ func RemoveDashboardAcl(cmd *m.RemoveDashboardAclCommand) error { ...@@ -126,14 +126,10 @@ func RemoveDashboardAcl(cmd *m.RemoveDashboardAclCommand) error {
} }
func GetDashboardAclInfoList(query *m.GetDashboardAclInfoListQuery) error { func GetDashboardAclInfoList(query *m.GetDashboardAclInfoListQuery) error {
dashboardFilter := fmt.Sprintf(`IN ( var err error
SELECT %d
UNION if query.DashboardId == 0 {
SELECT folder_id from dashboard where id = %d sql := `SELECT
)`, query.DashboardId, query.DashboardId)
rawSQL := `
SELECT
da.id, da.id,
da.org_id, da.org_id,
da.dashboard_id, da.dashboard_id,
...@@ -143,44 +139,71 @@ func GetDashboardAclInfoList(query *m.GetDashboardAclInfoListQuery) error { ...@@ -143,44 +139,71 @@ func GetDashboardAclInfoList(query *m.GetDashboardAclInfoListQuery) error {
da.role, da.role,
da.created, da.created,
da.updated, da.updated,
u.login AS user_login, '' as user_login,
u.email AS user_email, '' as user_email,
ug.name AS team '' as team
FROM` + dialect.Quote("dashboard_acl") + ` as da FROM dashboard_acl as da
LEFT OUTER JOIN ` + dialect.Quote("user") + ` AS u ON u.id = da.user_id WHERE da.dashboard_id = -1`
LEFT OUTER JOIN team ug on ug.id = da.team_id query.Result = make([]*m.DashboardAclInfoDTO, 0)
WHERE dashboard_id ` + dashboardFilter + ` AND da.org_id = ? err = x.SQL(sql).Find(&query.Result)
-- Also include default permission if has_acl = 0 } else {
dashboardFilter := fmt.Sprintf(`IN (
UNION SELECT %d
SELECT UNION
da.id, SELECT folder_id from dashboard where id = %d
da.org_id, )`, query.DashboardId, query.DashboardId)
da.dashboard_id,
da.user_id, rawSQL := `
da.team_id, SELECT
da.permission, da.id,
da.role, da.org_id,
da.created, da.dashboard_id,
da.updated, da.user_id,
'' as user_login, da.team_id,
'' as user_email, da.permission,
'' as team da.role,
FROM dashboard_acl as da, da.created,
dashboard as dash da.updated,
LEFT JOIN dashboard folder on dash.folder_id = folder.id u.login AS user_login,
WHERE u.email AS user_email,
dash.id = ? AND ( ug.name AS team
dash.has_acl = ` + dialect.BooleanStr(false) + ` or FROM` + dialect.Quote("dashboard_acl") + ` as da
folder.has_acl = ` + dialect.BooleanStr(false) + ` LEFT OUTER JOIN ` + dialect.Quote("user") + ` AS u ON u.id = da.user_id
) AND LEFT OUTER JOIN team ug on ug.id = da.team_id
da.dashboard_id = -1 WHERE dashboard_id ` + dashboardFilter + ` AND da.org_id = ?
ORDER BY 1 ASC
` -- Also include default permission if has_acl = 0
query.Result = make([]*m.DashboardAclInfoDTO, 0) UNION
err := x.SQL(rawSQL, query.OrgId, query.DashboardId).Find(&query.Result) SELECT
da.id,
da.org_id,
da.dashboard_id,
da.user_id,
da.team_id,
da.permission,
da.role,
da.created,
da.updated,
'' as user_login,
'' as user_email,
'' as team
FROM dashboard_acl as da,
dashboard as dash
LEFT JOIN dashboard folder on dash.folder_id = folder.id
WHERE
dash.id = ? AND (
dash.has_acl = ` + dialect.BooleanStr(false) + ` or
folder.has_acl = ` + dialect.BooleanStr(false) + `
) AND
da.dashboard_id = -1
ORDER BY 1 ASC
`
query.Result = make([]*m.DashboardAclInfoDTO, 0)
err = x.SQL(rawSQL, query.OrgId, query.DashboardId).Find(&query.Result)
}
for _, p := range query.Result { for _, p := range query.Result {
p.PermissionName = p.Permission.String() p.PermissionName = p.Permission.String()
......
...@@ -232,5 +232,23 @@ func TestDashboardAclDataAccess(t *testing.T) { ...@@ -232,5 +232,23 @@ func TestDashboardAclDataAccess(t *testing.T) {
}) })
}) })
Convey("Given a root folder", func() {
var rootFolderId int64 = 0
Convey("When reading dashboard acl should return default permissions", func() {
query := m.GetDashboardAclInfoListQuery{DashboardId: rootFolderId, OrgId: 1}
err := GetDashboardAclInfoList(&query)
So(err, ShouldBeNil)
So(len(query.Result), ShouldEqual, 2)
defaultPermissionsId := -1
So(query.Result[0].DashboardId, ShouldEqual, defaultPermissionsId)
So(*query.Result[0].Role, ShouldEqual, m.ROLE_VIEWER)
So(query.Result[1].DashboardId, ShouldEqual, defaultPermissionsId)
So(*query.Result[1].Role, ShouldEqual, m.ROLE_EDITOR)
})
})
}) })
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment