From a11b27d1f2366c55748248e7071326c3d87de84d Mon Sep 17 00:00:00 2001 From: Ben Cooke Date: Thu, 7 Dec 2023 16:39:10 -0500 Subject: [PATCH] [MM-54594] Adding new global relay type (#24672) * adding new global relay type, custom --- .../support/server/default_config.ts | 2 + server/i18n/en.json | 6 +- server/public/model/config.go | 23 +++++-- .../message_export_settings.test.jsx.snap | 8 +++ .../message_export_settings.test.jsx | 4 ++ .../admin_console/message_export_settings.tsx | 63 +++++++++++++++++++ webapp/channels/src/i18n/en.json | 7 +++ webapp/platform/types/src/config.ts | 2 + 8 files changed, 108 insertions(+), 7 deletions(-) diff --git a/e2e-tests/playwright/support/server/default_config.ts b/e2e-tests/playwright/support/server/default_config.ts index 1a1a0f07401..d8b9eca8564 100644 --- a/e2e-tests/playwright/support/server/default_config.ts +++ b/e2e-tests/playwright/support/server/default_config.ts @@ -630,6 +630,8 @@ const defaultServerConfig: AdminConfig = { SMTPPassword: '', EmailAddress: '', SMTPServerTimeout: 1800, + CustomSMTPServerName: '', + CustomSMTPPort: '25', }, }, JobSettings: { diff --git a/server/i18n/en.json b/server/i18n/en.json index 19beee848ae..78cffd3694e 100644 --- a/server/i18n/en.json +++ b/server/i18n/en.json @@ -8848,7 +8848,11 @@ }, { "id": "model.config.is_valid.message_export.global_relay.customer_type.app_error", - "translation": "Message export GlobalRelaySettings.CustomerType must be set to one of either 'A9' or 'A10'." + "translation": "Message export GlobalRelaySettings.CustomerType must be set to one of either 'A9', 'A10' or 'CUSTOM." + }, + { + "id": "model.config.is_valid.message_export.global_relay.customer_type_custom.app_error", + "translation": "If GlobalRelaySettings.CustomerType is 'CUSTOM', then GlobalRelaySettings.CustomSMTPServerName and GlobalRelaySettings.CustomSMTPPort must be set." }, { "id": "model.config.is_valid.message_export.global_relay.email_address.app_error", diff --git a/server/public/model/config.go b/server/public/model/config.go index 030f939e5c8..a13385a7ae1 100644 --- a/server/public/model/config.go +++ b/server/public/model/config.go @@ -226,6 +226,7 @@ const ( ComplianceExportTypeGlobalrelayZip = "globalrelay-zip" GlobalrelayCustomerTypeA9 = "A9" GlobalrelayCustomerTypeA10 = "A10" + GlobalrelayCustomerTypeCustom = "CUSTOM" ClientSideCertCheckPrimaryAuth = "primary" ClientSideCertCheckSecondaryAuth = "secondary" @@ -3108,11 +3109,13 @@ func (s *PluginSettings) SetDefaults(ls LogSettings) { } type GlobalRelayMessageExportSettings struct { - CustomerType *string `access:"compliance_compliance_export"` // must be either A9 or A10, dictates SMTP server url - SMTPUsername *string `access:"compliance_compliance_export"` - SMTPPassword *string `access:"compliance_compliance_export"` - EmailAddress *string `access:"compliance_compliance_export"` // the address to send messages to - SMTPServerTimeout *int `access:"compliance_compliance_export"` + CustomerType *string `access:"compliance_compliance_export"` // must be either A9, A10 or CUSTOM, dictates SMTP server url + SMTPUsername *string `access:"compliance_compliance_export"` + SMTPPassword *string `access:"compliance_compliance_export"` + EmailAddress *string `access:"compliance_compliance_export"` // the address to send messages to + SMTPServerTimeout *int `access:"compliance_compliance_export"` + CustomSMTPServerName *string `access:"compliance_compliance_export"` + CustomSMTPPort *string `access:"compliance_compliance_export"` } func (s *GlobalRelayMessageExportSettings) SetDefaults() { @@ -3131,6 +3134,12 @@ func (s *GlobalRelayMessageExportSettings) SetDefaults() { if s.SMTPServerTimeout == nil || *s.SMTPServerTimeout == 0 { s.SMTPServerTimeout = NewInt(1800) } + if s.CustomSMTPServerName == nil { + s.CustomSMTPServerName = NewString("") + } + if s.CustomSMTPPort == nil { + s.CustomSMTPPort = NewString("25") + } } type MessageExportSettings struct { @@ -4105,8 +4114,10 @@ func (s *MessageExportSettings) isValid() *AppError { if *s.ExportFormat == ComplianceExportTypeGlobalrelay { if s.GlobalRelaySettings == nil { return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.config_missing.app_error", nil, "", http.StatusBadRequest) - } else if s.GlobalRelaySettings.CustomerType == nil || (*s.GlobalRelaySettings.CustomerType != GlobalrelayCustomerTypeA9 && *s.GlobalRelaySettings.CustomerType != GlobalrelayCustomerTypeA10) { + } else if s.GlobalRelaySettings.CustomerType == nil || (*s.GlobalRelaySettings.CustomerType != GlobalrelayCustomerTypeA9 && *s.GlobalRelaySettings.CustomerType != GlobalrelayCustomerTypeA10 && *s.GlobalRelaySettings.CustomerType != GlobalrelayCustomerTypeCustom) { return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.customer_type.app_error", nil, "", http.StatusBadRequest) + } else if *s.GlobalRelaySettings.CustomerType == GlobalrelayCustomerTypeCustom && ((s.GlobalRelaySettings.CustomSMTPServerName == nil || *s.GlobalRelaySettings.CustomSMTPServerName == "") || (s.GlobalRelaySettings.CustomSMTPPort == nil || *s.GlobalRelaySettings.CustomSMTPPort == "")) { + return NewAppError("Config.IsValid", "model.config.is_valid.message_export.global_relay.customer_type_custom.app_error", nil, "", http.StatusBadRequest) } else if s.GlobalRelaySettings.EmailAddress == nil || !strings.Contains(*s.GlobalRelaySettings.EmailAddress, "@") { // validating email addresses is hard - just make sure it contains an '@' sign // see https://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address diff --git a/webapp/channels/src/components/admin_console/__snapshots__/message_export_settings.test.jsx.snap b/webapp/channels/src/components/admin_console/__snapshots__/message_export_settings.test.jsx.snap index e44cb8abdf8..ab26dc6f560 100644 --- a/webapp/channels/src/components/admin_console/__snapshots__/message_export_settings.test.jsx.snap +++ b/webapp/channels/src/components/admin_console/__snapshots__/message_export_settings.test.jsx.snap @@ -316,6 +316,10 @@ exports[`components/MessageExportSettings should match snapshot, disabled, globa "text": "A10/Type 10", "value": "A10", }, + Object { + "text": "Custom", + "value": "CUSTOM", + }, ] } /> @@ -757,6 +761,10 @@ exports[`components/MessageExportSettings should match snapshot, enabled, global "text": "A10/Type 10", "value": "A10", }, + Object { + "text": "Custom", + "value": "CUSTOM", + }, ] } /> diff --git a/webapp/channels/src/components/admin_console/message_export_settings.test.jsx b/webapp/channels/src/components/admin_console/message_export_settings.test.jsx index e842362cbe1..9902cdfe4ca 100644 --- a/webapp/channels/src/components/admin_console/message_export_settings.test.jsx +++ b/webapp/channels/src/components/admin_console/message_export_settings.test.jsx @@ -82,6 +82,8 @@ describe('components/MessageExportSettings', () => { SMTPUsername: 'globalRelayUser', SMTPPassword: 'globalRelayPassword', EmailAddress: 'globalRelay@mattermost.com', + CustomSMTPServerName: '', + CustomSMTPPort: '25', }, }, }; @@ -126,6 +128,8 @@ describe('components/MessageExportSettings', () => { SMTPUsername: 'globalRelayUser', SMTPPassword: 'globalRelayPassword', EmailAddress: 'globalRelay@mattermost.com', + CustomSMTPServerName: '', + CustomSMTPPort: '25', }, }, }; diff --git a/webapp/channels/src/components/admin_console/message_export_settings.tsx b/webapp/channels/src/components/admin_console/message_export_settings.tsx index f8590a1fbb9..43b9b515aca 100644 --- a/webapp/channels/src/components/admin_console/message_export_settings.tsx +++ b/webapp/channels/src/components/admin_console/message_export_settings.tsx @@ -32,6 +32,8 @@ interface State extends BaseState { globalRelaySMTPUsername: AdminConfig['MessageExportSettings']['GlobalRelaySettings']['SMTPUsername']; globalRelaySMTPPassword: AdminConfig['MessageExportSettings']['GlobalRelaySettings']['SMTPPassword']; globalRelayEmailAddress: AdminConfig['MessageExportSettings']['GlobalRelaySettings']['EmailAddress']; + globalRelayCustomSMTPServerName: AdminConfig['MessageExportSettings']['GlobalRelaySettings']['CustomSMTPServerName']; + globalRelayCustomSMTPPort: AdminConfig['MessageExportSettings']['GlobalRelaySettings']['CustomSMTPPort']; globalRelaySMTPServerTimeout: AdminConfig['MessageExportSettings']['GlobalRelaySettings']['SMTPServerTimeout']; } @@ -47,6 +49,8 @@ export default class MessageExportSettings extends AdminSettings ); + const globalRelaySMTPServerName = ( + + } + placeholder={Utils.localizeMessage('admin.complianceExport.globalRelayCustomSMTPServerName.example', 'E.g.: "feeds.globalrelay.com"')} + helpText={ + + } + value={this.state.globalRelayCustomSMTPServerName ? this.state.globalRelayCustomSMTPServerName : ''} + onChange={this.handleChange} + setByEnv={this.isSetByEnv('DataRetentionSettings.GlobalRelaySettings.CustomSMTPServerName')} + disabled={this.props.isDisabled || !this.state.enableComplianceExport} + /> + ); + + const globalRelaySMTPPort = ( + + } + placeholder={Utils.localizeMessage('admin.complianceExport.globalRelayCustomSMTPPort.example', 'E.g.: "25"')} + helpText={ + + } + value={this.state.globalRelayCustomSMTPPort ? this.state.globalRelayCustomSMTPPort : ''} + onChange={this.handleChange} + setByEnv={this.isSetByEnv('DataRetentionSettings.GlobalRelaySettings.CustomSMTPPort')} + disabled={this.props.isDisabled || !this.state.enableComplianceExport} + /> + ); + globalRelaySettings = ( {globalRelayCustomerType} {globalRelaySMTPUsername} {globalRelaySMTPPassword} {globalRelayEmail} + { + this.state.globalRelayCustomerType === 'CUSTOM' && + globalRelaySMTPServerName + } + { + this.state.globalRelayCustomerType === 'CUSTOM' && + globalRelaySMTPPort + } ); } diff --git a/webapp/channels/src/i18n/en.json b/webapp/channels/src/i18n/en.json index b1cc1ea9342..d2a025db3fc 100644 --- a/webapp/channels/src/i18n/en.json +++ b/webapp/channels/src/i18n/en.json @@ -607,8 +607,15 @@ "admin.complianceExport.exportJobStartTime.title": "Compliance Export time:", "admin.complianceExport.globalRelayCustomerType.a10.description": "A10/Type 10", "admin.complianceExport.globalRelayCustomerType.a9.description": "A9/Type 9", + "admin.complianceExport.globalRelayCustomerType.custom.description": "Custom", "admin.complianceExport.globalRelayCustomerType.description": "Type of Global Relay customer account your organization has.", "admin.complianceExport.globalRelayCustomerType.title": "Global Relay Customer Account:", + "admin.complianceExport.globalRelayCustomSMTPPort.description": "The SMTP server port that will receive your Global Relay EML.", + "admin.complianceExport.globalRelayCustomSMTPPort.example": "E.g.: \"25\"", + "admin.complianceExport.globalRelayCustomSMTPPort.title": "SMTP Server Port:", + "admin.complianceExport.globalRelayCustomSMTPServerName.description": "The SMTP server name that will receive your Global Relay EML.", + "admin.complianceExport.globalRelayCustomSMTPServerName.example": "E.g.: \"feeds.globalrelay.com\"", + "admin.complianceExport.globalRelayCustomSMTPServerName.title": "SMTP Server Name:", "admin.complianceExport.globalRelayEmailAddress.description": "The email address your Global Relay server monitors for incoming compliance exports.", "admin.complianceExport.globalRelayEmailAddress.example": "E.g.: \"globalrelay@mattermost.com\"", "admin.complianceExport.globalRelayEmailAddress.title": "Global Relay Email Address:", diff --git a/webapp/platform/types/src/config.ts b/webapp/platform/types/src/config.ts index 83fb2923b0e..e2bdb51996f 100644 --- a/webapp/platform/types/src/config.ts +++ b/webapp/platform/types/src/config.ts @@ -833,6 +833,8 @@ export type MessageExportSettings = { SMTPPassword: string; EmailAddress: string; SMTPServerTimeout: number; + CustomSMTPServerName: string; + CustomSMTPPort: string; }; };