Fix employeeNumber update: use direct LDAP modify instead of ORM save
- Replaced ORM .save() with direct ldap3.Connection.modify() - ORM save() tries to rebuild DN which fails without proper cn attribute - Direct modify only changes the employeeNumber attribute - Fixes Exception: Could not build Distinguished Name
This commit is contained in:
parent
4cf989e5b5
commit
36c5323e0e
@ -143,13 +143,15 @@ class UserService(BaseService):
|
||||
emp._skip_ldap_sync = True
|
||||
emp.save(update_fields=["password"])
|
||||
|
||||
# Запись employeeNumber в LDAP для связки
|
||||
ldap_user = LdapUser.objects.get(dn=dn)
|
||||
# Запись employeeNumber в LDAP для связки через прямую модификацию
|
||||
# Используем ldap3 напрямую, т.к. ORM .save() пытается перестроить DN
|
||||
from ldap3 import MODIFY_REPLACE
|
||||
conn.modify(
|
||||
dn,
|
||||
{'employeeNumber': [(MODIFY_REPLACE, [str(emp.pk)])]}
|
||||
)
|
||||
guid = None
|
||||
|
||||
ldap_user.employee_number = str(emp.pk)
|
||||
ldap_user.save()
|
||||
|
||||
self._touch_state(
|
||||
model="employee",
|
||||
object_pk=emp.pk,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user