From 76aa3a75f2e5b93877a229e29326b8b4ea815aea 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 --- 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 0dc3f438af..991d3efeba 100644 --- a/InvenTree/templates/js/translated/attachment.js +++ b/InvenTree/templates/js/translated/attachment.js @@ -228,7 +228,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 825e1a8094..35de58dd97 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -1358,7 +1358,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 fcbaba7336..952806bce2 100644 --- a/InvenTree/templates/js/translated/tables.js +++ b/InvenTree/templates/js/translated/tables.js @@ -184,6 +184,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; @@ -194,7 +201,7 @@ function renderLink(text, url, options={}) { text = `${text_start}...${text_end}`; } - return '' + text + ''; + return `${text}`; }