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:
Torkel Ödegaard 2015-09-21 09:19:50 +02:00
parent 8d87db58c6
commit 7f1af24318

View File

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