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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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{}{}
}
orgIDs := []int64{} // IDs of the orgs the user is a member of
orgRolesMap := map[int64]models.RoleType{}
for _, group := range serverConfig.Groups {
// 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,
OrgId: group.OrgId, OrgRole: group.OrgRole})
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)
}
u.Teams, err = hs.ldapGroups.GetTeams(user.Groups)
u.Teams, err = hs.ldapGroups.GetTeams(user.Groups, orgIDs)
if err != nil {
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"
type Groups interface {
GetTeams(groups []string) ([]models.TeamOrgGroupDTO, error)
GetTeams(groups []string, orgIDs []int64) ([]models.TeamOrgGroupDTO, error)
}
type OSSGroups struct{}
@ -12,6 +12,6 @@ func ProvideGroupsService() *OSSGroups {
return &OSSGroups{}
}
func (*OSSGroups) GetTeams(_ []string) ([]models.TeamOrgGroupDTO, error) {
func (*OSSGroups) GetTeams(_ []string, _ []int64) ([]models.TeamOrgGroupDTO, error) {
return nil, nil
}