From 1a42be3166a0882914d70a10243bdd76adac9c17 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 15 Jun 2022 18:31:56 +1000 Subject: [PATCH] Merge pull request from GHSA-fr2w-mp56-g4xp * Enforce file download for attachments table(s) * Enforce file download for attachment in 'StockItemTestResult' table (cherry picked from commit 76aa3a75f2e5b93877a229e29326b8b4ea815aea) --- InvenTree/templates/js/translated/attachment.js | 2 +- InvenTree/templates/js/translated/stock.js | 3 ++- InvenTree/templates/js/translated/tables.js | 9 ++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/InvenTree/templates/js/translated/attachment.js b/InvenTree/templates/js/translated/attachment.js index dd1fe31c66..53b1d90b6d 100644 --- a/InvenTree/templates/js/translated/attachment.js +++ b/InvenTree/templates/js/translated/attachment.js @@ -149,7 +149,7 @@ function loadAttachmentTable(url, options) { var html = ` ${filename}`; - return renderLink(html, value); + return renderLink(html, value, {download: true}); } else if (row.link) { var html = ` ${row.link}`; return renderLink(html, row.link); diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index f0b7b28a73..3a664b1f4d 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -1306,7 +1306,8 @@ function loadStockTestResultsTable(table, options) { var html = value; if (row.attachment) { - html += ``; + var text = ``; + html += renderLink(text, row.attachment, {download: true}); } return html; diff --git a/InvenTree/templates/js/translated/tables.js b/InvenTree/templates/js/translated/tables.js index a20978dd7d..2e40a6bbc5 100644 --- a/InvenTree/templates/js/translated/tables.js +++ b/InvenTree/templates/js/translated/tables.js @@ -92,6 +92,13 @@ function renderLink(text, url, options={}) { var max_length = options.max_length || -1; + var extra = ''; + + if (options.download) { + var fn = url.split('/').at(-1); + extra += ` download='${fn}'`; + } + // Shorten the displayed length if required if ((max_length > 0) && (text.length > max_length)) { var slice_length = (max_length - 3) / 2; @@ -102,7 +109,7 @@ function renderLink(text, url, options={}) { text = `${text_start}...${text_end}`; } - return '' + text + ''; + return `${text}`; }