From 2d70a1a1695173decc0d479263256cbe00b815d6 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 14 Jul 2020 15:51:17 +0200 Subject: [PATCH] IDEMPIERE-1117 Attachment -> Disable preview over certain size (#145) * IDEMPIERE-1117 Attachment -> Disable preview over certain size New SysConfig key ZK_MAX_ATTACHMENT_PREVIEW_SIZE * IDEMPIERE-1117 move scripts to 7.1 --- .../oracle/202006262307_IDEMPIERE-1117.sql | 15 +++++++++ .../202006262307_IDEMPIERE-1117.sql | 12 +++++++ .../src/org/compiere/model/MSysConfig.java | 3 +- .../adempiere/webui/panel/WAttachment.java | 32 ++++++++++++++++--- 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 migration/i7.1/oracle/202006262307_IDEMPIERE-1117.sql create mode 100644 migration/i7.1/postgresql/202006262307_IDEMPIERE-1117.sql diff --git a/migration/i7.1/oracle/202006262307_IDEMPIERE-1117.sql b/migration/i7.1/oracle/202006262307_IDEMPIERE-1117.sql new file mode 100644 index 0000000000..bcb3f7d4e4 --- /dev/null +++ b/migration/i7.1/oracle/202006262307_IDEMPIERE-1117.sql @@ -0,0 +1,15 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- IDEMPIERE-1117 Attachment -> Disable preview over certain size +-- Jun 26, 2020, 11:05:28 PM CEST +INSERT INTO AD_SysConfig (AD_SysConfig_ID,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive,Name,Value,Description,EntityType,ConfigurationLevel,AD_SysConfig_UU) VALUES (200154,0,0,TO_DATE('2020-06-26 23:05:27','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2020-06-26 23:05:27','YYYY-MM-DD HH24:MI:SS'),100,100,'Y','ZK_MAX_ATTACHMENT_PREVIEW_SIZE','1048576','Max size in bytes for a file to be previewed in attachment window','D','C','c1eb659c-2e44-4717-8407-d9075f2436ed') +; + +-- Jun 26, 2020, 11:07:11 PM CEST +INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('I','The file is too large for automatic viewing, click the Preview button to load it',0,0,'Y',TO_DATE('2020-06-26 23:07:10','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2020-06-26 23:07:10','YYYY-MM-DD HH24:MI:SS'),100,200620,'FileTooBigForPreview','D','013da62e-8989-4682-9f1b-36f568d773d4') +; + +SELECT register_migration_script('202006262307_IDEMPIERE-1117.sql') FROM dual +; + diff --git a/migration/i7.1/postgresql/202006262307_IDEMPIERE-1117.sql b/migration/i7.1/postgresql/202006262307_IDEMPIERE-1117.sql new file mode 100644 index 0000000000..68f784485b --- /dev/null +++ b/migration/i7.1/postgresql/202006262307_IDEMPIERE-1117.sql @@ -0,0 +1,12 @@ +-- IDEMPIERE-1117 Attachment -> Disable preview over certain size +-- Jun 26, 2020, 11:05:28 PM CEST +INSERT INTO AD_SysConfig (AD_SysConfig_ID,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive,Name,Value,Description,EntityType,ConfigurationLevel,AD_SysConfig_UU) VALUES (200154,0,0,TO_TIMESTAMP('2020-06-26 23:05:27','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2020-06-26 23:05:27','YYYY-MM-DD HH24:MI:SS'),100,100,'Y','ZK_MAX_ATTACHMENT_PREVIEW_SIZE','1048576','Max size in bytes for a file to be previewed in attachment window','D','C','c1eb659c-2e44-4717-8407-d9075f2436ed') +; + +-- Jun 26, 2020, 11:07:11 PM CEST +INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('I','The file is too large for automatic viewing, click the Preview button to load it',0,0,'Y',TO_TIMESTAMP('2020-06-26 23:07:10','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2020-06-26 23:07:10','YYYY-MM-DD HH24:MI:SS'),100,200620,'FileTooBigForPreview','D','013da62e-8989-4682-9f1b-36f568d773d4') +; + +SELECT register_migration_script('202006262307_IDEMPIERE-1117.sql') FROM dual +; + diff --git a/org.adempiere.base/src/org/compiere/model/MSysConfig.java b/org.adempiere.base/src/org/compiere/model/MSysConfig.java index 803eea47ef..fccd7710a7 100644 --- a/org.adempiere.base/src/org/compiere/model/MSysConfig.java +++ b/org.adempiere.base/src/org/compiere/model/MSysConfig.java @@ -43,7 +43,7 @@ public class MSysConfig extends X_AD_SysConfig /** * */ - private static final long serialVersionUID = -1766118478735242840L; + private static final long serialVersionUID = 4339975517612838655L; public static final String ADDRESS_VALIDATION = "ADDRESS_VALIDATION"; public static final String ALERT_SEND_ATTACHMENT_AS_XLS = "ALERT_SEND_ATTACHMENT_AS_XLS"; @@ -182,6 +182,7 @@ public class MSysConfig extends X_AD_SysConfig public static final String ZK_LOGIN_ALLOW_REMEMBER_ME = "ZK_LOGIN_ALLOW_REMEMBER_ME"; public static final String ZK_LOGO_LARGE = "ZK_LOGO_LARGE"; public static final String ZK_LOGO_SMALL = "ZK_LOGO_SMALL"; + public static final String ZK_MAX_ATTACHMENT_PREVIEW_SIZE = "ZK_MAX_ATTACHMENT_PREVIEW_SIZE"; public static final String ZK_MAX_UPLOAD_SIZE = "ZK_MAX_UPLOAD_SIZE"; public static final String ZK_MOBILE_PAGING_SIZE = "ZK_MOBILE_PAGING_SIZE"; public static final String ZK_PAGING_DETAIL_SIZE = "ZK_PAGING_DETAIL_SIZE"; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java index 50c2f07992..1ecd8c63ac 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java @@ -44,8 +44,10 @@ import org.adempiere.webui.factory.ButtonFactory; import org.adempiere.webui.theme.ThemeManager; import org.adempiere.webui.util.ZKUpdateUtil; import org.adempiere.webui.window.FDialog; +import org.adempiere.webui.window.WTextEditorDialog; import org.compiere.model.MAttachment; import org.compiere.model.MAttachmentEntry; +import org.compiere.model.MSysConfig; import org.compiere.model.MTable; import org.compiere.util.CLogger; import org.compiere.util.Env; @@ -107,7 +109,7 @@ public class WAttachment extends Window implements EventListener private Button bLoad = new Button(); private Button bCancel = ButtonFactory.createNamedButton(ConfirmPanel.A_CANCEL, false, true); private Button bOk = ButtonFactory.createNamedButton(ConfirmPanel.A_OK, false, true); - private Button bRefresh = ButtonFactory.createNamedButton(ConfirmPanel.A_REFRESH, false, true); + private Button bPreview = new Button(); private Panel previewPanel = new Panel(); @@ -121,6 +123,8 @@ public class WAttachment extends Window implements EventListener private String orientation; + private int maxPreviewSize; + private static List autoPreviewList; static { @@ -163,6 +167,7 @@ public class WAttachment extends Window implements EventListener int AD_Table_ID, int Record_ID, String trxName, EventListener eventListener) { super(); + maxPreviewSize = MSysConfig.getIntValue(MSysConfig.ZK_MAX_ATTACHMENT_PREVIEW_SIZE, 1048576, Env.getAD_Client_ID(Env.getCtx())); if (log.isLoggable(Level.CONFIG)) log.config("ID=" + AD_Attachment_ID + ", Table=" + AD_Table_ID + ", Record=" + Record_ID); @@ -336,10 +341,16 @@ public class WAttachment extends Window implements EventListener bDeleteAll.addEventListener(Events.ON_CLICK, this); bDeleteAll.setTooltiptext(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "DeleteAll"))); - bRefresh.addEventListener(Events.ON_CLICK, this); + if (ThemeManager.isUseFontIconForImage()) + bPreview.setIconSclass("z-icon-Find"); + else + bPreview.setImage(ThemeManager.getThemeResource("images/Find24.png")); + bPreview.setSclass("img-btn"); + bPreview.addEventListener(Events.ON_CLICK, this); + bPreview.setTooltiptext(Msg.getMsg(Env.getCtx(), "Preview")); confirmPanel.appendChild(bDeleteAll); - confirmPanel.appendChild(bRefresh); + confirmPanel.appendChild(bPreview); ZKUpdateUtil.setHflex(confirmPanel, "1"); Hbox hbox = new Hbox(); hbox.setPack("end"); @@ -438,7 +449,17 @@ public class WAttachment extends Window implements EventListener if (autoPreviewList.contains(mimeType)) { - displayData(index, immediate); + if (data.length <= maxPreviewSize) { + displayData(index, immediate); + } else { + clearPreview(); + String msg = WTextEditorDialog.sanitize(Msg.getMsg(Env.getCtx(), "FileTooBigForPreview")); + Media media = new AMedia(null, null, "text/html", msg.getBytes()); + preview.setContent(media); + preview.setVisible(true); + bPreview.setEnabled(true); + return false; + } return true; } else @@ -473,6 +494,7 @@ public class WAttachment extends Window implements EventListener displaySelected(); else Clients.response(new AuEcho(this, "displaySelected", null)); + bPreview.setEnabled(false); } // displayData private void clearPreview() @@ -584,7 +606,7 @@ public class WAttachment extends Window implements EventListener } else if (e.getTarget() == bSave) { // Open Attachment saveAttachmentToFile(); - } else if (e.getTarget() == bRefresh) { + } else if (e.getTarget() == bPreview) { displayData(cbContent.getSelectedIndex(), true); } else if (e.getTarget() == bSaveAllAsZip) { saveAllAsZip();