Task Comments #138
|
@ -276,7 +276,7 @@ const ErrCodeTaskDoesNotExist = 4002
|
|||
|
||||
// HTTPError holds the http error description
|
||||
func (err ErrTaskDoesNotExist) HTTPError() web.HTTPError {
|
||||
return web.HTTPError{HTTPCode: http.StatusNotFound, Code: ErrCodeTaskDoesNotExist, Message: "This list task does not exist"}
|
||||
return web.HTTPError{HTTPCode: http.StatusNotFound, Code: ErrCodeTaskDoesNotExist, Message: "This task does not exist"}
|
||||
}
|
||||
|
||||
// ErrBulkTasksMustBeInSameList represents a "ErrBulkTasksMustBeInSameList" kind of error.
|
||||
|
|
|
@ -20,26 +20,26 @@ package models
|
|||
import "code.vikunja.io/web"
|
||||
|
||||
func (tc *TaskComment) CanRead(a web.Auth) (bool, error) {
|
||||
t := Task{ID: tc.ID}
|
||||
t := Task{ID: tc.TaskID}
|
||||
return t.CanRead(a)
|
||||
}
|
||||
|
||||
func (tc *TaskComment) CanWrite(a web.Auth) (bool, error) {
|
||||
t := Task{ID: tc.ID}
|
||||
t := Task{ID: tc.TaskID}
|
||||
return t.CanWrite(a)
|
||||
}
|
||||
|
||||
func (tc *TaskComment) CanDelete(a web.Auth) (bool, error) {
|
||||
t := Task{ID: tc.ID}
|
||||
t := Task{ID: tc.TaskID}
|
||||
return t.CanWrite(a)
|
||||
}
|
||||
|
||||
func (tc *TaskComment) CanUpdate(a web.Auth) (bool, error) {
|
||||
t := Task{ID: tc.ID}
|
||||
t := Task{ID: tc.TaskID}
|
||||
return t.CanWrite(a)
|
||||
}
|
||||
|
||||
func (tc *TaskComment) CanCreate(a web.Auth) (bool, error) {
|
||||
t := Task{ID: tc.ID}
|
||||
t := Task{ID: tc.TaskID}
|
||||
return t.CanWrite(a)
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ type TaskComment struct {
|
|||
Author *user.User `xorm:"-" json:"author"`
|
||||
TaskID int64 `xorm:"not null" json:"-" param:"task"`
|
||||
|
||||
Created timeutil.TimeStamp `xorm:"created"`
|
||||
Updated timeutil.TimeStamp `xorm:"updated"`
|
||||
Created timeutil.TimeStamp `xorm:"created" json:"created"`
|
||||
Updated timeutil.TimeStamp `xorm:"updated" json:"updated"`
|
||||
|
||||
web.CRUDable `xorm:"-" json:"-"`
|
||||
web.Rights `xorm:"-" json:"-"`
|
||||
|
@ -82,8 +82,7 @@ func (tc *TaskComment) ReadOne() (err error) {
|
|||
func (tc *TaskComment) ReadAll(auth web.Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfTotalItems int64, err error) {
|
||||
|
||||
// Check if the user has access to the task
|
||||
t := &Task{ID: tc.TaskID}
|
||||
canRead, err := t.CanRead(auth)
|
||||
canRead, err := tc.CanRead(auth)
|
||||
if err != nil {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
|
@ -98,7 +97,7 @@ func (tc *TaskComment) ReadAll(auth web.Auth, search string, page int, perPage i
|
|||
AuthorFromDB *user.User `xorm:"extends" json:"-"`
|
||||
}
|
||||
|
||||
comments := []*TaskCommentWithAuthor{}
|
||||
comments := []*TaskComment{}
|
||||
err = x.
|
||||
Where("task_id = ? AND comment like ?", tc.TaskID, "%"+search+"%").
|
||||
Join("LEFT", "users", "users.id = task_comments.author_id").
|
||||
|
@ -108,12 +107,24 @@ func (tc *TaskComment) ReadAll(auth web.Auth, search string, page int, perPage i
|
|||
return
|
||||
}
|
||||
|
||||
for _, c := range comments {
|
||||
c.Author = c.AuthorFromDB
|
||||
// Get all authors
|
||||
authors := make(map[int64]*user.User)
|
||||
err = x.
|
||||
Select("users.*").
|
||||
Table("task_comments").
|
||||
Where("task_id = ? AND comment like ?", tc.TaskID, "%"+search+"%").
|
||||
Join("INNER", "users", "users.id = task_comments.author_id").
|
||||
Find(&authors)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, comment := range comments {
|
||||
comment.Author = authors[comment.AuthorID]
|
||||
}
|
||||
|
||||
numberOfTotalItems, err = x.
|
||||
Where("task_id = ? AND comment like ?", tc.TaskID, "%"+search+"%").
|
||||
Count(&comments)
|
||||
Count(&TaskCommentWithAuthor{})
|
||||
return comments, len(comments), numberOfTotalItems, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue