feat: assign users to teams via OIDC claims #1393

Merged
konrad merged 93 commits from viehlieb/api:950_reworked_assign_teams_via_oidc into main 2024-03-02 08:47:12 +00:00
Showing only changes of commit 27eb746b98 - Show all commits

View File

@ -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

Please return a pointer to a

Please return a pointer to a

team i suppose.done, tx

team i suppose.done, tx
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

Did you try passing the

Did you try passing the

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

Get will always return one entry, no need for Asc or Limit.

`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

Please handle the error.

Please handle the error.
return team, ErrTeamsDoNotExist{id}
}
viehlieb marked this conversation as resolved Outdated

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)

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.

That sounds like it could work. Easiest way would be to add a OrderBy clause here.

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