Merge branch 'develop' into apikey_hashed
Conflicts: pkg/api/apikey.go pkg/services/sqlstore/migrations.go
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Typed errors
|
||||
var (
|
||||
ErrAccountNotFound = errors.New("Account not found")
|
||||
)
|
||||
|
||||
type Account struct {
|
||||
Id int64
|
||||
Version int
|
||||
Name string
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
}
|
||||
|
||||
// ---------------------
|
||||
// COMMANDS
|
||||
|
||||
type CreateAccountCommand struct {
|
||||
Name string `json:"name" binding:"Required"`
|
||||
|
||||
// initial admin user for account
|
||||
UserId int64 `json:"-"`
|
||||
Result Account `json:"-"`
|
||||
}
|
||||
|
||||
type UpdateAccountCommand struct {
|
||||
Name string `json:"name" binding:"Required"`
|
||||
AccountId int64 `json:"-"`
|
||||
}
|
||||
|
||||
type GetUserAccountsQuery struct {
|
||||
UserId int64
|
||||
Result []*UserAccountDTO
|
||||
}
|
||||
|
||||
type GetAccountByIdQuery struct {
|
||||
Id int64
|
||||
Result *Account
|
||||
}
|
||||
|
||||
type GetAccountByNameQuery struct {
|
||||
Name string
|
||||
Result *Account
|
||||
}
|
||||
|
||||
type AccountDTO struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type UserAccountDTO struct {
|
||||
AccountId int64 `json:"accountId"`
|
||||
Name string `json:"name"`
|
||||
Role RoleType `json:"role"`
|
||||
IsUsing bool `json:"isUsing"`
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Typed errors
|
||||
var (
|
||||
ErrInvalidRoleType = errors.New("Invalid role type")
|
||||
ErrLastAccountAdmin = errors.New("Cannot remove last account admin")
|
||||
)
|
||||
|
||||
type RoleType string
|
||||
|
||||
const (
|
||||
ROLE_VIEWER RoleType = "Viewer"
|
||||
ROLE_EDITOR RoleType = "Editor"
|
||||
ROLE_ADMIN RoleType = "Admin"
|
||||
)
|
||||
|
||||
func (r RoleType) IsValid() bool {
|
||||
return r == ROLE_VIEWER || r == ROLE_ADMIN || r == ROLE_EDITOR
|
||||
}
|
||||
|
||||
type AccountUser struct {
|
||||
AccountId int64
|
||||
UserId int64
|
||||
Role RoleType
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
}
|
||||
|
||||
// ---------------------
|
||||
// COMMANDS
|
||||
|
||||
type RemoveAccountUserCommand struct {
|
||||
UserId int64
|
||||
AccountId int64
|
||||
}
|
||||
|
||||
type AddAccountUserCommand struct {
|
||||
LoginOrEmail string `json:"loginOrEmail" binding:"Required"`
|
||||
Role RoleType `json:"role" binding:"Required"`
|
||||
|
||||
AccountId int64 `json:"-"`
|
||||
UserId int64 `json:"-"`
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
// QUERIES
|
||||
|
||||
type GetAccountUsersQuery struct {
|
||||
AccountId int64
|
||||
Result []*AccountUserDTO
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
// Projections and DTOs
|
||||
|
||||
type AccountUserDTO struct {
|
||||
AccountId int64 `json:"accountId"`
|
||||
UserId int64 `json:"userId"`
|
||||
Email string `json:"email"`
|
||||
Login string `json:"login"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
+16
-16
@@ -8,22 +8,22 @@ import (
|
||||
var ErrInvalidApiKey = errors.New("Invalid API Key")
|
||||
|
||||
type ApiKey struct {
|
||||
Id int64
|
||||
AccountId int64
|
||||
Name string
|
||||
Key string
|
||||
Role RoleType
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
Id int64
|
||||
OrgId int64
|
||||
Name string
|
||||
Key string
|
||||
Role RoleType
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
}
|
||||
|
||||
// ---------------------
|
||||
// COMMANDS
|
||||
type AddApiKeyCommand struct {
|
||||
Name string `json:"name" binding:"Required"`
|
||||
Role RoleType `json:"role" binding:"Required"`
|
||||
AccountId int64 `json:"-"`
|
||||
Key string `json:"-"`
|
||||
Name string `json:"name" binding:"Required"`
|
||||
Role RoleType `json:"role" binding:"Required"`
|
||||
OrgId int64 `json:"-"`
|
||||
Key string `json:"-"`
|
||||
|
||||
Result *ApiKey `json:"-"`
|
||||
}
|
||||
@@ -33,20 +33,20 @@ type UpdateApiKeyCommand struct {
|
||||
Name string `json:"name"`
|
||||
Role RoleType `json:"role"`
|
||||
|
||||
AccountId int64 `json:"-"`
|
||||
OrgId int64 `json:"-"`
|
||||
}
|
||||
|
||||
type DeleteApiKeyCommand struct {
|
||||
Id int64 `json:"id"`
|
||||
AccountId int64 `json:"-"`
|
||||
Id int64 `json:"id"`
|
||||
OrgId int64 `json:"-"`
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
// QUERIES
|
||||
|
||||
type GetApiKeysQuery struct {
|
||||
AccountId int64
|
||||
Result []*ApiKey
|
||||
OrgId int64
|
||||
Result []*ApiKey
|
||||
}
|
||||
|
||||
type GetApiKeyByKeyQuery struct {
|
||||
|
||||
+10
-10
@@ -14,10 +14,10 @@ var (
|
||||
)
|
||||
|
||||
type Dashboard struct {
|
||||
Id int64
|
||||
Slug string
|
||||
AccountId int64
|
||||
Version int
|
||||
Id int64
|
||||
Slug string
|
||||
OrgId int64
|
||||
Version int
|
||||
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
@@ -53,7 +53,7 @@ func (cmd *SaveDashboardCommand) GetDashboardModel() *Dashboard {
|
||||
dash := &Dashboard{}
|
||||
dash.Data = cmd.Dashboard
|
||||
dash.Title = dash.Data["title"].(string)
|
||||
dash.AccountId = cmd.AccountId
|
||||
dash.OrgId = cmd.OrgId
|
||||
dash.UpdateSlug()
|
||||
|
||||
if dash.Data["id"] != nil {
|
||||
@@ -80,14 +80,14 @@ func (dash *Dashboard) UpdateSlug() {
|
||||
|
||||
type SaveDashboardCommand struct {
|
||||
Dashboard map[string]interface{} `json:"dashboard"`
|
||||
AccountId int64 `json:"-"`
|
||||
OrgId int64 `json:"-"`
|
||||
|
||||
Result *Dashboard
|
||||
}
|
||||
|
||||
type DeleteDashboardCommand struct {
|
||||
Slug string
|
||||
AccountId int64
|
||||
Slug string
|
||||
OrgId int64
|
||||
}
|
||||
|
||||
//
|
||||
@@ -95,8 +95,8 @@ type DeleteDashboardCommand struct {
|
||||
//
|
||||
|
||||
type GetDashboardQuery struct {
|
||||
Slug string
|
||||
AccountId int64
|
||||
Slug string
|
||||
OrgId int64
|
||||
|
||||
Result *Dashboard
|
||||
}
|
||||
|
||||
+20
-12
@@ -8,7 +8,9 @@ import (
|
||||
const (
|
||||
DS_GRAPHITE = "graphite"
|
||||
DS_INFLUXDB = "influxdb"
|
||||
DS_INFLUXDB_08 = "influxdb_08"
|
||||
DS_ES = "elasticsearch"
|
||||
DS_OPENTSDB = "opentsdb"
|
||||
DS_ACCESS_DIRECT = "direct"
|
||||
DS_ACCESS_PROXY = "proxy"
|
||||
)
|
||||
@@ -22,9 +24,9 @@ type DsType string
|
||||
type DsAccess string
|
||||
|
||||
type DataSource struct {
|
||||
Id int64
|
||||
AccountId int64
|
||||
Version int
|
||||
Id int64
|
||||
OrgId int64
|
||||
Version int
|
||||
|
||||
Name string
|
||||
Type DsType
|
||||
@@ -47,7 +49,7 @@ type DataSource struct {
|
||||
|
||||
// Also acts as api DTO
|
||||
type AddDataSourceCommand struct {
|
||||
AccountId int64 `json:"-"`
|
||||
OrgId int64 `json:"-"`
|
||||
Name string
|
||||
Type DsType
|
||||
Access DsAccess
|
||||
@@ -63,7 +65,7 @@ type AddDataSourceCommand struct {
|
||||
// Also acts as api DTO
|
||||
type UpdateDataSourceCommand struct {
|
||||
Id int64
|
||||
AccountId int64
|
||||
OrgId int64
|
||||
Name string
|
||||
Type DsType
|
||||
Access DsAccess
|
||||
@@ -75,22 +77,28 @@ type UpdateDataSourceCommand struct {
|
||||
}
|
||||
|
||||
type DeleteDataSourceCommand struct {
|
||||
Id int64
|
||||
AccountId int64
|
||||
Id int64
|
||||
OrgId int64
|
||||
}
|
||||
|
||||
// ---------------------
|
||||
// QUERIES
|
||||
|
||||
type GetDataSourcesQuery struct {
|
||||
AccountId int64
|
||||
Result []*DataSource
|
||||
OrgId int64
|
||||
Result []*DataSource
|
||||
}
|
||||
|
||||
type GetDataSourceByIdQuery struct {
|
||||
Id int64
|
||||
AccountId int64
|
||||
Result DataSource
|
||||
Id int64
|
||||
OrgId int64
|
||||
Result DataSource
|
||||
}
|
||||
|
||||
type GetDataSourceByNameQuery struct {
|
||||
Name string
|
||||
OrgId int64
|
||||
Result DataSource
|
||||
}
|
||||
|
||||
// ---------------------
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Typed errors
|
||||
var (
|
||||
ErrOrgNotFound = errors.New("Organization not found")
|
||||
)
|
||||
|
||||
type Org struct {
|
||||
Id int64
|
||||
Version int
|
||||
Name string
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
}
|
||||
|
||||
// ---------------------
|
||||
// COMMANDS
|
||||
|
||||
type CreateOrgCommand struct {
|
||||
Name string `json:"name" binding:"Required"`
|
||||
|
||||
// initial admin user for account
|
||||
UserId int64 `json:"-"`
|
||||
Result Org `json:"-"`
|
||||
}
|
||||
|
||||
type DeleteOrgCommand struct {
|
||||
Id int64
|
||||
}
|
||||
|
||||
type UpdateOrgCommand struct {
|
||||
Name string `json:"name" binding:"Required"`
|
||||
OrgId int64 `json:"-"`
|
||||
}
|
||||
|
||||
type GetOrgByIdQuery struct {
|
||||
Id int64
|
||||
Result *Org
|
||||
}
|
||||
|
||||
type GetOrgByNameQuery struct {
|
||||
Name string
|
||||
Result *Org
|
||||
}
|
||||
|
||||
type GetOrgListQuery struct {
|
||||
Result []*Org
|
||||
}
|
||||
|
||||
type OrgDTO struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type UserOrgDTO struct {
|
||||
OrgId int64 `json:"orgId"`
|
||||
Name string `json:"name"`
|
||||
Role RoleType `json:"role"`
|
||||
IsUsing bool `json:"isUsing"`
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Typed errors
|
||||
var (
|
||||
ErrInvalidRoleType = errors.New("Invalid role type")
|
||||
ErrLastOrgAdmin = errors.New("Cannot remove last organization admin")
|
||||
)
|
||||
|
||||
type RoleType string
|
||||
|
||||
const (
|
||||
ROLE_VIEWER RoleType = "Viewer"
|
||||
ROLE_EDITOR RoleType = "Editor"
|
||||
ROLE_ADMIN RoleType = "Admin"
|
||||
)
|
||||
|
||||
func (r RoleType) IsValid() bool {
|
||||
return r == ROLE_VIEWER || r == ROLE_ADMIN || r == ROLE_EDITOR
|
||||
}
|
||||
|
||||
type OrgUser struct {
|
||||
OrgId int64
|
||||
UserId int64
|
||||
Role RoleType
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
}
|
||||
|
||||
// ---------------------
|
||||
// COMMANDS
|
||||
|
||||
type RemoveOrgUserCommand struct {
|
||||
UserId int64
|
||||
OrgId int64
|
||||
}
|
||||
|
||||
type AddOrgUserCommand struct {
|
||||
LoginOrEmail string `json:"loginOrEmail" binding:"Required"`
|
||||
Role RoleType `json:"role" binding:"Required"`
|
||||
|
||||
OrgId int64 `json:"-"`
|
||||
UserId int64 `json:"-"`
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
// QUERIES
|
||||
|
||||
type GetOrgUsersQuery struct {
|
||||
OrgId int64
|
||||
Result []*OrgUserDTO
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
// Projections and DTOs
|
||||
|
||||
type OrgUserDTO struct {
|
||||
OrgId int64 `json:"orgId"`
|
||||
UserId int64 `json:"userId"`
|
||||
Email string `json:"email"`
|
||||
Login string `json:"login"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
@@ -11,7 +11,6 @@ type DashboardSearchHit struct {
|
||||
Title string `json:"title"`
|
||||
Slug string `json:"slug"`
|
||||
Tags []string `json:"tags"`
|
||||
Url string `json:"url"`
|
||||
IsStarred bool `json:"isStarred"`
|
||||
}
|
||||
|
||||
@@ -23,7 +22,7 @@ type DashboardTagCloudItem struct {
|
||||
type SearchDashboardsQuery struct {
|
||||
Title string
|
||||
Tag string
|
||||
AccountId int64
|
||||
OrgId int64
|
||||
UserId int64
|
||||
Limit int
|
||||
IsStarred bool
|
||||
@@ -32,6 +31,6 @@ type SearchDashboardsQuery struct {
|
||||
}
|
||||
|
||||
type GetDashboardTagsQuery struct {
|
||||
AccountId int64
|
||||
Result []*DashboardTagCloudItem
|
||||
OrgId int64
|
||||
Result []*DashboardTagCloudItem
|
||||
}
|
||||
|
||||
+49
-20
@@ -11,18 +11,20 @@ var (
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Id int64
|
||||
Version int
|
||||
Email string
|
||||
Name string
|
||||
Login string
|
||||
Password string
|
||||
Salt string
|
||||
Rands string
|
||||
Company string
|
||||
Id int64
|
||||
Version int
|
||||
Email string
|
||||
Name string
|
||||
Login string
|
||||
Password string
|
||||
Salt string
|
||||
Rands string
|
||||
Company string
|
||||
EmailVerified bool
|
||||
Theme string
|
||||
|
||||
IsAdmin bool
|
||||
AccountId int64
|
||||
IsAdmin bool
|
||||
OrgId int64
|
||||
|
||||
Created time.Time
|
||||
Updated time.Time
|
||||
@@ -50,9 +52,25 @@ type UpdateUserCommand struct {
|
||||
UserId int64 `json:"-"`
|
||||
}
|
||||
|
||||
type SetUsingAccountCommand struct {
|
||||
UserId int64
|
||||
AccountId int64
|
||||
type ChangeUserPasswordCommand struct {
|
||||
OldPassword string `json:"oldPassword"`
|
||||
NewPassword string `json:"newPassword"`
|
||||
|
||||
UserId int64 `json:"-"`
|
||||
}
|
||||
|
||||
type UpdateUserPermissionsCommand struct {
|
||||
IsGrafanaAdmin bool
|
||||
UserId int64 `json:"-"`
|
||||
}
|
||||
|
||||
type DeleteUserCommand struct {
|
||||
UserId int64
|
||||
}
|
||||
|
||||
type SetUsingOrgCommand struct {
|
||||
UserId int64
|
||||
OrgId int64
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
@@ -63,6 +81,11 @@ type GetUserByLoginQuery struct {
|
||||
Result *User
|
||||
}
|
||||
|
||||
type GetUserByIdQuery struct {
|
||||
Id int64
|
||||
Result *User
|
||||
}
|
||||
|
||||
type GetSignedInUserQuery struct {
|
||||
UserId int64
|
||||
Result *SignedInUser
|
||||
@@ -81,14 +104,19 @@ type SearchUsersQuery struct {
|
||||
Result []*UserSearchHitDTO
|
||||
}
|
||||
|
||||
type GetUserOrgListQuery struct {
|
||||
UserId int64
|
||||
Result []*UserOrgDTO
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
// DTO & Projections
|
||||
|
||||
type SignedInUser struct {
|
||||
UserId int64
|
||||
AccountId int64
|
||||
AccountName string
|
||||
AccountRole RoleType
|
||||
OrgId int64
|
||||
OrgName string
|
||||
OrgRole RoleType
|
||||
Login string
|
||||
Name string
|
||||
Email string
|
||||
@@ -97,9 +125,10 @@ type SignedInUser struct {
|
||||
}
|
||||
|
||||
type UserDTO struct {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Login string `json:"login"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Login string `json:"login"`
|
||||
IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
|
||||
}
|
||||
|
||||
type UserSearchHitDTO struct {
|
||||
|
||||
Reference in New Issue
Block a user