Chore: Remove dashboards from models pkg (#61578)
* Copy dashboard models to dashboard pkg * Use some models from current pkg instead of models * Adjust api pkg * Adjust pkg services * Fix lint * Chore: Remove dashboards models * Remove dashboards from models pkg * Fix lint in tests * Fix lint in tests 2 * Fix for import in auth * Remove newline * Revert unused fix
This commit is contained in:
@@ -18,7 +18,7 @@ type DashboardService interface {
|
||||
GetDashboard(ctx context.Context, query *GetDashboardQuery) error
|
||||
GetDashboardACLInfoList(ctx context.Context, query *models.GetDashboardACLInfoListQuery) error
|
||||
GetDashboards(ctx context.Context, query *GetDashboardsQuery) error
|
||||
GetDashboardTags(ctx context.Context, query *models.GetDashboardTagsQuery) error
|
||||
GetDashboardTags(ctx context.Context, query *GetDashboardTagsQuery) error
|
||||
GetDashboardUIDByID(ctx context.Context, query *GetDashboardRefByIDQuery) error
|
||||
HasAdminPermissionInDashboardsOrFolders(ctx context.Context, query *models.HasAdminPermissionInDashboardsOrFoldersQuery) error
|
||||
HasEditPermissionInFolders(ctx context.Context, query *models.HasEditPermissionInFoldersQuery) error
|
||||
@@ -33,18 +33,18 @@ type DashboardService interface {
|
||||
|
||||
// PluginService is a service for operating on plugin dashboards.
|
||||
type PluginService interface {
|
||||
GetDashboardsByPluginID(ctx context.Context, query *models.GetDashboardsByPluginIdQuery) error
|
||||
GetDashboardsByPluginID(ctx context.Context, query *GetDashboardsByPluginIDQuery) error
|
||||
}
|
||||
|
||||
// DashboardProvisioningService is a service for operating on provisioned dashboards.
|
||||
//
|
||||
//go:generate mockery --name DashboardProvisioningService --structname FakeDashboardProvisioning --inpackage --filename dashboard_provisioning_mock.go
|
||||
type DashboardProvisioningService interface {
|
||||
DeleteOrphanedProvisionedDashboards(ctx context.Context, cmd *models.DeleteOrphanedProvisionedDashboardsCommand) error
|
||||
DeleteOrphanedProvisionedDashboards(ctx context.Context, cmd *DeleteOrphanedProvisionedDashboardsCommand) error
|
||||
DeleteProvisionedDashboard(ctx context.Context, dashboardID int64, orgID int64) error
|
||||
GetProvisionedDashboardData(ctx context.Context, name string) ([]*models.DashboardProvisioning, error)
|
||||
GetProvisionedDashboardDataByDashboardID(ctx context.Context, dashboardID int64) (*models.DashboardProvisioning, error)
|
||||
GetProvisionedDashboardDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*models.DashboardProvisioning, error)
|
||||
GetProvisionedDashboardData(ctx context.Context, name string) ([]*DashboardProvisioning, error)
|
||||
GetProvisionedDashboardDataByDashboardID(ctx context.Context, dashboardID int64) (*DashboardProvisioning, error)
|
||||
GetProvisionedDashboardDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*DashboardProvisioning, error)
|
||||
SaveFolderForProvisionedDashboards(context.Context, *SaveDashboardDTO) (*Dashboard, error)
|
||||
SaveProvisionedDashboard(ctx context.Context, dto *SaveDashboardDTO, provisioning *DashboardProvisioning) (*Dashboard, error)
|
||||
UnprovisionDashboard(ctx context.Context, dashboardID int64) error
|
||||
@@ -54,19 +54,19 @@ type DashboardProvisioningService interface {
|
||||
//
|
||||
//go:generate mockery --name Store --structname FakeDashboardStore --inpackage --filename store_mock.go
|
||||
type Store interface {
|
||||
DeleteDashboard(ctx context.Context, cmd *models.DeleteDashboardCommand) error
|
||||
DeleteOrphanedProvisionedDashboards(ctx context.Context, cmd *models.DeleteOrphanedProvisionedDashboardsCommand) error
|
||||
DeleteDashboard(ctx context.Context, cmd *DeleteDashboardCommand) error
|
||||
DeleteOrphanedProvisionedDashboards(ctx context.Context, cmd *DeleteOrphanedProvisionedDashboardsCommand) error
|
||||
FindDashboards(ctx context.Context, query *models.FindPersistedDashboardsQuery) ([]DashboardSearchProjection, error)
|
||||
GetDashboard(ctx context.Context, query *GetDashboardQuery) (*Dashboard, error)
|
||||
GetDashboardACLInfoList(ctx context.Context, query *models.GetDashboardACLInfoListQuery) error
|
||||
GetDashboardUIDByID(ctx context.Context, query *GetDashboardRefByIDQuery) error
|
||||
GetDashboards(ctx context.Context, query *GetDashboardsQuery) error
|
||||
// GetDashboardsByPluginID retrieves dashboards identified by plugin.
|
||||
GetDashboardsByPluginID(ctx context.Context, query *models.GetDashboardsByPluginIdQuery) error
|
||||
GetDashboardTags(ctx context.Context, query *models.GetDashboardTagsQuery) error
|
||||
GetProvisionedDashboardData(ctx context.Context, name string) ([]*models.DashboardProvisioning, error)
|
||||
GetProvisionedDataByDashboardID(ctx context.Context, dashboardID int64) (*models.DashboardProvisioning, error)
|
||||
GetProvisionedDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*models.DashboardProvisioning, error)
|
||||
GetDashboardsByPluginID(ctx context.Context, query *GetDashboardsByPluginIDQuery) error
|
||||
GetDashboardTags(ctx context.Context, query *GetDashboardTagsQuery) error
|
||||
GetProvisionedDashboardData(ctx context.Context, name string) ([]*DashboardProvisioning, error)
|
||||
GetProvisionedDataByDashboardID(ctx context.Context, dashboardID int64) (*DashboardProvisioning, error)
|
||||
GetProvisionedDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*DashboardProvisioning, error)
|
||||
HasAdminPermissionInDashboardsOrFolders(ctx context.Context, query *models.HasAdminPermissionInDashboardsOrFoldersQuery) error
|
||||
HasEditPermissionInFolders(ctx context.Context, query *models.HasEditPermissionInFoldersQuery) error
|
||||
// SaveAlerts saves dashboard alerts.
|
||||
|
||||
@@ -5,7 +5,6 @@ package dashboards
|
||||
import (
|
||||
context "context"
|
||||
|
||||
models "github.com/grafana/grafana/pkg/models"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
@@ -15,11 +14,11 @@ type FakeDashboardProvisioning struct {
|
||||
}
|
||||
|
||||
// DeleteOrphanedProvisionedDashboards provides a mock function with given fields: ctx, cmd
|
||||
func (_m *FakeDashboardProvisioning) DeleteOrphanedProvisionedDashboards(ctx context.Context, cmd *models.DeleteOrphanedProvisionedDashboardsCommand) error {
|
||||
func (_m *FakeDashboardProvisioning) DeleteOrphanedProvisionedDashboards(ctx context.Context, cmd *DeleteOrphanedProvisionedDashboardsCommand) error {
|
||||
ret := _m.Called(ctx, cmd)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *models.DeleteOrphanedProvisionedDashboardsCommand) error); ok {
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *DeleteOrphanedProvisionedDashboardsCommand) error); ok {
|
||||
r0 = rf(ctx, cmd)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
@@ -43,15 +42,15 @@ func (_m *FakeDashboardProvisioning) DeleteProvisionedDashboard(ctx context.Cont
|
||||
}
|
||||
|
||||
// GetProvisionedDashboardData provides a mock function with given fields: ctx, name
|
||||
func (_m *FakeDashboardProvisioning) GetProvisionedDashboardData(ctx context.Context, name string) ([]*models.DashboardProvisioning, error) {
|
||||
func (_m *FakeDashboardProvisioning) GetProvisionedDashboardData(ctx context.Context, name string) ([]*DashboardProvisioning, error) {
|
||||
ret := _m.Called(ctx, name)
|
||||
|
||||
var r0 []*models.DashboardProvisioning
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string) []*models.DashboardProvisioning); ok {
|
||||
var r0 []*DashboardProvisioning
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string) []*DashboardProvisioning); ok {
|
||||
r0 = rf(ctx, name)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*models.DashboardProvisioning)
|
||||
r0 = ret.Get(0).([]*DashboardProvisioning)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,15 +65,15 @@ func (_m *FakeDashboardProvisioning) GetProvisionedDashboardData(ctx context.Con
|
||||
}
|
||||
|
||||
// GetProvisionedDashboardDataByDashboardID provides a mock function with given fields: ctx, dashboardID
|
||||
func (_m *FakeDashboardProvisioning) GetProvisionedDashboardDataByDashboardID(ctx context.Context, dashboardID int64) (*models.DashboardProvisioning, error) {
|
||||
func (_m *FakeDashboardProvisioning) GetProvisionedDashboardDataByDashboardID(ctx context.Context, dashboardID int64) (*DashboardProvisioning, error) {
|
||||
ret := _m.Called(ctx, dashboardID)
|
||||
|
||||
var r0 *models.DashboardProvisioning
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64) *models.DashboardProvisioning); ok {
|
||||
var r0 *DashboardProvisioning
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64) *DashboardProvisioning); ok {
|
||||
r0 = rf(ctx, dashboardID)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*models.DashboardProvisioning)
|
||||
r0 = ret.Get(0).(*DashboardProvisioning)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,15 +88,15 @@ func (_m *FakeDashboardProvisioning) GetProvisionedDashboardDataByDashboardID(ct
|
||||
}
|
||||
|
||||
// GetProvisionedDashboardDataByDashboardUID provides a mock function with given fields: ctx, orgID, dashboardUID
|
||||
func (_m *FakeDashboardProvisioning) GetProvisionedDashboardDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*models.DashboardProvisioning, error) {
|
||||
func (_m *FakeDashboardProvisioning) GetProvisionedDashboardDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*DashboardProvisioning, error) {
|
||||
ret := _m.Called(ctx, orgID, dashboardUID)
|
||||
|
||||
var r0 *models.DashboardProvisioning
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, string) *models.DashboardProvisioning); ok {
|
||||
var r0 *DashboardProvisioning
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, string) *DashboardProvisioning); ok {
|
||||
r0 = rf(ctx, orgID, dashboardUID)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*models.DashboardProvisioning)
|
||||
r0 = ret.Get(0).(*DashboardProvisioning)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -138,11 +138,11 @@ func (_m *FakeDashboardService) GetDashboardACLInfoList(ctx context.Context, que
|
||||
}
|
||||
|
||||
// GetDashboardTags provides a mock function with given fields: ctx, query
|
||||
func (_m *FakeDashboardService) GetDashboardTags(ctx context.Context, query *models.GetDashboardTagsQuery) error {
|
||||
func (_m *FakeDashboardService) GetDashboardTags(ctx context.Context, query *GetDashboardTagsQuery) error {
|
||||
ret := _m.Called(ctx, query)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *models.GetDashboardTagsQuery) error); ok {
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardTagsQuery) error); ok {
|
||||
r0 = rf(ctx, query)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
|
||||
@@ -100,40 +100,40 @@ func (d *DashboardStore) GetFolderByTitle(ctx context.Context, orgID int64, titl
|
||||
|
||||
// there is a unique constraint on org_id, folder_id, title
|
||||
// there are no nested folders so the parent folder id is always 0
|
||||
dashboard := models.Dashboard{OrgId: orgID, FolderId: 0, Title: title}
|
||||
dashboard := dashboards.Dashboard{OrgID: orgID, FolderID: 0, Title: title}
|
||||
err := d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
has, err := sess.Table(&models.Dashboard{}).Where("is_folder = " + d.store.GetDialect().BooleanStr(true)).Where("folder_id=0").Get(&dashboard)
|
||||
has, err := sess.Table(&dashboards.Dashboard{}).Where("is_folder = " + d.store.GetDialect().BooleanStr(true)).Where("folder_id=0").Get(&dashboard)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !has {
|
||||
return dashboards.ErrFolderNotFound
|
||||
}
|
||||
dashboard.SetId(dashboard.Id)
|
||||
dashboard.SetUid(dashboard.Uid)
|
||||
dashboard.SetID(dashboard.ID)
|
||||
dashboard.SetUID(dashboard.UID)
|
||||
return nil
|
||||
})
|
||||
return folder.FromDashboard(&dashboard), err
|
||||
return dashboards.FromDashboard(&dashboard), err
|
||||
}
|
||||
|
||||
func (d *DashboardStore) GetFolderByID(ctx context.Context, orgID int64, id int64) (*folder.Folder, error) {
|
||||
dashboard := models.Dashboard{OrgId: orgID, FolderId: 0, Id: id}
|
||||
dashboard := dashboards.Dashboard{OrgID: orgID, FolderID: 0, ID: id}
|
||||
err := d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
has, err := sess.Table(&models.Dashboard{}).Where("is_folder = " + d.store.GetDialect().BooleanStr(true)).Where("folder_id=0").Get(&dashboard)
|
||||
has, err := sess.Table(&dashboards.Dashboard{}).Where("is_folder = " + d.store.GetDialect().BooleanStr(true)).Where("folder_id=0").Get(&dashboard)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !has {
|
||||
return dashboards.ErrFolderNotFound
|
||||
}
|
||||
dashboard.SetId(dashboard.Id)
|
||||
dashboard.SetUid(dashboard.Uid)
|
||||
dashboard.SetID(dashboard.ID)
|
||||
dashboard.SetUID(dashboard.UID)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return folder.FromDashboard(&dashboard), nil
|
||||
return dashboards.FromDashboard(&dashboard), nil
|
||||
}
|
||||
|
||||
func (d *DashboardStore) GetFolderByUID(ctx context.Context, orgID int64, uid string) (*folder.Folder, error) {
|
||||
@@ -141,42 +141,42 @@ func (d *DashboardStore) GetFolderByUID(ctx context.Context, orgID int64, uid st
|
||||
return nil, dashboards.ErrDashboardIdentifierNotSet
|
||||
}
|
||||
|
||||
dashboard := models.Dashboard{OrgId: orgID, FolderId: 0, Uid: uid}
|
||||
dashboard := dashboards.Dashboard{OrgID: orgID, FolderID: 0, UID: uid}
|
||||
err := d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
has, err := sess.Table(&models.Dashboard{}).Where("is_folder = " + d.store.GetDialect().BooleanStr(true)).Where("folder_id=0").Get(&dashboard)
|
||||
has, err := sess.Table(&dashboards.Dashboard{}).Where("is_folder = " + d.store.GetDialect().BooleanStr(true)).Where("folder_id=0").Get(&dashboard)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !has {
|
||||
return dashboards.ErrFolderNotFound
|
||||
}
|
||||
dashboard.SetId(dashboard.Id)
|
||||
dashboard.SetUid(dashboard.Uid)
|
||||
dashboard.SetID(dashboard.ID)
|
||||
dashboard.SetUID(dashboard.UID)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return folder.FromDashboard(&dashboard), nil
|
||||
return dashboards.FromDashboard(&dashboard), nil
|
||||
}
|
||||
|
||||
func (d *DashboardStore) GetProvisionedDataByDashboardID(ctx context.Context, dashboardID int64) (*models.DashboardProvisioning, error) {
|
||||
var data models.DashboardProvisioning
|
||||
func (d *DashboardStore) GetProvisionedDataByDashboardID(ctx context.Context, dashboardID int64) (*dashboards.DashboardProvisioning, error) {
|
||||
var data dashboards.DashboardProvisioning
|
||||
err := d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
_, err := sess.Where("dashboard_id = ?", dashboardID).Get(&data)
|
||||
return err
|
||||
})
|
||||
|
||||
if data.DashboardId == 0 {
|
||||
if data.DashboardID == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return &data, err
|
||||
}
|
||||
|
||||
func (d *DashboardStore) GetProvisionedDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*models.DashboardProvisioning, error) {
|
||||
var provisionedDashboard models.DashboardProvisioning
|
||||
func (d *DashboardStore) GetProvisionedDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*dashboards.DashboardProvisioning, error) {
|
||||
var provisionedDashboard dashboards.DashboardProvisioning
|
||||
err := d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
var dashboard models.Dashboard
|
||||
var dashboard dashboards.Dashboard
|
||||
exists, err := sess.Where("org_id = ? AND uid = ?", orgID, dashboardUID).Get(&dashboard)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -184,7 +184,7 @@ func (d *DashboardStore) GetProvisionedDataByDashboardUID(ctx context.Context, o
|
||||
if !exists {
|
||||
return dashboards.ErrDashboardNotFound
|
||||
}
|
||||
exists, err = sess.Where("dashboard_id = ?", dashboard.Id).Get(&provisionedDashboard)
|
||||
exists, err = sess.Where("dashboard_id = ?", dashboard.ID).Get(&provisionedDashboard)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -196,8 +196,8 @@ func (d *DashboardStore) GetProvisionedDataByDashboardUID(ctx context.Context, o
|
||||
return &provisionedDashboard, err
|
||||
}
|
||||
|
||||
func (d *DashboardStore) GetProvisionedDashboardData(ctx context.Context, name string) ([]*models.DashboardProvisioning, error) {
|
||||
var result []*models.DashboardProvisioning
|
||||
func (d *DashboardStore) GetProvisionedDashboardData(ctx context.Context, name string) ([]*dashboards.DashboardProvisioning, error) {
|
||||
var result []*dashboards.DashboardProvisioning
|
||||
err := d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
return sess.Where("name = ?", name).Find(&result)
|
||||
})
|
||||
@@ -251,7 +251,7 @@ func (d *DashboardStore) UpdateDashboardACL(ctx context.Context, dashboardID int
|
||||
}
|
||||
|
||||
// Update dashboard HasACL flag
|
||||
dashboard := models.Dashboard{HasACL: true}
|
||||
dashboard := dashboards.Dashboard{HasACL: true}
|
||||
_, err = sess.Cols("has_acl").Where("id=?", dashboardID).Update(&dashboard)
|
||||
return err
|
||||
})
|
||||
@@ -280,14 +280,14 @@ func (d *DashboardStore) SaveAlerts(ctx context.Context, dashID int64, alerts []
|
||||
// The dashboard will still have `created_by = -1` to see it was not created by any particular user.
|
||||
func (d *DashboardStore) UnprovisionDashboard(ctx context.Context, id int64) error {
|
||||
return d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
_, err := sess.Where("dashboard_id = ?", id).Delete(&models.DashboardProvisioning{})
|
||||
_, err := sess.Where("dashboard_id = ?", id).Delete(&dashboards.DashboardProvisioning{})
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (d *DashboardStore) DeleteOrphanedProvisionedDashboards(ctx context.Context, cmd *models.DeleteOrphanedProvisionedDashboardsCommand) error {
|
||||
func (d *DashboardStore) DeleteOrphanedProvisionedDashboards(ctx context.Context, cmd *dashboards.DeleteOrphanedProvisionedDashboardsCommand) error {
|
||||
return d.store.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
var result []*models.DashboardProvisioning
|
||||
var result []*dashboards.DashboardProvisioning
|
||||
|
||||
convertedReaderNames := make([]interface{}, len(cmd.ReaderNames))
|
||||
for index, readerName := range cmd.ReaderNames {
|
||||
@@ -300,7 +300,7 @@ func (d *DashboardStore) DeleteOrphanedProvisionedDashboards(ctx context.Context
|
||||
}
|
||||
|
||||
for _, deleteDashCommand := range result {
|
||||
err := d.DeleteDashboard(ctx, &models.DeleteDashboardCommand{Id: deleteDashCommand.DashboardId})
|
||||
err := d.DeleteDashboard(ctx, &dashboards.DeleteDashboardCommand{ID: deleteDashCommand.DashboardID})
|
||||
if err != nil && !errors.Is(err, dashboards.ErrDashboardNotFound) {
|
||||
return err
|
||||
}
|
||||
@@ -357,7 +357,7 @@ func (d *DashboardStore) Count(ctx context.Context, scopeParams *quota.ScopePara
|
||||
func getExistingDashboardByIDOrUIDForUpdate(sess *db.Session, dash *dashboards.Dashboard, dialect migrator.Dialect, overwrite bool) (bool, error) {
|
||||
dashWithIdExists := false
|
||||
isParentFolderChanged := false
|
||||
var existingById models.Dashboard
|
||||
var existingById dashboards.Dashboard
|
||||
|
||||
if dash.ID > 0 {
|
||||
var err error
|
||||
@@ -371,12 +371,12 @@ func getExistingDashboardByIDOrUIDForUpdate(sess *db.Session, dash *dashboards.D
|
||||
}
|
||||
|
||||
if dash.UID == "" {
|
||||
dash.SetUID(existingById.Uid)
|
||||
dash.SetUID(existingById.UID)
|
||||
}
|
||||
}
|
||||
|
||||
dashWithUidExists := false
|
||||
var existingByUid models.Dashboard
|
||||
var existingByUid dashboards.Dashboard
|
||||
|
||||
if dash.UID != "" {
|
||||
var err error
|
||||
@@ -387,7 +387,7 @@ func getExistingDashboardByIDOrUIDForUpdate(sess *db.Session, dash *dashboards.D
|
||||
}
|
||||
|
||||
if dash.FolderID > 0 {
|
||||
var existingFolder models.Dashboard
|
||||
var existingFolder dashboards.Dashboard
|
||||
folderExists, err := sess.Where("org_id=? AND id=? AND is_folder=?", dash.OrgID, dash.FolderID,
|
||||
dialect.BooleanStr(true)).Get(&existingFolder)
|
||||
if err != nil {
|
||||
@@ -403,15 +403,15 @@ func getExistingDashboardByIDOrUIDForUpdate(sess *db.Session, dash *dashboards.D
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if dashWithIdExists && dashWithUidExists && existingById.Id != existingByUid.Id {
|
||||
if dashWithIdExists && dashWithUidExists && existingById.ID != existingByUid.ID {
|
||||
return false, dashboards.ErrDashboardWithSameUIDExists
|
||||
}
|
||||
|
||||
existing := existingById
|
||||
|
||||
if !dashWithIdExists && dashWithUidExists {
|
||||
dash.SetID(existingByUid.Id)
|
||||
dash.SetUID(existingByUid.Uid)
|
||||
dash.SetID(existingByUid.ID)
|
||||
dash.SetUID(existingByUid.UID)
|
||||
existing = existingByUid
|
||||
}
|
||||
|
||||
@@ -420,7 +420,7 @@ func getExistingDashboardByIDOrUIDForUpdate(sess *db.Session, dash *dashboards.D
|
||||
return isParentFolderChanged, dashboards.ErrDashboardTypeMismatch
|
||||
}
|
||||
|
||||
if !dash.IsFolder && dash.FolderID != existing.FolderId {
|
||||
if !dash.IsFolder && dash.FolderID != existing.FolderID {
|
||||
isParentFolderChanged = true
|
||||
}
|
||||
|
||||
@@ -434,8 +434,8 @@ func getExistingDashboardByIDOrUIDForUpdate(sess *db.Session, dash *dashboards.D
|
||||
}
|
||||
|
||||
// do not allow plugin dashboard updates without overwrite flag
|
||||
if existing.PluginId != "" && !overwrite {
|
||||
return isParentFolderChanged, dashboards.UpdatePluginDashboardError{PluginId: existing.PluginId}
|
||||
if existing.PluginID != "" && !overwrite {
|
||||
return isParentFolderChanged, dashboards.UpdatePluginDashboardError{PluginId: existing.PluginID}
|
||||
}
|
||||
|
||||
return isParentFolderChanged, nil
|
||||
@@ -443,14 +443,14 @@ func getExistingDashboardByIDOrUIDForUpdate(sess *db.Session, dash *dashboards.D
|
||||
|
||||
func getExistingDashboardByTitleAndFolder(sess *db.Session, dash *dashboards.Dashboard, dialect migrator.Dialect, overwrite,
|
||||
isParentFolderChanged bool) (bool, error) {
|
||||
var existing models.Dashboard
|
||||
var existing dashboards.Dashboard
|
||||
exists, err := sess.Where("org_id=? AND slug=? AND (is_folder=? OR folder_id=?)", dash.OrgID, dash.Slug,
|
||||
dialect.BooleanStr(true), dash.FolderID).Get(&existing)
|
||||
if err != nil {
|
||||
return isParentFolderChanged, fmt.Errorf("SQL query for existing dashboard by org ID or folder ID failed: %w", err)
|
||||
}
|
||||
|
||||
if exists && dash.ID != existing.Id {
|
||||
if exists && dash.ID != existing.ID {
|
||||
if existing.IsFolder && !dash.IsFolder {
|
||||
return isParentFolderChanged, dashboards.ErrDashboardWithSameNameAsFolder
|
||||
}
|
||||
@@ -459,13 +459,13 @@ func getExistingDashboardByTitleAndFolder(sess *db.Session, dash *dashboards.Das
|
||||
return isParentFolderChanged, dashboards.ErrDashboardFolderWithSameNameAsDashboard
|
||||
}
|
||||
|
||||
if !dash.IsFolder && (dash.FolderID != existing.FolderId || dash.ID == 0) {
|
||||
if !dash.IsFolder && (dash.FolderID != existing.FolderID || dash.ID == 0) {
|
||||
isParentFolderChanged = true
|
||||
}
|
||||
|
||||
if overwrite {
|
||||
dash.SetID(existing.Id)
|
||||
dash.SetUID(existing.Uid)
|
||||
dash.SetID(existing.ID)
|
||||
dash.SetUID(existing.UID)
|
||||
dash.SetVersion(existing.Version)
|
||||
} else {
|
||||
return isParentFolderChanged, dashboards.ErrDashboardWithSameNameInFolderExists
|
||||
@@ -485,7 +485,7 @@ func saveDashboard(sess *db.Session, cmd *dashboards.SaveDashboardCommand, emitE
|
||||
}
|
||||
|
||||
if dash.ID > 0 {
|
||||
var existing models.Dashboard
|
||||
var existing dashboards.Dashboard
|
||||
dashWithIdExists, err := sess.Where("id=? AND org_id=?", dash.ID, dash.OrgID).Get(&existing)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -504,8 +504,8 @@ func saveDashboard(sess *db.Session, cmd *dashboards.SaveDashboardCommand, emitE
|
||||
}
|
||||
|
||||
// do not allow plugin dashboard updates without overwrite flag
|
||||
if existing.PluginId != "" && !cmd.Overwrite {
|
||||
return dashboards.UpdatePluginDashboardError{PluginId: existing.PluginId}
|
||||
if existing.PluginID != "" && !cmd.Overwrite {
|
||||
return dashboards.UpdatePluginDashboardError{PluginId: existing.PluginID}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -599,7 +599,7 @@ func generateNewDashboardUid(sess *db.Session, orgId int64) (string, error) {
|
||||
for i := 0; i < 3; i++ {
|
||||
uid := util.GenerateShortUID()
|
||||
|
||||
exists, err := sess.Where("org_id=? AND uid=?", orgId, uid).Get(&models.Dashboard{})
|
||||
exists, err := sess.Where("org_id=? AND uid=?", orgId, uid).Get(&dashboards.Dashboard{})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -613,18 +613,18 @@ func generateNewDashboardUid(sess *db.Session, orgId int64) (string, error) {
|
||||
}
|
||||
|
||||
func saveProvisionedData(sess *db.Session, provisioning *dashboards.DashboardProvisioning, dashboard *dashboards.Dashboard) error {
|
||||
result := &models.DashboardProvisioning{}
|
||||
result := &dashboards.DashboardProvisioning{}
|
||||
|
||||
exist, err := sess.Where("dashboard_id=? AND name = ?", dashboard.ID, provisioning.Name).Get(result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
provisioning.ID = result.Id
|
||||
provisioning.ID = result.ID
|
||||
provisioning.DashboardID = dashboard.ID
|
||||
|
||||
if exist {
|
||||
_, err = sess.ID(result.Id).Update(provisioning)
|
||||
_, err = sess.ID(result.ID).Update(provisioning)
|
||||
} else {
|
||||
_, err = sess.Insert(provisioning)
|
||||
}
|
||||
@@ -749,25 +749,25 @@ func (d *DashboardStore) deleteAlertByIdInternal(alertId int64, reason string, s
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DashboardStore) GetDashboardsByPluginID(ctx context.Context, query *models.GetDashboardsByPluginIdQuery) error {
|
||||
func (d *DashboardStore) GetDashboardsByPluginID(ctx context.Context, query *dashboards.GetDashboardsByPluginIDQuery) error {
|
||||
return d.store.WithDbSession(ctx, func(dbSession *db.Session) error {
|
||||
var dashboards = make([]*models.Dashboard, 0)
|
||||
var dashboards = make([]*dashboards.Dashboard, 0)
|
||||
whereExpr := "org_id=? AND plugin_id=? AND is_folder=" + d.store.GetDialect().BooleanStr(false)
|
||||
|
||||
err := dbSession.Where(whereExpr, query.OrgId, query.PluginId).Find(&dashboards)
|
||||
err := dbSession.Where(whereExpr, query.OrgID, query.PluginID).Find(&dashboards)
|
||||
query.Result = dashboards
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (d *DashboardStore) DeleteDashboard(ctx context.Context, cmd *models.DeleteDashboardCommand) error {
|
||||
func (d *DashboardStore) DeleteDashboard(ctx context.Context, cmd *dashboards.DeleteDashboardCommand) error {
|
||||
return d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
return d.deleteDashboard(cmd, sess, d.emitEntityEvent())
|
||||
})
|
||||
}
|
||||
|
||||
func (d *DashboardStore) deleteDashboard(cmd *models.DeleteDashboardCommand, sess *db.Session, emitEntityEvent bool) error {
|
||||
dashboard := dashboards.Dashboard{ID: cmd.Id, OrgID: cmd.OrgId}
|
||||
func (d *DashboardStore) deleteDashboard(cmd *dashboards.DeleteDashboardCommand, sess *db.Session, emitEntityEvent bool) error {
|
||||
dashboard := dashboards.Dashboard{ID: cmd.ID, OrgID: cmd.OrgID}
|
||||
has, err := sess.Get(&dashboard)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1066,7 +1066,7 @@ func (d *DashboardStore) FindDashboards(ctx context.Context, query *models.FindP
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (d *DashboardStore) GetDashboardTags(ctx context.Context, query *models.GetDashboardTagsQuery) error {
|
||||
func (d *DashboardStore) GetDashboardTags(ctx context.Context, query *dashboards.GetDashboardTagsQuery) error {
|
||||
return d.store.WithDbSession(ctx, func(dbSession *db.Session) error {
|
||||
sql := `SELECT
|
||||
COUNT(*) as count,
|
||||
@@ -1077,8 +1077,8 @@ func (d *DashboardStore) GetDashboardTags(ctx context.Context, query *models.Get
|
||||
GROUP BY term
|
||||
ORDER BY term`
|
||||
|
||||
query.Result = make([]*models.DashboardTagCloudItem, 0)
|
||||
sess := dbSession.SQL(sql, query.OrgId)
|
||||
query.Result = make([]*dashboards.DashboardTagCloudItem, 0)
|
||||
sess := dbSession.SQL(sql, query.OrgID)
|
||||
err := sess.Find(&query.Result)
|
||||
return err
|
||||
})
|
||||
@@ -1096,7 +1096,7 @@ func (d *DashboardStore) CountDashboardsInFolder(
|
||||
err = d.store.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
session := sess.In("folder_id", req.FolderID).In("org_id", req.OrgID).
|
||||
In("is_folder", d.store.GetDialect().BooleanStr(false))
|
||||
count, err = session.Count(&models.Dashboard{})
|
||||
count, err = session.Count(&dashboards.Dashboard{})
|
||||
return err
|
||||
})
|
||||
return count, err
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
|
||||
@@ -86,7 +85,7 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, query.Result)
|
||||
|
||||
deleteCmd := &models.DeleteOrphanedProvisionedDashboardsCommand{ReaderNames: []string{"default"}}
|
||||
deleteCmd := &dashboards.DeleteOrphanedProvisionedDashboardsCommand{ReaderNames: []string{"default"}}
|
||||
require.Nil(t, dashboardStore.DeleteOrphanedProvisionedDashboards(context.Background(), deleteCmd))
|
||||
|
||||
query = &dashboards.GetDashboardsQuery{DashboardIDs: []int64{dash.ID, anotherDash.ID}}
|
||||
@@ -102,7 +101,7 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, 1, len(rslt))
|
||||
require.Equal(t, dashId, rslt[0].DashboardId)
|
||||
require.Equal(t, dashId, rslt[0].DashboardID)
|
||||
require.Equal(t, now.Unix(), rslt[0].Updated)
|
||||
})
|
||||
|
||||
@@ -119,9 +118,9 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Deleting folder should delete provision meta data", func(t *testing.T) {
|
||||
deleteCmd := &models.DeleteDashboardCommand{
|
||||
Id: dash.ID,
|
||||
OrgId: 1,
|
||||
deleteCmd := &dashboards.DeleteDashboardCommand{
|
||||
ID: dash.ID,
|
||||
OrgID: 1,
|
||||
}
|
||||
|
||||
require.Nil(t, dashboardStore.DeleteDashboard(context.Background(), deleteCmd))
|
||||
|
||||
@@ -159,9 +159,9 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
setup()
|
||||
dash := insertTestDashboard(t, dashboardStore, "delete me", 1, 0, false, "delete this")
|
||||
|
||||
err := dashboardStore.DeleteDashboard(context.Background(), &models.DeleteDashboardCommand{
|
||||
Id: dash.ID,
|
||||
OrgId: 1,
|
||||
err := dashboardStore.DeleteDashboard(context.Background(), &dashboards.DeleteDashboardCommand{
|
||||
ID: dash.ID,
|
||||
OrgID: 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
})
|
||||
@@ -233,14 +233,14 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
setup()
|
||||
emptyFolder := insertTestDashboard(t, dashboardStore, "2 test dash folder", 1, 0, true, "prod", "webapp")
|
||||
|
||||
deleteCmd := &models.DeleteDashboardCommand{Id: emptyFolder.ID}
|
||||
deleteCmd := &dashboards.DeleteDashboardCommand{ID: emptyFolder.ID}
|
||||
err := dashboardStore.DeleteDashboard(context.Background(), deleteCmd)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("Should be not able to delete a dashboard if force delete rules is disabled", func(t *testing.T) {
|
||||
setup()
|
||||
deleteCmd := &models.DeleteDashboardCommand{Id: savedFolder.ID, ForceDeleteFolderRules: false}
|
||||
deleteCmd := &dashboards.DeleteDashboardCommand{ID: savedFolder.ID, ForceDeleteFolderRules: false}
|
||||
err := dashboardStore.DeleteDashboard(context.Background(), deleteCmd)
|
||||
require.True(t, errors.Is(err, dashboards.ErrFolderContainsAlertRules))
|
||||
})
|
||||
@@ -266,7 +266,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
pubdashConfig, _ := publicDashboardStore.FindByAccessToken(context.Background(), "an-access-token")
|
||||
require.NotNil(t, pubdashConfig)
|
||||
|
||||
deleteCmd := &models.DeleteDashboardCommand{Id: savedDash.ID, OrgId: savedDash.OrgID}
|
||||
deleteCmd := &dashboards.DeleteDashboardCommand{ID: savedDash.ID, OrgID: savedDash.OrgID}
|
||||
err = dashboardStore.DeleteDashboard(context.Background(), deleteCmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -301,7 +301,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
pubdashConfig, _ := publicDashboardStore.FindByAccessToken(context.Background(), "an-access-token")
|
||||
require.NotNil(t, pubdashConfig)
|
||||
|
||||
deleteCmd := &models.DeleteDashboardCommand{Id: savedFolder.ID, ForceDeleteFolderRules: true}
|
||||
deleteCmd := &dashboards.DeleteDashboardCommand{ID: savedFolder.ID, ForceDeleteFolderRules: true}
|
||||
err = dashboardStore.DeleteDashboard(context.Background(), deleteCmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -319,7 +319,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("Should be able to delete a dashboard folder and its children if force delete rules is enabled", func(t *testing.T) {
|
||||
setup()
|
||||
deleteCmd := &models.DeleteDashboardCommand{Id: savedFolder.ID, ForceDeleteFolderRules: true}
|
||||
deleteCmd := &dashboards.DeleteDashboardCommand{ID: savedFolder.ID, ForceDeleteFolderRules: true}
|
||||
err := dashboardStore.DeleteDashboard(context.Background(), deleteCmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -380,7 +380,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("Should be able to get dashboard tags", func(t *testing.T) {
|
||||
setup()
|
||||
query := models.GetDashboardTagsQuery{OrgId: 1}
|
||||
query := dashboards.GetDashboardTagsQuery{OrgID: 1}
|
||||
|
||||
err := dashboardStore.GetDashboardTags(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
@@ -598,9 +598,9 @@ func TestIntegrationDashboardDataAccessGivenPluginWithImportedDashboards(t *test
|
||||
insertTestDashboardForPlugin(t, dashboardStore, "app-dash1", 1, appFolder.ID, false, pluginId)
|
||||
insertTestDashboardForPlugin(t, dashboardStore, "app-dash2", 1, appFolder.ID, false, pluginId)
|
||||
|
||||
query := models.GetDashboardsByPluginIdQuery{
|
||||
PluginId: pluginId,
|
||||
OrgId: 1,
|
||||
query := dashboards.GetDashboardsByPluginIDQuery{
|
||||
PluginID: pluginId,
|
||||
OrgID: 1,
|
||||
}
|
||||
|
||||
err = dashboardStore.GetDashboardsByPluginID(context.Background(), &query)
|
||||
@@ -866,7 +866,7 @@ func makeQueryResult(query *models.FindPersistedDashboardsQuery, res []dashboard
|
||||
UID: item.UID,
|
||||
Title: item.Title,
|
||||
URI: "db/" + item.Slug,
|
||||
URL: models.GetDashboardFolderUrl(item.IsFolder, item.UID, item.Slug),
|
||||
URL: dashboards.GetDashboardFolderURL(item.IsFolder, item.UID, item.Slug),
|
||||
Type: hitType,
|
||||
FolderID: item.FolderID,
|
||||
FolderUID: item.FolderUID,
|
||||
@@ -875,7 +875,7 @@ func makeQueryResult(query *models.FindPersistedDashboardsQuery, res []dashboard
|
||||
}
|
||||
|
||||
if item.FolderID > 0 {
|
||||
hit.FolderURL = models.GetFolderUrl(item.FolderUID, item.FolderSlug)
|
||||
hit.FolderURL = dashboards.GetFolderURL(item.FolderUID, item.FolderSlug)
|
||||
}
|
||||
|
||||
if query.Sort.MetaName != "" {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Code generated by mockery v2.14.0. DO NOT EDIT.
|
||||
// Code generated by mockery v2.16.0. DO NOT EDIT.
|
||||
|
||||
package dashboards
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
models "github.com/grafana/grafana/pkg/models"
|
||||
folder "github.com/grafana/grafana/pkg/services/folder"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
@@ -15,15 +15,15 @@ type FakeFolderStore struct {
|
||||
}
|
||||
|
||||
// GetFolderByID provides a mock function with given fields: ctx, orgID, id
|
||||
func (_m *FakeFolderStore) GetFolderByID(ctx context.Context, orgID int64, id int64) (*models.Folder, error) {
|
||||
func (_m *FakeFolderStore) GetFolderByID(ctx context.Context, orgID int64, id int64) (*folder.Folder, error) {
|
||||
ret := _m.Called(ctx, orgID, id)
|
||||
|
||||
var r0 *models.Folder
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, int64) *models.Folder); ok {
|
||||
var r0 *folder.Folder
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, int64) *folder.Folder); ok {
|
||||
r0 = rf(ctx, orgID, id)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*models.Folder)
|
||||
r0 = ret.Get(0).(*folder.Folder)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,15 +38,15 @@ func (_m *FakeFolderStore) GetFolderByID(ctx context.Context, orgID int64, id in
|
||||
}
|
||||
|
||||
// GetFolderByTitle provides a mock function with given fields: ctx, orgID, title
|
||||
func (_m *FakeFolderStore) GetFolderByTitle(ctx context.Context, orgID int64, title string) (*models.Folder, error) {
|
||||
func (_m *FakeFolderStore) GetFolderByTitle(ctx context.Context, orgID int64, title string) (*folder.Folder, error) {
|
||||
ret := _m.Called(ctx, orgID, title)
|
||||
|
||||
var r0 *models.Folder
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, string) *models.Folder); ok {
|
||||
var r0 *folder.Folder
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, string) *folder.Folder); ok {
|
||||
r0 = rf(ctx, orgID, title)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*models.Folder)
|
||||
r0 = ret.Get(0).(*folder.Folder)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,15 +61,15 @@ func (_m *FakeFolderStore) GetFolderByTitle(ctx context.Context, orgID int64, ti
|
||||
}
|
||||
|
||||
// GetFolderByUID provides a mock function with given fields: ctx, orgID, uid
|
||||
func (_m *FakeFolderStore) GetFolderByUID(ctx context.Context, orgID int64, uid string) (*models.Folder, error) {
|
||||
func (_m *FakeFolderStore) GetFolderByUID(ctx context.Context, orgID int64, uid string) (*folder.Folder, error) {
|
||||
ret := _m.Called(ctx, orgID, uid)
|
||||
|
||||
var r0 *models.Folder
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, string) *models.Folder); ok {
|
||||
var r0 *folder.Folder
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, string) *folder.Folder); ok {
|
||||
r0 = rf(ctx, orgID, uid)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*models.Folder)
|
||||
r0 = ret.Get(0).(*folder.Folder)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -260,9 +260,9 @@ type GetDashboardsQuery struct {
|
||||
Result []*Dashboard
|
||||
}
|
||||
|
||||
type GetDashboardsByPluginIdQuery struct {
|
||||
type GetDashboardsByPluginIDQuery struct {
|
||||
OrgID int64
|
||||
PluginId string
|
||||
PluginID string
|
||||
Result []*Dashboard
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ func FromDashboard(dash *Dashboard) *folder.Folder {
|
||||
UID: dash.UID,
|
||||
Title: dash.Title,
|
||||
HasACL: dash.HasACL,
|
||||
Url: models.GetFolderUrl(dash.UID, dash.Slug),
|
||||
Url: GetFolderURL(dash.UID, dash.Slug),
|
||||
Version: dash.Version,
|
||||
Created: dash.Created,
|
||||
CreatedBy: dash.CreatedBy,
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package dashboards
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/slugify"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetDashboardUrl(t *testing.T) {
|
||||
origAppURL := setting.AppUrl
|
||||
t.Cleanup(func() { setting.AppUrl = origAppURL })
|
||||
|
||||
setting.AppUrl = ""
|
||||
url := GetDashboardURL("uid", "my-dashboard")
|
||||
assert.Equal(t, "/d/uid/my-dashboard", url)
|
||||
}
|
||||
|
||||
func TestGetFullDashboardUrl(t *testing.T) {
|
||||
origAppURL := setting.AppUrl
|
||||
t.Cleanup(func() { setting.AppUrl = origAppURL })
|
||||
|
||||
setting.AppUrl = "http://grafana.local/"
|
||||
url := GetFullDashboardURL("uid", "my-dashboard")
|
||||
assert.Equal(t, "http://grafana.local/d/uid/my-dashboard", url)
|
||||
}
|
||||
|
||||
func TestDashboard_UpdateSlug(t *testing.T) {
|
||||
dashboard := NewDashboard("Grafana Play Home")
|
||||
assert.Equal(t, "grafana-play-home", dashboard.Slug)
|
||||
|
||||
dashboard.UpdateSlug()
|
||||
assert.Equal(t, "grafana-play-home", dashboard.Slug)
|
||||
}
|
||||
|
||||
func TestNewDashboardFromJson(t *testing.T) {
|
||||
json := simplejson.New()
|
||||
json.Set("title", "test dash")
|
||||
json.Set("tags", "")
|
||||
|
||||
dash := NewDashboardFromJson(json)
|
||||
assert.Equal(t, "test dash", dash.Title)
|
||||
require.Empty(t, dash.GetTags())
|
||||
}
|
||||
|
||||
func TestSaveDashboardCommand_GetDashboardModel(t *testing.T) {
|
||||
t.Run("should set IsFolder", func(t *testing.T) {
|
||||
json := simplejson.New()
|
||||
json.Set("title", "test dash")
|
||||
|
||||
cmd := &SaveDashboardCommand{Dashboard: json, IsFolder: true}
|
||||
dash := cmd.GetDashboardModel()
|
||||
|
||||
assert.Equal(t, "test dash", dash.Title)
|
||||
assert.True(t, dash.IsFolder)
|
||||
})
|
||||
|
||||
t.Run("should set FolderId", func(t *testing.T) {
|
||||
json := simplejson.New()
|
||||
json.Set("title", "test dash")
|
||||
|
||||
cmd := &SaveDashboardCommand{Dashboard: json, FolderID: 1}
|
||||
dash := cmd.GetDashboardModel()
|
||||
|
||||
assert.Equal(t, int64(1), dash.FolderID)
|
||||
})
|
||||
}
|
||||
|
||||
func TestSlugifyTitle(t *testing.T) {
|
||||
testCases := map[string]string{
|
||||
"Grafana Play Home": "grafana-play-home",
|
||||
"snöräv-över-ån": "snorav-over-an",
|
||||
"漢字": "5ryi5a2X", // "han-zi", // Hanzi for hanzi
|
||||
"🇦🇶": "8J-HpvCfh7Y", // flag of Antarctica-emoji, using fallback
|
||||
"𒆠": "8JKGoA", // cuneiform Ki, using fallback
|
||||
}
|
||||
|
||||
for input, expected := range testCases {
|
||||
t.Run(input, func(t *testing.T) {
|
||||
slug := slugify.Slugify(input)
|
||||
assert.Equal(t, expected, slug)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -64,15 +64,15 @@ func ProvideDashboardService(
|
||||
}
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) GetProvisionedDashboardData(ctx context.Context, name string) ([]*models.DashboardProvisioning, error) {
|
||||
func (dr *DashboardServiceImpl) GetProvisionedDashboardData(ctx context.Context, name string) ([]*dashboards.DashboardProvisioning, error) {
|
||||
return dr.dashboardStore.GetProvisionedDashboardData(ctx, name)
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) GetProvisionedDashboardDataByDashboardID(ctx context.Context, dashboardID int64) (*models.DashboardProvisioning, error) {
|
||||
func (dr *DashboardServiceImpl) GetProvisionedDashboardDataByDashboardID(ctx context.Context, dashboardID int64) (*dashboards.DashboardProvisioning, error) {
|
||||
return dr.dashboardStore.GetProvisionedDataByDashboardID(ctx, dashboardID)
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) GetProvisionedDashboardDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*models.DashboardProvisioning, error) {
|
||||
func (dr *DashboardServiceImpl) GetProvisionedDashboardDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*dashboards.DashboardProvisioning, error) {
|
||||
return dr.dashboardStore.GetProvisionedDataByDashboardUID(ctx, orgID, dashboardUID)
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func (dr *DashboardServiceImpl) BuildSaveDashboardCommand(ctx context.Context, d
|
||||
return nil, dashboards.ErrDashboardFolderCannotHaveParent
|
||||
}
|
||||
|
||||
if dash.IsFolder && strings.EqualFold(dash.Title, models.RootFolderName) {
|
||||
if dash.IsFolder && strings.EqualFold(dash.Title, dashboards.RootFolderName) {
|
||||
return nil, dashboards.ErrDashboardFolderNameExists
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ func (dr *DashboardServiceImpl) UpdateDashboardACL(ctx context.Context, uid int6
|
||||
return dr.dashboardStore.UpdateDashboardACL(ctx, uid, items)
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) DeleteOrphanedProvisionedDashboards(ctx context.Context, cmd *models.DeleteOrphanedProvisionedDashboardsCommand) error {
|
||||
func (dr *DashboardServiceImpl) DeleteOrphanedProvisionedDashboards(ctx context.Context, cmd *dashboards.DeleteOrphanedProvisionedDashboardsCommand) error {
|
||||
return dr.dashboardStore.DeleteOrphanedProvisionedDashboards(ctx, cmd)
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ func (dr *DashboardServiceImpl) DeleteDashboard(ctx context.Context, dashboardId
|
||||
return dr.deleteDashboard(ctx, dashboardId, orgId, true)
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) GetDashboardByPublicUid(ctx context.Context, dashboardPublicUid string) (*models.Dashboard, error) {
|
||||
func (dr *DashboardServiceImpl) GetDashboardByPublicUid(ctx context.Context, dashboardPublicUid string) (*dashboards.Dashboard, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -445,7 +445,7 @@ func (dr *DashboardServiceImpl) deleteDashboard(ctx context.Context, dashboardId
|
||||
return dashboards.ErrDashboardCannotDeleteProvisionedDashboard
|
||||
}
|
||||
}
|
||||
cmd := &models.DeleteDashboardCommand{OrgId: orgId, Id: dashboardId}
|
||||
cmd := &dashboards.DeleteDashboardCommand{OrgID: orgId, ID: dashboardId}
|
||||
return dr.dashboardStore.DeleteDashboard(ctx, cmd)
|
||||
}
|
||||
|
||||
@@ -481,7 +481,7 @@ func (dr *DashboardServiceImpl) UnprovisionDashboard(ctx context.Context, dashbo
|
||||
return dr.dashboardStore.UnprovisionDashboard(ctx, dashboardId)
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) GetDashboardsByPluginID(ctx context.Context, query *models.GetDashboardsByPluginIdQuery) error {
|
||||
func (dr *DashboardServiceImpl) GetDashboardsByPluginID(ctx context.Context, query *dashboards.GetDashboardsByPluginIDQuery) error {
|
||||
return dr.dashboardStore.GetDashboardsByPluginID(ctx, query)
|
||||
}
|
||||
|
||||
@@ -571,7 +571,7 @@ func makeQueryResult(query *models.FindPersistedDashboardsQuery, res []dashboard
|
||||
UID: item.UID,
|
||||
Title: item.Title,
|
||||
URI: "db/" + item.Slug,
|
||||
URL: models.GetDashboardFolderUrl(item.IsFolder, item.UID, item.Slug),
|
||||
URL: dashboards.GetDashboardFolderURL(item.IsFolder, item.UID, item.Slug),
|
||||
Type: getHitType(item),
|
||||
FolderID: item.FolderID,
|
||||
FolderUID: item.FolderUID,
|
||||
@@ -580,7 +580,7 @@ func makeQueryResult(query *models.FindPersistedDashboardsQuery, res []dashboard
|
||||
}
|
||||
|
||||
if item.FolderID > 0 {
|
||||
hit.FolderURL = models.GetFolderUrl(item.FolderUID, item.FolderSlug)
|
||||
hit.FolderURL = dashboards.GetFolderURL(item.FolderUID, item.FolderSlug)
|
||||
}
|
||||
|
||||
if query.Sort.MetaName != "" {
|
||||
@@ -609,7 +609,7 @@ func (dr *DashboardServiceImpl) HasEditPermissionInFolders(ctx context.Context,
|
||||
return dr.dashboardStore.HasEditPermissionInFolders(ctx, query)
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) GetDashboardTags(ctx context.Context, query *models.GetDashboardTagsQuery) error {
|
||||
func (dr *DashboardServiceImpl) GetDashboardTags(ctx context.Context, query *dashboards.GetDashboardTagsQuery) error {
|
||||
return dr.dashboardStore.GetDashboardTags(ctx, query)
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ func TestDashboardService(t *testing.T) {
|
||||
|
||||
t.Run("Should return validation error if dashboard is provisioned", func(t *testing.T) {
|
||||
fakeStore.On("ValidateDashboardBeforeSave", mock.Anything, mock.Anything, mock.AnythingOfType("bool")).Return(true, nil).Once()
|
||||
fakeStore.On("GetProvisionedDataByDashboardID", mock.Anything, mock.AnythingOfType("int64")).Return(&models.DashboardProvisioning{}, nil).Once()
|
||||
fakeStore.On("GetProvisionedDataByDashboardID", mock.Anything, mock.AnythingOfType("int64")).Return(&dashboards.DashboardProvisioning{}, nil).Once()
|
||||
|
||||
dto.Dashboard = dashboards.NewDashboard("Dash")
|
||||
dto.Dashboard.SetID(3)
|
||||
@@ -176,7 +176,7 @@ func TestDashboardService(t *testing.T) {
|
||||
|
||||
t.Run("Should return validation error if dashboard is provisioned", func(t *testing.T) {
|
||||
fakeStore.On("ValidateDashboardBeforeSave", mock.Anything, mock.Anything, mock.AnythingOfType("bool")).Return(true, nil).Once()
|
||||
fakeStore.On("GetProvisionedDataByDashboardID", mock.Anything, mock.AnythingOfType("int64")).Return(&models.DashboardProvisioning{}, nil).Once()
|
||||
fakeStore.On("GetProvisionedDataByDashboardID", mock.Anything, mock.AnythingOfType("int64")).Return(&dashboards.DashboardProvisioning{}, nil).Once()
|
||||
|
||||
dto.Dashboard = dashboards.NewDashboard("Dash")
|
||||
dto.Dashboard.SetID(3)
|
||||
@@ -188,14 +188,14 @@ func TestDashboardService(t *testing.T) {
|
||||
|
||||
t.Run("Given provisioned dashboard", func(t *testing.T) {
|
||||
t.Run("DeleteProvisionedDashboard should delete it", func(t *testing.T) {
|
||||
args := &models.DeleteDashboardCommand{OrgId: 1, Id: 1}
|
||||
args := &dashboards.DeleteDashboardCommand{OrgID: 1, ID: 1}
|
||||
fakeStore.On("DeleteDashboard", mock.Anything, args).Return(nil).Once()
|
||||
err := service.DeleteProvisionedDashboard(context.Background(), 1, 1)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("DeleteDashboard should fail to delete it when provisioning information is missing", func(t *testing.T) {
|
||||
fakeStore.On("GetProvisionedDataByDashboardID", mock.Anything, mock.AnythingOfType("int64")).Return(&models.DashboardProvisioning{}, nil).Once()
|
||||
fakeStore.On("GetProvisionedDataByDashboardID", mock.Anything, mock.AnythingOfType("int64")).Return(&dashboards.DashboardProvisioning{}, nil).Once()
|
||||
err := service.DeleteDashboard(context.Background(), 1, 1)
|
||||
require.Equal(t, err, dashboards.ErrDashboardCannotDeleteProvisionedDashboard)
|
||||
})
|
||||
@@ -203,14 +203,14 @@ func TestDashboardService(t *testing.T) {
|
||||
|
||||
t.Run("Given non provisioned dashboard", func(t *testing.T) {
|
||||
t.Run("DeleteProvisionedDashboard should delete the dashboard", func(t *testing.T) {
|
||||
args := &models.DeleteDashboardCommand{OrgId: 1, Id: 1, ForceDeleteFolderRules: false}
|
||||
args := &dashboards.DeleteDashboardCommand{OrgID: 1, ID: 1, ForceDeleteFolderRules: false}
|
||||
fakeStore.On("DeleteDashboard", mock.Anything, args).Return(nil).Once()
|
||||
err := service.DeleteProvisionedDashboard(context.Background(), 1, 1)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("DeleteDashboard should delete it", func(t *testing.T) {
|
||||
args := &models.DeleteDashboardCommand{OrgId: 1, Id: 1}
|
||||
args := &dashboards.DeleteDashboardCommand{OrgID: 1, ID: 1}
|
||||
fakeStore.On("DeleteDashboard", mock.Anything, args).Return(nil).Once()
|
||||
fakeStore.On("GetProvisionedDataByDashboardID", mock.Anything, mock.AnythingOfType("int64")).Return(nil, nil).Once()
|
||||
err := service.DeleteDashboard(context.Background(), 1, 1)
|
||||
|
||||
@@ -77,11 +77,11 @@ func (_m *FakeDashboardStore) DeleteACLByUser(_a0 context.Context, _a1 int64) er
|
||||
}
|
||||
|
||||
// DeleteDashboard provides a mock function with given fields: ctx, cmd
|
||||
func (_m *FakeDashboardStore) DeleteDashboard(ctx context.Context, cmd *models.DeleteDashboardCommand) error {
|
||||
func (_m *FakeDashboardStore) DeleteDashboard(ctx context.Context, cmd *DeleteDashboardCommand) error {
|
||||
ret := _m.Called(ctx, cmd)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *models.DeleteDashboardCommand) error); ok {
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *DeleteDashboardCommand) error); ok {
|
||||
r0 = rf(ctx, cmd)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
@@ -91,11 +91,11 @@ func (_m *FakeDashboardStore) DeleteDashboard(ctx context.Context, cmd *models.D
|
||||
}
|
||||
|
||||
// DeleteOrphanedProvisionedDashboards provides a mock function with given fields: ctx, cmd
|
||||
func (_m *FakeDashboardStore) DeleteOrphanedProvisionedDashboards(ctx context.Context, cmd *models.DeleteOrphanedProvisionedDashboardsCommand) error {
|
||||
func (_m *FakeDashboardStore) DeleteOrphanedProvisionedDashboards(ctx context.Context, cmd *DeleteOrphanedProvisionedDashboardsCommand) error {
|
||||
ret := _m.Called(ctx, cmd)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *models.DeleteOrphanedProvisionedDashboardsCommand) error); ok {
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *DeleteOrphanedProvisionedDashboardsCommand) error); ok {
|
||||
r0 = rf(ctx, cmd)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
@@ -165,11 +165,11 @@ func (_m *FakeDashboardStore) GetDashboardACLInfoList(ctx context.Context, query
|
||||
}
|
||||
|
||||
// GetDashboardTags provides a mock function with given fields: ctx, query
|
||||
func (_m *FakeDashboardStore) GetDashboardTags(ctx context.Context, query *models.GetDashboardTagsQuery) error {
|
||||
func (_m *FakeDashboardStore) GetDashboardTags(ctx context.Context, query *GetDashboardTagsQuery) error {
|
||||
ret := _m.Called(ctx, query)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *models.GetDashboardTagsQuery) error); ok {
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardTagsQuery) error); ok {
|
||||
r0 = rf(ctx, query)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
@@ -207,11 +207,11 @@ func (_m *FakeDashboardStore) GetDashboards(ctx context.Context, query *GetDashb
|
||||
}
|
||||
|
||||
// GetDashboardsByPluginID provides a mock function with given fields: ctx, query
|
||||
func (_m *FakeDashboardStore) GetDashboardsByPluginID(ctx context.Context, query *models.GetDashboardsByPluginIdQuery) error {
|
||||
func (_m *FakeDashboardStore) GetDashboardsByPluginID(ctx context.Context, query *GetDashboardsByPluginIDQuery) error {
|
||||
ret := _m.Called(ctx, query)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *models.GetDashboardsByPluginIdQuery) error); ok {
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardsByPluginIDQuery) error); ok {
|
||||
r0 = rf(ctx, query)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
@@ -290,15 +290,15 @@ func (_m *FakeDashboardStore) GetFolderByUID(ctx context.Context, orgID int64, u
|
||||
}
|
||||
|
||||
// GetProvisionedDashboardData provides a mock function with given fields: ctx, name
|
||||
func (_m *FakeDashboardStore) GetProvisionedDashboardData(ctx context.Context, name string) ([]*models.DashboardProvisioning, error) {
|
||||
func (_m *FakeDashboardStore) GetProvisionedDashboardData(ctx context.Context, name string) ([]*DashboardProvisioning, error) {
|
||||
ret := _m.Called(ctx, name)
|
||||
|
||||
var r0 []*models.DashboardProvisioning
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string) []*models.DashboardProvisioning); ok {
|
||||
var r0 []*DashboardProvisioning
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string) []*DashboardProvisioning); ok {
|
||||
r0 = rf(ctx, name)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*models.DashboardProvisioning)
|
||||
r0 = ret.Get(0).([]*DashboardProvisioning)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,15 +313,15 @@ func (_m *FakeDashboardStore) GetProvisionedDashboardData(ctx context.Context, n
|
||||
}
|
||||
|
||||
// GetProvisionedDataByDashboardID provides a mock function with given fields: ctx, dashboardID
|
||||
func (_m *FakeDashboardStore) GetProvisionedDataByDashboardID(ctx context.Context, dashboardID int64) (*models.DashboardProvisioning, error) {
|
||||
func (_m *FakeDashboardStore) GetProvisionedDataByDashboardID(ctx context.Context, dashboardID int64) (*DashboardProvisioning, error) {
|
||||
ret := _m.Called(ctx, dashboardID)
|
||||
|
||||
var r0 *models.DashboardProvisioning
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64) *models.DashboardProvisioning); ok {
|
||||
var r0 *DashboardProvisioning
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64) *DashboardProvisioning); ok {
|
||||
r0 = rf(ctx, dashboardID)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*models.DashboardProvisioning)
|
||||
r0 = ret.Get(0).(*DashboardProvisioning)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,15 +336,15 @@ func (_m *FakeDashboardStore) GetProvisionedDataByDashboardID(ctx context.Contex
|
||||
}
|
||||
|
||||
// GetProvisionedDataByDashboardUID provides a mock function with given fields: ctx, orgID, dashboardUID
|
||||
func (_m *FakeDashboardStore) GetProvisionedDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*models.DashboardProvisioning, error) {
|
||||
func (_m *FakeDashboardStore) GetProvisionedDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*DashboardProvisioning, error) {
|
||||
ret := _m.Called(ctx, orgID, dashboardUID)
|
||||
|
||||
var r0 *models.DashboardProvisioning
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, string) *models.DashboardProvisioning); ok {
|
||||
var r0 *DashboardProvisioning
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, string) *DashboardProvisioning); ok {
|
||||
r0 = rf(ctx, orgID, dashboardUID)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*models.DashboardProvisioning)
|
||||
r0 = ret.Get(0).(*DashboardProvisioning)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user