mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Folders: Do not allow modifying the folder UID via the API (#74684)
* Folders: Do not allow changing the folder UID via the API * Update Swagger/OpenAPI docs * Update HTTP API docs
This commit is contained in:
committed by
GitHub
parent
2fac3bd41e
commit
376f9a75db
@@ -373,18 +373,9 @@ func (s *Service) Update(ctx context.Context, cmd *folder.UpdateFolderCommand) (
|
||||
return dashFolder, nil
|
||||
}
|
||||
|
||||
if cmd.NewUID != nil && *cmd.NewUID != "" {
|
||||
if !util.IsValidShortUID(*cmd.NewUID) {
|
||||
return nil, dashboards.ErrDashboardInvalidUid
|
||||
} else if util.IsShortUIDTooLong(*cmd.NewUID) {
|
||||
return nil, dashboards.ErrDashboardUidTooLong
|
||||
}
|
||||
}
|
||||
|
||||
foldr, err := s.store.Update(ctx, folder.UpdateFolderCommand{
|
||||
UID: cmd.UID,
|
||||
OrgID: cmd.OrgID,
|
||||
NewUID: cmd.NewUID,
|
||||
NewTitle: cmd.NewTitle,
|
||||
NewDescription: cmd.NewDescription,
|
||||
SignedInUser: user,
|
||||
@@ -471,10 +462,6 @@ func prepareForUpdate(dashFolder *dashboards.Dashboard, orgId int64, userId int6
|
||||
dashFolder.Title = strings.TrimSpace(title)
|
||||
dashFolder.Data.Set("title", dashFolder.Title)
|
||||
|
||||
if cmd.NewUID != nil && *cmd.NewUID != "" {
|
||||
dashFolder.SetUID(*cmd.NewUID)
|
||||
}
|
||||
|
||||
dashFolder.SetVersion(cmd.Version)
|
||||
dashFolder.IsFolder = true
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ func (ss *sqlStore) Update(ctx context.Context, cmd folder.UpdateFolderCommand)
|
||||
|
||||
var foldr *folder.Folder
|
||||
|
||||
if cmd.NewDescription == nil && cmd.NewTitle == nil && cmd.NewUID == nil && cmd.NewParentUID == nil {
|
||||
if cmd.NewDescription == nil && cmd.NewTitle == nil && cmd.NewParentUID == nil {
|
||||
return nil, folder.ErrBadRequest.Errorf("nothing to update")
|
||||
}
|
||||
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
@@ -110,12 +110,6 @@ func (ss *sqlStore) Update(ctx context.Context, cmd folder.UpdateFolderCommand)
|
||||
args = append(args, *cmd.NewTitle)
|
||||
}
|
||||
|
||||
if cmd.NewUID != nil {
|
||||
columnsToUpdate = append(columnsToUpdate, "uid = ?")
|
||||
uid = *cmd.NewUID
|
||||
args = append(args, *cmd.NewUID)
|
||||
}
|
||||
|
||||
if cmd.NewParentUID != nil {
|
||||
if *cmd.NewParentUID == "" {
|
||||
columnsToUpdate = append(columnsToUpdate, "parent_uid = NULL")
|
||||
|
||||
@@ -286,30 +286,6 @@ func TestIntegrationUpdate(t *testing.T) {
|
||||
f = updated
|
||||
})
|
||||
|
||||
t.Run("updating folder UID should succeed", func(t *testing.T) {
|
||||
newUID := "new"
|
||||
existingTitle := f.Title
|
||||
existingDesc := f.Description
|
||||
updated, err := folderStore.Update(context.Background(), folder.UpdateFolderCommand{
|
||||
UID: f.UID,
|
||||
OrgID: f.OrgID,
|
||||
NewUID: &newUID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, newUID, updated.UID)
|
||||
|
||||
updated, err = folderStore.Get(context.Background(), folder.GetFolderQuery{
|
||||
UID: &updated.UID,
|
||||
OrgID: orgID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, newUID, updated.UID)
|
||||
assert.Equal(t, existingTitle, updated.Title)
|
||||
assert.Equal(t, existingDesc, updated.Description)
|
||||
assert.NotEmpty(t, updated.URL)
|
||||
})
|
||||
|
||||
t.Run("updating folder parent UID", func(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
|
||||
Reference in New Issue
Block a user