mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Revert "Nested Folders: Fix fetching a folder by title" (#76469)
Revert "Nested Folders: Fix fetching a folder by title (#74725)"
This reverts commit 0eac9aff7f
.
This commit is contained in:
parent
29cf60988b
commit
bdeb829cf6
@ -166,15 +166,7 @@ func (ss *sqlStore) Get(ctx context.Context, q folder.GetFolderQuery) (*folder.F
|
|||||||
case q.ID != nil:
|
case q.ID != nil:
|
||||||
exists, err = sess.SQL("SELECT * FROM folder WHERE id = ?", q.ID).Get(foldr)
|
exists, err = sess.SQL("SELECT * FROM folder WHERE id = ?", q.ID).Get(foldr)
|
||||||
case q.Title != nil:
|
case q.Title != nil:
|
||||||
args := []any{*q.Title, q.OrgID}
|
exists, err = sess.SQL("SELECT * FROM folder WHERE title = ? AND org_id = ?", q.Title, q.OrgID).Get(foldr)
|
||||||
s := "SELECT * FROM folder WHERE title = ? AND org_id = ?"
|
|
||||||
if q.ParentUID != nil {
|
|
||||||
s = s + " AND parent_uid = ?"
|
|
||||||
args = append(args, *q.ParentUID)
|
|
||||||
} else {
|
|
||||||
s = s + " AND parent_uid IS NULL"
|
|
||||||
}
|
|
||||||
exists, err = sess.SQL(s, args...).Get(foldr)
|
|
||||||
default:
|
default:
|
||||||
return folder.ErrBadRequest.Errorf("one of ID, UID, or Title must be included in the command")
|
return folder.ErrBadRequest.Errorf("one of ID, UID, or Title must be included in the command")
|
||||||
}
|
}
|
||||||
|
@ -384,17 +384,6 @@ func TestIntegrationGet(t *testing.T) {
|
|||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// create subfolder with same title
|
|
||||||
subfolderUID := util.GenerateShortUID()
|
|
||||||
subfolder, err := folderStore.Create(context.Background(), folder.CreateFolderCommand{
|
|
||||||
Title: folderTitle,
|
|
||||||
Description: folderDsc,
|
|
||||||
OrgID: orgID,
|
|
||||||
UID: subfolderUID,
|
|
||||||
ParentUID: f.UID,
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
err := folderStore.Delete(context.Background(), f.UID, orgID)
|
err := folderStore.Delete(context.Background(), f.UID, orgID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -416,14 +405,15 @@ func TestIntegrationGet(t *testing.T) {
|
|||||||
assert.Equal(t, f.OrgID, ff.OrgID)
|
assert.Equal(t, f.OrgID, ff.OrgID)
|
||||||
assert.Equal(t, f.Title, ff.Title)
|
assert.Equal(t, f.Title, ff.Title)
|
||||||
assert.Equal(t, f.Description, ff.Description)
|
assert.Equal(t, f.Description, ff.Description)
|
||||||
|
//assert.Equal(t, folder.GeneralFolderUID, ff.ParentUID)
|
||||||
assert.NotEmpty(t, ff.Created)
|
assert.NotEmpty(t, ff.Created)
|
||||||
assert.NotEmpty(t, ff.Updated)
|
assert.NotEmpty(t, ff.Updated)
|
||||||
assert.NotEmpty(t, ff.URL)
|
assert.NotEmpty(t, ff.URL)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get folder by title should return folder under root", func(t *testing.T) {
|
t.Run("get folder by title should succeed", func(t *testing.T) {
|
||||||
ff, err := folderStore.Get(context.Background(), folder.GetFolderQuery{
|
ff, err := folderStore.Get(context.Background(), folder.GetFolderQuery{
|
||||||
Title: &folderTitle,
|
Title: &f.Title,
|
||||||
OrgID: orgID,
|
OrgID: orgID,
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -432,30 +422,13 @@ func TestIntegrationGet(t *testing.T) {
|
|||||||
assert.Equal(t, f.OrgID, ff.OrgID)
|
assert.Equal(t, f.OrgID, ff.OrgID)
|
||||||
assert.Equal(t, f.Title, ff.Title)
|
assert.Equal(t, f.Title, ff.Title)
|
||||||
assert.Equal(t, f.Description, ff.Description)
|
assert.Equal(t, f.Description, ff.Description)
|
||||||
|
//assert.Equal(t, folder.GeneralFolderUID, ff.ParentUID)
|
||||||
assert.NotEmpty(t, ff.Created)
|
assert.NotEmpty(t, ff.Created)
|
||||||
assert.NotEmpty(t, ff.Updated)
|
assert.NotEmpty(t, ff.Updated)
|
||||||
assert.NotEmpty(t, ff.URL)
|
assert.NotEmpty(t, ff.URL)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("get folder by title and parent UID should return subfolder", func(t *testing.T) {
|
t.Run("get folder by title should succeed", func(t *testing.T) {
|
||||||
ff, err := folderStore.Get(context.Background(), folder.GetFolderQuery{
|
|
||||||
Title: &folderTitle,
|
|
||||||
OrgID: orgID,
|
|
||||||
ParentUID: &f.UID,
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
assert.Equal(t, subfolder.ID, ff.ID)
|
|
||||||
assert.Equal(t, subfolder.UID, ff.UID)
|
|
||||||
assert.Equal(t, subfolder.OrgID, ff.OrgID)
|
|
||||||
assert.Equal(t, subfolder.Title, ff.Title)
|
|
||||||
assert.Equal(t, subfolder.Description, ff.Description)
|
|
||||||
assert.Equal(t, subfolder.ParentUID, ff.ParentUID)
|
|
||||||
assert.NotEmpty(t, subfolder.Created)
|
|
||||||
assert.NotEmpty(t, subfolder.Updated)
|
|
||||||
assert.NotEmpty(t, subfolder.URL)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("get folder by ID should succeed", func(t *testing.T) {
|
|
||||||
ff, err := folderStore.Get(context.Background(), folder.GetFolderQuery{
|
ff, err := folderStore.Get(context.Background(), folder.GetFolderQuery{
|
||||||
ID: &f.ID,
|
ID: &f.ID,
|
||||||
})
|
})
|
||||||
@ -465,6 +438,7 @@ func TestIntegrationGet(t *testing.T) {
|
|||||||
assert.Equal(t, f.OrgID, ff.OrgID)
|
assert.Equal(t, f.OrgID, ff.OrgID)
|
||||||
assert.Equal(t, f.Title, ff.Title)
|
assert.Equal(t, f.Title, ff.Title)
|
||||||
assert.Equal(t, f.Description, ff.Description)
|
assert.Equal(t, f.Description, ff.Description)
|
||||||
|
//assert.Equal(t, folder.GeneralFolderUID, ff.ParentUID)
|
||||||
assert.NotEmpty(t, ff.Created)
|
assert.NotEmpty(t, ff.Created)
|
||||||
assert.NotEmpty(t, ff.Updated)
|
assert.NotEmpty(t, ff.Updated)
|
||||||
assert.NotEmpty(t, ff.URL)
|
assert.NotEmpty(t, ff.URL)
|
||||||
|
@ -125,15 +125,13 @@ type DeleteFolderCommand struct {
|
|||||||
|
|
||||||
// GetFolderQuery is used for all folder Get requests. Only one of UID, ID, or
|
// GetFolderQuery is used for all folder Get requests. Only one of UID, ID, or
|
||||||
// Title should be set; if multiple fields are set by the caller the dashboard
|
// Title should be set; if multiple fields are set by the caller the dashboard
|
||||||
// service will select the field with the most specificity, in order: UID, ID
|
// service will select the field with the most specificity, in order: ID, UID,
|
||||||
// Title. If Title is set, it will fetch the folder in the root folder.
|
// Title.
|
||||||
// Callers can additionally set the ParentUID field to fetch a folder by title under a specific folder.
|
|
||||||
type GetFolderQuery struct {
|
type GetFolderQuery struct {
|
||||||
UID *string
|
UID *string
|
||||||
ParentUID *string
|
ID *int64
|
||||||
ID *int64
|
Title *string
|
||||||
Title *string
|
OrgID int64
|
||||||
OrgID int64
|
|
||||||
|
|
||||||
SignedInUser identity.Requester `json:"-"`
|
SignedInUser identity.Requester `json:"-"`
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,7 @@ type Service interface {
|
|||||||
// GetFolder takes a GetFolderCommand and returns a folder matching the
|
// GetFolder takes a GetFolderCommand and returns a folder matching the
|
||||||
// request. One of ID, UID, or Title must be included. If multiple values
|
// request. One of ID, UID, or Title must be included. If multiple values
|
||||||
// are included in the request, Grafana will select one in order of
|
// are included in the request, Grafana will select one in order of
|
||||||
// specificity (UID, ID,Title).
|
// specificity (ID, UID, Title).
|
||||||
// If Title is set, it will fetch the folder in the root folder.
|
|
||||||
// If nested folders are enabled, callers can additionally set the ParentUID field
|
|
||||||
// to fetch a folder by title under a specific folder.
|
|
||||||
Get(ctx context.Context, cmd *GetFolderQuery) (*Folder, error)
|
Get(ctx context.Context, cmd *GetFolderQuery) (*Folder, error)
|
||||||
|
|
||||||
// Update is used to update a folder's UID, Title and Description. To change
|
// Update is used to update a folder's UID, Title and Description. To change
|
||||||
|
Loading…
Reference in New Issue
Block a user