Make duplicating actually work
This commit is contained in:
parent
babce6a327
commit
bfc5577e9e
|
@ -111,7 +111,15 @@ func (ld *ListDuplicate) Create(a web.Auth) (err error) {
|
|||
}
|
||||
|
||||
for _, attachment := range attachments {
|
||||
attachment.ID = 0
|
||||
attachment.TaskID = oldTaskIDs[attachment.TaskID]
|
||||
attachment.File = &files.File{ID: attachment.FileID}
|
||||
if err := attachment.File.LoadFileMetaByID(); err != nil {
|
||||
if files.IsErrFileDoesNotExist(err) {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
if err := attachment.File.LoadFileByID(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -121,7 +129,9 @@ func (ld *ListDuplicate) Create(a web.Auth) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
_ = attachment.File.File.Close()
|
||||
if attachment.File.File != nil {
|
||||
_ = attachment.File.File.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// Copy label tasks (not the labels)
|
||||
|
@ -166,6 +176,7 @@ func (ld *ListDuplicate) Create(a web.Auth) (err error) {
|
|||
return
|
||||
}
|
||||
for _, c := range comments {
|
||||
c.ID = 0
|
||||
c.TaskID = taskMap[c.TaskID]
|
||||
if _, err := x.Insert(c); err != nil {
|
||||
return err
|
||||
|
@ -176,7 +187,7 @@ func (ld *ListDuplicate) Create(a web.Auth) (err error) {
|
|||
// Low-Effort: Only copy those relations which are between tasks in the same list
|
||||
// because we can do that without a lot of hassle
|
||||
relations := []*TaskRelation{}
|
||||
err = x.In("task_id", oldTaskIDs).Find(relations)
|
||||
err = x.In("task_id", oldTaskIDs).Find(&relations)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -185,6 +196,7 @@ func (ld *ListDuplicate) Create(a web.Auth) (err error) {
|
|||
if !exists {
|
||||
continue
|
||||
}
|
||||
r.ID = 0
|
||||
r.OtherTaskID = otherTaskID
|
||||
r.TaskID = taskMap[r.TaskID]
|
||||
if _, err := x.Insert(r); err != nil {
|
||||
|
@ -205,7 +217,7 @@ func (ld *ListDuplicate) Create(a web.Auth) (err error) {
|
|||
|
||||
file, err := files.Create(f.File, f.Name, f.Size, a)
|
||||
if err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
// Get unsplash info if applicable
|
||||
|
|
|
@ -18,6 +18,7 @@ package models
|
|||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/files"
|
||||
"code.vikunja.io/api/pkg/user"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
@ -26,6 +27,7 @@ import (
|
|||
func TestListDuplicate(t *testing.T) {
|
||||
|
||||
db.LoadAndAssertFixtures(t)
|
||||
files.InitTestFileFixtures(t)
|
||||
|
||||
u := &user.User{
|
||||
ID: 1,
|
||||
|
|
Loading…
Reference in New Issue