Skip to content

Commit

Permalink
[MM-54594] Adding new global relay type (mattermost#24672)
Browse files Browse the repository at this point in the history
* adding new global relay type, custom
  • Loading branch information
BenCookie95 authored Dec 7, 2023
1 parent 769c7da commit a11b27d
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 7 deletions.
2 changes: 2 additions & 0 deletions e2e-tests/playwright/support/server/default_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,8 @@ const defaultServerConfig: AdminConfig = {
SMTPPassword: '',
EmailAddress: '',
SMTPServerTimeout: 1800,
CustomSMTPServerName: '',
CustomSMTPPort: '25',
},
},
JobSettings: {
Expand Down
6 changes: 5 additions & 1 deletion server/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 17 additions & 6 deletions server/public/model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ const (
ComplianceExportTypeGlobalrelayZip = "globalrelay-zip"
GlobalrelayCustomerTypeA9 = "A9"
GlobalrelayCustomerTypeA10 = "A10"
GlobalrelayCustomerTypeCustom = "CUSTOM"

ClientSideCertCheckPrimaryAuth = "primary"
ClientSideCertCheckSecondaryAuth = "secondary"
Expand Down Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ exports[`components/MessageExportSettings should match snapshot, disabled, globa
"text": "A10/Type 10",
"value": "A10",
},
Object {
"text": "Custom",
"value": "CUSTOM",
},
]
}
/>
Expand Down Expand Up @@ -757,6 +761,10 @@ exports[`components/MessageExportSettings should match snapshot, enabled, global
"text": "A10/Type 10",
"value": "A10",
},
Object {
"text": "Custom",
"value": "CUSTOM",
},
]
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ describe('components/MessageExportSettings', () => {
SMTPUsername: 'globalRelayUser',
SMTPPassword: 'globalRelayPassword',
EmailAddress: '[email protected]',
CustomSMTPServerName: '',
CustomSMTPPort: '25',
},
},
};
Expand Down Expand Up @@ -126,6 +128,8 @@ describe('components/MessageExportSettings', () => {
SMTPUsername: 'globalRelayUser',
SMTPPassword: 'globalRelayPassword',
EmailAddress: '[email protected]',
CustomSMTPServerName: '',
CustomSMTPPort: '25',
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

Expand All @@ -47,6 +49,8 @@ export default class MessageExportSettings extends AdminSettings<BaseProps, Stat
SMTPUsername: this.state.globalRelaySMTPUsername,
SMTPPassword: this.state.globalRelaySMTPPassword,
EmailAddress: this.state.globalRelayEmailAddress,
CustomSMTPServerName: this.state.globalRelayCustomSMTPServerName,
CustomSMTPPort: this.state.globalRelayCustomSMTPPort,
SMTPServerTimeout: this.state.globalRelaySMTPServerTimeout,
};
}
Expand All @@ -63,6 +67,8 @@ export default class MessageExportSettings extends AdminSettings<BaseProps, Stat
globalRelaySMTPPassword: '',
globalRelayEmailAddress: '',
globalRelaySMTPServerTimeout: 0,
globalRelayCustomSMTPServerName: '',
globalRelayCustomSMTPPort: '',
saveNeeded: false,
saving: false,
serverError: null,
Expand All @@ -73,6 +79,8 @@ export default class MessageExportSettings extends AdminSettings<BaseProps, Stat
state.globalRelaySMTPUsername = config.MessageExportSettings.GlobalRelaySettings.SMTPUsername;
state.globalRelaySMTPPassword = config.MessageExportSettings.GlobalRelaySettings.SMTPPassword;
state.globalRelayEmailAddress = config.MessageExportSettings.GlobalRelaySettings.EmailAddress;
state.globalRelayCustomSMTPServerName = config.MessageExportSettings.GlobalRelaySettings.CustomSMTPServerName;
state.globalRelayCustomSMTPPort = config.MessageExportSettings.GlobalRelaySettings.CustomSMTPPort;
}
return state;
}
Expand Down Expand Up @@ -148,6 +156,7 @@ export default class MessageExportSettings extends AdminSettings<BaseProps, Stat
values={[
{value: 'A9', text: Utils.localizeMessage('admin.complianceExport.globalRelayCustomerType.a9.description', 'A9/Type 9')},
{value: 'A10', text: Utils.localizeMessage('admin.complianceExport.globalRelayCustomerType.a10.description', 'A10/Type 10')},
{value: 'CUSTOM', text: Utils.localizeMessage('admin.complianceExport.globalRelayCustomerType.custom.description', 'Custom')},
]}
label={
<FormattedMessage
Expand Down Expand Up @@ -237,12 +246,66 @@ export default class MessageExportSettings extends AdminSettings<BaseProps, Stat
/>
);

const globalRelaySMTPServerName = (
<TextSetting
id='globalRelayCustomSMTPServerName'
label={
<FormattedMessage
id='admin.complianceExport.globalRelayCustomSMTPServerName.title'
defaultMessage='SMTP Server Name:'
/>
}
placeholder={Utils.localizeMessage('admin.complianceExport.globalRelayCustomSMTPServerName.example', 'E.g.: "feeds.globalrelay.com"')}
helpText={
<FormattedMessage
id='admin.complianceExport.globalRelayCustomSMTPServerName.description'
defaultMessage='The SMTP server name that will receive your Global Relay EML.'
/>
}
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 = (
<TextSetting
id='globalRelayCustomSMTPPort'
label={
<FormattedMessage
id='admin.complianceExport.globalRelayCustomSMTPPort.title'
defaultMessage='SMTP Server Port:'
/>
}
placeholder={Utils.localizeMessage('admin.complianceExport.globalRelayCustomSMTPPort.example', 'E.g.: "25"')}
helpText={
<FormattedMessage
id='admin.complianceExport.globalRelayCustomSMTPPort.description'
defaultMessage='The SMTP server port that will receive your Global Relay EML.'
/>
}
value={this.state.globalRelayCustomSMTPPort ? this.state.globalRelayCustomSMTPPort : ''}
onChange={this.handleChange}
setByEnv={this.isSetByEnv('DataRetentionSettings.GlobalRelaySettings.CustomSMTPPort')}
disabled={this.props.isDisabled || !this.state.enableComplianceExport}
/>
);

globalRelaySettings = (
<SettingsGroup id={'globalRelaySettings'} >
{globalRelayCustomerType}
{globalRelaySMTPUsername}
{globalRelaySMTPPassword}
{globalRelayEmail}
{
this.state.globalRelayCustomerType === 'CUSTOM' &&
globalRelaySMTPServerName
}
{
this.state.globalRelayCustomerType === 'CUSTOM' &&
globalRelaySMTPPort
}
</SettingsGroup>
);
}
Expand Down
7 changes: 7 additions & 0 deletions webapp/channels/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.: \"[email protected]\"",
"admin.complianceExport.globalRelayEmailAddress.title": "Global Relay Email Address:",
Expand Down
2 changes: 2 additions & 0 deletions webapp/platform/types/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@ export type MessageExportSettings = {
SMTPPassword: string;
EmailAddress: string;
SMTPServerTimeout: number;
CustomSMTPServerName: string;
CustomSMTPPort: string;
};
};

Expand Down

0 comments on commit a11b27d

Please sign in to comment.