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
|
2017-06-08 03:39:17 -05:00
|
|
|
PERMISSION_READ_ONLY_EDIT
|
2017-06-09 14:56:13 -05:00
|
|
|
PERMISSION_EDIT
|
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{
|
|
|
|
int(PERMISSION_VIEW): "View",
|
|
|
|
int(PERMISSION_READ_ONLY_EDIT): "Read-only Edit",
|
|
|
|
int(PERMISSION_EDIT): "Edit",
|
|
|
|
}
|
|
|
|
return names[int(p)]
|
|
|
|
}
|
|
|
|
|
2017-04-28 14:22:53 -05:00
|
|
|
// Typed errors
|
2017-06-09 14:56:13 -05:00
|
|
|
var (
|
2017-06-14 16:45:30 -05:00
|
|
|
ErrDashboardPermissionUserOrUserGroupEmpty = errors.New("User id and user group id cannot both be empty 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-05-08 08:35:34 -05:00
|
|
|
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"`
|
|
|
|
UserGroupId int64 `json:"userGroupId"`
|
|
|
|
Permissions PermissionType `json:"permissions"`
|
|
|
|
}
|
|
|
|
|
|
|
|
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"`
|
|
|
|
UserGroupId int64 `json:"userGroupId"`
|
|
|
|
UserGroup string `json:"userGroup"`
|
2017-06-16 20:25:24 -05:00
|
|
|
Permissions PermissionType `json:"permissions"`
|
|
|
|
PermissionName string `json:"permissionName"`
|
2017-04-28 14:22:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// COMMANDS
|
|
|
|
//
|
|
|
|
|
|
|
|
type AddOrUpdateDashboardPermissionCommand struct {
|
2017-06-09 14:56:13 -05:00
|
|
|
DashboardId int64 `json:"-"`
|
2017-04-28 14:22:53 -05:00
|
|
|
OrgId int64 `json:"-"`
|
|
|
|
UserId int64 `json:"userId"`
|
|
|
|
UserGroupId int64 `json:"userGroupId"`
|
|
|
|
PermissionType PermissionType `json:"permissionType" binding:"Required"`
|
2017-06-09 14:56:13 -05:00
|
|
|
|
|
|
|
Result DashboardAcl `json:"-"`
|
2017-04-28 14:22:53 -05:00
|
|
|
}
|
|
|
|
|
2017-05-03 04:32:21 -05:00
|
|
|
type RemoveDashboardPermissionCommand struct {
|
|
|
|
DashboardId int64 `json:"dashboardId" binding:"Required"`
|
|
|
|
OrgId int64 `json:"-"`
|
|
|
|
UserId int64 `json:"userId"`
|
|
|
|
UserGroupId int64 `json:"userGroupId"`
|
|
|
|
}
|
|
|
|
|
2017-04-28 14:22:53 -05:00
|
|
|
//
|
|
|
|
// QUERIES
|
|
|
|
//
|
|
|
|
|
|
|
|
type GetDashboardPermissionsQuery struct {
|
|
|
|
DashboardId int64 `json:"dashboardId" binding:"Required"`
|
2017-05-08 08:35:34 -05:00
|
|
|
Result []*DashboardAclInfoDTO
|
2017-04-28 14:22:53 -05:00
|
|
|
}
|