cast VikujGroups directly to []map[string]interface{}

changug []models.Team to []*models.Team
This commit is contained in:
viehlieb 2023-02-23 16:17:59 +01:00
parent d664e29873
commit f6ce982686

View File

@ -62,7 +62,7 @@ type claims struct {
Name string `json:"name"`
PreferredUsername string `json:"preferred_username"`
Nickname string `json:"nickname"`
VikunjaGroups interface{} `json:"vikunja_groups"`
VikunjaGroups []map[string]interface{} `json:"vikunja_groups"`
}
func init() {
@ -273,13 +273,10 @@ func SignOutFromTeamsByID(s *xorm.Session, u *user.User, teamIDs []int64) (errs
return errs
}
func getTeamDataFromToken(groups interface{}, provider *Provider) (teamData []models.TeamData, errs []error) {
func getTeamDataFromToken(groups []map[string]interface{}, provider *Provider) (teamData []models.TeamData, errs []error) {
teamData = []models.TeamData{}
errs = []error{}
if groups != nil {
el := groups.([]interface{})
for _, data := range el {
team := data.(map[string]interface{})
for _, team := range groups {
var name string
var description string
var oidcID string
@ -308,7 +305,6 @@ func getTeamDataFromToken(groups interface{}, provider *Provider) (teamData []mo
}
teamData = append(teamData, models.TeamData{TeamName: name, OidcID: oidcID, Description: description})
}
}
return teamData, errs
}
@ -323,8 +319,8 @@ func CreateTeamWithData(s *xorm.Session, teamData models.TeamData, u *user.User)
}
// this functions creates an array of existing teams that was generated from the oidc data.
func GetOrCreateTeamsByOIDCAndNames(s *xorm.Session, teamData []models.TeamData, u *user.User) (te []models.Team, err error) {
te = []models.Team{}
func GetOrCreateTeamsByOIDCAndNames(s *xorm.Session, teamData []models.TeamData, u *user.User) (te []*models.Team, err error) {
te = []*models.Team{}
// Procedure can only be successful if oidcID is set and converted to string
for _, oidcTeam := range teamData {
team, err := models.GetTeamByOidcIDAndName(s, oidcTeam.OidcID, oidcTeam.TeamName)
@ -334,12 +330,11 @@ func GetOrCreateTeamsByOIDCAndNames(s *xorm.Session, teamData []models.TeamData,
if err != nil {
return te, err
}
te = append(te, *newTeam)
te = append(te, newTeam)
} else {
log.Debugf("Team with oidc_id %v and name %v already exists.", team.OidcID, team.Name)
te = append(te, team)
te = append(te, &team)
}
}
return te, err
}