o
    ßý°jk   ã                   @   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r3g }g }|D ]	}| t|ƒ¡ q|D ]	}| t|ƒ¡ q%|}|}d}	d}
|r?| jj ¡ }	|
�s|D ]Ë}|r¢| j|dt	t
ddgd�}| jjs`|  |¡\}}n| jjrk|\}}}}n| j}| j}|d dks}t|d	 ƒ‚d|d
 d v r�|d
 d d ng ‰d|d
 d v rŸ|d
 d d ng ‰n|‰|‰dd„ ˆD ƒ‰dd„ ˆD ƒ‰tƒ }‡fdd„|D ƒ}‡fdd„|D ƒ}|rÑt|f|d< |rÙt|f|d< |�r| j|||rå|	gndd�}| jjsõ|  |¡\}}n| jj�r|\}}}}n| j}|d dk�rd}
 nqD|
�sì|D ]Ö}|�ry| j|dt	t
ddgd�}| jj�s3|  |¡\}}n| jj�r?|\}}}}n| j}| j}|d dk�sRt|d	 ƒ‚d|d
 d v �rc|d
 d d ng ‰d|d
 d v �rv|d
 d d ng ‰ n|‰|‰ dd„ ˆD ƒ‰dd„ ˆ D ƒ‰ tƒ }‡fdd„|D ƒ}‡ fdd„|D ƒ}|�r©t|f|d< |�r²t|f|d< |�rê| j|||�r¿|	gndd�}| jj�sÐ|  |¡\}}n| jj�rÜ|\}}}}n| j}|d dk�rêd}
 n�q|�r|
�rý| jjjd|	gd�}n
| jjjd|	gd�}|d dk�rd}
|
 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 inconsistences in the users-groups relation and fixes them
    :param transaction: activates an LDAP transaction
    :return: a boolean where True means that the operation was successful and False means an error has happened
    Removes users-groups relations following the eDirectory rules: groups are removed from securityEquals and groupMembership
    attributes in the member object while members are removed from member and equivalentToMe attributes in the group object.
    Raises LDAPInvalidDnError if members or groups are not found in the DIT.

    NFz(objectclass=*)ÚsecurityEqualsÚgroupMembership)Údereference_aliasesÚ
attributesÚdescriptionÚsuccessz
 not foundé    r   c                 S   ó   g | ]}|  ¡ ‘qS © ©Úlower©Ú.0Úelementr   r   úž/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/ldap3/extend/novell/removeMembersFromGroups.pyÚ
<listcomp>\   ó    z3edir_remove_members_from_groups.<locals>.<listcomp>c                 S   r   r   r   r   r   r   r   r   ]   r   c                    ó   g | ]
}|  ¡ ˆ v r|‘qS r   r   r   )Úexisting_security_equalsr   r   r   `   ó    c                    r   r   r   r   )Úexisting_group_membershipr   r   r   a   r   )ÚcontrolsTÚmemberÚequivalentToMec                 S   r   r   r   r   r   r   r   r   Š   r   c                 S   r   r   r   r   r   r   r   r   ‹   r   c                    r   r   r   r   )Úexisting_membersr   r   r   Ž   r   c                    r   r   r   r   )Úexisting_equivalent_to_mer   r   r   �   r   )Úcommitr   )Ú
isinstancer   Úcheck_namesÚappendr   ÚextendÚnovellÚstart_transactionÚsearchr   r   ÚstrategyÚsyncÚget_responseÚthread_safeÚresponseÚresultr   Údictr   ÚmodifyÚend_transaction)Ú
connectionÚ
members_dnÚ	groups_dnÚfixÚtransactionÚsafe_members_dnÚsafe_groups_dnÚ	member_dnÚgroup_dnÚtransaction_controlÚerrorr   r0   r/   Ú_ÚchangesÚsecurity_equals_to_removeÚgroup_membership_to_removeÚgroupÚmember_to_removeÚequivalent_to_me_to_remover   )r"   r   r!   r   r   Úedir_remove_members_from_groups   sÀ   

$&
€

&(

€rF   N)Ú__doc__Úcore.exceptionsr   Ú r   r   r   r   Úutils.dnr   rF   r   r   r   r   Ú<module>   s
    