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:
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
ngModels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
@@ -671,12 +672,12 @@ func createAlert(t *testing.T, orgId int64, dashboardId int64, panelsId int64, n
|
||||
}
|
||||
|
||||
// createDashboard creates a dashboard for inserting into the test database.
|
||||
func createDashboard(t *testing.T, id int64, orgId int64, uid string) *models.Dashboard {
|
||||
func createDashboard(t *testing.T, id int64, orgId int64, uid string) *dashboards.Dashboard {
|
||||
t.Helper()
|
||||
return &models.Dashboard{
|
||||
Id: id,
|
||||
OrgId: orgId,
|
||||
Uid: uid,
|
||||
return &dashboards.Dashboard{
|
||||
ID: id,
|
||||
OrgID: orgId,
|
||||
UID: uid,
|
||||
Created: now,
|
||||
Updated: now,
|
||||
Title: uid, // Not tested, needed to satisfy contraint.
|
||||
@@ -744,7 +745,7 @@ func setupLegacyAlertsTables(t *testing.T, x *xorm.Engine, legacyChannels []*mod
|
||||
}
|
||||
|
||||
// Setup dashboards.
|
||||
dashboards := []models.Dashboard{
|
||||
dashboards := []dashboards.Dashboard{
|
||||
*createDashboard(t, 1, 1, "dash1-1"),
|
||||
*createDashboard(t, 2, 1, "dash2-1"),
|
||||
*createDashboard(t, 3, 2, "dash3-2"),
|
||||
|
||||
@@ -144,7 +144,7 @@ func (m *folderHelper) generateNewDashboardUid(orgId int64) (string, error) {
|
||||
for i := 0; i < 3; i++ {
|
||||
uid := util.GenerateShortUID()
|
||||
|
||||
exists, err := m.sess.Where("org_id=? AND uid=?", orgId, uid).Get(&models.Dashboard{})
|
||||
exists, err := m.sess.Where("org_id=? AND uid=?", orgId, uid).Get(&dashboards.Dashboard{})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -252,7 +252,7 @@ func (m *folderHelper) setACL(orgID int64, dashboardID int64, items []*dashboard
|
||||
}
|
||||
|
||||
// Update dashboard HasACL flag
|
||||
dashboard := models.Dashboard{HasACL: true}
|
||||
dashboard := dashboards.Dashboard{HasACL: true}
|
||||
_, err := m.sess.Cols("has_acl").Where("id=?", dashboardID).Update(&dashboard)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -148,13 +148,13 @@ func TestIntegration_DashboardPermissionFilter(t *testing.T) {
|
||||
func setupTest(t *testing.T, numFolders, numDashboards int, permissions []accesscontrol.Permission) db.DB {
|
||||
store := db.InitTestDB(t)
|
||||
err := store.WithDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
|
||||
dashes := make([]models.Dashboard, 0, numFolders+numDashboards)
|
||||
dashes := make([]dashboards.Dashboard, 0, numFolders+numDashboards)
|
||||
for i := 1; i <= numFolders; i++ {
|
||||
str := strconv.Itoa(i)
|
||||
dashes = append(dashes, models.Dashboard{
|
||||
OrgId: 1,
|
||||
dashes = append(dashes, dashboards.Dashboard{
|
||||
OrgID: 1,
|
||||
Slug: str,
|
||||
Uid: str,
|
||||
UID: str,
|
||||
Title: str,
|
||||
IsFolder: true,
|
||||
Data: simplejson.New(),
|
||||
@@ -169,11 +169,11 @@ func setupTest(t *testing.T, numFolders, numDashboards int, permissions []access
|
||||
if i%numFolders != 0 {
|
||||
folderID = i % numFolders
|
||||
}
|
||||
dashes = append(dashes, models.Dashboard{
|
||||
OrgId: 1,
|
||||
dashes = append(dashes, dashboards.Dashboard{
|
||||
OrgID: 1,
|
||||
IsFolder: false,
|
||||
FolderId: int64(folderID),
|
||||
Uid: str,
|
||||
FolderID: int64(folderID),
|
||||
UID: str,
|
||||
Slug: str,
|
||||
Title: str,
|
||||
Data: simplejson.New(),
|
||||
|
||||
@@ -41,13 +41,13 @@ func setupBenchMark(b *testing.B, numUsers, numDashboards int) db.DB {
|
||||
store := db.InitTestDB(b)
|
||||
now := time.Now()
|
||||
err := store.WithDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
|
||||
dashes := make([]models.Dashboard, 0, numDashboards)
|
||||
dashes := make([]dashboards.Dashboard, 0, numDashboards)
|
||||
for i := 1; i <= numDashboards; i++ {
|
||||
str := strconv.Itoa(i)
|
||||
dashes = append(dashes, models.Dashboard{
|
||||
OrgId: 1,
|
||||
dashes = append(dashes, dashboards.Dashboard{
|
||||
OrgID: 1,
|
||||
IsFolder: false,
|
||||
Uid: str,
|
||||
UID: str,
|
||||
Slug: str,
|
||||
Title: str,
|
||||
Data: simplejson.New(),
|
||||
@@ -82,7 +82,7 @@ func setupBenchMark(b *testing.B, numUsers, numDashboards int) db.DB {
|
||||
permissions = append(permissions, accesscontrol.Permission{
|
||||
RoleID: int64(i),
|
||||
Action: dashboards.ActionDashboardsRead,
|
||||
Scope: dashboards.ScopeDashboardsProvider.GetResourceScopeUID(dash.Uid),
|
||||
Scope: dashboards.ScopeDashboardsProvider.GetResourceScopeUID(dash.UID),
|
||||
Updated: now,
|
||||
Created: now,
|
||||
})
|
||||
|
||||
@@ -173,11 +173,11 @@ func createDashboards(t *testing.T, store db.DB, startID, endID int, orgID int64
|
||||
}`))
|
||||
require.NoError(t, err)
|
||||
|
||||
var dash *models.Dashboard
|
||||
var dash *dashboards.Dashboard
|
||||
err = store.WithDbSession(context.Background(), func(sess *db.Session) error {
|
||||
dash = models.NewDashboardFromJson(dashboard)
|
||||
dash.OrgId = orgID
|
||||
dash.Uid = util.GenerateShortUID()
|
||||
dash = dashboards.NewDashboardFromJson(dashboard)
|
||||
dash.OrgID = orgID
|
||||
dash.UID = util.GenerateShortUID()
|
||||
dash.CreatedBy = 1
|
||||
dash.UpdatedBy = 1
|
||||
_, err := sess.Insert(dash)
|
||||
@@ -186,7 +186,7 @@ func createDashboards(t *testing.T, store db.DB, startID, endID int, orgID int64
|
||||
tags := dash.GetTags()
|
||||
if len(tags) > 0 {
|
||||
for _, tag := range tags {
|
||||
if _, err := sess.Insert(&DashboardTag{DashboardId: dash.Id, Term: tag}); err != nil {
|
||||
if _, err := sess.Insert(&DashboardTag{DashboardId: dash.ID, Term: tag}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ func createDashboards(t *testing.T, store db.DB, startID, endID int, orgID int64
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
createdIds = append(createdIds, dash.Id)
|
||||
createdIds = append(createdIds, dash.ID)
|
||||
}
|
||||
|
||||
return createdIds
|
||||
|
||||
Reference in New Issue
Block a user