add functionality of searching teams by oidcId and name to teams.go
This commit is contained in:
parent
db1f1423bb
commit
962e09174f
|
@ -123,7 +123,7 @@ func GetTeamByID(s *xorm.Session, id int64) (team *Team, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// GetTeamByID gets teams by name
|
||||
// GetTeamByName gets teams by name
|
||||
func GetTeamsByName(s *xorm.Session, name string) (teams []*Team, err error) {
|
||||
if name == "" {
|
||||
return teams, ErrTeamsDoNotExist{name}
|
||||
|
@ -131,18 +131,28 @@ func GetTeamsByName(s *xorm.Session, name string) (teams []*Team, err error) {
|
|||
|
||||
var ts []*Team
|
||||
|
||||
exists := s.
|
||||
err = s.
|
||||
Where("name = ?", name).
|
||||
Find(&ts)
|
||||
if exists != nil {
|
||||
return
|
||||
}
|
||||
if len(ts) == 0 {
|
||||
if err != nil || len(ts) == 0 {
|
||||
return ts, ErrTeamsDoNotExist{name}
|
||||
}
|
||||
teams = ts
|
||||
return teams, err
|
||||
}
|
||||
|
||||
return
|
||||
// GetTeamByOidcIDAndName gets teams where oidc_id and name match parameters
|
||||
// For oidc team creation oidcID and Name need to be set
|
||||
func GetTeamByOidcIDAndName(s *xorm.Session, id string, name string) (team Team, err error) {
|
||||
exists, err := s.
|
||||
Table("teams").
|
||||
Where("oidc_id = ? AND name = ?", id, name).
|
||||
Get(&team)
|
||||
log.Debugf("GetTeamByOidcIDAndName: %v, exists: %v", team.Name, exists)
|
||||
if exists && err == nil {
|
||||
return team, nil
|
||||
}
|
||||
return team, ErrTeamsDoNotExist{id}
|
||||
}
|
||||
|
||||
func addMoreInfoToTeams(s *xorm.Session, teams []*Team) (err error) {
|
||||
|
@ -295,8 +305,7 @@ func (t *Team) Create(s *xorm.Session, a web.Auth) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
var admin bool = true
|
||||
// }
|
||||
var admin = true
|
||||
tm := TeamMember{TeamID: t.ID, Username: doer.Username, Admin: admin}
|
||||
if err = tm.Create(s, doer); err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue