From 3954bc56c55c99bbaf56bc7fa2f81b18fac35a6b Mon Sep 17 00:00:00 2001 From: Mitch Gaffigan Date: Sun, 1 Jun 2025 23:50:00 -0500 Subject: [PATCH] Allow telemetry options to be enabled/disabled via BrandingConstants Adds the following settings to BrandingConstants in client-core: - CENTRAL_USER_REGISTRATION - When false, disables the sending of user demographic information and hides the registration and marketing consent boxes from the first time login screen. - MANDATORY_USER_REGISTRATION - used in conjunction with CENTRAL_USER_REGISTRATION. When this is setting is true and the user id is 1, then the user will not be able to unselect the registration checkbox. - CHECK_FOR_NOTIFICATIONS - When false, allows for notification fetching from the client to be disabled. The notification menu task is also removed. - SEND_USAGE_STATISTICS - When false, allows for sending of usage statistics to be disabled. Also hides the setting which allows users to opt-in or opt-out of sending statistics. With the restoration of the registration checkbox when the appropriate settings are enabled, the adjustment of which fields are required on the user profile has also been restored. Co-authored-by: Tony Germano Signed-off-by: Mitch Gaffigan Signed-off-by: Tony Germano Issue: https://github.com/OpenIntegrationEngine/engine/issues/5 --- .../connect/client/ui/FirstLoginDialog.java | 21 +++++++++++------- .../com/mirth/connect/client/ui/Frame.java | 20 ++++++++++++++++- .../mirth/connect/client/ui/LoginPanel.java | 5 ++++- .../client/ui/SettingsPanelServer.java | 14 ++++++++---- .../client/core/BrandingConstants.java | 8 +++++++ .../client/core/ConnectServiceUtil.java | 22 +++++++++++++++++-- .../src/com/mirth/connect/server/Mirth.java | 6 +++-- 7 files changed, 78 insertions(+), 18 deletions(-) diff --git a/client/src/com/mirth/connect/client/ui/FirstLoginDialog.java b/client/src/com/mirth/connect/client/ui/FirstLoginDialog.java index fbfa5e90d..8d340c0bf 100644 --- a/client/src/com/mirth/connect/client/ui/FirstLoginDialog.java +++ b/client/src/com/mirth/connect/client/ui/FirstLoginDialog.java @@ -9,6 +9,9 @@ package com.mirth.connect.client.ui; +import static com.mirth.connect.client.core.BrandingConstants.CENTRAL_USER_REGISTRATION; +import static com.mirth.connect.client.core.BrandingConstants.MANDATORY_USER_REGISTRATION; + import java.awt.Desktop; import java.awt.Dimension; import java.awt.Point; @@ -47,10 +50,14 @@ public FirstLoginDialog(User currentUser) { finishButton.setEnabled(false); userEditPanel.setUser(this, currentUser); - userEditPanel.setRequiredFields(false, true); - if (currentUser.getId() == 1) { - registerCheckBox.setVisible(false); - } + + final boolean isRegistrationMandatory = CENTRAL_USER_REGISTRATION && MANDATORY_USER_REGISTRATION && currentUser.getId() == 1; + registerCheckBox.setSelected(isRegistrationMandatory); + registerCheckBox.setEnabled(!isRegistrationMandatory); + registerCheckBox.setVisible(CENTRAL_USER_REGISTRATION); + registerCheckBoxActionPerformed(null); + userConsentCheckBox.setVisible(CENTRAL_USER_REGISTRATION); + contentTextPane.setVisible(CENTRAL_USER_REGISTRATION); jLabel2.setForeground(UIConstants.HEADER_TITLE_TEXT_COLOR); setModal(true); @@ -151,7 +158,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { jScrollPane1.setViewportView(jTextPane1); registerCheckBox.setBackground(new java.awt.Color(255, 255, 255)); - registerCheckBox.setSelected(true); registerCheckBox.setText(String.format("Register user with %s", BrandingConstants.COMPANY_NAME)); registerCheckBox.setToolTipText(String.format("Register your user information with %s to help us
improve the product and provide better service.", BrandingConstants.COMPANY_NAME)); registerCheckBox.addActionListener(new java.awt.event.ActionListener() { @@ -161,7 +167,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { }); userConsentCheckBox.setBackground(new java.awt.Color(255, 255, 255)); - userConsentCheckBox.setSelected(true); userConsentCheckBox.setText(String.format("I consent to receive email updates and marketing messages from %s.", BrandingConstants.COMPANY_NAME)); userConsentCheckBox.setToolTipText(""); @@ -273,7 +278,7 @@ private void finishButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN- return; } - if (registerCheckBox.isSelected()) { + if (registerCheckBox.isSelected() && CENTRAL_USER_REGISTRATION) { parent.registerUser(user); } @@ -316,7 +321,7 @@ private void registerCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {// userConsentCheckBox.setSelected(false); userConsentCheckBox.setEnabled(false); } - userEditPanel.setRequiredFields(false, true); + userEditPanel.setRequiredFields(allRequired, true); }//GEN-LAST:event_registerCheckBoxActionPerformed public boolean getResult() { diff --git a/client/src/com/mirth/connect/client/ui/Frame.java b/client/src/com/mirth/connect/client/ui/Frame.java index 717803561..ea33bcfda 100644 --- a/client/src/com/mirth/connect/client/ui/Frame.java +++ b/client/src/com/mirth/connect/client/ui/Frame.java @@ -9,6 +9,10 @@ package com.mirth.connect.client.ui; +import static com.mirth.connect.client.core.BrandingConstants.CENTRAL_USER_REGISTRATION; +import static com.mirth.connect.client.core.BrandingConstants.CHECK_FOR_NOTIFICATIONS; +import static com.mirth.connect.client.core.BrandingConstants.SEND_USAGE_STATISTICS; + import java.awt.AWTEvent; import java.awt.BorderLayout; import java.awt.Color; @@ -1250,7 +1254,9 @@ private void createOtherPane() { otherPane.setTitle("Other"); otherPane.setName(TaskConstants.OTHER_KEY); otherPane.setFocusable(false); - addTask(TaskConstants.OTHER_NOTIFICATIONS, UIConstants.VIEW_NOTIFICATIONS, String.format("View notifications from %s.", BrandingConstants.PRODUCT_NAME), "", new ImageIcon(com.mirth.connect.client.ui.Frame.class.getResource("images/flag_orange.png")), otherPane, null); + if (CHECK_FOR_NOTIFICATIONS) { + addTask(TaskConstants.OTHER_NOTIFICATIONS, UIConstants.VIEW_NOTIFICATIONS, String.format("View notifications from %s.", BrandingConstants.PRODUCT_NAME), "", new ImageIcon(com.mirth.connect.client.ui.Frame.class.getResource("images/flag_orange.png")), otherPane, null); + } addTask(TaskConstants.OTHER_VIEW_USER_API, "View User API", String.format("View documentation for the %s User API.", BrandingConstants.PRODUCT_NAME), "", new ImageIcon(com.mirth.connect.client.ui.Frame.class.getResource("images/page_white_text.png")), otherPane, null); addTask(TaskConstants.OTHER_VIEW_CLIENT_API, "View Client API", String.format("View documentation for the %s Client API.", BrandingConstants.PRODUCT_NAME), "", new ImageIcon(com.mirth.connect.client.ui.Frame.class.getResource("images/page_white_text.png")), otherPane, null); addTask(TaskConstants.OTHER_HELP, "Help", String.format("View help for %s.", BrandingConstants.PRODUCT_NAME), "", new ImageIcon(com.mirth.connect.client.ui.Frame.class.getResource("images/help.png")), otherPane, null); @@ -1268,6 +1274,10 @@ public JXTaskPane getOtherPane() { } public void updateNotificationTaskName(int notifications) { + if (!CHECK_FOR_NOTIFICATIONS) { + return; + } + String taskName = UIConstants.VIEW_NOTIFICATIONS; if (notifications > 0) { taskName += " (" + notifications + ")"; @@ -1949,6 +1959,10 @@ public User getCurrentUser(Component parentComponent, boolean alertOnFailure) { } public void registerUser(final User user) { + if (!CENTRAL_USER_REGISTRATION) { + return; + } + final String workingId = startWorking("Registering user..."); SwingWorker worker = new SwingWorker() { @@ -1972,6 +1986,10 @@ public void done() { } public void sendUsageStatistics() { + if (!SEND_USAGE_STATISTICS) { + return; + } + UpdateSettings updateSettings = null; try { updateSettings = mirthClient.getUpdateSettings(); diff --git a/client/src/com/mirth/connect/client/ui/LoginPanel.java b/client/src/com/mirth/connect/client/ui/LoginPanel.java index d1c6bfef7..5a78f8614 100644 --- a/client/src/com/mirth/connect/client/ui/LoginPanel.java +++ b/client/src/com/mirth/connect/client/ui/LoginPanel.java @@ -9,6 +9,8 @@ package com.mirth.connect.client.ui; +import static com.mirth.connect.client.core.BrandingConstants.CHECK_FOR_NOTIFICATIONS; + import java.awt.Color; import java.awt.Cursor; import java.util.Collections; @@ -609,7 +611,8 @@ private boolean handleSuccess(LoginStatus loginStatus) throws ClientException { // Check for new notifications from update server if enabled String checkForNotifications = userPreferences.getProperty("checkForNotifications"); - if (checkForNotifications == null || BooleanUtils.toBoolean(checkForNotifications)) { + if (CHECK_FOR_NOTIFICATIONS + && (checkForNotifications == null || BooleanUtils.toBoolean(checkForNotifications))) { Set archivedNotifications = new HashSet(); String archivedNotificationString = userPreferences.getProperty("archivedNotifications"); if (archivedNotificationString != null) { diff --git a/client/src/com/mirth/connect/client/ui/SettingsPanelServer.java b/client/src/com/mirth/connect/client/ui/SettingsPanelServer.java index c277a3d60..bd1d523a7 100644 --- a/client/src/com/mirth/connect/client/ui/SettingsPanelServer.java +++ b/client/src/com/mirth/connect/client/ui/SettingsPanelServer.java @@ -9,6 +9,8 @@ package com.mirth.connect.client.ui; +import static com.mirth.connect.client.core.BrandingConstants.SEND_USAGE_STATISTICS; + import java.awt.Color; import java.awt.Cursor; import java.awt.Font; @@ -81,8 +83,12 @@ public SettingsPanelServer(String tabName) { addTask(TaskConstants.SETTINGS_SERVER_RESTORE, "Restore Config", "Restore your server configuration from a server configuration XML file. This will remove and restore your channels, alerts, code templates, server properties, global scripts, and plugin properties.", "", new ImageIcon(com.mirth.connect.client.ui.Frame.class.getResource("images/report_go.png"))); addTask(TaskConstants.SETTINGS_CLEAR_ALL_STATS, "Clear All Statistics", "Reset the current and lifetime statistics for all channels.", "", new ImageIcon(com.mirth.connect.client.ui.Frame.class.getResource("images/chart_bar_delete.png"))); - provideUsageStatsMoreInfoLabel.setToolTipText(BrandingConstants.PRIVACY_TOOLTIP); - provideUsageStatsMoreInfoLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); + if (!SEND_USAGE_STATISTICS) { + provideUsageStatsLabel.setVisible(false); + provideUsageStatsYesRadio.setVisible(false); + provideUsageStatsNoRadio.setVisible((false)); + provideUsageStatsMoreInfoLabel.setVisible(false); + } queueBufferSizeField.setDocument(new MirthFieldConstraints(8, false, false, true)); smtpTimeoutField.setDocument(new MirthFieldConstraints(0, false, false, false)); administratorAutoLogoutIntervalField.setDocument(new MirthFieldConstraints(2, false, false, true)); @@ -728,8 +734,8 @@ public void actionPerformed(ActionEvent evt) { provideUsageStatsButtonGroup.add(provideUsageStatsNoRadio); provideUsageStatsMoreInfoLabel = new JLabel("More Info"); - provideUsageStatsMoreInfoLabel.setEnabled(false); - provideUsageStatsMoreInfoLabel.setVisible(false); + provideUsageStatsMoreInfoLabel.setToolTipText(BrandingConstants.PRIVACY_TOOLTIP); + provideUsageStatsMoreInfoLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); provideUsageStatsMoreInfoLabel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { provideUsageStatsMoreInfoLabelMouseClicked(evt); diff --git a/server/src/com/mirth/connect/client/core/BrandingConstants.java b/server/src/com/mirth/connect/client/core/BrandingConstants.java index b9d5cfe50..d7cc29761 100644 --- a/server/src/com/mirth/connect/client/core/BrandingConstants.java +++ b/server/src/com/mirth/connect/client/core/BrandingConstants.java @@ -9,4 +9,12 @@ public class BrandingConstants { public static final String CLIENT_CONNECTION_HEADER = "openintegrationengine-client"; public static final String SERVER_CERTIFICATE_CN = "oie-engine"; + + public static final String CONNECT_SERVER_URL = "https://connect.openintegrationengine.org"; + public static final String NOTIFICATIONS_URL = "https://api.github.com/repos/openintegrationengine/engine/releases"; + + public static final boolean CENTRAL_USER_REGISTRATION = false; + public static final boolean MANDATORY_USER_REGISTRATION = false; + public static final boolean CHECK_FOR_NOTIFICATIONS = true; + public static final boolean SEND_USAGE_STATISTICS = false; } diff --git a/server/src/com/mirth/connect/client/core/ConnectServiceUtil.java b/server/src/com/mirth/connect/client/core/ConnectServiceUtil.java index 426629f96..ea7e1efa3 100644 --- a/server/src/com/mirth/connect/client/core/ConnectServiceUtil.java +++ b/server/src/com/mirth/connect/client/core/ConnectServiceUtil.java @@ -51,21 +51,27 @@ import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; + import com.github.zafarkhaja.semver.Version; + import com.mirth.connect.model.User; import com.mirth.connect.model.converters.ObjectXMLSerializer; import com.mirth.connect.model.notification.Notification; import com.mirth.connect.util.MirthSSLUtil; public class ConnectServiceUtil { - private final static String URL_CONNECT_SERVER = "https://connect.mirthcorp.com"; + private final static String URL_CONNECT_SERVER = BrandingConstants.CONNECT_SERVER_URL; private final static String URL_REGISTRATION_SERVLET = "/RegistrationServlet"; private final static String URL_USAGE_SERVLET = "/UsageStatisticsServlet"; - private static String URL_NOTIFICATIONS = "https://api.github.com/repos/openintegrationengine/engine/releases"; + private static String URL_NOTIFICATIONS = BrandingConstants.NOTIFICATIONS_URL; private final static int TIMEOUT = 10000; public final static Integer MILLIS_PER_DAY = 86400000; public static void registerUser(String serverId, String mirthVersion, User user, String[] protocols, String[] cipherSuites) throws ClientException { + if (!BrandingConstants.CENTRAL_USER_REGISTRATION) { + throw new UnsupportedOperationException("User Registration is disabled"); + } + CloseableHttpClient httpClient = null; CloseableHttpResponse httpResponse = null; NameValuePair[] params = { new BasicNameValuePair("serverId", serverId), @@ -107,6 +113,10 @@ public static void registerUser(String serverId, String mirthVersion, User user, * @throws Exception should anything fail dealing with the web request and the handling of its response */ public static List getNotifications(String serverId, String mirthVersion, Map extensionVersions, String[] protocols, String[] cipherSuites) throws Exception { + if (!BrandingConstants.CHECK_FOR_NOTIFICATIONS) { + throw new UnsupportedOperationException("Checking for Notifications is disabled."); + } + List validNotifications = Collections.emptyList(); Optional parsedMirthVersion = Version.tryParse(mirthVersion); if (!parsedMirthVersion.isPresent()) { @@ -208,6 +218,10 @@ protected static Notification toNotification(JsonNode node) { } public static int getNotificationCount(String serverId, String mirthVersion, Map extensionVersions, Set archivedNotifications, String[] protocols, String[] cipherSuites) { + if (!BrandingConstants.CHECK_FOR_NOTIFICATIONS) { + throw new UnsupportedOperationException("Checking for Notifications is disabled."); + } + Long notificationCount = 0L; try { notificationCount = getNotifications(serverId, mirthVersion, extensionVersions, protocols, cipherSuites) @@ -222,6 +236,10 @@ public static int getNotificationCount(String serverId, String mirthVersion, Map } public static boolean sendStatistics(String serverId, String mirthVersion, boolean server, String data, String[] protocols, String[] cipherSuites) { + if (!BrandingConstants.SEND_USAGE_STATISTICS) { + throw new UnsupportedOperationException("Sending Usage Statistics is disabled."); + } + if (data == null) { return false; } diff --git a/server/src/com/mirth/connect/server/Mirth.java b/server/src/com/mirth/connect/server/Mirth.java index 24c64874a..5e8cacfcf 100644 --- a/server/src/com/mirth/connect/server/Mirth.java +++ b/server/src/com/mirth/connect/server/Mirth.java @@ -401,8 +401,10 @@ public void startup() { printSplashScreen(); // schedule usage statistics to be sent at startup and every 24 hours - Timer timer = new Timer(); - timer.schedule(new UsageSenderTask(), 0, ConnectServiceUtil.MILLIS_PER_DAY); + if (BrandingConstants.SEND_USAGE_STATISTICS) { + Timer timer = new Timer(); + timer.schedule(new UsageSenderTask(), 0, ConnectServiceUtil.MILLIS_PER_DAY); + } } /**