dashboard acl work
This commit is contained in:
@@ -23,7 +23,39 @@ func GetDashboardAclList(c *middleware.Context) Response {
|
||||
return ApiError(500, "Failed to get Dashboard ACL", err)
|
||||
}
|
||||
|
||||
return Json(200, &query.Result)
|
||||
list := query.Result
|
||||
hasViewRoleAcl := false
|
||||
hasEditRoleAcl := false
|
||||
|
||||
for _, item := range list {
|
||||
if item.Role == m.ROLE_EDITOR {
|
||||
hasEditRoleAcl = true
|
||||
}
|
||||
if item.Role == m.ROLE_VIEWER {
|
||||
hasViewRoleAcl = true
|
||||
}
|
||||
}
|
||||
|
||||
if !hasEditRoleAcl {
|
||||
tmpList := append([]*m.DashboardAclInfoDTO{}, &m.DashboardAclInfoDTO{
|
||||
Id: 0,
|
||||
Role: m.ROLE_EDITOR,
|
||||
Permissions: m.PERMISSION_EDIT,
|
||||
PermissionName: "Edit",
|
||||
})
|
||||
list = append(tmpList, list...)
|
||||
}
|
||||
if !hasViewRoleAcl {
|
||||
tmpList := append([]*m.DashboardAclInfoDTO{}, &m.DashboardAclInfoDTO{
|
||||
Id: 0,
|
||||
Role: m.ROLE_VIEWER,
|
||||
Permissions: m.PERMISSION_VIEW,
|
||||
PermissionName: "View",
|
||||
})
|
||||
list = append(tmpList, list...)
|
||||
}
|
||||
|
||||
return Json(200, list)
|
||||
}
|
||||
|
||||
func PostDashboardAcl(c *middleware.Context, cmd m.SetDashboardAclCommand) Response {
|
||||
|
||||
@@ -8,16 +8,18 @@ import (
|
||||
type PermissionType int
|
||||
|
||||
const (
|
||||
PERMISSION_NONE = 0
|
||||
PERMISSION_VIEW PermissionType = 1 << iota
|
||||
PERMISSION_READ_ONLY_EDIT
|
||||
PERMISSION_EDIT
|
||||
PERMISSION_ADMIN
|
||||
)
|
||||
|
||||
func (p PermissionType) String() string {
|
||||
names := map[int]string{
|
||||
int(PERMISSION_VIEW): "View",
|
||||
int(PERMISSION_READ_ONLY_EDIT): "Read-only Edit",
|
||||
int(PERMISSION_EDIT): "Edit",
|
||||
int(PERMISSION_NONE): "None",
|
||||
int(PERMISSION_VIEW): "View",
|
||||
int(PERMISSION_EDIT): "Edit",
|
||||
int(PERMISSION_ADMIN): "Admin",
|
||||
}
|
||||
return names[int(p)]
|
||||
}
|
||||
@@ -55,6 +57,7 @@ type DashboardAclInfoDTO struct {
|
||||
UserEmail string `json:"userEmail"`
|
||||
UserGroupId int64 `json:"userGroupId"`
|
||||
UserGroup string `json:"userGroup"`
|
||||
Role RoleType `json:"role"`
|
||||
Permissions PermissionType `json:"permissions"`
|
||||
PermissionName string `json:"permissionName"`
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func (g *DashboardGuardian) CanSave() (bool, error) {
|
||||
}
|
||||
|
||||
func (g *DashboardGuardian) CanEdit() (bool, error) {
|
||||
return g.HasPermission(m.PERMISSION_READ_ONLY_EDIT, m.ROLE_READ_ONLY_EDITOR)
|
||||
return g.HasPermission(m.PERMISSION_EDIT, m.ROLE_READ_ONLY_EDITOR)
|
||||
}
|
||||
|
||||
func (g *DashboardGuardian) CanView() (bool, error) {
|
||||
|
||||
Reference in New Issue
Block a user