@@ -105,7 +105,9 @@ def purchase_detail(self, purchase_id, embed=False, **kwargs):
105105 auth = "public" ,
106106 website = True ,
107107 )
108- def purchase_attachment_download (self , purchase_id , attachment_line_id , ** kwargs ):
108+ def purchase_attachment_download (
109+ self , purchase_id , attachment_line_id , embed = False , ** kwargs
110+ ):
109111 Requisition = request .env ["purchase.requisition" ].sudo ()
110112 purchase = Requisition .search (
111113 [
@@ -135,15 +137,24 @@ def purchase_attachment_download(self, purchase_id, attachment_line_id, **kwargs
135137 if attachment_line .require_email :
136138 email = kwargs .get ("email" , "" ).strip ()
137139 if not email :
138- # Redirigir a formulario de email
139- return request .render (
140- "sipreco_purchase_web.purchase_email_gate_template" ,
140+ template = (
141+ "sipreco_purchase_web.purchase_email_gate_embed_template"
142+ if embed
143+ else "sipreco_purchase_web.purchase_email_gate_template"
144+ )
145+ response = request .render (
146+ template ,
141147 {
142148 "purchase" : purchase ,
143149 "attachment_line" : attachment_line ,
144150 "page_name" : "purchase_email_gate" ,
151+ "embed" : bool (embed ),
145152 },
146153 )
154+ if embed :
155+ response .headers ["X-Frame-Options" ] = "ALLOWALL"
156+ response .headers ["Content-Security-Policy" ] = "frame-ancestors *"
157+ return response
147158 _logger .info (
148159 'Descarga de archivo "%s" (id=%s) por email: %s' ,
149160 attachment_line .name ,
@@ -181,23 +192,23 @@ def purchase_attachment_download(self, purchase_id, attachment_line_id, **kwargs
181192 csrf = True ,
182193 )
183194 def purchase_attachment_email_submit (
184- self , purchase_id , attachment_line_id , email = "" , ** kwargs
195+ self , purchase_id , attachment_line_id , email = "" , embed = False , ** kwargs
185196 ):
186197 # Validación básica del email recibido por POST
187198 email = email .strip ()
199+ embed_qs = "&embed=1" if embed else ""
188200 if not email or "@" not in email :
189201 return request .redirect (
190- "/compras/%d/descargar/%d" % (purchase_id , attachment_line_id )
202+ "/compras/%d/descargar/%d?%s"
203+ % (purchase_id , attachment_line_id , embed_qs .lstrip ("&" ))
191204 )
192- # Registrar y redirigir con el email como parámetro para que el
193- # controlador principal sirva el archivo
194205 _logger .info (
195206 "Email registrado para descarga de archivo (requisition=%d, attachment=%d): %s" ,
196207 purchase_id ,
197208 attachment_line_id ,
198209 email ,
199210 )
200211 return request .redirect (
201- "/compras/%d/descargar/%d?email=%s"
202- % (purchase_id , attachment_line_id , email )
212+ "/compras/%d/descargar/%d?email=%s%s "
213+ % (purchase_id , attachment_line_id , email , embed_qs )
203214 )
0 commit comments