Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix API Bug (fail on empty assignees) #8873

Merged
merged 23 commits into from
Nov 10, 2019
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions models/issue_assignees.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package models

import (
"code.gitea.io/gitea/modules/util"
6543 marked this conversation as resolved.
Show resolved Hide resolved
"fmt"

"xorm.io/xorm"
Expand Down Expand Up @@ -171,25 +172,31 @@ func toggleUserAssignee(e *xorm.Session, issue *Issue, assigneeID int64) (remove
// MakeIDsFromAPIAssigneesToAdd returns an array with all assignee IDs
func MakeIDsFromAPIAssigneesToAdd(oneAssignee string, multipleAssignees []string) (assigneeIDs []int64, err error) {

var requestAssignees []string

// Keeping the old assigning method for compatibility reasons
if oneAssignee != "" {
if !util.ExistsInSlice(oneAssignee, multipleAssignees) {
requestAssignees = append(requestAssignees, oneAssignee)
}

// Prevent double adding assignees
var isDouble bool
//Prevent empty assignerees
if util.ExistsInSlice("", multipleAssignees) {
6543 marked this conversation as resolved.
Show resolved Hide resolved
for _, assignee := range multipleAssignees {
if assignee == oneAssignee {
isDouble = true
break
if assignee == "" {
continue
}
requestAssignees = append(requestAssignees, assignee)
}

if !isDouble {
multipleAssignees = append(multipleAssignees, oneAssignee)
}
} else {
requestAssignees = append(requestAssignees, multipleAssignees...)
}

// Get the IDs of all assignees
assigneeIDs, err = GetUserIDsByNames(multipleAssignees, false)
if len(requestAssignees) > 0 {
// Get the IDs of all assignees
assigneeIDs, err = GetUserIDsByNames(requestAssignees, false)
} else {
return nil, nil
}

return
}