mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
fix(ldap): fixed ldap org roles sync, did only add one new role per login, now all roles are added, fixes #2766
This commit is contained in:
parent
8d87db58c6
commit
7f1af24318
@ -151,9 +151,12 @@ func (a *ldapAuther) syncOrgRoles(user *m.User, ldapUser *ldapUserInfo) error {
|
||||
return err
|
||||
}
|
||||
|
||||
handledOrgIds := map[int64]bool{}
|
||||
|
||||
// update or remove org roles
|
||||
for _, org := range orgsQuery.Result {
|
||||
match := false
|
||||
handledOrgIds[org.OrgId] = true
|
||||
|
||||
for _, group := range a.server.LdapGroups {
|
||||
if org.OrgId != group.OrgId {
|
||||
@ -189,22 +192,18 @@ func (a *ldapAuther) syncOrgRoles(user *m.User, ldapUser *ldapUserInfo) error {
|
||||
continue
|
||||
}
|
||||
|
||||
match := false
|
||||
for _, org := range orgsQuery.Result {
|
||||
if group.OrgId == org.OrgId {
|
||||
match = true
|
||||
break
|
||||
}
|
||||
if _, exists := handledOrgIds[group.OrgId]; exists {
|
||||
continue
|
||||
}
|
||||
|
||||
if !match {
|
||||
// add role
|
||||
cmd := m.AddOrgUserCommand{UserId: user.Id, Role: group.OrgRole, OrgId: group.OrgId}
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
break
|
||||
// add role
|
||||
cmd := m.AddOrgUserCommand{UserId: user.Id, Role: group.OrgRole, OrgId: group.OrgId}
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// mark this group has handled so we do not process it again
|
||||
handledOrgIds[group.OrgId] = true
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user