1
0

feat(views): decouple buckets from projects

This commit is contained in:
kolaente
2024-03-15 10:32:38 +01:00
parent d1d07f462c
commit 0a3f45ab11
6 changed files with 148 additions and 26 deletions

View File

@ -35,6 +35,8 @@ type Bucket struct {
Title string `xorm:"text not null" valid:"required" minLength:"1" json:"title"`
// The project this bucket belongs to.
ProjectID int64 `xorm:"bigint not null" json:"project_id" param:"project"`
// The project view this bucket belongs to.
ProjectViewID int64 `xorm:"bigint not null" json:"project_view_id" param:"view"`
// All tasks which belong to this bucket.
Tasks []*Task `xorm:"-" json:"tasks"`
@ -167,13 +169,13 @@ func GetTasksInBucketsForView(s *xorm.Session, view *ProjectView, opts *taskSear
if view.BucketConfigurationMode == BucketConfigurationModeFilter {
for id, bc := range view.BucketConfiguration {
buckets = append(buckets, &Bucket{
ID: int64(id),
Title: bc.Title,
ProjectID: view.ProjectID,
Position: float64(id),
CreatedByID: auth.GetID(),
Created: time.Now(),
Updated: time.Now(),
ID: int64(id),
Title: bc.Title,
ProjectViewID: view.ID,
Position: float64(id),
CreatedByID: auth.GetID(),
Created: time.Now(),
Updated: time.Now(),
})
}
}

View File

@ -23,8 +23,8 @@ import (
// CanCreate checks if a user can create a new bucket
func (b *Bucket) CanCreate(s *xorm.Session, a web.Auth) (bool, error) {
l := &Project{ID: b.ProjectID}
return l.CanWrite(s, a)
pv := &ProjectView{ID: b.ProjectViewID}
return pv.CanUpdate(s, a)
}
// CanUpdate checks if a user can update an existing bucket
@ -43,6 +43,6 @@ func (b *Bucket) canDoBucket(s *xorm.Session, a web.Auth) (bool, error) {
if err != nil {
return false, err
}
l := &Project{ID: bb.ProjectID}
return l.CanWrite(s, a)
pv := &ProjectView{ID: bb.ProjectViewID}
return pv.CanUpdate(s, a)
}

View File

@ -777,19 +777,7 @@ func CreateProject(s *xorm.Session, project *Project, auth web.Auth, createBackl
}
}
if createBacklogBucket {
// Create a new first bucket for this project
b := &Bucket{
ProjectID: project.ID,
Title: "Backlog",
}
err = b.Create(s, auth)
if err != nil {
return
}
}
err = CreateDefaultViewsForProject(s, project, auth)
err = CreateDefaultViewsForProject(s, project, auth, createBacklogBucket)
if err != nil {
return
}

View File

@ -295,7 +295,7 @@ func GetProjectViewByID(s *xorm.Session, id, projectID int64) (view *ProjectView
return
}
func CreateDefaultViewsForProject(s *xorm.Session, project *Project, a web.Auth) (err error) {
func CreateDefaultViewsForProject(s *xorm.Session, project *Project, a web.Auth, createBacklogBucket bool) (err error) {
list := &ProjectView{
ProjectID: project.ID,
Title: "List",
@ -336,5 +336,18 @@ func CreateDefaultViewsForProject(s *xorm.Session, project *Project, a web.Auth)
Position: 400,
}
err = kanban.Create(s, a)
if err != nil {
return
}
if createBacklogBucket {
// Create a new first bucket for this project
b := &Bucket{
ProjectViewID: kanban.ID,
Title: "Backlog",
}
err = b.Create(s, a)
}
return
}

View File

@ -123,7 +123,7 @@ func (sf *SavedFilter) Create(s *xorm.Session, auth web.Auth) (err error) {
return
}
err = CreateDefaultViewsForProject(s, &Project{ID: getProjectIDFromSavedFilterID(sf.ID)}, auth)
err = CreateDefaultViewsForProject(s, &Project{ID: getProjectIDFromSavedFilterID(sf.ID)}, auth, false)
return err
}