From b446b4e01b33aa339ffb63e35300c6c47f79bdaf Mon Sep 17 00:00:00 2001
From: Yann Papouin <ypa@decgroupe.com>
Date: Wed, 29 Mar 2023 10:05:25 +0200
Subject: [PATCH] [PR #463] [IMP] helpdesk_mgmt: Generate `access_token` for
 all attachments added on ticket submit

Otherwise they stay "private" and are not displayed on the portal.
---
 helpdesk_mgmt/controllers/main.py                 |  5 ++++-
 helpdesk_mgmt/views/helpdesk_ticket_templates.xml | 14 ++++++--------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/helpdesk_mgmt/controllers/main.py b/helpdesk_mgmt/controllers/main.py
index 4c43176d0c..0fe3799d4f 100644
--- a/helpdesk_mgmt/controllers/main.py
+++ b/helpdesk_mgmt/controllers/main.py
@@ -91,10 +91,12 @@ def submit_ticket(self, **kw):
         new_ticket = request.env["helpdesk.ticket"].sudo().create(vals)
         new_ticket.message_subscribe(partner_ids=request.env.user.partner_id.ids)
         if kw.get("attachment"):
+            IrAttachment = request.env["ir.attachment"]
+            attachment_ids = IrAttachment
             for c_file in request.httprequest.files.getlist("attachment"):
                 data = c_file.read()
                 if c_file.filename:
-                    request.env["ir.attachment"].sudo().create(
+                    attachment_ids += IrAttachment.sudo().create(
                         {
                             "name": c_file.filename,
                             "datas": base64.b64encode(data),
@@ -102,4 +104,5 @@ def submit_ticket(self, **kw):
                             "res_id": new_ticket.id,
                         }
                     )
+            attachment_ids.sudo().generate_access_token()
         return werkzeug.utils.redirect("/my/ticket/%s" % new_ticket.id)
diff --git a/helpdesk_mgmt/views/helpdesk_ticket_templates.xml b/helpdesk_mgmt/views/helpdesk_ticket_templates.xml
index 832a95934f..10d1e112dd 100644
--- a/helpdesk_mgmt/views/helpdesk_ticket_templates.xml
+++ b/helpdesk_mgmt/views/helpdesk_ticket_templates.xml
@@ -298,15 +298,13 @@
                         for="attachment"
                     >Add Attachments</label>
                     <div class="col-md-7 col-sm-8">
-                        <div class="btn btn-default btn-file col-md-12">
                             <input
-                                class="form-control o_website_form_input"
-                                name="attachment"
-                                id="attachment"
-                                type="file"
-                                multiple="multiple"
-                            />
-                        </div>
+                            class="form-control o_website_form_input"
+                            name="attachment"
+                            id="attachment"
+                            type="file"
+                            multiple="multiple"
+                        />
                     </div>
                 </div>
                 <div class="form-group">