Ship a list of default experiments from the backend and allow disabling
With this commit, we ship a list of default experiments from the backend to the frontend and allow administrators to disable default experiments using a config in gerrit.config. Change-Id: I2b47042475f330b1816195b230c03a3594ebdaa7
This commit is contained in:
@@ -20,6 +20,7 @@ import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.common.UsedAt;
|
||||
@@ -48,6 +49,10 @@ import org.eclipse.jgit.lib.Config;
|
||||
public class IndexHtmlUtil {
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
static final ImmutableSet<String> DEFAULT_EXPERIMENTS =
|
||||
ImmutableSet.of(
|
||||
"UiFeature__patchset_comments", "UiFeature__patchset_choice_for_comment_links");
|
||||
|
||||
private static final Gson GSON = OutputFormat.JSON_COMPACT.newGson();
|
||||
/**
|
||||
* Returns both static and dynamic parameters of {@code index.html}. The result is to be used when
|
||||
@@ -69,9 +74,13 @@ public class IndexHtmlUtil {
|
||||
canonicalURL, cdnPath, faviconPath, urlParameterMap, urlInScriptTagOrdainer))
|
||||
.putAll(dynamicTemplateData(gerritApi, requestedURL));
|
||||
|
||||
Set<String> enabledExperiments = new HashSet<>(experimentData(urlParameterMap));
|
||||
Set<String> enabledExperiments = new HashSet<>();
|
||||
Arrays.stream(gerritServerConfig.getStringList("experiments", null, "enabled"))
|
||||
.forEach(enabledExperiments::add);
|
||||
DEFAULT_EXPERIMENTS.forEach(enabledExperiments::add);
|
||||
Arrays.stream(gerritServerConfig.getStringList("experiments", null, "disabled"))
|
||||
.forEach(enabledExperiments::remove);
|
||||
experimentData(urlParameterMap).forEach(enabledExperiments::add);
|
||||
if (!enabledExperiments.isEmpty()) {
|
||||
data.put("enabledExperiments", serializeObject(GSON, enabledExperiments).toString());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user