From 1b04d7730f56a08c935974504b2d849d01870c02 Mon Sep 17 00:00:00 2001 From: James Moger Date: Thu, 5 Jun 2014 14:14:54 -0400 Subject: [PATCH] Add clone transport user preference --- releases.moxie | 1 + .../java/com/gitblit/ConfigUserService.java | 9 ++++++++ src/main/java/com/gitblit/GitBlit.java | 19 +++++++++++++++++ .../com/gitblit/models/UserPreferences.java | 11 ++++++++++ .../gitblit/wicket/GitBlitWebApp.properties | 4 +++- .../com/gitblit/wicket/pages/UserPage.html | 1 + .../com/gitblit/wicket/pages/UserPage.java | 21 +++++++++++++++++++ 7 files changed, 65 insertions(+), 1 deletion(-) diff --git a/releases.moxie b/releases.moxie index fc139b77..c1e11d98 100644 --- a/releases.moxie +++ b/releases.moxie @@ -43,6 +43,7 @@ r24: { - Simplified repository creation, offer simple README generation, and insertion of a pre-defined .gitignore file (ticket-76) - Added an extension point for monitoring onStartup and onShutdown (ticket-79) - Tag server-side merges when incremental push tags are enabled (issue-432, ticket-85) + - Add a user preference for the clone transport (ticket-90) - Add setting to control default thread pool size for miscellaneous background tasks (ticket-92) dependencyChanges: - Update to javax.mail 1.5.1 (issue-417, ticket-58) diff --git a/src/main/java/com/gitblit/ConfigUserService.java b/src/main/java/com/gitblit/ConfigUserService.java index 9759eff7..0c5b2a58 100644 --- a/src/main/java/com/gitblit/ConfigUserService.java +++ b/src/main/java/com/gitblit/ConfigUserService.java @@ -36,6 +36,7 @@ import org.slf4j.LoggerFactory; import com.gitblit.Constants.AccessPermission; import com.gitblit.Constants.AccountType; +import com.gitblit.Constants.Transport; import com.gitblit.manager.IRuntimeManager; import com.gitblit.models.TeamModel; import com.gitblit.models.UserModel; @@ -98,6 +99,8 @@ public class ConfigUserService implements IUserService { private static final String EMAILONMYTICKETCHANGES = "emailMeOnMyTicketChanges"; + private static final String TRANSPORT = "transport"; + private static final String ACCOUNTTYPE = "accountType"; private static final String DISABLED = "disabled"; @@ -713,7 +716,12 @@ public class ConfigUserService implements IUserService { String val = model.getPreferences().getLocale().getLanguage() + "_" + model.getPreferences().getLocale().getCountry(); config.setString(USER, model.username, LOCALE, val); } + config.setBoolean(USER, model.username, EMAILONMYTICKETCHANGES, model.getPreferences().isEmailMeOnMyTicketChanges()); + + if (model.getPreferences().getTransport() != null) { + config.setString(USER, model.username, TRANSPORT, model.getPreferences().getTransport().name()); + } } // user roles @@ -891,6 +899,7 @@ public class ConfigUserService implements IUserService { // preferences user.getPreferences().setLocale(config.getString(USER, username, LOCALE)); user.getPreferences().setEmailMeOnMyTicketChanges(config.getBoolean(USER, username, EMAILONMYTICKETCHANGES, true)); + user.getPreferences().setTransport(Transport.fromString(config.getString(USER, username, TRANSPORT))); // user roles Set roles = new HashSet(Arrays.asList(config.getStringList( diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java index 81793850..f9d9be9f 100644 --- a/src/main/java/com/gitblit/GitBlit.java +++ b/src/main/java/com/gitblit/GitBlit.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; @@ -264,6 +265,24 @@ public class GitBlit extends GitblitManager { } }); + // consider the user's transport preference + RepositoryUrl preferredUrl = null; + Transport preferredTransport = user.getPreferences().getTransport(); + if (preferredTransport != null) { + Iterator itr = list.iterator(); + while (itr.hasNext()) { + RepositoryUrl url = itr.next(); + if (url.transport.equals(preferredTransport)) { + itr.remove(); + preferredUrl = url; + break; + } + } + } + if (preferredUrl != null) { + list.add(0, preferredUrl); + } + return list; } diff --git a/src/main/java/com/gitblit/models/UserPreferences.java b/src/main/java/com/gitblit/models/UserPreferences.java index c95b0da5..90c034fc 100644 --- a/src/main/java/com/gitblit/models/UserPreferences.java +++ b/src/main/java/com/gitblit/models/UserPreferences.java @@ -23,6 +23,7 @@ import java.util.Locale; import java.util.Map; import java.util.TreeMap; +import com.gitblit.Constants.Transport; import com.gitblit.utils.StringUtils; /** @@ -41,6 +42,8 @@ public class UserPreferences implements Serializable { private Boolean emailMeOnMyTicketChanges; + private Transport transport; + private final Map repositoryPreferences = new TreeMap(); public UserPreferences(String username) { @@ -113,4 +116,12 @@ public class UserPreferences implements Serializable { public void setEmailMeOnMyTicketChanges(boolean value) { this.emailMeOnMyTicketChanges = value; } + + public Transport getTransport() { + return transport; + } + + public void setTransport(Transport transport) { + this.transport = transport; + } } diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties index c80d45ce..eb92e2d2 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties @@ -739,4 +739,6 @@ gb.key = Key gb.comment = Comment gb.sshKeyCommentDescription = Enter an optional comment. If blank, the comment will be extracted from the key data. gb.permission = Permission -gb.sshKeyPermissionDescription = Specify the access permission for the SSH key \ No newline at end of file +gb.sshKeyPermissionDescription = Specify the access permission for the SSH key +gb.transportPreference = Transport Preference +gb.transportPreferenceDescription = Set the transport that you prefer to use for cloning \ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/pages/UserPage.html b/src/main/java/com/gitblit/wicket/pages/UserPage.html index 017fcb1f..8dccfee7 100644 --- a/src/main/java/com/gitblit/wicket/pages/UserPage.html +++ b/src/main/java/com/gitblit/wicket/pages/UserPage.html @@ -66,6 +66,7 @@
+
diff --git a/src/main/java/com/gitblit/wicket/pages/UserPage.java b/src/main/java/com/gitblit/wicket/pages/UserPage.java index 00a36272..306eea65 100644 --- a/src/main/java/com/gitblit/wicket/pages/UserPage.java +++ b/src/main/java/com/gitblit/wicket/pages/UserPage.java @@ -35,6 +35,7 @@ import org.apache.wicket.markup.repeater.data.ListDataProvider; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; +import com.gitblit.Constants.Transport; import com.gitblit.GitBlitException; import com.gitblit.Keys; import com.gitblit.models.Menu.ParameterMenuItem; @@ -221,6 +222,7 @@ public class UserPage extends RootPage { final IModel emailAddress = Model.of(user.emailAddress == null ? "" : user.emailAddress); final IModel language = Model.of(preferredLanguage); final IModel emailMeOnMyTicketChanges = Model.of(user.getPreferences().isEmailMeOnMyTicketChanges()); + final IModel transport = Model.of(user.getPreferences().getTransport()); prefs.add(new TextOption("displayName", getString("gb.displayName"), @@ -243,6 +245,24 @@ public class UserPage extends RootPage { getString("gb.emailMeOnMyTicketChangesDescription"), emailMeOnMyTicketChanges).setVisible(app().notifier().isSendingMail())); + List availableTransports = new ArrayList<>(); + if (app().gitblit().isServingSSH()) { + availableTransports.add(Transport.SSH); + } + if (app().gitblit().isServingHTTP()) { + availableTransports.add(Transport.HTTPS); + availableTransports.add(Transport.HTTP); + } + if (app().gitblit().isServingGIT()) { + availableTransports.add(Transport.GIT); + } + + prefs.add(new ChoiceOption("transport", + getString("gb.transportPreference"), + getString("gb.transportPreferenceDescription"), + transport, + availableTransports)); + prefs.add(new AjaxButton("save") { private static final long serialVersionUID = 1L; @@ -261,6 +281,7 @@ public class UserPage extends RootPage { } user.getPreferences().setEmailMeOnMyTicketChanges(emailMeOnMyTicketChanges.getObject()); + user.getPreferences().setTransport(transport.getObject()); try { app().gitblit().reviseUser(user.username, user); -- 2.39.5