Chore: Deprecate FolderID from Dashboard (#77823)
* Chore: Deprecate FolderID from Dashboard * chore: add two missing nolint comments
This commit is contained in:
@@ -330,6 +330,7 @@ func getExistingDashboardByIDOrUIDForUpdate(sess *db.Session, dash *dashboards.D
|
||||
}
|
||||
}
|
||||
|
||||
// nolint:staticcheck
|
||||
if dash.FolderID > 0 {
|
||||
var existingFolder dashboards.Dashboard
|
||||
folderExists, err := sess.Where("org_id=? AND id=? AND is_folder=?", dash.OrgID, dash.FolderID,
|
||||
@@ -364,6 +365,7 @@ func getExistingDashboardByIDOrUIDForUpdate(sess *db.Session, dash *dashboards.D
|
||||
return isParentFolderChanged, dashboards.ErrDashboardTypeMismatch
|
||||
}
|
||||
|
||||
// nolint:staticcheck
|
||||
if !dash.IsFolder && dash.FolderID != existing.FolderID {
|
||||
isParentFolderChanged = true
|
||||
}
|
||||
@@ -389,6 +391,7 @@ 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 dashboards.Dashboard
|
||||
// nolint:staticcheck
|
||||
exists, err := sess.Where("org_id=? AND title=? AND (is_folder=? OR folder_id=?)", dash.OrgID, dash.Title,
|
||||
dialect.BooleanStr(true), dash.FolderID).Get(&existing)
|
||||
if err != nil {
|
||||
@@ -403,6 +406,7 @@ func getExistingDashboardByTitleAndFolder(sess *db.Session, dash *dashboards.Das
|
||||
return isParentFolderChanged, dashboards.ErrDashboardFolderWithSameNameAsDashboard
|
||||
}
|
||||
|
||||
// nolint:staticcheck
|
||||
if !dash.IsFolder && (dash.FolderID != existing.FolderID || dash.ID == 0) {
|
||||
isParentFolderChanged = true
|
||||
}
|
||||
@@ -897,6 +901,7 @@ func (d *dashboardStore) GetDashboard(ctx context.Context, query *dashboards.Get
|
||||
}
|
||||
// nolint:staticcheck
|
||||
if query.FolderID != nil {
|
||||
// nolint:staticcheck
|
||||
dashboard.FolderID = *query.FolderID
|
||||
mustCols = append(mustCols, "folder_id")
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
require.Equal(t, savedDash.Slug, "test-dash-23")
|
||||
require.NotEqual(t, savedDash.ID, 0)
|
||||
require.False(t, savedDash.IsFolder)
|
||||
// nolint:staticcheck
|
||||
require.Positive(t, savedDash.FolderID)
|
||||
require.Positive(t, len(savedDash.UID))
|
||||
|
||||
@@ -68,6 +69,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
require.Equal(t, savedFolder.Slug, "1-test-dash-folder")
|
||||
require.NotEqual(t, savedFolder.ID, 0)
|
||||
require.True(t, savedFolder.IsFolder)
|
||||
// nolint:staticcheck
|
||||
require.EqualValues(t, savedFolder.FolderID, 0)
|
||||
require.Positive(t, len(savedFolder.UID))
|
||||
})
|
||||
@@ -222,6 +224,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
}
|
||||
dash, err := dashboardStore.SaveDashboard(context.Background(), cmd)
|
||||
require.NoError(t, err)
|
||||
// nolint:staticcheck
|
||||
require.EqualValues(t, dash.FolderID, 2)
|
||||
|
||||
cmd = dashboards.SaveDashboardCommand{
|
||||
@@ -245,6 +248,7 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
|
||||
queryResult, err := dashboardStore.GetDashboard(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
// nolint:staticcheck
|
||||
require.Equal(t, queryResult.FolderID, int64(0))
|
||||
require.Equal(t, queryResult.CreatedBy, savedDash.CreatedBy)
|
||||
require.WithinDuration(t, queryResult.Created, savedDash.Created, 3*time.Second)
|
||||
@@ -700,6 +704,7 @@ func TestGetExistingDashboardByTitleAndFolder(t *testing.T) {
|
||||
savedFolder := insertTestDashboard(t, dashboardStore, "test dash folder", 1, 0, "", true, "prod", "webapp")
|
||||
savedDash := insertTestDashboard(t, dashboardStore, "test dash", 1, savedFolder.ID, savedFolder.UID, false, "prod", "webapp")
|
||||
err = sqlStore.WithDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
|
||||
// nolint:staticcheck
|
||||
_, err = getExistingDashboardByTitleAndFolder(sess, &dashboards.Dashboard{Title: savedDash.Title, FolderID: savedFolder.ID, OrgID: 1}, sqlStore.GetDialect(), false, false)
|
||||
return err
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user