
     Xj}                         d dl Z d dlmZmZ d dlmZ d dlmZ  e j                  e	      Z
dZ G d dej                        Zy)    N)_http)	UserError)requesta  <!DOCTYPE html><html><head><meta charset="utf-8">
<title>Leave Request</title></head>
<body style="font-family:Arial,Helvetica,sans-serif;background:#f8f9fa;">
<div style="max-width:480px;margin:80px auto;text-align:center;padding:2rem;
            background:#fff;border:1px solid #d8e1e4;border-radius:8px;">
<h2 style="color:%(color)s;margin-top:0;">%(message)s</h2>
</div></body></html>c                   V    e Zd Zd	dZ ej
                  dddddd      	 	 d
d       Zy)XenoLeaveEmailControllerc                 R    |rdnd}t        j                  t        ||dz  dg      S )Nz#1f7a4dz#b21f22)colormessage)zContent-Typeztext/html; charset=utf-8)headers)r   make_response_PAGE)selfr   okr
   s       xeno_leave/controllers/main.py_pagezXenoLeaveEmailController._page   s1    	Y$$e88AB
 	
    z/odoo/leave/email_actionr   publicF)typeauthwebsitesitemapcsrfNc                 R   t         j                  }|d   j                         }		 t        |      t        |      t        |      t        |      f\  }}}}|dvr| j                  t        d      d      S |	j                  |      j                  j                         j                  j                  }
|
r1 |t        |j                  |
            }|d   j                         }	|	j                  ||||||      s| j                  t        d      d      S |	j                  |      }|d	   j                         j                  |      }|d
   j                         j                  |      }|j                         r/|j                         r|j                         r|j                   |k7  r| j                  t        d      d      S |j"                  dk7  r| j                  t        d            S |j%                         |k7  r| j                  t        d            S |j'                  |      }	 |dk(  r,|j)                  d       | j                  t        d            S |j+                          | j                  t        d            S # t        t
        f$ r | j                  t        d      d      cY S w xY w# t,        $ r&}| j                  t/        |      d      cY d}~S d}~wt0        $ r6 t2        j5                  d||       | j                  t        d      d      cY S w xY w)a1  Approve/Reject a leave straight from the notification email.
        Authorization is the signed token itself (see hr.leave.
        _xeno_verify_email_token) -- it proves this exact link was issued by
        us for this exact leave/step/action/user and hasn't expired, which
        replaces "are you logged in" for a recipient who almost certainly
        isn't. The actual business permission (is this user allowed to act
        on this step right now) still runs through the same
        action_approve/action_refuse checks as the in-app buttons.
        zhr.leavezThis link is malformed.F)r   )approvereject)lang)contextz$This link is invalid or has expired.zxeno.leave.approval.stepz	res.usersz$This leave request no longer exists.pendingz.This leave request has already been processed.zYThis step was already handled (possibly by someone else) or is no longer awaiting action.r   )check_statezApproved. Thank you.z	Rejected.Nz3xeno_leave email_action failed for leave %s step %szISomething went wrong processing this request. Please use the app instead.)r   envsudoint	TypeError
ValueErrorr   r   browseemployee_iduser_idr   dictr   _xeno_verify_email_tokenexistsleave_idstate_xeno_current_pending_step	with_useraction_approveaction_refuser   str	Exception_logger	exception)r   r,   step_idactionr(   exptokenkwr!   Leave
leave_langleavestepuserleave_as_useres                   r   email_actionz%XenoLeaveEmailController.email_action   s    kkJ$$&	F.1(mS\3w<Y\]`Ya.a+Hgw ..::a 9:u:EE \\(+77<<>FFKK
d3;;Z@AC
O((*E--hRUW\]::a FGE:RRX&-.335<<WE;$$&--g64;;=T[[]t}}X]G]::a FGE:RR::"::a PQRR++-5::a34 5 5 -	",,,?zz!$:";<<'')::an--O :& 	F::a 9:u:EE	FP  	0::c!f:// 	SU]_fg::a[   	s;   /J	 .0J: )J: 	+J76J7:	L&K$L&$?L&%L&)T)NNNNNN)__name__
__module____qualname__r   r   routerB    r   r   r   r      s>    
 TZZ"(E5u @D48>	>r   r   )loggingodoor   r   odoo.exceptionsr   	odoo.httpr   	getLoggerrC   r4   r   
Controllerr   rG   r   r   <module>rN      s<      % 
'

H
%	Kt Kr   