o
    ßý°j  ã                   @   sH   d Z ddlmZmZ ddlmZmZmZmZ ddl	m
Z
 	d	dd„ZdS )
Ú
é   )ÚLDAPInvalidDnErrorÚLDAPOperationsErrorResult)ÚSEQUENCE_TYPESÚMODIFY_DELETEÚBASEÚDEREF_NEVER©Úsafe_dnFc                    s¤  t |tƒs|g}t |tƒs|g}| jr!dd„ |D ƒ}dd„ |D ƒ}d}|D ]©}|rp| 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 ‰ n|‰ dd„ ˆ D ƒ‰ tƒ }
‡ fdd„|D ƒ}|r�t|f|
d< |
rÎ|  ||
¡}| jjs¡|  |¡\}	}n| jj	r¬|\}	}}	}	n| j}|d d	krÎd}g d¢‰|rÊt‡fdd„| ¡ D ƒƒ‚ | S q%| S )aH  
    :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
    :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
    Removes users-groups relations following the Activwe Directory rules: users are removed from groups' member attribute

    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/removeMembersFromGroups.pyÚ
<listcomp>5   ó    z1ad_remove_members_from_groups.<locals>.<listcomp>c                 S   r   r   r	   )r   Úgroup_dnr   r   r   r   6   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   N   r   c                    s   g | ]
}|  ¡ ˆ v r|‘qS r   r   r   )Úexisting_membersr   r   r   P   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_remover   )r   r#   r   Úad_remove_members_from_groups   sT   

&€ r9   N)F)Ú__doc__Úcore.exceptionsr   r   Ú r   r   r   r   Úutils.dnr
   r9   r   r   r   r   Ú<module>   s    ü