B
    ß%Q[v  ã               @   s@   d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 dd„ Z
dS )Ú
é   )ÚLDAPInvalidDnError)ÚSEQUENCE_TYPESÚMODIFY_DELETEÚBASEÚDEREF_NEVER)Úsafe_dnc                sˆ  t |tƒs|g}t |tƒs |g}| jrng }g }x|D ]}| t|ƒ¡ q4W x|D ]}| t|ƒ¡ qPW |}|}d}�x|D �]}	|�r | j|	dttdgd�}
| jj	s´|  
|
¡\}}
n| j| j }}
|
d dksÚt|	d ƒ‚d|d d	 krú|d d	 d ng ‰ n|‰ d
d„ ˆ D ƒ‰ tƒ }‡ fdd„|D ƒ}|�r<t|f|d< |rz|  |	|¡}
| jj	�sf|  
|
¡\}}
n| j}
|
d dkrzd}P qzW | S )aë  
    :param connection: a bound Connection object
    :param members_dn: the list of members to remove from groups
    :param groups_dn: the list of groups where members are to be removed
    :param fix: checks for group existence and existing members
    :return: a boolean where True means that the operation was successful and False means an error has happened
    Removes users-groups relations following the Activwe Directory rules: users are removed from groups' member attribute

    Fz(objectclass=*)Úmember)Zdereference_aliasesÚ
attributesÚdescriptionÚsuccessz
 not foundé    r
   c             S   s   g | ]}|  ¡ ‘qS © )Úlower)Ú.0Úelementr   r   úqC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6i93dh7p\ldap3\ldap3\extend\microsoft\removeMembersFromGroups.pyú
<listcomp>N   s    z1ad_remove_members_from_groups.<locals>.<listcomp>c                s   g | ]}|  ¡ ˆ kr|‘qS r   )r   )r   r   )Úexisting_membersr   r   r   P   s    T)Ú
isinstancer   Zcheck_namesÚappendr   Úsearchr   r   ZstrategyZsyncZget_responseÚresponseÚresultr   Údictr   Úmodify)Ú
connectionZ
members_dnZ	groups_dnZfixZsafe_members_dnZsafe_groups_dnZ	member_dnZgroup_dnÚerrorÚgroupr   r   ZchangesZmember_to_removeÚ_r   )r   r   Úad_remove_members_from_groups   sL    



&
r    N)Ú__doc__Zcore.exceptionsr   Ú r   r   r   r   Zutils.dnr   r    r   r   r   r   Ú<module>   s   