fix(views): import
This commit is contained in:
parent
8b90eb4a15
commit
f3cdd7d15f
@ -349,6 +349,7 @@ func (b *Bucket) Update(s *xorm.Session, _ web.Auth) (err error) {
|
||||
"title",
|
||||
"limit",
|
||||
"position",
|
||||
"project_view_id",
|
||||
).
|
||||
Update(b)
|
||||
return
|
||||
|
@ -422,5 +422,12 @@ func CreateDefaultViewsForProject(s *xorm.Session, project *Project, a web.Auth,
|
||||
return
|
||||
}
|
||||
|
||||
project.Views = []*ProjectView{
|
||||
list,
|
||||
gantt,
|
||||
table,
|
||||
kanban,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -126,6 +126,7 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
||||
originalBuckets := project.Buckets
|
||||
originalBackgroundInformation := project.BackgroundInformation
|
||||
needsDefaultBucket := false
|
||||
oldViews := project.Views
|
||||
|
||||
// Saving the archived status to archive the project again after creating it
|
||||
var wasArchived bool
|
||||
@ -182,6 +183,47 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
||||
log.Debugf("[creating structure] Created bucket %d, old ID was %d", bucket.ID, oldID)
|
||||
}
|
||||
|
||||
// Create all views, create default views if we don't have any
|
||||
if len(oldViews) > 0 {
|
||||
for _, view := range oldViews {
|
||||
view.ID = 0
|
||||
|
||||
if view.DefaultBucketID != 0 {
|
||||
bucket, has := buckets[view.DefaultBucketID]
|
||||
if has {
|
||||
view.DefaultBucketID = bucket.ID
|
||||
}
|
||||
}
|
||||
|
||||
if view.DoneBucketID != 0 {
|
||||
bucket, has := buckets[view.DoneBucketID]
|
||||
if has {
|
||||
view.DoneBucketID = bucket.ID
|
||||
}
|
||||
}
|
||||
|
||||
err = view.Create(s, user)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Only using the default views
|
||||
// Add all buckets to the default kanban view
|
||||
for _, view := range project.Views {
|
||||
if view.ViewKind == models.ProjectViewKindKanban {
|
||||
for _, b := range buckets {
|
||||
b.ProjectViewID = view.ID
|
||||
err = b.Update(s, user)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("[creating structure] Creating %d tasks", len(tasks))
|
||||
|
||||
setBucketOrDefault := func(task *models.Task) {
|
||||
@ -205,7 +247,6 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
||||
oldid := t.ID
|
||||
t.ProjectID = project.ID
|
||||
err = t.Create(s, user)
|
||||
|
||||
if err != nil && models.IsErrTaskCannotBeEmpty(err) {
|
||||
continue
|
||||
}
|
||||
@ -332,6 +373,14 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
||||
// All tasks brought their own bucket with them, therefore the newly created default bucket is just extra space
|
||||
if !needsDefaultBucket {
|
||||
b := &models.Bucket{ProjectID: project.ID}
|
||||
|
||||
for _, view := range project.Views {
|
||||
if view.ViewKind == models.ProjectViewKindKanban {
|
||||
b.ProjectViewID = view.ID
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
bucketsIn, _, _, err := b.ReadAll(s, user, "", 1, 1)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -341,6 +390,7 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
||||
for _, b := range buckets {
|
||||
if b.Title == "Backlog" {
|
||||
newBacklogBucket = b
|
||||
newBacklogBucket.ProjectID = project.ID
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -142,12 +142,11 @@ func TestInsertFromStructure(t *testing.T) {
|
||||
"title": testStructure[1].Title,
|
||||
"description": testStructure[1].Description,
|
||||
}, false)
|
||||
db.AssertExists(t, "tasks", map[string]interface{}{
|
||||
"title": testStructure[1].Tasks[5].Title,
|
||||
db.AssertExists(t, "task_buckets", map[string]interface{}{
|
||||
"task_id": testStructure[1].Tasks[5].ID,
|
||||
"bucket_id": testStructure[1].Buckets[0].ID,
|
||||
}, false)
|
||||
db.AssertMissing(t, "tasks", map[string]interface{}{
|
||||
"title": testStructure[1].Tasks[6].Title,
|
||||
db.AssertMissing(t, "task_buckets", map[string]interface{}{
|
||||
"bucket_id": 1111, // No task with that bucket should exist
|
||||
})
|
||||
db.AssertExists(t, "tasks", map[string]interface{}{
|
||||
|
Loading…
x
Reference in New Issue
Block a user