diff options
author | James Moger <james.moger@gitblit.com> | 2014-06-05 12:19:03 -0600 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-06-05 12:19:03 -0600 |
commit | 37c0e22f7bab9846e81626964942b17a49cf6bfd (patch) | |
tree | e6e18f88ed99c825f58f0cfaceb7123aec75dba7 | |
parent | 6551f2c076fd5b4a836bdc9bd3e09205b0673472 (diff) | |
parent | 1b04d7730f56a08c935974504b2d849d01870c02 (diff) | |
download | gitblit-37c0e22f7bab9846e81626964942b17a49cf6bfd.tar.gz gitblit-37c0e22f7bab9846e81626964942b17a49cf6bfd.zip |
Merged #90 "Add a user preference for the clone transport"
-rw-r--r-- | releases.moxie | 1 | ||||
-rw-r--r-- | src/main/java/com/gitblit/ConfigUserService.java | 9 | ||||
-rw-r--r-- | src/main/java/com/gitblit/GitBlit.java | 19 | ||||
-rw-r--r-- | src/main/java/com/gitblit/models/UserPreferences.java | 11 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/GitBlitWebApp.properties | 4 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/UserPage.html | 1 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/UserPage.java | 21 |
7 files changed, 65 insertions, 1 deletions
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<String> roles = new HashSet<String>(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<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; } 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<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; + } } 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 @@ <div wicket:id="emailAddress"></div>
<div wicket:id="language"></div>
<div wicket:id="emailMeOnMyTicketChanges"></div>
+ <div wicket:id="transport"></div>
<div class="form-actions"><input class="btn btn-appmenu" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" /></div>
</form>
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<String> emailAddress = Model.of(user.emailAddress == null ? "" : user.emailAddress);
final IModel<Language> language = Model.of(preferredLanguage);
final IModel<Boolean> emailMeOnMyTicketChanges = Model.of(user.getPreferences().isEmailMeOnMyTicketChanges());
+ final IModel<Transport> 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<Transport> 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>("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);
|