2017-04-28 14:22:53 -05:00
|
|
|
package models
|
|
|
|
|
2017-06-09 14:56:13 -05:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"time"
|
|
|
|
)
|
2017-04-28 14:22:53 -05:00
|
|
|
|
|
|
|
type PermissionType int
|
|
|
|
|
|
|
|
const (
|
2017-06-09 14:56:13 -05:00
|
|
|
PERMISSION_VIEW PermissionType = 1 << iota
|
|
|
|
PERMISSION_EDIT
|
2017-06-20 16:18:20 -05:00
|
|
|
PERMISSION_ADMIN
|
2017-04-28 14:22:53 -05:00
|
|
|
)
|
|
|
|
|
2017-06-08 03:39:17 -05:00
|
|
|
func (p PermissionType) String() string {
|
|
|
|
names := map[int]string{
|
2017-06-20 16:18:20 -05:00
|
|
|
int(PERMISSION_VIEW): "View",
|
|
|
|
int(PERMISSION_EDIT): "Edit",
|
|
|
|
int(PERMISSION_ADMIN): "Admin",
|
2017-06-08 03:39:17 -05:00
|
|
|
}
|
|
|
|
return names[int(p)]
|
|
|
|
}
|
|
|
|
|
2017-04-28 14:22:53 -05:00
|
|
|
// Typed errors
|
2017-06-09 14:56:13 -05:00
|
|
|
var (
|
2017-12-08 09:25:45 -06:00
|
|
|
ErrDashboardAclInfoMissing = errors.New("User id and team id cannot both be empty for a dashboard permission.")
|
2017-06-19 17:55:34 -05:00
|
|
|
ErrDashboardPermissionDashboardEmpty = errors.New("Dashboard Id must be greater than zero for a dashboard permission.")
|
2017-06-09 14:56:13 -05:00
|
|
|
)
|
2017-04-28 14:22:53 -05:00
|
|
|
|
|
|
|
// Dashboard ACL model
|
|
|
|
type DashboardAcl struct {
|
2017-06-19 17:19:58 -05:00
|
|
|
Id int64
|
|
|
|
OrgId int64
|
|
|
|
DashboardId int64
|
2017-05-08 08:35:34 -05:00
|
|
|
|
2017-12-11 10:46:05 -06:00
|
|
|
UserId int64
|
|
|
|
TeamId int64
|
|
|
|
Role *RoleType // pointer to be nullable
|
|
|
|
Permission PermissionType
|
2017-05-08 08:35:34 -05:00
|
|
|
|
2017-06-19 17:19:58 -05:00
|
|
|
Created time.Time
|
|
|
|
Updated time.Time
|
2017-05-08 08:35:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type DashboardAclInfoDTO struct {
|
|
|
|
Id int64 `json:"id"`
|
|
|
|
OrgId int64 `json:"-"`
|
|
|
|
DashboardId int64 `json:"dashboardId"`
|
2017-04-28 14:22:53 -05:00
|
|
|
|
2017-05-08 08:35:34 -05:00
|
|
|
Created time.Time `json:"created"`
|
|
|
|
Updated time.Time `json:"updated"`
|
2017-04-28 14:22:53 -05:00
|
|
|
|
2017-06-08 03:39:17 -05:00
|
|
|
UserId int64 `json:"userId"`
|
|
|
|
UserLogin string `json:"userLogin"`
|
|
|
|
UserEmail string `json:"userEmail"`
|
2017-12-11 10:46:05 -06:00
|
|
|
TeamId int64 `json:"teamId"`
|
|
|
|
Team string `json:"team"`
|
2017-06-22 16:10:43 -05:00
|
|
|
Role *RoleType `json:"role,omitempty"`
|
2017-06-21 13:11:16 -05:00
|
|
|
Permission PermissionType `json:"permission"`
|
2017-06-16 20:25:24 -05:00
|
|
|
PermissionName string `json:"permissionName"`
|
2017-04-28 14:22:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// COMMANDS
|
|
|
|
//
|
|
|
|
|
2017-06-21 18:02:03 -05:00
|
|
|
type UpdateDashboardAclCommand struct {
|
|
|
|
DashboardId int64
|
|
|
|
Items []*DashboardAcl
|
|
|
|
}
|
|
|
|
|
2017-06-19 16:15:25 -05:00
|
|
|
type SetDashboardAclCommand struct {
|
2017-06-21 18:02:03 -05:00
|
|
|
DashboardId int64
|
|
|
|
OrgId int64
|
|
|
|
UserId int64
|
2017-12-11 10:46:05 -06:00
|
|
|
TeamId int64
|
2017-06-21 18:02:03 -05:00
|
|
|
Permission PermissionType
|
2017-06-09 14:56:13 -05:00
|
|
|
|
2017-06-21 18:02:03 -05:00
|
|
|
Result DashboardAcl
|
2017-04-28 14:22:53 -05:00
|
|
|
}
|
|
|
|
|
2017-06-19 16:15:25 -05:00
|
|
|
type RemoveDashboardAclCommand struct {
|
2017-06-19 17:11:30 -05:00
|
|
|
AclId int64
|
|
|
|
OrgId int64
|
2017-05-03 04:32:21 -05:00
|
|
|
}
|
|
|
|
|
2017-04-28 14:22:53 -05:00
|
|
|
//
|
|
|
|
// QUERIES
|
|
|
|
//
|
2017-06-19 16:30:54 -05:00
|
|
|
type GetDashboardAclInfoListQuery struct {
|
2017-06-19 10:03:54 -05:00
|
|
|
DashboardId int64
|
2017-06-19 10:54:37 -05:00
|
|
|
OrgId int64
|
2017-06-22 16:10:43 -05:00
|
|
|
Result []*DashboardAclInfoDTO
|
2017-06-19 10:03:54 -05:00
|
|
|
}
|