Add task assignee created event
This commit is contained in:
parent
a93aab6024
commit
73bed1ce31
|
@ -85,7 +85,7 @@ func (bt *BulkTask) Update(s *xorm.Session, a web.Auth) (err error) {
|
||||||
updateDone(oldtask, &bt.Task)
|
updateDone(oldtask, &bt.Task)
|
||||||
|
|
||||||
// Update the assignees
|
// Update the assignees
|
||||||
if err := oldtask.updateTaskAssignees(s, bt.Assignees); err != nil {
|
if err := oldtask.updateTaskAssignees(s, bt.Assignees, a); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,9 @@
|
||||||
|
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import "code.vikunja.io/api/pkg/user"
|
import (
|
||||||
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
)
|
||||||
|
|
||||||
type TaskCreatedEvent struct {
|
type TaskCreatedEvent struct {
|
||||||
Task *Task
|
Task *Task
|
||||||
|
@ -43,3 +45,17 @@ func (t *TaskUpdatedEvent) TopicName() string {
|
||||||
func (t *TaskUpdatedEvent) Message() interface{} {
|
func (t *TaskUpdatedEvent) Message() interface{} {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TaskAssigneeCreatedEvent struct {
|
||||||
|
Task *Task
|
||||||
|
Assignee *user.User
|
||||||
|
Doer *user.User
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TaskAssigneeCreatedEvent) TopicName() string {
|
||||||
|
return "task.assignee.created"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TaskAssigneeCreatedEvent) Message() interface{} {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
|
@ -67,15 +67,15 @@ func (ld *ListDuplicate) CanCreate(s *xorm.Session, a web.Auth) (canCreate bool,
|
||||||
// @Failure 500 {object} models.Message "Internal error"
|
// @Failure 500 {object} models.Message "Internal error"
|
||||||
// @Router /lists/{listID}/duplicate [put]
|
// @Router /lists/{listID}/duplicate [put]
|
||||||
//nolint:gocyclo
|
//nolint:gocyclo
|
||||||
func (ld *ListDuplicate) Create(s *xorm.Session, a web.Auth) (err error) {
|
func (ld *ListDuplicate) Create(s *xorm.Session, doer web.Auth) (err error) {
|
||||||
|
|
||||||
log.Debugf("Duplicating list %d", ld.ListID)
|
log.Debugf("Duplicating list %d", ld.ListID)
|
||||||
|
|
||||||
ld.List.ID = 0
|
ld.List.ID = 0
|
||||||
ld.List.Identifier = "" // Reset the identifier to trigger regenerating a new one
|
ld.List.Identifier = "" // Reset the identifier to trigger regenerating a new one
|
||||||
// Set the owner to the current user
|
// Set the owner to the current user
|
||||||
ld.List.OwnerID = a.GetID()
|
ld.List.OwnerID = doer.GetID()
|
||||||
if err := CreateOrUpdateList(s, ld.List, a); err != nil {
|
if err := CreateOrUpdateList(s, ld.List, doer); err != nil {
|
||||||
// If there is no available unique list identifier, just reset it.
|
// If there is no available unique list identifier, just reset it.
|
||||||
if IsErrListIdentifierIsNotUnique(err) {
|
if IsErrListIdentifierIsNotUnique(err) {
|
||||||
ld.List.Identifier = ""
|
ld.List.Identifier = ""
|
||||||
|
@ -99,7 +99,7 @@ func (ld *ListDuplicate) Create(s *xorm.Session, a web.Auth) (err error) {
|
||||||
oldID := b.ID
|
oldID := b.ID
|
||||||
b.ID = 0
|
b.ID = 0
|
||||||
b.ListID = ld.List.ID
|
b.ListID = ld.List.ID
|
||||||
if err := b.Create(s, a); err != nil {
|
if err := b.Create(s, doer); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
bucketMap[oldID] = b.ID
|
bucketMap[oldID] = b.ID
|
||||||
|
@ -108,7 +108,7 @@ func (ld *ListDuplicate) Create(s *xorm.Session, a web.Auth) (err error) {
|
||||||
log.Debugf("Duplicated all buckets from list %d into %d", ld.ListID, ld.List.ID)
|
log.Debugf("Duplicated all buckets from list %d into %d", ld.ListID, ld.List.ID)
|
||||||
|
|
||||||
// Get all tasks + all task details
|
// Get all tasks + all task details
|
||||||
tasks, _, _, err := getTasksForLists(s, []*List{{ID: ld.ListID}}, a, &taskOptions{})
|
tasks, _, _, err := getTasksForLists(s, []*List{{ID: ld.ListID}}, doer, &taskOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ func (ld *ListDuplicate) Create(s *xorm.Session, a web.Auth) (err error) {
|
||||||
t.ListID = ld.List.ID
|
t.ListID = ld.List.ID
|
||||||
t.BucketID = bucketMap[t.BucketID]
|
t.BucketID = bucketMap[t.BucketID]
|
||||||
t.UID = ""
|
t.UID = ""
|
||||||
err := createTask(s, t, a, false)
|
err := createTask(s, t, doer, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ func (ld *ListDuplicate) Create(s *xorm.Session, a web.Auth) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err := attachment.NewAttachment(s, attachment.File.File, attachment.File.Name, attachment.File.Size, a)
|
err := attachment.NewAttachment(s, attachment.File.File, attachment.File.Name, attachment.File.Size, doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ func (ld *ListDuplicate) Create(s *xorm.Session, a web.Auth) (err error) {
|
||||||
ID: taskMap[a.TaskID],
|
ID: taskMap[a.TaskID],
|
||||||
ListID: ld.List.ID,
|
ListID: ld.List.ID,
|
||||||
}
|
}
|
||||||
if err := t.addNewAssigneeByID(s, a.UserID, ld.List); err != nil {
|
if err := t.addNewAssigneeByID(s, a.UserID, ld.List, doer); err != nil {
|
||||||
if IsErrUserDoesNotHaveAccessToList(err) {
|
if IsErrUserDoesNotHaveAccessToList(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,7 @@ func (ld *ListDuplicate) Create(s *xorm.Session, a web.Auth) (err error) {
|
||||||
}
|
}
|
||||||
defer f.File.Close()
|
defer f.File.Close()
|
||||||
|
|
||||||
file, err := files.Create(f.File, f.Name, f.Size, a)
|
file, err := files.Create(f.File, f.Name, f.Size, doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.vikunja.io/api/pkg/events"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
@ -57,7 +58,7 @@ func getRawTaskAssigneesForTasks(s *xorm.Session, taskIDs []int64) (taskAssignee
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create or update a bunch of task assignees
|
// Create or update a bunch of task assignees
|
||||||
func (t *Task) updateTaskAssignees(s *xorm.Session, assignees []*user.User) (err error) {
|
func (t *Task) updateTaskAssignees(s *xorm.Session, assignees []*user.User, doer web.Auth) (err error) {
|
||||||
|
|
||||||
// Load the current assignees
|
// Load the current assignees
|
||||||
currentAssignees, err := getRawTaskAssigneesForTasks(s, []int64{t.ID})
|
currentAssignees, err := getRawTaskAssigneesForTasks(s, []int64{t.ID})
|
||||||
|
@ -132,7 +133,7 @@ func (t *Task) updateTaskAssignees(s *xorm.Session, assignees []*user.User) (err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the new assignee
|
// Add the new assignee
|
||||||
err = t.addNewAssigneeByID(s, u.ID, list)
|
err = t.addNewAssigneeByID(s, u.ID, list, doer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -198,10 +199,10 @@ func (la *TaskAssginee) Create(s *xorm.Session, a web.Auth) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
task := &Task{ID: la.TaskID}
|
task := &Task{ID: la.TaskID}
|
||||||
return task.addNewAssigneeByID(s, la.UserID, list)
|
return task.addNewAssigneeByID(s, la.UserID, list, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) addNewAssigneeByID(s *xorm.Session, newAssigneeID int64, list *List) (err error) {
|
func (t *Task) addNewAssigneeByID(s *xorm.Session, newAssigneeID int64, list *List, auth web.Auth) (err error) {
|
||||||
// Check if the user exists and has access to the list
|
// Check if the user exists and has access to the list
|
||||||
newAssignee, err := user.GetUserByID(s, newAssigneeID)
|
newAssignee, err := user.GetUserByID(s, newAssigneeID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -223,6 +224,20 @@ func (t *Task) addNewAssigneeByID(s *xorm.Session, newAssigneeID int64, list *Li
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doer, err := user.GetFromAuth(auth)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = events.Publish(&TaskAssigneeCreatedEvent{
|
||||||
|
Task: t,
|
||||||
|
Assignee: newAssignee,
|
||||||
|
Doer: doer,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = updateListLastUpdated(s, &List{ID: t.ListID})
|
err = updateListLastUpdated(s, &List{ID: t.ListID})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -313,6 +328,6 @@ func (ba *BulkAssignees) Create(s *xorm.Session, a web.Auth) (err error) {
|
||||||
task.Assignees = append(task.Assignees, &a.User)
|
task.Assignees = append(task.Assignees, &a.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = task.updateTaskAssignees(s, ba.Assignees)
|
err = task.updateTaskAssignees(s, ba.Assignees, a)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -815,7 +815,7 @@ func createTask(s *xorm.Session, t *Task, a web.Auth, updateAssignees bool) (err
|
||||||
|
|
||||||
// Update the assignees
|
// Update the assignees
|
||||||
if updateAssignees {
|
if updateAssignees {
|
||||||
if err := t.updateTaskAssignees(s, t.Assignees); err != nil {
|
if err := t.updateTaskAssignees(s, t.Assignees, a); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -879,7 +879,7 @@ func (t *Task) Update(s *xorm.Session, a web.Auth) (err error) {
|
||||||
updateDone(&ot, t)
|
updateDone(&ot, t)
|
||||||
|
|
||||||
// Update the assignees
|
// Update the assignees
|
||||||
if err := ot.updateTaskAssignees(s, t.Assignees); err != nil {
|
if err := ot.updateTaskAssignees(s, t.Assignees, a); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue