Nested folders: Fix moving folder under root (#65684)
* Nested folders: Fix moving folder under root * Add store test for not empty parent after update * Modify folder and document store update implementation Move folder only if NewParentUID is not nil * Apply suggestion from code review
This commit is contained in:
@@ -92,6 +92,10 @@ func (ss *sqlStore) Update(ctx context.Context, cmd folder.UpdateFolderCommand)
|
||||
uid := cmd.UID
|
||||
|
||||
var foldr *folder.Folder
|
||||
|
||||
if cmd.NewDescription == nil && cmd.NewTitle == nil && cmd.NewUID == nil && cmd.NewParentUID == nil {
|
||||
return nil, folder.ErrBadRequest.Errorf("nothing to update")
|
||||
}
|
||||
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
sql := strings.Builder{}
|
||||
sql.Write([]byte("UPDATE folder SET "))
|
||||
@@ -114,8 +118,12 @@ func (ss *sqlStore) Update(ctx context.Context, cmd folder.UpdateFolderCommand)
|
||||
}
|
||||
|
||||
if cmd.NewParentUID != nil {
|
||||
columnsToUpdate = append(columnsToUpdate, "parent_uid = ?")
|
||||
args = append(args, *cmd.NewParentUID)
|
||||
if *cmd.NewParentUID == "" {
|
||||
columnsToUpdate = append(columnsToUpdate, "parent_uid = NULL")
|
||||
} else {
|
||||
columnsToUpdate = append(columnsToUpdate, "parent_uid = ?")
|
||||
args = append(args, *cmd.NewParentUID)
|
||||
}
|
||||
}
|
||||
|
||||
if len(columnsToUpdate) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user