Ë
    daºiÛ€  ã                   ó^   — d dl Z d dlmZ ddlmZ  e j
                  e«      Z G d„ de«      Zy)é    N)Ú	HTTPErroré   )ÚAtlassianRestAPIc                   ó–  — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z		 	 d7d	„Z
d
„ Zd„ Zd„ Zd8d„Zd7d„Zd7d„Zd9d„Zd:d„Zd;d„Zd„ Zd<d„ZeZd„ Zd8d„Zd„ Zd„ Zd„ Zd„ Zg g fd„Zg g fd„Z	 	 d=d„Z	 	 d=d„Z d„ Z!d=d „Z"d=d!„Z#d8d"„Z$d#„ Z%d9d$„Z&d8d%„Z'd&„ Z(d'„ Z)d(„ Z*d<d)„Z+g g fd*„Z,g g fd+„Z-d>d,„Z.d8d-„Z/d.„ Z0d/„ Z1d0„ Z2d1„ Z3d2„ Z4d3„ Z5d4„ Z6d5„ Z7d6„ Z8y)?ÚServiceDeskz%
    JIRA ServiceDesk API object
    c                 ó<   — | j                  d| j                  ¬«      S )zGet info about Service Desk appzrest/servicedeskapi/info©Úheaders©ÚgetÚexperimental_headers)Úselfs    úN/var/www/timesheet/venv/lib/python3.12/site-packages/atlassian/service_desk.pyÚget_infozServiceDesk.get_info   s   € ð �x‰xÐ2¸D×<UÑ<UˆxÓVÐVó    c                 ó‚   — | j                  d| j                  ¬«      }| j                  r|S |xs i j                  d«      S )zª
        Returns all service desks in the Jira Service Desk application
        with the option to include archived service desks

        :return: Service Desks
        zrest/servicedeskapi/servicedeskr	   Úvalues©r   r   Úadvanced_mode)r   Úservice_desks_lists     r   Úget_service_deskszServiceDesk.get_service_desks   sK   € ð "ŸX™XØ-Ø×-Ñ-ð &ó 
Ðð ×ÒØ%Ð%à&Ò,¨"×1Ñ1°(Ó;Ð;r   c                 óB   — | j                  d|› �| j                  ¬«      S )z‰
        Returns the service desk for a given service desk ID

        :param service_desk_id: str
        :return: Service Desk
        ú rest/servicedeskapi/servicedesk/r	   r   ©r   Úservice_desk_ids     r   Úget_service_desk_by_idz"ServiceDesk.get_service_desk_by_id&   s.   € ð �x‰xØ.¨Ð.?Ð@Ø×-Ñ-ð ó 
ð 	
r   c                 ór   — t         j                  d«       ||dœ}| j                  d| j                  |¬«      S )z›
        Creating customer user.
        :param full_name: str - full name
        :param email: str - email address
        :return: New customer
        z1Creating customer using create_customer method...)ÚfullNameÚemailzrest/servicedeskapi/customer©r
   Údata©ÚlogÚinfoÚpostr   )r   Ú	full_namer   r!   s       r   Úcreate_customerzServiceDesk.create_customer4   s@   € ô 	�‰ÐDÔEØ%°Ñ6ˆà�y‰yØ*Ø×-Ñ-Øð ó 
ð 	
r   c                 óB   — | j                  d|› �| j                  ¬«      S )zk
        Get single request

        :param issue_id_or_key: str
        :return: Customer request
        úrest/servicedeskapi/request/r	   r   )r   Úissue_id_or_keys     r   Úget_customer_requestz ServiceDesk.get_customer_requestD   s.   € ð �x‰xØ*¨?Ð*;Ð<Ø×-Ñ-ð ó 
ð 	
r   c                 ó‚   — | j                  d| j                  ¬«      }| j                  r|S |xs i j                  d«      S )z-Returning requests where you are the assigneeúrest/servicedeskapi/requestr	   r   r   )r   Úresponses     r   Úget_my_customer_requestsz$ServiceDesk.get_my_customer_requestsQ   s>   € à—8‘8Ð9À4×C\ÑC\�8Ó]ˆØ×ÒØˆOØ’˜B×#Ñ# HÓ-Ð-r   Nc                 óê   — t         j                  d«       |||dœ}|r||d<   |r||d<   d| j                  i}t        |t        «      r||d<   nt        |t
        «      r||d<    | j                  di |¤ŽS )	a  
        Creating customer request

        :param service_desk_id: str
        :param request_type_id: str
        :param values_dict: str/dict
        :param raise_on_behalf_of: str
        :param request_participants: list
        :return: New request
        zCreating request...)ÚserviceDeskIdÚrequestTypeIdÚrequestFieldValuesÚraiseOnBehalfOfÚrequestParticipantsr
   Újsonr!   )r-   )r#   r$   r   Ú
isinstanceÚdictÚstrr%   )r   r   Úrequest_type_idÚvalues_dictÚraise_on_behalf_ofÚrequest_participantsr!   Ú	param_maps           r   Úcreate_customer_requestz#ServiceDesk.create_customer_requestX   s‹   € ô$ 	�‰Ð&Ô'à,Ø,Ø"-ñ
ˆñ Ø&8ˆDÐ"Ñ#áØ*>ˆDÐ&Ñ'à × 9Ñ 9Ð:ˆ	ä�k¤4Ô(Ø $ˆI�fÒÜ˜¤SÔ)Ø $ˆI�fÑàˆt�y‰yÑD¸)ÑDÐDr   c                 óÖ   — | j                  d|› d�| j                  ¬«      }| j                  r|S |r7|j                  dg «      r%|j                  dg «      d   j                  di «      S i S )zt
        Get customer request status name

        :param issue_id_or_key: str
        :return: Status name
        r)   z/statusr	   r   r   Ústatusr   )r   r*   Úrequests      r   Úget_customer_request_statusz'ServiceDesk.get_customer_request_status€   sv   € ð —(‘(Ø*¨?Ð*;¸7ÐCØ×-Ñ-ð ó 
ˆð ×ÒØˆNÙØ�{‰{˜8 RÔ(Ø—{‘{ 8¨RÓ0°Ñ3×7Ñ7¸À"ÓEÐEØˆ	r   c                 óH   — d|› d�}| j                  || j                  ¬«      S )z�
        Returns a list of transitions that customers can perform on the request

        :param issue_id_or_key: str
        :return:
        r)   ú/transitionr	   r   )r   r*   Úurls      r   Úget_customer_transitionsz$ServiceDesk.get_customer_transitions’   s,   € ð -¨_Ð,=¸[ÐIˆà�x‰x˜ T×%>Ñ%>ˆxÓ?Ð?r   c                 óD   — | j                  d|› d�| j                  ¬«      S )zy
        Gets request types

        :param service_desk_id: str
        :return: all service desk request types
        r   ú/requesttyper	   r   r   s     r   Úget_request_typeszServiceDesk.get_request_types�   s0   € ð �x‰xØ.¨Ð.?¸|ÐLØ×-Ñ-ð ó 
ð 	
r   c                 óÔ   — d|› d�}i }|�t        |«      |d<   |�t        |«      |d<   | j                  ||| j                  ¬«      }| j                  r|S |xs i j                  d«      S )z½
        Get request participants

        :param issue_id_or_key: str
        :param start: OPTIONAL: int
        :param limit: OPTIONAL: int
        :return: Request participants
        r)   ú/participantÚstartÚlimit©Úparamsr
   r   ©Úintr   r   r   ©r   r*   rM   rN   rF   rP   r.   s          r   Úget_request_participantsz$ServiceDesk.get_request_participants«   s{   € ð -¨_Ð,=¸\ÐJˆØˆØÐÜ! %›jˆF�7‰OØÐÜ! %›jˆF�7‰Oà—8‘8˜C¨¸×8QÑ8Q�8ÓRˆØ×ÒØˆOØ’˜B×#Ñ# HÓ-Ð-r   c                 ój   — d|› d�}i }|�||d<   |�||d<   | j                  ||| j                  ¬«      S )a"  
        Add users as participants to an existing customer request
        The calling user must have permission to manage participants for this customer request

        :param issue_id_or_key: str
        :param users_list: list
        :param account_list: list
        :return:
        r)   rL   Ú	usernamesÚ
accountIds©r!   r
   ©r%   r   ©r   r*   Ú
users_listÚaccount_listrF   r!   s         r   Úadd_request_participantsz$ServiceDesk.add_request_participantsÀ   sS   € ð -¨_Ð,=¸\ÐJˆØˆØÐ!Ø *ˆD�ÑØÐ#Ø!-ˆD�Ñà�y‰y˜ 4°×1JÑ1JˆyÓKÐKr   c                 ój   — d|› d�}i }|�||d<   |�||d<   | j                  ||| j                  ¬«      S )a  
        Remove participants from an existing customer request
        The calling user must have permission to manage participants for this customer request

        :param issue_id_or_key: str
        :param users_list: list
        :param account_list: list
        :return:
        r)   rL   rV   rW   rX   )Údeleter   rZ   s         r   Úremove_request_participantsz'ServiceDesk.remove_request_participantsÓ   sS   € ð -¨_Ð,=¸\ÐJˆØˆØÐ!Ø *ˆD�ÑØÐ#Ø!-ˆD�Ñà�{‰{˜3 T°4×3LÑ3Lˆ{ÓMÐMr   c                 óˆ   — t         j                  d|z   «       |d|idœ}d|› d�}| j                  || j                  |¬«      S )a-  
        Perform a customer transition for a given request and transition ID.
        An optional comment can be included to provide a reason for the transition.

        :param issue_id_or_key: str
        :param transition_id: str
        :param comment: OPTIONAL: str
        :return: None
        z!Performing transition for issue: Úbody)ÚidÚadditionalCommentr)   rE   r    r"   )r   r*   Útransition_idÚcommentr!   rF   s         r   Úperform_transitionzServiceDesk.perform_transitionç   sO   € ô 	�‰Ð4°ÑFÔGØ#¸6À7Ð:KÑLˆØ,¨_Ð,=¸[ÐIˆà�y‰y˜ d×&?Ñ&?ÀdˆyÓKÐKr   c                 ó~   — t         j                  d«       ||dœ}d|› d�}| j                  ||| j                  ¬«      S )z½
        Creating request comment

        :param issue_id_or_key: str
        :param body: str
        :param public: OPTIONAL: bool (default is True)
        :return: New comment
        zCreating comment...)rb   Úpublicr)   ú/comment)Úpathr!   r
   r"   )r   r*   rb   ri   r!   rF   s         r   Úcreate_request_commentz"ServiceDesk.create_request_commentø   sE   € ô 	�‰Ð&Ô'Ø¨Ñ/ˆØ,¨_Ð,=¸XÐFˆà�y‰y˜c¨°d×6OÑ6OˆyÓPÐPr   c                 ó  — d|› d�}i }|�t        |«      |d<   |�t        |«      |d<   |�t        |«      |d<   |�t        |«      |d<   | j                  ||| j                  ¬«      }| j                  r|S |xs i j                  d«      S )	a  
        Get all comments in issue

        :param issue_id_or_key: str
        :param start: OPTIONAL: int
        :param limit: OPTIONAL: int
        :param public: OPTIONAL: bool
        :param internal: OPTIONAL: bool
        :return: Issue comments
        r)   rj   rM   rN   ri   ÚinternalrO   r   )rR   Úboolr   r   r   )	r   r*   rM   rN   ri   rn   rF   rP   r.   s	            r   Úget_request_commentsz ServiceDesk.get_request_comments  s£   € ð -¨_Ð,=¸XÐFˆØˆØÐÜ! %›jˆF�7‰OØÐÜ! %›jˆF�7‰OØÐÜ# F›|ˆF�8ÑØÐÜ!% h£ˆF�:Ñà—8‘8˜C¨¸×8QÑ8Q�8ÓRˆØ×ÒØˆOØ’˜B×#Ñ# HÓ-Ð-r   c                 óH   — | j                  d|› d|› �| j                  ¬«      S )zŽ
        Get single comment by ID

        :param issue_id_or_key: str
        :param comment_id: str
        :return: Single comment
        r)   z	/comment/r	   r   )r   r*   Ú
comment_ids      r   Úget_request_comment_by_idz%ServiceDesk.get_request_comment_by_id"  s4   € ð �x‰xØ*¨?Ð*;¸9ÀZÀLÐQØ×-Ñ-ð ó 
ð 	
r   c                 óÒ   — d}d|› d�}i }|�t        |«      |d<   |�t        |«      |d<   |€| j                  || j                  |¬«      S | j                  || j                  |¬«      S )aa  
        Returns a list of organizations in the Jira instance. If the user is not an agent,
        the resource returns a list of organizations the user is a member of.

        :param service_desk_id: OPTIONAL: str Get organizations from single Service Desk
        :param start: OPTIONAL: int The starting index of the returned objects.
                     Base index: 0. See the Pagination section for more details.
        :param limit: OPTIONAL: int The maximum number of users to return per page.
                     Default: 50. See the Pagination section for more details.
        :return:
        ú rest/servicedeskapi/organizationr   ú/organizationrM   rN   ©r
   rP   ©rR   r   r   )r   r   rM   rN   Úurl_without_sd_idÚurl_with_sd_idrP   s          r   Úget_organisationszServiceDesk.get_organisations1  s�   € ð ?ÐØ;¸OÐ;LÈMÐZˆØˆØÐÜ! %›jˆF�7‰OØÐÜ! %›jˆF�7‰OàÐ"Ø—8‘8Ø!Ø×1Ñ1Øð ó ð ð
 �x‰x˜°×0IÑ0IÐRXˆxÓYÐYr   c                 óF   — d|› �}| j                  || j                  ¬«      S )z„
        Get an organization for a given organization ID

        :param organization_id: str
        :return: Organization
        ú!rest/servicedeskapi/organization/r	   r   ©r   Úorganization_idrF   s      r   Úget_organizationzServiceDesk.get_organizationP  s*   € ð 2°/Ð1BÐCˆà�x‰x˜ T×%>Ñ%>ˆxÓ?Ð?r   c                 óŽ   — d|› d�}i }|�t        |«      |d<   |�t        |«      |d<   | j                  || j                  |¬«      S )zØ
        Get all the users of a specified organization

        :param organization_id: str
        :param start: OPTIONAL: int
        :param limit: OPTIONAL: int
        :return: Users list in organization
        r}   ú/userrM   rN   rw   rx   )r   r   rM   rN   rF   rP   s         r   Úget_users_in_organizationz%ServiceDesk.get_users_in_organization[  sY   € ð 2°/Ð1BÀ%ÐHˆØˆØÐÜ! %›jˆF�7‰OØÐÜ! %›jˆF�7‰Oà�x‰x˜ T×%>Ñ%>ÀvˆxÓNÐNr   c                 óz   — t         j                  d|z   «       d}d|i}| j                  || j                  |¬«      S )zÄ
        To create an organization Jira administrator global or agent
        permission is required depending on the settings

        :param name: str
        :return: Organization data
        zCreating organization: ru   Únamer    r"   )r   r…   rF   r!   s       r   Úcreate_organizationzServiceDesk.create_organizationm  s?   € ô 	�‰Ð*¨TÑ1Ô2Ø0ˆØ˜ˆ~ˆà�y‰y˜ d×&?Ñ&?ÀdˆyÓKÐKr   c                 ó|   — t         j                  d«       d|› d�}d|i}| j                  || j                  |¬«      S )zÀ
        Adds an organization to a servicedesk for a given servicedesk ID and organization ID

        :param service_desk_id: str
        :param organization_id: int
        :return:
        zAdding organization...r   rv   ÚorganizationIdr    r"   ©r   r   r   rF   r!   s        r   Úadd_organizationzServiceDesk.add_organization{  sE   € ô 	�‰Ð)Ô*Ø0°Ð0AÀÐOˆØ  /Ð2ˆà�y‰y˜ d×&?Ñ&?ÀdˆyÓKÐKr   c                 ó|   — t         j                  d«       d|› d�}d|i}| j                  || j                  |¬«      S )zÅ
        Removes an organization from a servicedesk for a given servicedesk ID and organization ID

        :param service_desk_id: str
        :param organization_id: int
        :return:
        zRemoving organization...r   rv   rˆ   r    ©r#   r$   r_   r   r‰   s        r   Úremove_organizationzServiceDesk.remove_organization‰  sE   € ô 	�‰Ð+Ô,Ø0°Ð0AÀÐOˆØ  /Ð2ˆà�{‰{˜3¨×(AÑ(AÈˆ{ÓMÐMr   c                 ór   — t         j                  d|«       d|› �}| j                  || j                  ¬«      S )zw
        Deletes an organization for a given organization ID

        :param organization_id:
        :return:
        zDeleting organization: %s r}   r	   rŒ   r~   s      r   Údelete_organizationzServiceDesk.delete_organization—  s9   € ô 	�‰Ð-¨Ô?Ø1°/Ð1BÐCˆà�{‰{˜3¨×(AÑ(Aˆ{ÓBÐBr   c                 ó’   — t         j                  dt        |«      «       d|› d�}||dœ}| j                  || j                  |¬«      S )z÷
        Adds users to an organization
        users_list is a list of strings
        account_list is a list of accountIds

        :param account_list:
        :param organization_id: str
        :param users_list: list
        :return:
        zAdding users: %s r}   r‚   ©rV   rW   r    )r#   r$   r9   r%   r   ©r   r   r[   r\   rF   r!   s         r   Úadd_users_to_organizationz%ServiceDesk.add_users_to_organization£  sK   € ô 	�‰Ð$¤c¨*£oÔ6Ø1°/Ð1BÀ%ÐHˆØ'°|ÑDˆà�y‰y˜ d×&?Ñ&?ÀdˆyÓKÐKr   c                 ó’   — t         j                  dt        |«      «       d|› d�}||dœ}| j                  || j                  |¬«      S )a  
        Removes users from an organization
        users_list is a list of strings
        account_list is a list of accountIds

        :param organization_id: str
        :param users_list: list
        :param account_list: list
        :return:
        zRemoving users: %sr}   r‚   r‘   r    )r#   r$   r9   r_   r   r’   s         r   Úremove_users_from_organizationz*ServiceDesk.remove_users_from_organization´  sK   € ô 	�‰Ð%¤s¨:£Ô7Ø1°/Ð1BÀ%ÐHˆØ'°|ÑDˆà�{‰{˜3¨×(AÑ(AÈˆ{ÓMÐMr   c                 ó¨   — g }t        |t        «      s|g}|D ]%  }| j                  ||«      }|j                  |«       Œ' | j	                  ||||«      S )aá  
        Add attachment as a comment.
        Setting attachment visibility is dependent on the user's permission. For example,
        Agents can create either public or internal attachments,
        while Unlicensed users can only create internal attachments,
        and Customers can only create public attachments.
        An additional comment may be provided which will be prepended to the attachments.
        :param service_desk_id: str
        :param issue_id_or_key: str
        :param filenames: Union(List[str], str), name, if file in current directory or full path to file
        :param public: OPTIONAL: bool (default is True)
        :param comment: OPTIONAL: str (default is None)
        :return: Request info
        )r7   ÚlistÚattach_temporary_fileÚappendÚadd_attachments)	r   r   r*   Ú	filenamesri   rf   Útemp_attachment_idsÚfilenameÚtemp_attachment_ids	            r   Úcreate_attachmentszServiceDesk.create_attachmentsÆ  sg   € ð. !ÐÜ˜)¤TÔ*Ø"˜ˆIà!ò 	;ˆHØ!%×!;Ñ!;¸OÈXÓ!VÐØ×&Ñ&Ð'9Õ:ð	;ð
 ×#Ñ# OÐ5HÈ&ÐRYÓZÐZr   c                 óX   — t         j                  d«       | j                  |||||¬«      S )aÎ  
        Add attachment as a comment.
        Setting attachment visibility is dependent on the user's permission. For example,
        Agents can create either public or internal attachments,
        while Unlicensed users can only create internal attachments,
        and Customers can only create public attachments.
        An additional comment may be provided which will be prepended to the attachments.
        :param service_desk_id: str
        :param issue_id_or_key: str
        :param filename: str, name, if file in current directory or full path to file
        :param public: OPTIONAL: bool (default is True)
        :param comment: OPTIONAL: str (default is None)
        :return: Request info
        zCreating attachment...©ri   rf   )r#   r$   rŸ   )r   r   r*   r�   ri   rf   s         r   Úcreate_attachmentzServiceDesk.create_attachmentè  s8   € ô, 	�‰Ð)Ô*Ø×&Ñ&ØØØØØð 'ó 
ð 	
r   c                 óŒ  — d|› d�}| j                   j                  «       }|d= d|d<   t        |d«      5 }| j                  r4| j	                  ||d|i¬«      j                  «       j                  d	«      }n%| j	                  ||d|i¬«      j                  d	«      }|d
   j                  d«      }|cddd«       S # 1 sw Y   yxY w)zÏ
        Create temporary attachment, which can later be converted into permanent attachment
        :param service_desk_id: str
        :param filename: str
        :return: Temporary Attachment ID
        r   z/attachTemporaryFileúContent-Typeúno-checkúX-Atlassian-TokenÚrbÚfile)rk   r
   ÚfilesÚtemporaryAttachmentsr   ÚtemporaryAttachmentIdN)r   ÚcopyÚopenr   r%   r6   r   )r   r   r�   rF   r   r¨   Úresultrž   s           r   r˜   z!ServiceDesk.attach_temporary_file  sß   € ð 1°Ð0AÐAUÐVˆð  $×8Ñ8×=Ñ=Ó?ÐØ  Ð0Ø4>ÐÐ0Ñ1ä�(˜DÓ!ð 	& Tð ×!Ò!à—I‘I 3Ð0DÈVÐUYÈN�IÓ[ß‘T“Vß‘SÐ/Ó0ñ ð Ÿ™¨Ð5IÐRXÐZ^ÐQ_˜Ó`×dÑdØ*ó�ð "(¨¡§¡Ð/FÓ!GÐà%÷!	&÷ 	&ò 	&ús   µA;B:Â:Cc                 óZ   — ||d|idœ}d|› d�}| j                  || j                  |¬«      S )aR  
        Adds temporary attachment to customer request using attach_temporary_file function
        :param issue_id_or_key: str
        :param temp_attachment_ids: List[str], ID from result attach_temporary_file function
        :param public: bool (default is True)
        :param comment: str (default is None)
        :return:
        rb   )ÚtemporaryAttachmentIdsri   rd   r)   z/attachmentr    rY   )r   r*   rœ   ri   rf   r!   rF   s          r   rš   zServiceDesk.add_attachments(  sE   € ð ':ØØ"(¨'Ð!2ñ
ˆð
 -¨_Ð,=¸[ÐIˆà�y‰y˜ d×&?Ñ&?ÀdˆyÓKÐKr   c                 óX   — t         j                  d«       | j                  ||g||¬«      S )aK  
        Adds temporary attachment to customer request using attach_temporary_file function
        :param issue_id_or_key: str
        :param temp_attachment_id: str, ID from result attach_temporary_file function
        :param public: bool (default is True)
        :param comment: str (default is None)
        :return:
        zAdding attachmentr¡   )r#   r$   rš   )r   r*   rž   ri   rf   s        r   Úadd_attachmentzServiceDesk.add_attachment:  s8   € ô 	�‰Ð$Ô%Ø×#Ñ#ØØÐ ØØð	 $ó 
ð 	
r   c                 óÔ   — d|› d�}i }|�t        |«      |d<   |�t        |«      |d<   | j                  ||| j                  ¬«      }| j                  r|S |xs i j                  d«      S )aT  
        Get the SLA information for a customer request for a given request ID or key
        A request can have zero or more SLA values
        IMPORTANT: The calling user must be an agent

        :param issue_id_or_key: str
        :param start: OPTIONAL: int
        :param limit: OPTIONAL: int
        :return: SLA information
        r)   z/slarM   rN   rO   r   rQ   rS   s          r   Úget_slazServiceDesk.get_slaL  s{   € ð -¨_Ð,=¸TÐBˆØˆØÐÜ! %›jˆF�7‰OØÐÜ! %›jˆF�7‰Oà—8‘8˜C¨¸×8QÑ8Q�8ÓRˆØ×ÒØˆOØ’˜B×#Ñ# HÓ-Ð-r   c                 óL   — d|› d|› �}| j                  || j                  ¬«      S )zú
        Get customer request SLA information for given request ID or key and SLA metric ID
        IMPORTANT: The calling user must be an agent

        :param issue_id_or_key: str
        :param sla_id: str
        :return: SLA information
        r)   z/sla/r	   r   )r   r*   Úsla_idrF   s       r   Úget_sla_by_idzServiceDesk.get_sla_by_idc  s0   € ð -¨_Ð,=¸UÀ6À(ÐKˆà�x‰x˜ T×%>Ñ%>ˆxÓ?Ð?r   c                 ó4   — |€g }d}| j                  ||¬«      S )z÷
        Fix corrupted or missing sla
        https://confluence.atlassian.com/jirakb/missing-or-corrupted-sla-data-in-jira-service-management-828790603.html
        :param tickets: list of tickets like [XXX-123, XXX-124]
        :return:
        zErest/servicedesk/1/servicedesk/sla/admin/task/destructive/reconstruct)r!   )r%   )r   ÚticketsrF   s      r   Úsla_rebuildzServiceDesk.sla_rebuildp  s&   € ð ˆ?ØˆGØUˆØ�y‰y˜ 7ˆyÓ+Ð+r   c                 óÔ   — d|› d�}i }|�t        |«      |d<   |�t        |«      |d<   | j                  || j                  |¬«      }| j                  r|S |xs i j                  d«      S )zÊ
        Get all approvals on a request, for a given request ID/Key

        :param issue_id_or_key: str
        :param start: OPTIONAL: int
        :param limit: OPTIONAL: int
        :return:
        r)   z	/approvalrM   rN   rw   r   rQ   rS   s          r   Úget_approvalszServiceDesk.get_approvals~  s{   € ð -¨_Ð,=¸YÐGˆØˆØÐÜ! %›jˆF�7‰OØÐÜ! %›jˆF�7‰Oà—8‘8˜C¨×)BÑ)BÈ6�8ÓRˆØ×ÒØˆOØ’˜B×#Ñ# HÓ-Ð-r   c                 óL   — d|› d|› �}| j                  || j                  ¬«      S )z�
        Get an approval for a given approval ID

        :param issue_id_or_key: str
        :param approval_id: str
        :return:
        r)   ú
/approval/r	   r   )r   r*   Úapproval_idrF   s       r   Úget_approval_by_idzServiceDesk.get_approval_by_id“  s0   € ð -¨_Ð,=¸ZÈÀ}ÐUˆà�x‰x˜ T×%>Ñ%>ˆxÓ?Ð?r   c                 óV   — d|› d|› �}d|i}| j                  || j                  |¬«      S )zž
        Answer a pending approval

        :param issue_id_or_key: str
        :param approval_id: str
        :param decision: str
        :return:
        r)   r¾   Údecisionr    rY   )r   r*   r¿   rÂ   rF   r!   s         r   Úanswer_approvalzServiceDesk.answer_approvalŸ  s<   € ð -¨_Ð,=¸ZÈÀ}ÐUˆØ˜HÐ%ˆà�y‰y˜ d×&?Ñ&?ÀdˆyÓKÐKr   c                 óF   — d|› �}| j                  || j                  ¬«      S )za
        Get queue settings on project

        :param project_key: str
        :return:
        zrest/servicedeskapi/queues/r	   r   )r   Úproject_keyrF   s      r   Úget_queue_settingszServiceDesk.get_queue_settings­  s)   € ð ,¨K¨=Ð9ˆà�x‰x˜ T×%>Ñ%>ˆxÓ?Ð?r   c                 óœ   — d|› d�}i }|�t        |«      |d<   |�t        |«      |d<   |�||d<   | j                  || j                  |¬«      S )a  
        Returns a list of the customers on a service desk.

        The returned list of customers can be filtered using the query parameter.
        The parameter is matched against customers' displayName, name, or email.
        For example, searching for "John", "Jo", "Smi", or "Smith" will match a
        user with display name "John Smith"..

        :param query:
        :param start:
        :param limit:
        :param service_desk_id: str
        :return: the customers added to the service desk
        r   ú	/customerrM   rN   Úqueryrw   rx   )r   r   rÉ   rM   rN   rF   rP   s          r   Úget_customerszServiceDesk.get_customers¸  sh   € ð 1°Ð0AÀÐKˆØˆØÐÜ! %›jˆF�7‰OØÐÜ! %›jˆF�7‰OØÐØ#ˆF�7‰Oà�x‰x˜ T×%>Ñ%>ÀvˆxÓNÐNr   c                 ó~   — d|› d�}||dœ}t         j                  d«       | j                  || j                  |¬«      S )aÑ  
        Adds one or more existing customers to the given service desk.
        If you need to create a customer, see Create customer method.

        Administer project permission is required, or agents if public signups
        and invites are enabled for the Service Desk project.

        :param service_desk_id: str
        :param list_of_usernames: list
        :param list_of_accountids: list
        :return: the customers added to the service desk
        r   rÈ   r‘   zAdding customers...r    r"   ©r   r   Úlist_of_usernamesÚlist_of_accountidsrF   r!   s         r   Úadd_customerszServiceDesk.add_customersÒ  sJ   € ð 1°Ð0AÀÐKˆà*Ø,ñ
ˆô
 	�‰Ð&Ô'Ø�y‰y˜ d×&?Ñ&?ÀdˆyÓKÐKr   c                 ó~   — d|› d�}||dœ}t         j                  d«       | j                  || j                  |¬«      S )aÕ  
        Removes one or more customers from a service desk. The service
        desk must have closed access. If any of the passed customers are
        not associated with the service desk, no changes will be made for
        those customers and the resource returns a 204 success code.

        :param service_desk_id: str
        :param list_of_usernames: list
        :param list_of_accountids: list
        :return: the customers added to the service desk
        r   rÈ   r‘   zRemoving customers...r    rŒ   rÌ   s         r   Úremove_customerszServiceDesk.remove_customersè  sJ   € ð 1°Ð0AÀÐKˆà*Ø,ñ
ˆô
 	�‰Ð(Ô)Ø�{‰{˜3¨×(AÑ(AÈˆ{ÓMÐMr   c                 ó®   — d|› d�}i }|�t        |«      |d<   |�t        |«      |d<   |�t        |«      |d<   | j                  || j                  |¬«      S )a÷  
        Returns a page of queues defined inside a service desk, for a given service desk ID.
        The returned queues will include issue counts for each queue (issueCount field)
        if the query param includeCount is set to true (default=false).

        Permissions: The calling user must be an agent of the given service desk.

        :param service_desk_id: str
        :param include_count: bool
        :param start: int
        :param limit: int
        :return: a page of queues
        r   z/queueÚincludeCountrM   rN   rw   )ro   rR   r   r   )r   r   Úinclude_countrM   rN   rF   rP   s          r   Ú
get_queueszServiceDesk.get_queuesý  sn   € ð 1°Ð0AÀÐHˆØˆàÐ$Ü%)¨-Ó%8ˆF�>Ñ"ØÐÜ! %›jˆF�7‰OØÐÜ! %›jˆF�7‰Oà�x‰x˜ T×%>Ñ%>ÀvˆxÓNÐNr   c                 ó”   — d|› d|› d�}i }|�t        |«      |d<   |�t        |«      |d<   | j                  || j                  |¬«      S )a{  
        Returns a page of issues inside a queue for a given queue ID.
        Only fields that the queue is configured to show are returned.
        For example, if a queue is configured to show only Description and Due Date,
        then only those two fields are returned for each issue in the queue.

        Permissions: The calling user must have permission to view the requested queue,
        i.e. they must be an agent of the service desk that the queue belongs to.

        :param service_desk_id: str
        :param queue_id: str
        :param start: int
        :param limit: int
        :return: a page of issues
        r   z/queue/z/issuerM   rN   rw   rx   )r   r   Úqueue_idrM   rN   rF   rP   s          r   Úget_issues_in_queuezServiceDesk.get_issues_in_queue  s`   € ð  1°Ð0AÀÈÈ
ÐRXÐYˆØˆàÐÜ! %›jˆF�7‰OØÐÜ! %›jˆF�7‰Oà�x‰x˜ T×%>Ñ%>ÀvˆxÓNÐNr   c                 óB   — d}| j                  || j                  d¬«      S )zR
        Provide plugins info
        :return a json of installed plugins
        úrest/plugins/1.0/T©r
   Útrailing©r   Úno_check_headers©r   rF   s     r   Úget_plugins_infozServiceDesk.get_plugins_info1  s$   € ð
 "ˆØ�x‰x˜ T×%:Ñ%:ÀTˆxÓJÐJr   c                 óJ   — d|› d�}| j                  || j                  d¬«      S )zQ
        Provide plugin info
        :return a json of installed plugins
        rÚ   ú-keyTrÛ   rÝ   ©r   Ú
plugin_keyrF   s      r   Úget_plugin_infozServiceDesk.get_plugin_info9  s-   € ð
 " * ¨TÐ2ˆØ�x‰x˜ T×%:Ñ%:ÀTˆxÓJÐJr   c                 óJ   — d|› d�}| j                  || j                  d¬«      S )z[
        Provide plugin license info
        :return a json specific License query
        rÚ   z-key/licenseTrÛ   rÝ   rã   s      r   Úget_plugin_license_infoz#ServiceDesk.get_plugin_license_infoA  s-   € ð
 " * ¨\Ð:ˆØ�x‰x˜ T×%:Ñ%:ÀTˆxÓJÐJr   c                 ó¼   — dt        |d«      i}| j                  dd| j                  d¬«      j                  d   }d|› �}| j	                  ||| j                  ¬	«      S )
zƒ
        Provide plugin path for upload into Jira e.g. useful for auto deploy
        :param plugin_path:
        :return:
        Úpluginr§   ÚGETrÚ   T)Úmethodrk   r
   rÜ   z	upm-tokenzrest/plugins/1.0/?token=)r©   r
   )r­   rB   rÞ   r
   r%   )r   Úplugin_pathr©   Ú	upm_tokenrF   s        r   Úupload_pluginzServiceDesk.upload_pluginI  sq   € ð œ4 ¨TÓ2Ð3ˆØ—L‘LØØ$Ø×)Ñ)Øð	 !ó 
÷
 ‰'�+ñˆ	ð )¨¨Ð4ˆØ�y‰y˜ E°4×3HÑ3HˆyÓIÐIr   c                 ó0   — d|› d�}| j                  |«      S )zK
        Delete plugin
        :param plugin_key:
        :return:
        rÚ   râ   )r_   rã   s      r   Údelete_pluginzServiceDesk.delete_pluginY  s!   € ð " * ¨TÐ2ˆØ�{‰{˜3ÓÐr   c                 óB   — d}| j                  d|| j                  ¬«      S )Nzrest/plugins/latest/safe-moderê   )rë   rk   r
   )rB   Úsafe_mode_headersrß   s     r   Úcheck_plugin_manager_statusz'ServiceDesk.check_plugin_manager_statusb  s"   € Ø-ˆØ�|‰| 5¨s¸D×<RÑ<Rˆ|ÓSÐSr   c                 óH   — dddœ}d|› d�}d|i}| j                  |||¬«      S )zs
        Update license for plugin
        :param plugin_key:
        :param raw_license:
        :return:
        r¥   z application/vnd.atl.plugins+json)r¦   r¤   z/plugins/1.0/z/licenseÚ
rawLicenserX   )Úput)r   rä   Úraw_licenseÚapp_headersrF   r!   s         r   Úupdate_plugin_licensez!ServiceDesk.update_plugin_licensef  s@   € ð ",Ø>ñ
ˆð ˜j˜\¨Ð2ˆØ˜kÐ*ˆØ�x‰x˜ $°ˆxÓ<Ð<r   c                 ó‚   — t         j                  d«       ||||dœ}d|› d�}| j                  || j                  |¬«      S )zØ
        Creating a request type
        :param request_type_id:
        :param request_help_text:
        :param service_desk_id: str
        :param request_name: str
        :param request_description: str
        zCreating request type)ÚissueTypeIdr…   ÚdescriptionÚhelpTextr   rI   r    r"   )r   r   r:   Úrequest_nameÚrequest_descriptionÚrequest_help_textr!   rF   s           r   Úcreate_request_typezServiceDesk.create_request_typeu  sP   € ô  	�‰Ð(Ô)à*Ø Ø.Ø)ñ	
ˆð 1°Ð0AÀÐNˆØ�y‰y˜ d×&?Ñ&?ÀdˆyÓKÐKr   c                 ód  — |j                   dk(  r+|j                  j                  d«      dk7  rt        d|¬«      ‚d|j                   cxk  rdk  r&n y		 |j	                  «       }|d   }t        ||¬«      ‚y	# t
        $ r/}t        j                  |«       |j                  «        Y d	}~y	d	}~ww xY w)
z©
        Checks the response for an error status and raises an exception with the error message provided by the server
        :param response:
        :return:
        i‘  r¤   zapplication/json;charset=UTF-8zUnauthorized (401))r.   i�  iX  ÚerrorMessageN)	Ústatus_coder
   r   r   r6   Ú	Exceptionr#   ÚerrorÚraise_for_status)r   r.   ÚjÚ	error_msgÚes        r   r  zServiceDesk.raise_for_status�  s¦   € ð ×Ñ 3Ò&¨8×+;Ñ+;×+?Ñ+?ÀÓ+OÐSsÒ+sÜÐ0¸8ÔDÐDà�(×&Ñ&Ô,¨Õ,ð>Ø—M‘M“O�Ø˜nÑ-�	ô
   	°HÔ=Ð=ð -øô ò ,Ü—	‘	˜!”Ø×)Ñ)×+Ñ+ûð,ús   ÁA7 Á7	B/Â %B*Â*B/)NN)r   é2   )N)T)r   r  TT)Nr   r  )TN)Fr   r  )9Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r'   r+   r/   r?   rC   rG   rJ   rT   r]   r`   rg   rl   rp   rs   r{   Úget_organizationsr€   rƒ   r†   rŠ   r�   r�   r“   r•   rŸ   r¢   r˜   rš   r²   r´   r·   rº   r¼   rÀ   rÃ   rÆ   rÊ   rÏ   rÑ   rÕ   rØ   rà   rå   rç   rî   rð   ró   rù   r  r  © r   r   r   r      sw  „ ñò
Wò
<ò 
ò
ò 
ò.ð  Ø!ó&EòPò$	@ò
ó.ó*Ló&Nó(Ló"Qó.ò6
óZð: *Ðò	@óOò$LòLòNò
Cð EGÐUWó Lð" JLÐZ\ó Nð. Øó [ðN Øó
ò>&óBLó$
ó$.ò.@ó
,ó.ò*
@òLò	@óOð4 @BÐVXó Lð, CEÐY[ó Nó*Oó4Oò4KòKòKòJò  òTò=òLó6>r   r   )	ÚloggingÚrequestsr   Úrest_clientr   Ú	getLoggerr  r#   r   r  r   r   ú<module>r     s/   ðã å å )à€g×Ñ˜Ó!€ôV>Ð"õ V>r   