
    3fiWT                         d dl Z d dlmZ d dlmZ ddlmZmZ ddlm	Z	m
Z
mZmZ dZ e j                  e      Z G d d	e      Z G d
 de      Zy)    N)parse)	HTTPError   )MessageRecipientType)ME_RESOURCENEXT_LINK_KEYWORDApiComponent
Paginationusersc                        e Zd ZdddZeZddd fd
Zd Zd Zd	 Z	d
 Z
ed        Zdej                  ddZddZd Z xZS )Userz/photo/$valuez/photos/{size}/$value)photo
photo_sizeNparentconc                   |r|rt        d      |r|j                  n|| _        |j                  dd      xs |rt        |dd      nd}|j	                  | j
                  i       }|j	                  d      | _        |t        k(  r|d| j                   z  }t        | %  |r|j                  n|j	                  d      |       | j                  j                  }| j                  }|j	                  d      | _        |j	                   |d	            | _        |j	                   |d
            | _        |j	                   |d      d      | _        |j	                   |d      d      | _        |j	                   |d            | _        |j	                   |d      g       | _        |j	                   |d            | _        |j	                   |d            | _        |j	                   |d            | _        |j	                   |d            | _        |j	                   |d            | _        |j	                   |d            | _        |j	                   |d            | _        |j	                   |d            | _        |j	                   |d            | _        |j	                   |d            }|rt;        |      j=                  |      nd| _        |j	                   |d            | _         |j	                   |d            | _!        |j	                   |d            | _"        |j	                   |d            | _#        |j	                   |d            }	|	rt;        |	      j=                  |      nd| _$        |j	                   |d            | _%        |j	                   |d             | _&        |j	                   |d!            | _'        |j	                   |d"            }
|
rt;        |
      j=                  |      nd| _(        |j	                   |d#            | _)        |j	                   |d$            | _*        |j	                   |d%            | _+        |j	                   |d&            }|rt;        |      j=                  |      nd| _,        |j	                   |d'            | _-        |j	                   |d(            | _.        |j	                   |d)            | _/        |j	                   |d*            | _0        |j	                   |d+            | _1        |j	                   |d,            | _2        |j	                   |d-            | _3        |j	                   |d.            | _4        |j	                   |d/            | _5        |j	                   |d0            | _6        |j	                   |d1            | _7        |j	                   |d2            | _8        |j	                   |d3            | _9        |j	                   |d4            | _:        |j	                   |d5            | _;        |j	                   |d6            | _<        |j	                   |d7      d8      | _=        |j	                   |d9            | _>        |j	                   |d:            }|rt;        |      j=                  |      nd| _?        |j	                   |d;            | _@        |j	                   |d<            | _A        |j	                   |d=            | _B        |j	                   |d>            | _C        |j	                   |d?            | _D        y)@au   Represents an Azure AD user account

        :param parent: parent object
        :type parent: Account
        :param Connection con: connection to use if no parent specified
        :param Protocol protocol: protocol to use if no parent specified
         (kwargs)
        :param str main_resource: use this resource instead of parent resource
         (kwargs)
        *Need a parent or a connection but not bothmain_resourceNid/protocolr   r   z@odata.typeuserPrincipalNamedisplayName	givenName surnamemailbusinessPhonesjobTitlemobilePhoneofficeLocationpreferredLanguageaboutMeaccountEnabledageGroupassignedLicensesassignedPlansbirthdaycitycompanyNameconsentProvidedForMinorcountrycreatedDateTime
department
employeeId	faxNumberhireDateimAddresses	interestsisResourceAccountlastPasswordChangeDateTimelegalAgeGroupClassificationlicenseAssignmentStatesmailboxSettingsmailNicknamemySite
otherMailspasswordPoliciespasswordProfilepastProjects
postalCodepreferredDataLocationpreferredNameprovisionedPlansproxyAddressesresponsibilitiesschoolsshowInAddressListTskillssignInSessionsValidFromDateTimestatestreetAddressusageLocationuserTypeonPremisesSamAccountName)E
ValueErrorr   popgetattrget_cloud_data_key	object_idUSERS_RESOURCEsuper__init__r   timezone_cctypeuser_principal_namedisplay_name
given_namer   r    business_phones	job_titlemobile_phoneoffice_locationpreferred_languageabout_meaccount_enabled	age_groupassigned_licensesassigned_plansr   
astimezoner+   r,   company_nameconsent_provided_for_minorr/   createdr1   employee_id
fax_number	hire_dateim_addressesr6   is_resource_accountlast_password_changelegal_age_group_classificationlicense_assignment_statesmailbox_settingsmail_nicknamemy_siteother_mailspassword_policiespassword_profilepast_projectspostal_codepreferred_data_locationpreferred_nameprovisioned_plansproxy_addressesrG   rH   show_in_address_listrJ   sign_in_sessions_valid_fromrL   street_addressusage_location	user_typeon_premises_sam_account_name)selfr   r   kwargsr   
cloud_datalocal_tzccr+   rm   rp   rs   r   	__class__s                L/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/O365/directory.pyrY   zUser.__init__   sD    cIJJ!'6::S 

?D9 H6<GFOT2$ 	 ZZ 4 4b9
 $-N*q 011M(.V__FJJz4J' 	 	) ==))XX NN=1	 $.>>"5H2I#J &NN2m+<=$..K"=!~~bmR8NN2f:.	)~~b1A.BBG#:7&NN2m+<=)~~b1A.BC #-..4G1H"I #r)}5)~~b1A.BC#:7 ",3E0F!G(nnR-@A>>"Z.1@Hh228<dNN2f:.	&NN2m+<=*4..<U9V*W' "~~bm4..$5!67 ! W~00&* 	 %..L)9:%>>"\*:;$..K9NN2j>2	 # y)44(, 	 'NN2m+<=#;8#->>"5H2I#J )~~b1M.NO
 . %**>$?$J$J%37 	! /9nnR@]=^._+ *4;T8U)V& *r2C/D E'^^B~,>?!~~bl3 &>>"\*:;!+3E0F!G *r2C/D E'^^B~,>?%>>"\*:;'1~~b9P6Q'R$ )nnR-@A!+3E0F!G  *~~b1A.BC *r2D/E F!~~bm4 %/NN26I3JD$Q! nnR\2&0nnR8Y5Z&[# 5 ,11L+M+X+X,:> 	(  ^^BwK0
(nnR-@A(nnR-@A $:7 -7NN2>X;Y,Z)    c                 "    | j                         S N)__repr__r   s    r   __str__zUser.__str__   s    }}r   c                 Z    | j                   xs | j                  xs | j                  xs dS )NzUnknown Name)r^   	full_namer]   r   s    r   r   zUser.__repr__   s(      `DNN`d6N6N`R``r   c                 4    | j                   |j                   k(  S r   )rV   )r   others     r   __eq__zUser.__eq__   s    ~~00r   c                 6    | j                   j                         S r   )rV   __hash__r   s    r   r   zUser.__hash__   s    ~~&&((r   c                 T    | j                    d| j                   j                         S )z8 Full Name (Name + Surname)
        :rtype: str
         )r_   r   stripr   s    r   r   zUser.full_name   s'    
 //"!DLL>288::r   )recipient_typec                    t        |t              rt        |      }|xs | j                  }|sy| j	                  | d      }t        |t        |j                              }|j                  |       |S )a   This method returns a new draft Message instance with this
        user email as a recipient

        :param Recipient recipient: a Recipient instance where to send this
         message. If None the email of this contact will be used
        :param RecipientType recipient_type: section to add recipient into
        :return: newly created message
        :rtype: Message or None
        NT)r   is_draft)
isinstancestrr   r    message_constructorrS   valueadd)r   	recipientr   new_messagetarget_recipientss        r   r   zUser.new_message   sm     nc**>:N*	..dT.J#K^5I5I1JKi(r   c                    |+| j                  | j                  j                  d            }n:| j                  | j                  j                  d      j                  |            }	 | j                  j                  |      }|sy|j                  S # t
        $ r"}t        j                  d|        Y d}~yd}~ww xY w)zReturns the user profile photo

        :param str size: 48x48, 64x64, 96x96, 120x120, 240x240,
         360x360, 432x432, 504x504, and 648x648
        Nr   r   )sizez6Error while retrieving the user profile photo. Error: )		build_url
_endpointsrT   formatr   r   logdebugcontent)r   r   urlresponsees        r   get_profile_photozUser.get_profile_photo   s     <..!4!4W!=>C..!4!4\!B!I!It!I!TUC	xx||C(H
   	IINqcRS	s   )B 	B>B99B>c                     | j                  | j                  j                  d            }| j                  j	                  ||ddi      }t        |      S )z] Updates this user profile photo
        :param bytes photo: the photo data in bytes
        r   zContent-typez
image/jpeg)dataheaders)r   r   rT   r   patchbool)r   r   r   r   s       r   update_profile_photozUser.update_profile_photo  sH    
 nnT__009:88>>#ENL;Y>ZH~r   r   )__name__
__module____qualname__r   r   r   rY   r   r   r   r   propertyr   r   TOr   r   r   __classcell__r   s   @r   r   r      sl     !-J
 "!%4 l[\a1) ; ;M<L<L 2 ,r   r   c                   |     e Zd ZddiZeZddd fd
Zd ZddddddZdd	Z	dd
Z
ddZddZddddddZ xZS )	Directoryget_userz/{email}Nr   c                    |r|rt        d      |r|j                  n|| _        |j                  dd      xs |rt        |dd      nd}t        |   |r|j                  n|j                  d      |       y)aq   Represents the Active Directory

        :param parent: parent object
        :type parent: Account
        :param Connection con: connection to use if no parent specified
        :param Protocol protocol: protocol to use if no parent specified
         (kwargs)
        :param str main_resource: use this resource instead of parent resource
         (kwargs)
        r   r   Nr   r   )rQ   r   rR   rS   rX   rY   r   rT   )r   r   r   r   r   r   s        r   rY   zDirectory.__init__  s{     cIJJ!'6::S 

?D9 H6<GFOT2$ 	 	(.V__FJJz4J' 	 	)r   c                      y)NzActive Directory r   s    r   r   zDirectory.__repr__1  s    !r   )queryorder_bybatchc                *     j                  d      }|| j                  j                  kD  r j                  j                  }d|r|n|i}|r||d<   |r5t        |t              r||d<   n|j                  |j                                 j                  j                  ||      }|st        d      S |j                         } fd|j                  d	g       D        }	|j                  t        d      }
|r|
rt         |	 j                  |
|
      S |	S )ad   Gets a list of users from the active directory

        When querying the Active Directory the Users endpoint will be used.
        Only a limited set of information will be available unless you have
        access to scope 'User.Read.All' which requires App Administration
        Consent.

        Also using endpoints has some limitations on the querying capabilities.

        To use query an order_by check the OData specification here:
        http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/
        part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions
        -complete.html

        :param limit: max no. of contacts to get. Over 999 uses batch.
        :type limit: int or None
        :param query: applies a OData filter to the request
        :type query: Query or str
        :param order_by: orders the result set based on this condition
        :type order_by: Query or str
        :param int batch: batch size, retrieves items in
         batches allowing to retrieve more items than the limit.
        :return: list of users
        :rtype: list[User] or Pagination
        r   N$top$orderby$filterparamsr   c              3   ^   K   | ]$  } j                   dd ij                  |i & ywr   Nr   user_constructorrU   .0userr   s     r   	<genexpr>z&Directory.get_users.<locals>.<genexpr>f  s9      4 '&&SdSt7K7KT6RS 4   *-r   r   r   constructor	next_linklimit)r   r   max_top_valuer   r   update	as_paramsr   rT   iterjsonr	   r   r   )r   r   r   r   r   r   r   r   r   r   r   s   `          r   	get_userszDirectory.get_users4  s   6 nnR =EDMM$?$??MM//E5%e4!)F:%%$)y!eoo/088<<F<38O}}4!XXgr24 HH.5	YT*.*?*?(1@ @ Lr   c                    i }|r5t        |t              r||d<   n|j                  |j                                | j                  j                  ||      }|sy|j                         } | j                  dd| i| j                  |iS )zHelper method so DRYr   r   Nr   r   )	r   r   r   r   r   rT   r   r   rU   )r   r   r   r   r   r   s         r   	_get_userzDirectory._get_userr  s     %%$)y!eoo/088<<F<3}} %t$$QDQT5I5I44PQQr   c                     | j                  | j                  j                  d      j                  |            }| j	                  ||      S )z Returns a User by it's id or user principal name

        :param str user: the user id or user principal name
        :return: User for specified email
        :rtype: User
        r   emailr   r   r   rT   r   r   r   r   r   r   s       r   r   zDirectory.get_user  sB     nnT__00<CC$COP~~c~//r   c                     | j                   t        k7  rt        dt         d      | j                  d      }| j	                  ||      S )z# Returns the current logged-in userz>Can't get the current user. The main resource must be set to ''r   r   )r   r   rQ   r   r   )r   r   r   s      r   get_current_userzDirectory.get_current_user  sK     ,]^i]jjklmmnnR ~~c~//r   c                     | j                  | j                  j                  d      j                  |            }| j	                  |dz   |      S )z Returns a Users' manager by the users id, or user principal name

        :param str user: the user id or user principal name
        :return: User for specified email
        :rtype: User
        r   r   z/managerr   r   r   s       r   get_user_managerzDirectory.get_user_manager  sG     nnT__00<CC$COP~~cJ.e~<<r   c                     j                   j                  j                  d      j                  |            }|| j                  j
                  kD  r j                  j
                  }d|r|n|i}|r||d<   |r5t        |t              r||d<   n|j                  |j                                 j                  j                  |dz   |      }|st        d	      S |j                         }	 fd
|	j                  dg       D        }
|	j                  t        d      }|r|rt         |
 j                  ||      S |
S )a   Gets a list of direct reports for the user provided from the active directory

        When querying the Active Directory the Users endpoint will be used.

        Also using endpoints has some limitations on the querying capabilities.

        To use query an order_by check the OData specification here:
        http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/
        part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions
        -complete.html

        :param limit: max no. of contacts to get. Over 999 uses batch.
        :type limit: int or None
        :param query: applies a OData filter to the request
        :type query: Query or str
        :param order_by: orders the result set based on this condition
        :type order_by: Query or str
        :param int batch: batch size, retrieves items in
         batches allowing to retrieve more items than the limit.
        :return: list of users
        :rtype: list[User] or Pagination
        r   r   Nr   r   r   z/directReportsr   r   c              3   ^   K   | ]$  } j                   dd ij                  |i & ywr   r   r   s     r   r   z4Directory.get_user_direct_reports.<locals>.<genexpr>  s:      / 0$//\t\@T@TVZ?[\ /r   r   r   )r   r   rT   r   r   r   r   r   r   r   r   r   r   r	   r   r   )r   r   r   r   r   r   r   r   r   r   direct_reportsr   s   `           r   get_user_direct_reportsz!Directory.get_user_direct_reports  s(   0 nnT__00<CC$COP=EDMM$?$??MM//E5%e4!)F:%%$)y!eoo/088<<&6 6v<F8O}}/"-/ HH.5	YT*.*?*?(1@ @ "!r   )d   r   )r   r   r   r   r   r   rY   r   r   r   r   r   r   r   r   r   s   @r   r   r     sd     	JJ !%4 )0"<D4t <|R&00=9"t[_ 9" 9"r   r   )loggingdateutil.parserr   requests.exceptionsr   messager   r   utilsr   r	   r
   r   rW   	getLoggerr   r   r   r   r   r   r   <module>r      sK     ! ) + K Kg!A< AHI" I"r   