feat: assign users to teams via OIDC claims #1393
|
@ -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.
|
||||
viehlieb marked this conversation as resolved
Outdated
|
||||
Where("name = ?", name).
|
||||
Find(&ts)
|
||||
if exists != nil {
|
||||
return
|
||||
}
|
||||
if len(ts) == 0 {
|
||||
if err != nil || len(ts) == 0 {
|
||||
return ts, ErrTeamsDoNotExist{name}
|
||||
}
|
||||
konrad marked this conversation as resolved
Outdated
konrad
commented
Did you try passing the Did you try passing the
viehlieb
commented
Ups, I guess here is something missing Ups, I guess here is something missing
|
||||
teams = ts
|
||||
return teams, err
|
||||
viehlieb marked this conversation as resolved
Outdated
konrad
commented
`Get` will always return one entry, no need for `Asc` or `Limit`.
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
viehlieb marked this conversation as resolved
Outdated
konrad
commented
Please handle the error. Please handle the error.
|
||||
return team, ErrTeamsDoNotExist{id}
|
||||
}
|
||||
|
||||
viehlieb marked this conversation as resolved
Outdated
konrad
commented
What happens if there's more than one team with that combination (unlikely, but not handled) What happens if there's more than one team with that combination (unlikely, but not handled)
viehlieb
commented
I tend to just changing functionality to take the first team with that specific setting. I tend to just changing functionality to take the first team with that specific setting.
konrad
commented
That sounds like it could work. Easiest way would be to add a That sounds like it could work. Easiest way would be to add a `OrderBy` clause here.
|
||||
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
Block a user
Please return a pointer to a
team i suppose.done, tx