File tree Expand file tree Collapse file tree 4 files changed +40
-0
lines changed
Expand file tree Collapse file tree 4 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ Features
4545 reference/settings_reference
4646 reference/ldap_settings
4747 reference/decorators
48+ reference/signals
4849 reference/models
4950 reference/management_commands
5051 reference/change_log
Original file line number Diff line number Diff line change 1+
2+ Signals
3+ =======
4+
5+ ldap_user_sync
6+ --------------
7+
8+ Whenever a user is synced against LDAP, pre-saving.
9+
10+ Arguments:
11+ * **sender ** The LDAPUser instance that is being synced.
12+ * **ldap_user ** The ``ldap3 `` Entry instance received from LDAP server of the user being synced
13+ * **group_reader ** Reader cursor for all the user's groups, already queried.
14+
15+ Example:
16+
17+ .. code-block :: python
18+
19+ from django.dispatch import receiver
20+ from ldap3 import Entry, Reader
21+
22+ from windows_auth.models import LDAPUser
23+ from windows_auth.signals import ldap_user_sync
24+
25+
26+ @receiver (ldap_user_sync)
27+ def on_ldap_sync (sender : LDAPUser, ldap_user : Entry = None , group_reader : Reader = None ):
28+ # do something...
29+ pass
30+
31+ .. warning ::
32+ Any unhandled exception raised during the signal will terminate the sync process.
Original file line number Diff line number Diff line change 1010from windows_auth import logger
1111from windows_auth .conf import WAUTH_USE_CACHE , WAUTH_USE_SPN , WAUTH_LOWERCASE_USERNAME
1212from windows_auth .ldap import LDAPManager , get_ldap_manager
13+ from windows_auth .signals import ldap_user_sync
1314from windows_auth .utils import LogExecutionTime
1415
1516
@@ -201,6 +202,9 @@ def sync(self) -> None:
201202 with LogExecutionTime (f"Perform field updates for user { self } " ):
202203 get_user_model ().objects .filter (pk = self .user .pk ).update (** updated_fields )
203204
205+ # send signals
206+ ldap_user_sync .send (self , ldap_user = ldap_user , group_reader = group_reader )
207+
204208 # update sync time
205209 if not WAUTH_USE_CACHE :
206210 with LogExecutionTime (f"Save LDAP User { self } " ):
Original file line number Diff line number Diff line change 1+ from django .dispatch import Signal
2+
3+ ldap_user_sync = Signal ()
You can’t perform that action at this time.
0 commit comments