diff --git a/services/graph/pkg/identity/ldap.go b/services/graph/pkg/identity/ldap.go index 5224716be..696d16477 100644 --- a/services/graph/pkg/identity/ldap.go +++ b/services/graph/pkg/identity/ldap.go @@ -274,36 +274,23 @@ func (i *LDAP) UpdateUser(ctx context.Context, nameOrID string, user libregraph. } mr := ldap.ModifyRequest{DN: e.DN} - if user.GetDisplayName() != "" { - if e.GetEqualFoldAttributeValue(i.userAttributeMap.displayName) != user.GetDisplayName() { - mr.Replace(i.userAttributeMap.displayName, []string{user.GetDisplayName()}) - updateNeeded = true - } - } - if user.GetMail() != "" { - if e.GetEqualFoldAttributeValue(i.userAttributeMap.mail) != user.GetMail() { - mr.Replace(i.userAttributeMap.mail, []string{user.GetMail()}) - updateNeeded = true - } - } - if user.GetSurname() != "" { - if e.GetEqualFoldAttributeValue(i.userAttributeMap.surname) != user.GetSurname() { - mr.Replace(i.userAttributeMap.surname, []string{user.GetSurname()}) - updateNeeded = true - } - } - if user.GetGivenName() != "" { - if e.GetEqualFoldAttributeValue(i.userAttributeMap.givenName) != user.GetGivenName() { - mr.Replace(i.userAttributeMap.givenName, []string{user.GetGivenName()}) - updateNeeded = true - } - } - if user.GetUserType() != "" { - if e.GetEqualFoldAttributeValue(i.userAttributeMap.userType) != user.GetUserType() { - mr.Replace(i.userAttributeMap.userType, []string{user.GetUserType()}) - updateNeeded = true + properties := map[string]string{ + i.userAttributeMap.displayName: user.GetDisplayName(), + i.userAttributeMap.mail: user.GetMail(), + i.userAttributeMap.surname: user.GetSurname(), + i.userAttributeMap.givenName: user.GetGivenName(), + i.userAttributeMap.userType: user.GetUserType(), + } + + for attribute, value := range properties { + if value != "" { + if e.GetEqualFoldAttributeValue(attribute) != value { + mr.Replace(attribute, []string{value}) + updateNeeded = true + } } } + if user.PasswordProfile != nil && user.PasswordProfile.GetPassword() != "" { if i.usePwModifyExOp { if err := i.updateUserPassowrd(ctx, e.DN, user.PasswordProfile.GetPassword()); err != nil { diff --git a/services/graph/pkg/identity/ldap_education_user.go b/services/graph/pkg/identity/ldap_education_user.go index 03e1d1824..9c9a8cbae 100644 --- a/services/graph/pkg/identity/ldap_education_user.go +++ b/services/graph/pkg/identity/ldap_education_user.go @@ -109,36 +109,24 @@ func (i *LDAP) UpdateEducationUser(ctx context.Context, nameOrID string, user li } mr := ldap.ModifyRequest{DN: e.DN} - if user.GetDisplayName() != "" { - if e.GetEqualFoldAttributeValue(i.userAttributeMap.displayName) != user.GetDisplayName() { - mr.Replace(i.userAttributeMap.displayName, []string{user.GetDisplayName()}) - updateNeeded = true - } - } - if user.GetMail() != "" { - if e.GetEqualFoldAttributeValue(i.userAttributeMap.mail) != user.GetMail() { - mr.Replace(i.userAttributeMap.mail, []string{user.GetMail()}) - updateNeeded = true - } - } - if user.GetSurname() != "" { - if e.GetEqualFoldAttributeValue(i.userAttributeMap.surname) != user.GetSurname() { - mr.Replace(i.userAttributeMap.surname, []string{user.GetSurname()}) - updateNeeded = true - } - } - if user.GetGivenName() != "" { - if e.GetEqualFoldAttributeValue(i.userAttributeMap.givenName) != user.GetGivenName() { - mr.Replace(i.userAttributeMap.givenName, []string{user.GetGivenName()}) - updateNeeded = true - } - } - if user.GetUserType() != "" { - if e.GetEqualFoldAttributeValue(i.userAttributeMap.userType) != user.GetUserType() { - mr.Replace(i.userAttributeMap.userType, []string{user.GetUserType()}) - updateNeeded = true + properties := map[string]string{ + i.userAttributeMap.displayName: user.GetDisplayName(), + i.userAttributeMap.mail: user.GetMail(), + i.userAttributeMap.surname: user.GetSurname(), + i.userAttributeMap.givenName: user.GetGivenName(), + i.userAttributeMap.userType: user.GetUserType(), + i.educationConfig.userAttributeMap.primaryRole: user.GetPrimaryRole(), + } + + for attribute, value := range properties { + if value != "" { + if e.GetEqualFoldAttributeValue(attribute) != value { + mr.Replace(attribute, []string{value}) + updateNeeded = true + } } } + if user.AccountEnabled != nil { un, err := i.updateAccountEnabledState(logger, user.GetAccountEnabled(), e, &mr) @@ -162,12 +150,6 @@ func (i *LDAP) UpdateEducationUser(ctx context.Context, nameOrID string, user li updateNeeded = true } } - if user.GetPrimaryRole() != "" { - if e.GetEqualFoldAttributeValue(i.educationConfig.userAttributeMap.primaryRole) != user.GetPrimaryRole() { - mr.Replace(i.educationConfig.userAttributeMap.primaryRole, []string{user.GetPrimaryRole()}) - updateNeeded = true - } - } if identities, ok := user.GetIdentitiesOk(); ok { attrValues := make([]string, 0, len(identities)) for _, identity := range identities {