grafana/pkg/models/dashboard_acl.go

94 lines
2.0 KiB
Go
Raw Normal View History

package models
2017-06-09 14:56:13 -05:00
import (
"errors"
"time"
)
type PermissionType int
const (
2017-06-09 14:56:13 -05:00
PERMISSION_VIEW PermissionType = 1 << iota
PERMISSION_READ_ONLY_EDIT
2017-06-09 14:56:13 -05:00
PERMISSION_EDIT
)
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",
}
return names[int(p)]
}
// Typed errors
2017-06-09 14:56:13 -05:00
var (
2017-06-19 17:19:58 -05:00
ErrDashboardAclInfoMissing = errors.New("User id and user group id cannot both be empty for a dashboard permission.")
2017-06-09 14:56:13 -05:00
)
// Dashboard ACL model
type DashboardAcl struct {
2017-06-19 17:19:58 -05:00
Id int64
OrgId int64
DashboardId int64
2017-06-19 17:19:58 -05:00
UserId int64
UserGroupId int64
Permissions PermissionType
2017-06-19 17:19:58 -05:00
Created time.Time
Updated time.Time
}
type DashboardAclInfoDTO struct {
Id int64 `json:"id"`
OrgId int64 `json:"-"`
DashboardId int64 `json:"dashboardId"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
UserId int64 `json:"userId"`
UserLogin string `json:"userLogin"`
UserEmail string `json:"userEmail"`
UserGroupId int64 `json:"userGroupId"`
UserGroup string `json:"userGroup"`
2017-06-16 20:25:24 -05:00
Permissions PermissionType `json:"permissions"`
PermissionName string `json:"permissionName"`
}
//
// COMMANDS
//
type SetDashboardAclCommand struct {
2017-06-17 17:24:38 -05:00
DashboardId int64 `json:"-"`
OrgId int64 `json:"-"`
UserId int64 `json:"userId"`
UserGroupId int64 `json:"userGroupId"`
Permissions PermissionType `json:"permissions" binding:"Required"`
2017-06-09 14:56:13 -05:00
Result DashboardAcl `json:"-"`
}
type RemoveDashboardAclCommand struct {
AclId int64
OrgId int64
}
//
// QUERIES
//
2017-06-19 16:30:54 -05:00
type GetDashboardAclInfoListQuery struct {
2017-06-19 10:03:54 -05:00
DashboardId int64
Result []*DashboardAclInfoDTO
}
2017-06-19 10:03:54 -05:00
2017-06-19 10:54:37 -05:00
// Returns dashboard acl list items and parent folder items
type GetInheritedDashboardAclQuery struct {
2017-06-19 10:03:54 -05:00
DashboardId int64
2017-06-19 10:54:37 -05:00
OrgId int64
2017-06-19 10:03:54 -05:00
Result []*DashboardAcl
}