mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-20 23:57:42 +01:00
Fix User Group Search SQL error
User Group Query SQL error in some cases Signed-off-by: stonezdj <stonezdj@gmail.com>
This commit is contained in:
parent
3772ccc163
commit
f402db380b
@ -15,7 +15,6 @@
|
|||||||
package group
|
package group
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
@ -101,17 +100,13 @@ func GetUserGroup(id int) (*models.UserGroup, error) {
|
|||||||
// GetGroupIDByGroupName - Return the group ID by given group name. it is possible less group ID than the given group name if some group doesn't exist.
|
// GetGroupIDByGroupName - Return the group ID by given group name. it is possible less group ID than the given group name if some group doesn't exist.
|
||||||
func GetGroupIDByGroupName(groupName []string, groupType int) ([]int, error) {
|
func GetGroupIDByGroupName(groupName []string, groupType int) ([]int, error) {
|
||||||
var retGroupID []int
|
var retGroupID []int
|
||||||
var conditions []string
|
|
||||||
if len(groupName) == 0 {
|
if len(groupName) == 0 {
|
||||||
return retGroupID, nil
|
return retGroupID, nil
|
||||||
}
|
}
|
||||||
for _, gName := range groupName {
|
sql := fmt.Sprintf("select id from user_group where group_name in ( %s ) and group_type = ? ", dao.ParamPlaceholderForIn(len(groupName)))
|
||||||
con := "'" + gName + "'"
|
log.Debugf("GetGroupIDByGroupName: statement sql is %v", sql)
|
||||||
conditions = append(conditions, con)
|
|
||||||
}
|
|
||||||
sql := fmt.Sprintf("select id from user_group where group_name in ( %s ) and group_type = %v", strings.Join(conditions, ","), groupType)
|
|
||||||
o := dao.GetOrmer()
|
o := dao.GetOrmer()
|
||||||
cnt, err := o.Raw(sql).QueryRows(&retGroupID)
|
cnt, err := o.Raw(sql, groupName, groupType).QueryRows(&retGroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return retGroupID, err
|
return retGroupID, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user