o
    j|                     @   sJ   d Z ddlmZmZmZmZ ddlmZmZ ddl	m
Z
 		d
ddZd	S )
   )SEQUENCE_TYPES
MODIFY_ADDBASEDEREF_NEVER)LDAPInvalidDnErrorLDAPOperationsErrorResultsafe_dnTFc                    s  t |ts|g}t |ts|g}| jr!dd |D }dd |D }d}|D ]}|rw| j|dttdgd}| jjs@| |\}}n| jj	rK|\}	}}}	n| j
}| j}|d d	ks]t|d
 d|d d v rm|d d d ng  dd  D  ng  t }
 fdd|D }|rt|f|
d< |
r| ||
}| jjs| |\}	}n| jj	r|\}	}}	}	n| j}|d d	krd}g d|rtfdd| D  | S q%| S )a  
    :param connection: a bound Connection object
    :param members_dn: the list of members to add to groups
    :param groups_dn: the list of groups where members are to be added
    :param fix: checks for group existence and already assigned members
    :param raise_error: If the operation fails it raises an error instead of returning False
    :return: a boolean where True means that the operation was successful and False means an error has happened
    Establishes users-groups relations following the Active Directory rules: users are added to the member attribute of groups.
    Raises LDAPInvalidDnError if members or groups are not found in the DIT.
    c                 S      g | ]}t |qS  r	   ).0	member_dnr   r   /root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/ldap3/extend/microsoft/addMembersToGroups.py
<listcomp>6       z,ad_add_members_to_groups.<locals>.<listcomp>c                 S   r   r   r	   )r   group_dnr   r   r   r   7   r   Fz(objectclass=*)member)dereference_aliases
attributesdescriptionsuccessz
 not found    r   c                 S   s   g | ]}|  qS r   lowerr   elementr   r   r   r   J   r   c                    s   g | ]
}|   vr|qS r   r   r   )existing_membersr   r   r   O   s    T)resultr   dnmessagec                    s    g | ]\}}| v r||fqS r   r   )r   kv)result_error_paramsr   r   r   _   s     )
isinstancer   check_namessearchr   r   strategysyncget_responsethread_saferesponser   r   dictr   modifyr   items)
connection
members_dn	groups_dnfixraise_errorerrorgroupr   r+   _changesmember_to_addr   )r   r#   r   ad_add_members_to_groups   sT   

$ r9   N)TF)__doc__ r   r   r   r   core.exceptionsr   r   utils.dnr
   r9   r   r   r   r   <module>   s    