OutgoingEmail: Use UrlFormatter to get settings URL

The settings URL is hard coded based on the site URL, rather than
using the one provided by UrlFormatter.

Extend the UrlFormatter interface to support both the base settings
URL, and URLs for specific settings sections.

Change-Id: Ia4cf6566c3c786fa3822fe3bfd59aa9639717ed3
This commit is contained in:
David Pursehouse
2019-06-18 17:29:27 +09:00
parent 29ab7f8a5d
commit 87b2bc6919
2 changed files with 12 additions and 9 deletions

View File

@@ -61,9 +61,18 @@ public interface UrlFormatter {
}
/** Returns a URL pointing to a section of the settings page. */
default Optional<String> getSettingsUrl() {
return getWebUrl().map(url -> url + "settings");
}
/**
* Returns a URL pointing to a section of the settings page, or the settings page if {@code
* section} is null.
*/
default Optional<String> getSettingsUrl(@Nullable String section) {
return getWebUrl()
.map(url -> url + "settings" + (Strings.isNullOrEmpty(section) ? "" : "#" + section));
return Strings.isNullOrEmpty(section)
? getSettingsUrl()
: getSettingsUrl().map(url -> url + "#" + section);
}
/** Returns a URL pointing to a documentation page, at a given named anchor. */

View File

@@ -289,13 +289,7 @@ public abstract class OutgoingEmail {
}
public String getSettingsUrl() {
if (getGerritUrl() != null) {
final StringBuilder r = new StringBuilder();
r.append(getGerritUrl());
r.append("settings");
return r.toString();
}
return null;
return args.urlFormatter.get().getSettingsUrl().orElse(null);
}
private String getGerritUrl() {