Allow ordering of the scopes in the selection UX
Allow the sequencing of the scopes list in the screen that presents
the list of options for authorizing access to the user's profile.
Change-Id: I00c20fe55ce49d38a9d4556925f4c7c942508654
diff --git a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfig.java b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfig.java
index cdc817b..47387f7 100644
--- a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfig.java
+++ b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/GitHubOAuthConfig.java
@@ -26,6 +26,7 @@
import com.google.inject.Singleton;
import com.googlesource.gerrit.plugins.github.oauth.OAuthProtocol.Scope;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@@ -61,6 +62,7 @@
public final boolean enabled;
@Getter public final Map<ScopeKey, List<OAuthProtocol.Scope>> scopes;
+ @Getter public final List<ScopeKey> sortedScopesKeys;
public final int fileUpdateMaxRetryCount;
public final int fileUpdateMaxRetryIntervalMsec;
@@ -102,6 +104,12 @@
enabled = config.getString("auth", null, "type").equalsIgnoreCase(AuthType.HTTP.toString());
scopes = getScopes(config);
+ sortedScopesKeys =
+ scopes
+ .keySet()
+ .stream()
+ .sorted(Comparator.comparing(ScopeKey::getSequence))
+ .collect(Collectors.toList());
fileUpdateMaxRetryCount = config.getInt(CONF_SECTION, "fileUpdateMaxRetryCount", 3);
fileUpdateMaxRetryIntervalMsec =
@@ -139,9 +147,14 @@
.stream()
.filter(k -> k.startsWith("scopes"))
.filter(k -> !k.endsWith("Description"))
+ .filter(k -> !k.endsWith("Sequence"))
.collect(
Collectors.toMap(
- k -> new ScopeKey(k, config.getString(CONF_SECTION, null, k + "Description")),
+ k ->
+ new ScopeKey(
+ k,
+ config.getString(CONF_SECTION, null, k + "Description"),
+ config.getInt(CONF_SECTION, k + "Sequence", 0)),
v -> parseScopesString(config.getString(CONF_SECTION, null, v))));
}
diff --git a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/ScopeKey.java b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/ScopeKey.java
index 2b99a71..a4751c7 100644
--- a/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/ScopeKey.java
+++ b/github-oauth/src/main/java/com/googlesource/gerrit/plugins/github/oauth/ScopeKey.java
@@ -19,9 +19,11 @@
public class ScopeKey {
@Getter public final String name;
@Getter public final String description;
+ @Getter public final int sequence;
- public ScopeKey(String name, String description) {
+ public ScopeKey(String name, String description, int sequence) {
this.name = name;
this.description = description;
+ this.sequence = sequence;
}
}
diff --git a/github-plugin/src/main/resources/static/scope.html b/github-plugin/src/main/resources/static/scope.html
index dc9b4a7..5b46f4c 100644
--- a/github-plugin/src/main/resources/static/scope.html
+++ b/github-plugin/src/main/resources/static/scope.html
@@ -36,7 +36,7 @@
<form class="signupform" method="get" action="/login">
<h5>Which level of GitHub access do you need?</h5>
<ul class="scopes">
- #foreach ( $scope in $config.scopes.keySet() )
+ #foreach ( $scope in $config.sortedScopesKeys )
<li>
#set ( $scopeName = $scope.name.substring(6) )
#set ( $scopeDescription = $scope.description )