return single team for GetTeamByOidcIDAndName
Some checks failed
continuous-integration/drone/pr Build is failing

This commit is contained in:
viehlieb 2023-03-30 17:15:24 +02:00
parent 85307ce666
commit 146fa2c70a

View File

@ -20,7 +20,6 @@ import (
"time" "time"
"code.vikunja.io/api/pkg/db" "code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/events" "code.vikunja.io/api/pkg/events"
"code.vikunja.io/api/pkg/user" "code.vikunja.io/api/pkg/user"
@ -151,15 +150,16 @@ func GetTeamsByName(s *xorm.Session, name string) (teams []*Team, err error) {
// GetTeamByOidcIDAndName gets teams where oidc_id and name match parameters // GetTeamByOidcIDAndName gets teams where oidc_id and name match parameters
// For oidc team creation oidcID and Name need to be set // For oidc team creation oidcID and Name need to be set
func GetTeamByOidcIDAndName(s *xorm.Session, oidcID string, teamName string) (team Team, err error) { func GetTeamByOidcIDAndName(s *xorm.Session, oidcID string, teamName string) (team Team, err error) {
exists, err := s. err = s.
Table("teams"). Table("teams").
Where("oidc_id = ? AND name = ?", oidcID, teamName). Where("oidc_id = ? AND name = ?", oidcID, teamName).
Get(&team) OrderBy("name ASC").
log.Debugf("GetTeamByOidcIDAndName: %v, exists: %v", team.Name, exists) Limit(1).
if exists && err == nil { Find(&team)
return team, nil if err != nil {
return team, ErrOIDCTeamDoesNotExist{teamName, oidcID}
} }
return team, ErrOIDCTeamDoesNotExist{teamName, oidcID} return team, err
} }
func FindAllOidcTeamIDsForUser(s *xorm.Session, userID int64) (ts []int64, err error) { func FindAllOidcTeamIDsForUser(s *xorm.Session, userID int64) (ts []int64, err error) {