B
    ß%Q[@  ã               @   s6   d Z ddlmZ ddlmZmZmZmZ ddd„ZdS )	Ú
é   )ÚLDAPInvalidDnError)ÚSEQUENCE_TYPESÚ
MODIFY_ADDÚBASEÚDEREF_NEVERTc                s6  t |tƒs|g}t |tƒs |g}d}�x|D � ]þ}|r¾| j|dttdgd�}| jjsd|  |¡\}}n| j| j	 }}|d dksŠt
|d ƒ‚d|d d	 krª|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	}|d dkr,d}P q,W | 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
    :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.
    Fz(objectclass=*)Úmember)Zdereference_aliasesÚ
attributesÚdescriptionÚsuccessz
 not foundé    r	   c             S   s   g | ]}|  ¡ ‘qS © )Úlower)Ú.0Úelementr   r   úlC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6i93dh7p\ldap3\ldap3\extend\microsoft\addMembersToGroups.pyú
<listcomp>?   s    z,ad_add_members_to_groups.<locals>.<listcomp>c                s   g | ]}|  ¡ ˆ kr|‘qS r   )r   )r   r   )Úexisting_membersr   r   r   D   s    T)Ú
isinstancer   Úsearchr   r   ZstrategyZsyncZget_responseÚresponseÚresultr   Údictr   Úmodify)Ú
connectionZ
members_dnZ	groups_dnZfixÚerrorÚgroupr   r   ZchangesZmember_to_addÚ_r   )r   r   Úad_add_members_to_groups   s:    

$
r   N)T)	Ú__doc__Zcore.exceptionsr   Ú r   r   r   r   r   r   r   r   r   Ú<module>   s   