Kanban #393

Merged
konrad merged 14 commits from feature/kanban into master 2020-04-19 07:27:29 +00:00
2 changed files with 57 additions and 1 deletions
Showing only changes of commit 43eb8f4af5 - Show all commits

View File

@ -1223,3 +1223,31 @@ func (err ErrBucketDoesNotExist) HTTPError() web.HTTPError {
Message: "This bucket does not exist.",
}
}
// ErrBucketDoesNotBelongToList represents an error where a kanban bucket does not belong to a list
type ErrBucketDoesNotBelongToList struct {
BucketID int64
ListID int64
}
// IsErrBucketDoesNotBelongToList checks if an error is ErrBucketDoesNotBelongToList.
func IsErrBucketDoesNotBelongToList(err error) bool {
_, ok := err.(ErrBucketDoesNotBelongToList)
return ok
}
func (err ErrBucketDoesNotBelongToList) Error() string {
return fmt.Sprintf("Bucket does not not belong to list [BucketID: %d, ListID: %d]", err.BucketID, err.ListID)
}
// ErrCodeBucketDoesNotBelongToList holds the unique world-error code of this error
const ErrCodeBucketDoesNotBelongToList = 10002
// HTTPError holds the http error description
func (err ErrBucketDoesNotBelongToList) HTTPError() web.HTTPError {
return web.HTTPError{
HTTPCode: http.StatusBadRequest,
Code: ErrCodeBucketDoesNotBelongToList,
Message: "This bucket does not belong to that list.",
}
}

View File

@ -86,7 +86,7 @@ type Task struct {
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
// BucketID is the ID of the kanban bucket this task belongs to.
BucketID int64 `xorm:"int(11) null" json:"-"`
BucketID int64 `xorm:"int(11) null" json:"bucket_id"`
// The user who initially created the task.
CreatedBy *user.User `xorm:"-" json:"created_by" valid:"-"`
@ -462,6 +462,22 @@ func addMoreInfoToTasks(taskMap map[int64]*Task) (tasks []*Task, err error) {
return
}
func checkBucketAndTaskBelongToSameList(t *Task) (err error) {
if t.BucketID != 0 {
b, err := getBucketByID(t.BucketID)
if err != nil {
return
}
if t.ListID != b.ListID {
return ErrBucketDoesNotBelongToList{
ListID: t.ListID,
BucketID: t.BucketID,
}
}
}
return
}
// Create is the implementation to create a list task
// @Summary Create a task
// @Description Inserts a task into a list.
@ -501,6 +517,12 @@ func (t *Task) Create(a web.Auth) (err error) {
t.UID = utils.MakeRandomString(40)
}
// If there is a bucket set, make sure they belong to the same list as the task
err = checkBucketAndTaskBelongToSameList(t)
if err != nil {
return
}
// Get the index for this task
latestTask := &Task{}
_, err = x.Where("list_id = ?", t.ListID).OrderBy("id desc").Get(latestTask)
@ -576,6 +598,12 @@ func (t *Task) Update() (err error) {
return err
}
// If there is a bucket set, make sure they belong to the same list as the task
err = checkBucketAndTaskBelongToSameList(t)
if err != nil {
return
}
// Update the labels
//
// Maybe FIXME: