Fix: Change getExistingDashboardByTitleAndFolder to get dashboard by title, not slug (#70723)
* Fix: Change getExistingDashboardByTitleAndFolder to get dashboard by title, not slug * test: add tests for get dashboard with existing name, get dashboard with non existing name, get dashboard with existing name in a folder * Update pkg/services/dashboards/database/database_test.go Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> * require specific error for Should be able to get dashboard with existing name * Update pkg/services/dashboards/database/database_test.go Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> * implement sofia suggestions to check for specific err, remove logs * give test more specific name * implement daniel suggestion of formatting documentation comment in safe way * fix test title to refer to root directory not specific folder --------- Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
This commit is contained in:
co-authored by
Sofia Papagiannaki
parent
40bc6a95be
commit
67cdae4b7d
@@ -385,15 +385,15 @@ func getExistingDashboardByIDOrUIDForUpdate(sess *db.Session, dash *dashboards.D
|
||||
return isParentFolderChanged, nil
|
||||
}
|
||||
|
||||
// getExistingDashboardByTitleAndFolder returns a boolean (on whether the parent folder changed) and an error for if the dashboard already exists.
|
||||
func getExistingDashboardByTitleAndFolder(sess *db.Session, dash *dashboards.Dashboard, dialect migrator.Dialect, overwrite,
|
||||
isParentFolderChanged bool) (bool, error) {
|
||||
var existing dashboards.Dashboard
|
||||
exists, err := sess.Where("org_id=? AND slug=? AND (is_folder=? OR folder_id=?)", dash.OrgID, dash.Slug,
|
||||
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 {
|
||||
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 existing.IsFolder && !dash.IsFolder {
|
||||
return isParentFolderChanged, dashboards.ErrDashboardWithSameNameAsFolder
|
||||
|
||||
Reference in New Issue
Block a user