Add fallback mail host to global config

This commit is contained in:
René Pfeuffer
2020-10-12 20:32:53 +02:00
parent bb9f1adc52
commit 9c233c1926
9 changed files with 54 additions and 2 deletions

View File

@@ -80,6 +80,12 @@ public class ScmConfiguration implements Configuration {
*/
public static final String DEFAULT_LOGIN_INFO_URL = "https://login-info.scm-manager.org/api/v1/login-info";
/**
* Default e-mail host that will be used whenever we have to generate an e-mail address for a user that has no mail
* address configured.
*/
public static final String DEFAULT_MAIL_HOST = "scm-manager.local";
/**
* Default plugin url from version 1.0
*/
@@ -187,6 +193,8 @@ public class ScmConfiguration implements Configuration {
@XmlElement(name = "login-info-url")
private String loginInfoUrl = DEFAULT_LOGIN_INFO_URL;
@XmlElement(name = "mail-host")
private String mailHost = DEFAULT_MAIL_HOST;
/**
* Calls the {@link sonia.scm.ConfigChangedListener#configChanged(Object)}
@@ -227,6 +235,7 @@ public class ScmConfiguration implements Configuration {
this.namespaceStrategy = other.namespaceStrategy;
this.loginInfoUrl = other.loginInfoUrl;
this.releaseFeedUrl = other.releaseFeedUrl;
this.mailHost = other.mailHost;
}
/**
@@ -291,6 +300,15 @@ public class ScmConfiguration implements Configuration {
return releaseFeedUrl;
}
/**
* Returns the mail host, that will be used to create e-mail addresses for users without one whenever one is required.
*
* @since 2.8.0
*/
public String getMailHost() {
return mailHost;
}
/**
* Returns a set of glob patterns for urls which should excluded from
* proxy settings.
@@ -471,6 +489,16 @@ public class ScmConfiguration implements Configuration {
this.releaseFeedUrl = releaseFeedUrl;
}
/**
* Sets the mail host, that will be used to create e-mail addresses for users without one whenever one is required.
*
* @param mailHost The new mail host to use.
* @since 2.8.0
*/
public void setMailHost(String mailHost) {
this.mailHost = mailHost;
}
/**
* Set glob patterns for urls which are should be excluded from proxy
* settings.

View File

@@ -48,5 +48,6 @@ export type Config = {
namespaceStrategy: string;
loginInfoUrl: string;
releaseFeedUrl: string;
mailHost: string;
_links: Links;
};

View File

@@ -47,6 +47,7 @@
"skip-failed-authenticators": "Fehlgeschlagene Authentifizierer überspringen",
"plugin-url": "Plugin Center URL",
"release-feed-url": "Release Feed URL",
"mail-host": "Fallback Mail Host",
"enabled-xsrf-protection": "XSRF Protection aktivieren",
"namespace-strategy": "Namespace Strategie",
"login-info-url": "Login Info URL"
@@ -62,6 +63,7 @@
"dateFormatHelpText": "Moments Datumsformat. Zulässige Formate sind in der MomentJS Dokumentation beschrieben.",
"pluginUrlHelpText": "Die URL der Plugin Center API. Beschreibung der Platzhalter: version = SCM-Manager Version; os = Betriebssystem; arch = Architektur",
"releaseFeedUrlHelpText": "Die URL des RSS Release Feed des SCM-Manager. Darüber wird über die neue SCM-Manager Version informiert. Um diese Funktion zu deaktivieren lassen Sie dieses Feld leer.",
"mailHostHelpText": "Dieser Host Name wird genutzt, wenn für einen User eine E-Mail-Adresse benötigt wird, für den keine hinterlegt ist. Dieser Host wird nicht zum Versenden von E-Mails genutzt und auch keine anderweitige Verbindung aufgebaut.",
"enableForwardingHelpText": "mod_proxy Port Weiterleitung aktivieren.",
"disableGroupingGridHelpText": "Repository Gruppen deaktivieren. Nach einer Änderung an dieser Einstellung muss die Seite komplett neu geladen werden.",
"allowAnonymousAccessHelpText": "Anonyme Benutzer haben Zugriff auf freigegebene Repositories.",

View File

@@ -47,6 +47,7 @@
"skip-failed-authenticators": "Skip Failed Authenticators",
"plugin-url": "Plugin Center URL",
"release-feed-url": "Release Feed URL",
"mail-host": "Fallback Mail Host",
"enabled-xsrf-protection": "Enabled XSRF Protection",
"namespace-strategy": "Namespace Strategy",
"login-info-url": "Login Info URL"
@@ -62,6 +63,7 @@
"dateFormatHelpText": "Moments date format. Please have a look at the MomentJS documentation.",
"pluginUrlHelpText": "The url of the Plugin Center API. Explanation of the placeholders: version = SCM-Manager Version; os = Operation System; arch = Architecture",
"releaseFeedUrlHelpText": "The url of the RSS Release Feed for SCM-Manager. This provides up-to-date version information. To disable this feature just leave the url blank.",
"mailHostHelpText": "This host name will be used to create email addresses for users when needed and they have none configured. It will not be used to send mails nor will be accessed otherwise.",
"enableForwardingHelpText": "Enable mod_proxy port forwarding.",
"disableGroupingGridHelpText": "Disable repository Groups. A complete page reload is required after a change of this value.",
"allowAnonymousAccessHelpText": "Anonymous users have access on granted repositories.",

View File

@@ -144,6 +144,7 @@ class ConfigForm extends React.Component<Props, State> {
skipFailedAuthenticators={config.skipFailedAuthenticators}
pluginUrl={config.pluginUrl}
releaseFeedUrl={config.releaseFeedUrl}
mailHost={config.mailHost}
enabledXsrfProtection={config.enabledXsrfProtection}
namespaceStrategy={config.namespaceStrategy}
onChange={(isValid, changedValue, name) => this.onChange(isValid, changedValue, name)}

View File

@@ -36,6 +36,7 @@ type Props = WithTranslation & {
skipFailedAuthenticators: boolean;
pluginUrl: string;
releaseFeedUrl: string;
mailHost: string;
enabledXsrfProtection: boolean;
namespaceStrategy: string;
namespaceStrategies?: NamespaceStrategies;
@@ -51,6 +52,7 @@ class GeneralSettings extends React.Component<Props> {
loginInfoUrl,
pluginUrl,
releaseFeedUrl,
mailHost,
enabledXsrfProtection,
anonymousMode,
namespaceStrategy,
@@ -129,7 +131,7 @@ class GeneralSettings extends React.Component<Props> {
</div>
</div>
<div className="columns">
<div className="column">
<div className="column is-half">
<InputField
label={t("general-settings.release-feed-url")}
onChange={this.handleReleaseFeedUrlChange}
@@ -138,6 +140,15 @@ class GeneralSettings extends React.Component<Props> {
helpText={t("help.releaseFeedUrlHelpText")}
/>
</div>
<div className="column is-half">
<InputField
label={t("general-settings.mail-host")}
onChange={this.handleMailHostChange}
value={mailHost}
disabled={!hasUpdatePermission}
helpText={t("help.mailHostHelpText")}
/>
</div>
</div>
</div>
);
@@ -164,6 +175,9 @@ class GeneralSettings extends React.Component<Props> {
handleReleaseFeedUrlChange = (value: string) => {
this.props.onChange(true, value, "releaseFeedUrl");
};
handleMailHostChange = (value: string) => {
this.props.onChange(true, value, "mailHost");
};
}
export default withTranslation("config")(GeneralSettings);

View File

@@ -59,6 +59,7 @@ public class ConfigDto extends HalRepresentation {
private String namespaceStrategy;
private String loginInfoUrl;
private String releaseFeedUrl;
private String mailHost;
@Override
@SuppressWarnings("squid:S1185") // We want to have this method available in this package

View File

@@ -75,6 +75,7 @@ public class ConfigDtoToScmConfigurationMapperTest {
assertTrue(config.isEnabledXsrfProtection());
assertEquals("username", config.getNamespaceStrategy());
assertEquals("https://scm-manager.org/login-info", config.getLoginInfoUrl());
assertEquals("hitchhiker.mail", config.getMailHost());
}
@Test
@@ -113,6 +114,7 @@ public class ConfigDtoToScmConfigurationMapperTest {
configDto.setEnabledXsrfProtection(true);
configDto.setNamespaceStrategy("username");
configDto.setLoginInfoUrl("https://scm-manager.org/login-info");
configDto.setMailHost("hitchhiker.mail");
return configDto;
}

View File

@@ -106,6 +106,7 @@ public class ScmConfigurationToConfigDtoMapperTest {
assertEquals("username", dto.getNamespaceStrategy());
assertEquals("https://scm-manager.org/login-info", dto.getLoginInfoUrl());
assertEquals("https://www.scm-manager.org/download/rss.xml", dto.getReleaseFeedUrl());
assertEquals("scm-manager.local", dto.getMailHost());
assertEquals(expectedBaseUri.toString(), dto.getLinks().getLinkBy("self").get().getHref());
assertEquals(expectedBaseUri.toString(), dto.getLinks().getLinkBy("update").get().getHref());