TeamSync: Fix team syncing out of orgs mapped by auth method (#53257)

This commit is contained in:
Jo
2022-08-10 08:20:23 +00:00
committed by GitHub
parent bca8a5d153
commit 09c95bc31f
2 changed files with 5 additions and 3 deletions

View File

@ -331,6 +331,7 @@ func (hs *HTTPServer) GetUserFromLDAP(c *models.ReqContext) response.Response {
unmappedUserGroups[strings.ToLower(userGroup)] = struct{}{} unmappedUserGroups[strings.ToLower(userGroup)] = struct{}{}
} }
orgIDs := []int64{} // IDs of the orgs the user is a member of
orgRolesMap := map[int64]models.RoleType{} orgRolesMap := map[int64]models.RoleType{}
for _, group := range serverConfig.Groups { for _, group := range serverConfig.Groups {
// only use the first match for each org // only use the first match for each org
@ -343,6 +344,7 @@ func (hs *HTTPServer) GetUserFromLDAP(c *models.ReqContext) response.Response {
u.OrgRoles = append(u.OrgRoles, LDAPRoleDTO{GroupDN: group.GroupDN, u.OrgRoles = append(u.OrgRoles, LDAPRoleDTO{GroupDN: group.GroupDN,
OrgId: group.OrgId, OrgRole: group.OrgRole}) OrgId: group.OrgId, OrgRole: group.OrgRole})
delete(unmappedUserGroups, strings.ToLower(group.GroupDN)) delete(unmappedUserGroups, strings.ToLower(group.GroupDN))
orgIDs = append(orgIDs, group.OrgId)
} }
} }
@ -355,7 +357,7 @@ func (hs *HTTPServer) GetUserFromLDAP(c *models.ReqContext) response.Response {
return response.Error(http.StatusBadRequest, "An organization was not found - Please verify your LDAP configuration", err) return response.Error(http.StatusBadRequest, "An organization was not found - Please verify your LDAP configuration", err)
} }
u.Teams, err = hs.ldapGroups.GetTeams(user.Groups) u.Teams, err = hs.ldapGroups.GetTeams(user.Groups, orgIDs)
if err != nil { if err != nil {
return response.Error(http.StatusBadRequest, "Unable to find the teams for this user", err) return response.Error(http.StatusBadRequest, "Unable to find the teams for this user", err)
} }

View File

@ -3,7 +3,7 @@ package ldap
import "github.com/grafana/grafana/pkg/models" import "github.com/grafana/grafana/pkg/models"
type Groups interface { type Groups interface {
GetTeams(groups []string) ([]models.TeamOrgGroupDTO, error) GetTeams(groups []string, orgIDs []int64) ([]models.TeamOrgGroupDTO, error)
} }
type OSSGroups struct{} type OSSGroups struct{}
@ -12,6 +12,6 @@ func ProvideGroupsService() *OSSGroups {
return &OSSGroups{} return &OSSGroups{}
} }
func (*OSSGroups) GetTeams(_ []string) ([]models.TeamOrgGroupDTO, error) { func (*OSSGroups) GetTeams(_ []string, _ []int64) ([]models.TeamOrgGroupDTO, error) {
return nil, nil return nil, nil
} }