Search code examples
djangoldapopenldapldap-queryldap3

Is there any way to roll back execution of delete method with ldap3


I'm using Django 4.1 and ldap3 to connect directory service using ldap. Is there any way to roll back execution of delete method? the sample code likes below:

# import class and constants
from ldap3 import Server, Connection, ALL

# define the server
s = Server('servername', get_info=ALL)  # define an unsecure LDAP server, requesting info on DSE and schema

# define the connection
c = Connection(s, user='user_dn', password='user_password')

# perform the Delete operation
c.delete('cn=user1,ou=users,o=company')

#some checks here
#if condition:
#   user1.recover()

after some checking, I want to recover user's data based on a condition.

Thanks!

I've searched about rollback delete execution, but did not find any solution.


Solution

  • When the object is deleted from the LDAP directory by delete method, it's gone permanently.

    So in the rollback mechanism:

    First step: Copy the Object.

    Second Step: Storing the copy in a temporary location.

    Third Step: Delete the object. c.delete('cn=user1,ou=users,o=company')

    Otherwise there is no built in rollback mechanism to restore it once that is deleted by delete method of ldap3.