
    p:i'                         d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	 d dl
m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mZ  G d
 de          ZdS )    )
Attachment)	Component	TracError
implements)Ticket)TicketModule)get_reporter_id)from_utimestamp)_)IRequestFilterIRequestHandler)ITemplateProvider
add_notice
add_scriptadd_script_dataadd_stylesheetc                   P    e Zd ZdZ eeee           d Zd Z	d Z
d Zd Zd ZdS )	TicketDeletera  Ticket and ticket comment deleter.

    This component allows deleting ticket comments and complete tickets. For
    users having `TICKET_ADMIN` permission, it adds a "Delete" button next to
    each "Reply" button on the page. The button in the ticket description
    requests deletion of the complete ticket, and the buttons in the change
    history request deletion of a single comment.

    '''Comment and ticket deletion are irreversible (and therefore
    ''dangerous'') operations.''' For that reason, a confirmation step is
    requested. The confirmation page shows the ticket box (in the case of a
    ticket deletion) or the ticket change (in the case of a comment deletion).
    c              #   @   K   ddl m} d |t          d          fV  d S )Nr   resource_filename	ticketopthtdocspkg_resourcesr   __name__selfr   s     N/var/www/html/trac/venv/lib/python3.11/site-packages/tracopt/ticket/deleter.pyget_htdocs_dirszTicketDeleter.get_htdocs_dirs-   s=      333333,,Xx@@@@@@@@    c                 2    ddl m}  |t          d          gS )Nr   r   	templatesr   r   s     r   get_templates_dirsz TicketDeleter.get_templates_dirs1   s*    333333!!(K8899r!   c                 v    |t          | j                  ur|S |j                            d          }|dv r| S |S )Naction)deletedelete-comment)r   envargsget)r   reqhandlerr&   s       r   pre_process_requestz!TicketDeleter.pre_process_request7   sE    ,tx0000Nh''111KNr!   c                     |dv ru|                     d          }|r^|j        rWd|                    |j                  v r;t	          |d           t          |d|j                             d          i           |||fS )N)zticket.htmlzticket_preview.htmlticketTICKET_ADMINzticketopt/ticketdeleter.jsuse_symbolszui.use_symbols)ui)r+   existspermresourcer   r   session)r   r,   templatedatametadatar0   s         r   post_process_requestz"TicketDeleter.post_process_request@   s    ===XXh''F M6= M"chhv&?&???3 <===),9I)J)J)L M M M Mx''r!   c                     dS )NF )r   r,   s     r   match_requestzTicketDeleter.match_requestL   s    ur!   c           	      :   |j                             d          }|                    d|                              d           t	          | j        |          }|j         d         }|j                             d          }|j        dk    rd|j         v r=|j        	                    |          }|dk    r|d	|z  z  }|
                    |           |d
k    r|                                 t          |t          d|j                             |j                                        }d|j        v rB|j        d                                         }t%          |j                  |v r|j        d         }|
                    |           n|dk    rt'          t)          |j                             d                              }	|                    |	           t          |t          d||j                             |
                    |j        	                    |                     t-          | j                  }
|
                    ||          }|
                    |||t3          |d          i            |                    |d            |dk    r|j                             d          |d<   t'          t)          |d                             }	|d         D ]:}|                    d          |	k    r||d<   |                    d          |d<    n;t7          t          d|                    nN|d
k    rHt9          j        | j        |j        |j                  }|                    t?          |                     tA          |d           d|fS )Nidr0   r1   r&   cnumPOSTcancelr(   z#comment:%sr'   z0Ticket #%(num)s and all associated data removed.)numquery_tickets
query_hrefcdate)rG   z>The ticket comment %(num)s on ticket #%(id)s has been deleted.)rD   r@   author)r&   rG   changesdatechangezComment %(num)s not found)attachmentszcommon/css/ticket.csszticket_delete.html)!r*   getintr5   requirer   r)   r+   methodhrefr0   redirectr'   r   r   r@   queryr7   splitstrr
   intdelete_changer   _prepare_data_insert_ticket_datar	   updater   r   selectrealmlistr   )r   r,   r@   r0   r&   rA   rP   redirect_toticketsrG   tmr9   rK   rL   s                 r   process_requestzTicketDeleter.process_requestO   s   X__T""2&&~666"%%(#x||F##:38##xr**---MD00DT"""!!3 #-28)!= != != > > >!hnn.."ck11!k/:@@BBG69~~00&)k,&?[))))+++'CHLL,A,A(B(BCC$$5$1113 #>&*vy!: !: !: ; ; ; SX__R00111$(##V,,
sFD.sH==r	C 	C 	C6...%%%HLL11DM#CW$6$677Ey/ J J::f%%..%+DN#)::f#5#5DLE /
  "=4 H H HIII  x$+DHflFINNKKKD$5$5K666s3444#T))r!   N)r   
__module____qualname____doc__r   r   r   r   r    r$   r.   r;   r>   r`   r=   r!   r   r   r      s          J ./BBBA A A: : :  ( ( (  5* 5* 5* 5* 5*r!   r   N)trac.attachmentr   	trac.corer   r   r   trac.ticket.modelr   trac.ticket.web_uir   	trac.utilr	   trac.util.datefmtr
   trac.util.translationr   trac.web.apir   r   trac.web.chromer   r   r   r   r   r   r=   r!   r   <module>rm      s-   ' & & & & & 6 6 6 6 6 6 6 6 6 6 $ $ $ $ $ $ + + + + + + % % % % % % - - - - - - # # # # # # 8 8 8 8 8 8 8 8> > > > > > > > > > > > > >j* j* j* j* j*I j* j* j* j* j*r!   