Make sure tasks are properly attributed to link shares
This commit is contained in:
parent
9ca9540eba
commit
df21e04daf
@ -338,5 +338,11 @@
|
||||
bucket_id: 20
|
||||
created: 2018-12-01 01:12:04
|
||||
updated: 2018-12-01 01:12:04
|
||||
|
||||
|
||||
- id: 37
|
||||
title: 'task #37'
|
||||
done: false
|
||||
created_by_id: -2
|
||||
list_id: 2
|
||||
index: 2
|
||||
created: 2018-12-01 01:12:04
|
||||
updated: 2018-12-01 01:12:04
|
||||
|
@ -295,16 +295,16 @@ func TestTaskComments(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, rec.Body.String(), `"comment":"Lorem Ipsum"`)
|
||||
})
|
||||
t.Run("Link Share", func(t *testing.T) {
|
||||
rec, err := testHandlerLinkShareWrite.testCreateWithLinkShare(nil, map[string]string{"task": "13"}, `{"comment":"Lorem Ipsum"}`)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, rec.Body.String(), `"comment":"Lorem Ipsum"`)
|
||||
db.AssertExists(t, "task_comments", map[string]interface{}{
|
||||
"task_id": 13,
|
||||
"comment": "Lorem Ipsum",
|
||||
"author_id": -2,
|
||||
}, false)
|
||||
})
|
||||
})
|
||||
t.Run("Link Share", func(t *testing.T) {
|
||||
rec, err := testHandlerLinkShareWrite.testCreateWithLinkShare(nil, map[string]string{"task": "13"}, `{"comment":"Lorem Ipsum"}`)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, rec.Body.String(), `"comment":"Lorem Ipsum"`)
|
||||
db.AssertExists(t, "task_comments", map[string]interface{}{
|
||||
"task_id": 13,
|
||||
"comment": "Lorem Ipsum",
|
||||
"author_id": -2,
|
||||
}, false)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"testing"
|
||||
|
||||
"code.vikunja.io/api/pkg/models"
|
||||
@ -33,6 +34,20 @@ func TestTask(t *testing.T) {
|
||||
},
|
||||
t: t,
|
||||
}
|
||||
testHandlerLinkShareWrite := webHandlerTest{
|
||||
linkShare: &models.LinkSharing{
|
||||
ID: 2,
|
||||
Hash: "test2",
|
||||
ListID: 2,
|
||||
Right: models.RightWrite,
|
||||
SharingType: models.SharingTypeWithoutPassword,
|
||||
SharedByID: 1,
|
||||
},
|
||||
strFunc: func() handler.CObject {
|
||||
return &models.Task{}
|
||||
},
|
||||
t: t,
|
||||
}
|
||||
// Only run specific nested tests:
|
||||
// ^TestTask$/^Update$/^Update_task_items$/^Removing_Assignees_null$
|
||||
t.Run("Update", func(t *testing.T) {
|
||||
@ -489,5 +504,15 @@ func TestTask(t *testing.T) {
|
||||
assertHandlerErrorCode(t, err, models.ErrCodeBucketDoesNotExist)
|
||||
})
|
||||
})
|
||||
t.Run("Link Share", func(t *testing.T) {
|
||||
rec, err := testHandlerLinkShareWrite.testCreateWithLinkShare(nil, map[string]string{"list": "2"}, `{"title":"Lorem Ipsum"}`)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, rec.Body.String(), `"title":"Lorem Ipsum"`)
|
||||
db.AssertExists(t, "tasks", map[string]interface{}{
|
||||
"list_id": 2,
|
||||
"title": "Lorem Ipsum",
|
||||
"created_by_id": -2,
|
||||
}, false)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -670,7 +670,7 @@ func addMoreInfoToTasks(s *xorm.Session, taskMap map[int64]*Task) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
users, err := user.GetUsersByIDs(s, userIDs)
|
||||
users, err := getUsersOrLinkSharesFromIDs(s, userIDs)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -817,17 +817,11 @@ func createTask(s *xorm.Session, t *Task, a web.Auth, updateAssignees bool) (err
|
||||
return err
|
||||
}
|
||||
|
||||
if _, is := a.(*LinkSharing); is {
|
||||
// A negative user id indicates user share links
|
||||
t.CreatedByID = a.GetID() * -1
|
||||
} else {
|
||||
u, err := user.GetUserByID(s, a.GetID())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t.CreatedByID = u.ID
|
||||
t.CreatedBy = u
|
||||
createdBy, err := getUserOrLinkShareUser(s, a)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t.CreatedByID = createdBy.ID
|
||||
|
||||
// Generate a uuid if we don't already have one
|
||||
if t.UID == "" {
|
||||
@ -856,6 +850,8 @@ func createTask(s *xorm.Session, t *Task, a web.Auth, updateAssignees bool) (err
|
||||
return err
|
||||
}
|
||||
|
||||
t.CreatedBy = createdBy
|
||||
|
||||
// Update the assignees
|
||||
if updateAssignees {
|
||||
if err := t.updateTaskAssignees(s, t.Assignees, a); err != nil {
|
||||
@ -870,10 +866,9 @@ func createTask(s *xorm.Session, t *Task, a web.Auth, updateAssignees bool) (err
|
||||
|
||||
t.setIdentifier(l)
|
||||
|
||||
doer, _ := user.GetFromAuth(a)
|
||||
err = events.Dispatch(&TaskCreatedEvent{
|
||||
Task: t,
|
||||
Doer: doer,
|
||||
Doer: createdBy,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -579,4 +579,17 @@ func TestTask_ReadOne(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, task.Subscription)
|
||||
})
|
||||
t.Run("created by link share", func(t *testing.T) {
|
||||
db.LoadAndAssertFixtures(t)
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
task := &Task{ID: 37}
|
||||
err := task.ReadOne(s, u)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "task #37", task.Title)
|
||||
assert.Equal(t, int64(-2), task.CreatedByID)
|
||||
assert.NotNil(t, task.CreatedBy)
|
||||
assert.Equal(t, int64(-2), task.CreatedBy.ID)
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user