Use a strings.Builder to create the idQuery string (#11600)
* Use a strings.Builder to create the idQuery string * Use the query builder
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
c49f755a14
Коммит
7070b3596b
@@ -7,7 +7,6 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
sq "github.com/Masterminds/squirrel"
|
sq "github.com/Masterminds/squirrel"
|
||||||
@@ -1037,20 +1036,18 @@ func (s SqlTeamStore) GetTeamMembersForExport(userId string) ([]*model.TeamMembe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlTeamStore) UserBelongsToTeams(userId string, teamIds []string) (bool, *model.AppError) {
|
func (s SqlTeamStore) UserBelongsToTeams(userId string, teamIds []string) (bool, *model.AppError) {
|
||||||
props := make(map[string]interface{})
|
idQuery := sq.Eq{
|
||||||
props["UserId"] = userId
|
"UserId": userId,
|
||||||
idQuery := ""
|
"TeamId": teamIds,
|
||||||
|
"DeleteAt": 0,
|
||||||
for index, teamId := range teamIds {
|
|
||||||
if len(idQuery) > 0 {
|
|
||||||
idQuery += ", "
|
|
||||||
}
|
|
||||||
|
|
||||||
props["teamId"+strconv.Itoa(index)] = teamId
|
|
||||||
idQuery += ":teamId" + strconv.Itoa(index)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := s.GetReplica().SelectInt("SELECT Count(*) FROM TeamMembers WHERE UserId = :UserId AND TeamId IN ("+idQuery+") AND DeleteAt = 0", props)
|
query, params, err := s.getQueryBuilder().Select("Count(*)").From("TeamMembers").Where(idQuery).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return false, model.NewAppError("SqlTeamStore.UserBelongsToTeams", "store.sql_team.user_belongs_to_teams.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
c, err := s.GetReplica().SelectInt(query, params...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, model.NewAppError("SqlTeamStore.UserBelongsToTeams", "store.sql_team.user_belongs_to_teams.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return false, model.NewAppError("SqlTeamStore.UserBelongsToTeams", "store.sql_team.user_belongs_to_teams.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user