]> source.dussan.org Git - gitblit.git/commitdiff
Add clone transport user preference 90/90/1
authorJames Moger <james.moger@gitblit.com>
Thu, 5 Jun 2014 18:14:54 +0000 (14:14 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 5 Jun 2014 18:16:42 +0000 (14:16 -0400)
releases.moxie
src/main/java/com/gitblit/ConfigUserService.java
src/main/java/com/gitblit/GitBlit.java
src/main/java/com/gitblit/models/UserPreferences.java
src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
src/main/java/com/gitblit/wicket/pages/UserPage.html
src/main/java/com/gitblit/wicket/pages/UserPage.java

index fc139b7788a5b1774570fe08f84143b4bb882b0e..c1e11d9842f062aba0b0632fb314230396dc54b8 100644 (file)
@@ -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)
index 9759eff7802ac9fc4423d603113725b46e29f649..0c5b2a588f238a4c7a1e64c91fa1a29759705d1c 100644 (file)
@@ -36,6 +36,7 @@ import org.slf4j.LoggerFactory;
 \r
 import com.gitblit.Constants.AccessPermission;\r
 import com.gitblit.Constants.AccountType;\r
+import com.gitblit.Constants.Transport;\r
 import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.models.TeamModel;\r
 import com.gitblit.models.UserModel;\r
@@ -98,6 +99,8 @@ public class ConfigUserService implements IUserService {
 \r
        private static final String EMAILONMYTICKETCHANGES = "emailMeOnMyTicketChanges";\r
 \r
+       private static final String TRANSPORT = "transport";\r
+\r
        private static final String ACCOUNTTYPE = "accountType";\r
 \r
        private static final String DISABLED = "disabled";\r
@@ -713,7 +716,12 @@ public class ConfigUserService implements IUserService {
                                        String val = model.getPreferences().getLocale().getLanguage() + "_" + model.getPreferences().getLocale().getCountry();\r
                                        config.setString(USER, model.username, LOCALE, val);\r
                                }\r
+\r
                                config.setBoolean(USER, model.username, EMAILONMYTICKETCHANGES, model.getPreferences().isEmailMeOnMyTicketChanges());\r
+\r
+                               if (model.getPreferences().getTransport() != null) {\r
+                                       config.setString(USER, model.username, TRANSPORT, model.getPreferences().getTransport().name());\r
+                               }\r
                        }\r
 \r
                        // user roles\r
@@ -891,6 +899,7 @@ public class ConfigUserService implements IUserService {
                                        // preferences\r
                                        user.getPreferences().setLocale(config.getString(USER, username, LOCALE));\r
                                        user.getPreferences().setEmailMeOnMyTicketChanges(config.getBoolean(USER, username, EMAILONMYTICKETCHANGES, true));\r
+                                       user.getPreferences().setTransport(Transport.fromString(config.getString(USER, username, TRANSPORT)));\r
 \r
                                        // user roles\r
                                        Set<String> roles = new HashSet<String>(Arrays.asList(config.getStringList(\r
index 8179385026a24039e0abf3603434fb771aa474be..f9d9be9f3279efdb8dd6e30023d5b42a7baa9595 100644 (file)
@@ -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<RepositoryUrl> 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;
        }
 
index c95b0da5be34c26ed95fa027d137d152ab3edf83..90c034fc3104356243111cf55f9ec8af8cfaa585 100644 (file)
@@ -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<String, UserRepositoryPreferences> repositoryPreferences = new TreeMap<String, UserRepositoryPreferences>();
 
        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;
+       }
 }
index c80d45ced9e13971a3db34b8f05fbea74c098ba1..eb92e2d29e197ab8061e3756cb54e235f465062f 100644 (file)
@@ -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
index 017fcb1f3fc1ccc235acd1790f392ecb371e672f..8dccfee7dd0fc97e42c9b28f991a30ff88ff5493 100644 (file)
@@ -66,6 +66,7 @@
                        <div wicket:id="emailAddress"></div>\r
                        <div wicket:id="language"></div>\r
                        <div wicket:id="emailMeOnMyTicketChanges"></div>\r
+                       <div wicket:id="transport"></div>\r
                        \r
                        <div class="form-actions"><input class="btn btn-appmenu" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" /></div>\r
                </form> \r
index 00a36272ffdcf8bd0c60c3751a44689fbcaae69e..306eea65deb0bd367b5de45d3c0d385c8330215a 100644 (file)
@@ -35,6 +35,7 @@ import org.apache.wicket.markup.repeater.data.ListDataProvider;
 import org.apache.wicket.model.IModel;\r
 import org.apache.wicket.model.Model;\r
 \r
+import com.gitblit.Constants.Transport;\r
 import com.gitblit.GitBlitException;\r
 import com.gitblit.Keys;\r
 import com.gitblit.models.Menu.ParameterMenuItem;\r
@@ -221,6 +222,7 @@ public class UserPage extends RootPage {
                final IModel<String> emailAddress = Model.of(user.emailAddress == null ? "" : user.emailAddress);\r
                final IModel<Language> language = Model.of(preferredLanguage);\r
                final IModel<Boolean> emailMeOnMyTicketChanges = Model.of(user.getPreferences().isEmailMeOnMyTicketChanges());\r
+               final IModel<Transport> transport = Model.of(user.getPreferences().getTransport());\r
 \r
                prefs.add(new TextOption("displayName",\r
                                getString("gb.displayName"),\r
@@ -243,6 +245,24 @@ public class UserPage extends RootPage {
                                getString("gb.emailMeOnMyTicketChangesDescription"),\r
                                emailMeOnMyTicketChanges).setVisible(app().notifier().isSendingMail()));\r
 \r
+               List<Transport> availableTransports = new ArrayList<>();\r
+               if (app().gitblit().isServingSSH()) {\r
+                       availableTransports.add(Transport.SSH);\r
+               }\r
+               if (app().gitblit().isServingHTTP()) {\r
+                       availableTransports.add(Transport.HTTPS);\r
+                       availableTransports.add(Transport.HTTP);\r
+               }\r
+               if (app().gitblit().isServingGIT()) {\r
+                       availableTransports.add(Transport.GIT);\r
+               }\r
+\r
+               prefs.add(new ChoiceOption<Transport>("transport",\r
+                               getString("gb.transportPreference"),\r
+                               getString("gb.transportPreferenceDescription"),\r
+                               transport,\r
+                               availableTransports));\r
+\r
                prefs.add(new AjaxButton("save") {\r
 \r
                        private static final long serialVersionUID = 1L;\r
@@ -261,6 +281,7 @@ public class UserPage extends RootPage {
                                }\r
 \r
                                user.getPreferences().setEmailMeOnMyTicketChanges(emailMeOnMyTicketChanges.getObject());\r
+                               user.getPreferences().setTransport(transport.getObject());\r
 \r
                                try {\r
                                        app().gitblit().reviseUser(user.username, user);\r