List item creation is now done via handler
This commit is contained in:
@ -38,3 +38,38 @@ func CreateOrUpdateListItem(item *ListItem) (newItem *ListItem, err error) {
|
||||
|
||||
return &finalItem, err
|
||||
}
|
||||
|
||||
// Create is the implementation to create a list item
|
||||
func (i *ListItem) Create(doer *User, lID int64) (err error) {
|
||||
i.ListID = lID
|
||||
|
||||
// Check rights
|
||||
user, _, err := GetUserByID(doer.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
i.CreatedBy = user // Needed because we return the full item object
|
||||
i.CreatedByID = user.ID
|
||||
|
||||
// Get the list to check if the user has the right to write to that list
|
||||
list, err := GetListByID(lID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !list.CanWrite(&user) {
|
||||
return ErrNeedToBeListWriter{ListID: lID, UserID: user.ID}
|
||||
}
|
||||
|
||||
// Check if we have at least a text
|
||||
if i.Text == "" {
|
||||
return ErrListItemCannotBeEmpty{}
|
||||
}
|
||||
|
||||
_, err = x.Insert(i)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user