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 ƒ}|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 )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    ü