grafana/pkg/models/dashboard_acl.go

102 lines
2.1 KiB
Go
Raw Normal View History

package models
2017-06-10 03:56:13 +08:00
import (
"errors"
"time"
)
type PermissionType int
const (
2017-06-10 03:56:13 +08:00
PERMISSION_VIEW PermissionType = 1 << iota
PERMISSION_EDIT
2017-06-21 05:18:20 +08:00
PERMISSION_ADMIN
)
func (p PermissionType) String() string {
names := map[int]string{
2017-06-21 05:18:20 +08:00
int(PERMISSION_VIEW): "View",
int(PERMISSION_EDIT): "Edit",
int(PERMISSION_ADMIN): "Admin",
}
return names[int(p)]
}
// Typed errors
2017-06-10 03:56:13 +08:00
var (
ErrDashboardAclInfoMissing = errors.New("User id and user group id cannot both be empty for a dashboard permission.")
ErrDashboardPermissionDashboardEmpty = errors.New("Dashboard Id must be greater than zero for a dashboard permission.")
2017-06-10 03:56:13 +08:00
)
// Dashboard ACL model
type DashboardAcl struct {
2017-06-20 06:19:58 +08:00
Id int64
OrgId int64
DashboardId int64
2017-06-20 06:19:58 +08:00
UserId int64
UserGroupId int64
2017-06-22 07:02:03 +08:00
Role RoleType
2017-06-22 02:11:16 +08:00
Permission PermissionType
2017-06-20 06:19:58 +08: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-21 05:18:20 +08:00
Role RoleType `json:"role"`
2017-06-22 02:11:16 +08:00
Permission PermissionType `json:"permission"`
2017-06-17 09:25:24 +08:00
PermissionName string `json:"permissionName"`
}
//
// COMMANDS
//
2017-06-22 07:02:03 +08:00
type UpdateDashboardAclCommand struct {
DashboardId int64
Items []*DashboardAcl
}
type SetDashboardAclCommand struct {
2017-06-22 07:02:03 +08:00
DashboardId int64
OrgId int64
UserId int64
UserGroupId int64
Permission PermissionType
2017-06-10 03:56:13 +08:00
2017-06-22 07:02:03 +08:00
Result DashboardAcl
}
type RemoveDashboardAclCommand struct {
AclId int64
OrgId int64
}
//
// QUERIES
//
2017-06-20 05:30:54 +08:00
type GetDashboardAclInfoListQuery struct {
2017-06-19 23:03:54 +08:00
DashboardId int64
Result []*DashboardAclInfoDTO
}
2017-06-19 23:03:54 +08:00
2017-06-19 23:54:37 +08:00
// Returns dashboard acl list items and parent folder items
type GetInheritedDashboardAclQuery struct {
2017-06-19 23:03:54 +08:00
DashboardId int64
2017-06-19 23:54:37 +08:00
OrgId int64
2017-06-19 23:03:54 +08:00
Result []*DashboardAcl
}