mozreview: Don't overwrite valid ldap associations (
bug 1287988) r?smacleod
Ensure that if a user's ldap association is correct, we don't overwrite the
stored link.
This resolves a bug impacting Mozilla employees who use a different email
address in LDAP vs BMO.
MozReview-Commit-ID: A49fGBzPrX9
--- a/pylib/mozreview/mozreview/ldap/__init__.py
+++ b/pylib/mozreview/mozreview/ldap/__init__.py
@@ -138,29 +138,35 @@ def associate_employee_ldap(user, ldap_c
checked), and associate the user to LDAP.
Raises an exception if no matches or multiple matches were found.
Returns the found LDAP username, and a boolean indicating if the user
was updated.
"""
from mozreview.models import get_profile
+ mozreview_profile = get_profile(user)
+
+ # Don't overwrite existing and valid associations.
+ if mozreview_profile.ldap_username and user_exists(
+ mozreview_profile.ldap_username, ldap_connection):
+ return mozreview_profile.ldap_username, False
+
ldap_users = find_employee_ldap(user.email, ldap_connection)
if not ldap_users:
raise LDAPAssociationException(
'Failed to find match for %s' % user.email)
if len(ldap_users) > 1:
raise LDAPAssociationException(
'More than one match for %s' % user.email)
ldap_username = ldap_users[0]
updated = False
- mozreview_profile = get_profile(user)
if mozreview_profile.ldap_username != ldap_username:
if mozreview_profile.ldap_username:
logging.info("Existing ldap association '%s' replaced by '%s'"
% (mozreview_profile.ldap_username, ldap_username))
else:
logging.info('Associating user: %s with ldap_username: %s'
% (user.email, ldap_username))