mirror of https://github.com/go-gitea/gitea.git
Fix API Bug (fail on empty assignees) (#8873)
* keep sure if assigneeIDs == nil -> do nothing
* fix #8872
* Revert "keep sure if assigneeIDs == nil -> do nothing"
-> go handle it itself preaty well
This reverts commit e72d94129c
.
* clarity comparson
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* simplify
* Update models/issue_assignees.go
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* Update issue_assignees.go
* simplify more
* add --if oneAssignee != ""-- again
* Update models/issue_assignees.go
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* CI.restart()
* Update issue_assignees.go
* add Test for GetUserIDsByNames
* add Test for MakeIDsFromAPIAssigneesToAdd
* fix test
This commit is contained in:
parent
daab245167
commit
31416a5f4e
|
@ -7,6 +7,8 @@ package models
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -171,25 +173,20 @@ func toggleUserAssignee(e *xorm.Session, issue *Issue, assigneeID int64) (remove
|
||||||
// MakeIDsFromAPIAssigneesToAdd returns an array with all assignee IDs
|
// MakeIDsFromAPIAssigneesToAdd returns an array with all assignee IDs
|
||||||
func MakeIDsFromAPIAssigneesToAdd(oneAssignee string, multipleAssignees []string) (assigneeIDs []int64, err error) {
|
func MakeIDsFromAPIAssigneesToAdd(oneAssignee string, multipleAssignees []string) (assigneeIDs []int64, err error) {
|
||||||
|
|
||||||
|
var requestAssignees []string
|
||||||
|
|
||||||
// Keeping the old assigning method for compatibility reasons
|
// Keeping the old assigning method for compatibility reasons
|
||||||
if oneAssignee != "" {
|
if oneAssignee != "" && !util.IsStringInSlice(oneAssignee, multipleAssignees) {
|
||||||
|
requestAssignees = append(requestAssignees, oneAssignee)
|
||||||
|
}
|
||||||
|
|
||||||
// Prevent double adding assignees
|
//Prevent empty assignees
|
||||||
var isDouble bool
|
if len(multipleAssignees) > 0 && multipleAssignees[0] != "" {
|
||||||
for _, assignee := range multipleAssignees {
|
requestAssignees = append(requestAssignees, multipleAssignees...)
|
||||||
if assignee == oneAssignee {
|
|
||||||
isDouble = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !isDouble {
|
|
||||||
multipleAssignees = append(multipleAssignees, oneAssignee)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the IDs of all assignees
|
// Get the IDs of all assignees
|
||||||
assigneeIDs, err = GetUserIDsByNames(multipleAssignees, false)
|
assigneeIDs, err = GetUserIDsByNames(requestAssignees, false)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,3 +59,24 @@ func TestUpdateAssignee(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.False(t, isAssigned)
|
assert.False(t, isAssigned)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMakeIDsFromAPIAssigneesToAdd(t *testing.T) {
|
||||||
|
IDs, err := MakeIDsFromAPIAssigneesToAdd("", []string{""})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []int64{}, IDs)
|
||||||
|
|
||||||
|
IDs, err = MakeIDsFromAPIAssigneesToAdd("", []string{"none_existing_user"})
|
||||||
|
assert.Error(t, err)
|
||||||
|
|
||||||
|
IDs, err = MakeIDsFromAPIAssigneesToAdd("user1", []string{"user1"})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []int64{1}, IDs)
|
||||||
|
|
||||||
|
IDs, err = MakeIDsFromAPIAssigneesToAdd("user2", []string{""})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []int64{2}, IDs)
|
||||||
|
|
||||||
|
IDs, err = MakeIDsFromAPIAssigneesToAdd("", []string{"user1", "user2"})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []int64{1, 2}, IDs)
|
||||||
|
}
|
||||||
|
|
|
@ -373,3 +373,16 @@ func TestCreateUser_Issue5882(t *testing.T) {
|
||||||
assert.NoError(t, DeleteUser(v.user))
|
assert.NoError(t, DeleteUser(v.user))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetUserIDsByNames(t *testing.T) {
|
||||||
|
|
||||||
|
//ignore non existing
|
||||||
|
IDs, err := GetUserIDsByNames([]string{"user1", "user2", "none_existing_user"}, true)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []int64{1, 2}, IDs)
|
||||||
|
|
||||||
|
//ignore non existing
|
||||||
|
IDs, err = GetUserIDsByNames([]string{"user1", "do_not_exist"}, false)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Equal(t, []int64(nil), IDs)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue