1
0

User Data Export and import (#967)

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/api/pulls/967
Co-authored-by: konrad <k@knt.li>
Co-committed-by: konrad <k@knt.li>
This commit is contained in:
konrad
2021-09-04 19:26:31 +00:00
parent fc51a3e76f
commit 90146aea5b
46 changed files with 2395 additions and 582 deletions

View File

@ -144,16 +144,16 @@ func getTrelloData(token string) (trelloData []*trello.Board, err error) {
// Converts all previously obtained data from trello into the vikunja format.
// `trelloData` should contain all boards with their lists and cards respectively.
func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachie []*models.NamespaceWithLists, err error) {
func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachie []*models.NamespaceWithListsAndTasks, err error) {
log.Debugf("[Trello Migration] ")
fullVikunjaHierachie = []*models.NamespaceWithLists{
fullVikunjaHierachie = []*models.NamespaceWithListsAndTasks{
{
Namespace: models.Namespace{
Title: "Imported from Trello",
},
Lists: []*models.List{},
Lists: []*models.ListWithTasksAndBuckets{},
},
}
@ -162,10 +162,12 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
log.Debugf("[Trello Migration] Converting %d boards to vikunja lists", len(trelloData))
for _, board := range trelloData {
list := &models.List{
Title: board.Name,
Description: board.Desc,
IsArchived: board.Closed,
list := &models.ListWithTasksAndBuckets{
List: models.List{
Title: board.Name,
Description: board.Desc,
IsArchived: board.Closed,
},
}
// Background
@ -269,7 +271,7 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
log.Debugf("[Trello Migration] Downloaded card attachment %s", attachment.ID)
}
list.Tasks = append(list.Tasks, task)
list.Tasks = append(list.Tasks, &models.TaskWithComments{Task: *task})
}
list.Buckets = append(list.Buckets, bucket)

View File

@ -187,16 +187,18 @@ func TestConvertTrelloToVikunja(t *testing.T) {
}
trelloData[0].Prefs.BackgroundImage = "https://vikunja.io/testimage.jpg" // Using an image which we are hosting, so it'll still be up
expectedHierachie := []*models.NamespaceWithLists{
expectedHierachie := []*models.NamespaceWithListsAndTasks{
{
Namespace: models.Namespace{
Title: "Imported from Trello",
},
Lists: []*models.List{
Lists: []*models.ListWithTasksAndBuckets{
{
Title: "TestBoard",
Description: "This is a description",
BackgroundInformation: bytes.NewBuffer(exampleFile),
List: models.List{
Title: "TestBoard",
Description: "This is a description",
BackgroundInformation: bytes.NewBuffer(exampleFile),
},
Buckets: []*models.Bucket{
{
ID: 1,
@ -207,37 +209,40 @@ func TestConvertTrelloToVikunja(t *testing.T) {
Title: "Test List 2",
},
},
Tasks: []*models.Task{
Tasks: []*models.TaskWithComments{
{
Title: "Test Card 1",
Description: "Card Description",
BucketID: 1,
KanbanPosition: 123,
DueDate: time1,
Labels: []*models.Label{
{
Title: "Label 1",
HexColor: trelloColorMap["green"],
Task: models.Task{
Title: "Test Card 1",
Description: "Card Description",
BucketID: 1,
KanbanPosition: 123,
DueDate: time1,
Labels: []*models.Label{
{
Title: "Label 1",
HexColor: trelloColorMap["green"],
},
{
Title: "Label 2",
HexColor: trelloColorMap["orange"],
},
},
{
Title: "Label 2",
HexColor: trelloColorMap["orange"],
},
},
Attachments: []*models.TaskAttachment{
{
File: &files.File{
Name: "Testimage.jpg",
Mime: "image/jpg",
Size: uint64(len(exampleFile)),
FileContent: exampleFile,
Attachments: []*models.TaskAttachment{
{
File: &files.File{
Name: "Testimage.jpg",
Mime: "image/jpg",
Size: uint64(len(exampleFile)),
FileContent: exampleFile,
},
},
},
},
},
{
Title: "Test Card 2",
Description: `
Task: models.Task{
Title: "Test Card 2",
Description: `
## Checklist 1
@ -248,84 +253,105 @@ func TestConvertTrelloToVikunja(t *testing.T) {
* [ ] Pending Task
* [ ] Another Pending Task`,
BucketID: 1,
KanbanPosition: 124,
BucketID: 1,
KanbanPosition: 124,
},
},
{
Title: "Test Card 3",
BucketID: 1,
KanbanPosition: 126,
Task: models.Task{
Title: "Test Card 3",
BucketID: 1,
KanbanPosition: 126,
},
},
{
Title: "Test Card 4",
BucketID: 1,
KanbanPosition: 127,
Labels: []*models.Label{
{
Title: "Label 2",
HexColor: trelloColorMap["orange"],
Task: models.Task{
Title: "Test Card 4",
BucketID: 1,
KanbanPosition: 127,
Labels: []*models.Label{
{
Title: "Label 2",
HexColor: trelloColorMap["orange"],
},
},
},
},
{
Title: "Test Card 5",
BucketID: 2,
KanbanPosition: 111,
Labels: []*models.Label{
{
Title: "Label 3",
HexColor: trelloColorMap["blue"],
Task: models.Task{
Title: "Test Card 5",
BucketID: 2,
KanbanPosition: 111,
Labels: []*models.Label{
{
Title: "Label 3",
HexColor: trelloColorMap["blue"],
},
},
},
},
{
Title: "Test Card 6",
BucketID: 2,
KanbanPosition: 222,
DueDate: time1,
Task: models.Task{
Title: "Test Card 6",
BucketID: 2,
KanbanPosition: 222,
DueDate: time1,
},
},
{
Title: "Test Card 7",
BucketID: 2,
KanbanPosition: 333,
Task: models.Task{
Title: "Test Card 7",
BucketID: 2,
KanbanPosition: 333,
},
},
{
Title: "Test Card 8",
BucketID: 2,
KanbanPosition: 444,
Task: models.Task{
Title: "Test Card 8",
BucketID: 2,
KanbanPosition: 444,
},
},
},
},
{
Title: "TestBoard 2",
List: models.List{
Title: "TestBoard 2",
},
Buckets: []*models.Bucket{
{
ID: 3,
Title: "Test List 4",
},
},
Tasks: []*models.Task{
Tasks: []*models.TaskWithComments{
{
Title: "Test Card 634",
BucketID: 3,
KanbanPosition: 123,
Task: models.Task{
Title: "Test Card 634",
BucketID: 3,
KanbanPosition: 123,
},
},
},
},
{
Title: "TestBoard Archived",
IsArchived: true,
List: models.List{
Title: "TestBoard Archived",
IsArchived: true,
},
Buckets: []*models.Bucket{
{
ID: 4,
Title: "Test List 5",
},
},
Tasks: []*models.Task{
Tasks: []*models.TaskWithComments{
{
Title: "Test Card 63423",
BucketID: 4,
KanbanPosition: 123,
Task: models.Task{
Title: "Test Card 63423",
BucketID: 4,
KanbanPosition: 123,
},
},
},
},