From f76fee63ed9cb3a30d3c0c092d860b1cb93a481b Mon Sep 17 00:00:00 2001 From: Gerard Smyth <gerard.smyth@gmail.com> Date: Thu, 08 May 2014 13:09:30 -0400 Subject: [PATCH] Updated the SyndicationServlet to provide an additional option to return details of the tags in the repository instead of the commits. This uses a new 'ot' request parameter to indicate the object type of the content to return, which can be ither TAG or COMMIT. If this is not provided, then COMMIT is assumed to maintain backwards compatability. If tags are returned, then the paging parameters, 'l' and 'pg' are still supported, but searching options are currently ignored. --- src/main/java/com/gitblit/wicket/pages/EditTeamPage.java | 44 ++++++++++++++++++++++++++++++++++++-------- 1 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gitblit/wicket/pages/EditTeamPage.java b/src/main/java/com/gitblit/wicket/pages/EditTeamPage.java index 32905c9..a0d11a0 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditTeamPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditTeamPage.java @@ -18,6 +18,7 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -28,6 +29,7 @@ import org.apache.wicket.extensions.markup.html.form.palette.Palette; import org.apache.wicket.markup.html.form.Button; import org.apache.wicket.markup.html.form.CheckBox; +import org.apache.wicket.markup.html.form.ChoiceRenderer; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.model.CompoundPropertyModel; @@ -41,6 +43,8 @@ import com.gitblit.Keys; import com.gitblit.models.RegistrantAccessPermission; import com.gitblit.models.TeamModel; +import com.gitblit.models.UserChoice; +import com.gitblit.models.UserModel; import com.gitblit.utils.StringUtils; import com.gitblit.wicket.RequiresAdminRole; import com.gitblit.wicket.StringChoiceRenderer; @@ -97,7 +101,6 @@ List<String> repos = getAccessRestrictedRepositoryList(true, null); List<String> teamUsers = new ArrayList<String>(teamModel.users); - Collections.sort(teamUsers); List<String> preReceiveScripts = new ArrayList<String>(); List<String> postReceiveScripts = new ArrayList<String>(); @@ -105,9 +108,8 @@ final List<RegistrantAccessPermission> permissions = teamModel.getRepositoryPermissions(); // users palette - final Palette<String> users = new Palette<String>("users", new ListModel<String>( - new ArrayList<String>(teamUsers)), new CollectionModel<String>(app().users() - .getAllUsernames()), new StringChoiceRenderer(), 10, false); + final Palette<UserChoice> users = new Palette<UserChoice>("users", new ListModel<UserChoice>( + getTeamUsers(teamUsers)), new CollectionModel<UserChoice>(sortByDisplayName(getTeamUsers(app().users().getAllUsernames()))), new ChoiceRenderer<UserChoice>(null, "userId"), 10, false); // pre-receive palette if (teamModel.preReceiveScripts != null) { @@ -155,10 +157,10 @@ teamModel.setRepositoryPermission(repositoryPermission.registrant, repositoryPermission.permission); } - Iterator<String> selectedUsers = users.getSelectedChoices(); + Iterator<UserChoice> selectedUsers = users.getSelectedChoices(); List<String> members = new ArrayList<String>(); while (selectedUsers.hasNext()) { - members.add(selectedUsers.next().toLowerCase()); + members.add(selectedUsers.next().getUserId().toLowerCase()); } teamModel.users.clear(); teamModel.users.addAll(members); @@ -196,7 +198,11 @@ teamModel.postReceiveScripts.addAll(postReceiveScripts); try { - app().users().updateTeamModel(oldName, teamModel, isCreate); + if (isCreate) { + app().gitblit().addTeam(teamModel); + } else { + app().gitblit().reviseTeam(oldName, teamModel); + } } catch (GitBlitException e) { error(e.getMessage()); return; @@ -216,7 +222,7 @@ form.add(new SimpleAttributeModifier("autocomplete", "off")); // not all user services support manipulating team memberships - boolean editMemberships = app().users().supportsTeamMembershipChanges(null); + boolean editMemberships = app().authentication().supportsTeamMembershipChanges(teamModel); // field names reflective match TeamModel fields form.add(new TextField<String>("name")); @@ -251,4 +257,26 @@ add(form); } + + private List<UserChoice> getTeamUsers(List<String> teamUserIds) { + List<UserChoice> teamUsers = new ArrayList<UserChoice>(); + for (String teamUserId : teamUserIds) { + UserModel userModel = app().users().getUserModel(teamUserId); + if (userModel!=null) { + teamUsers.add(new UserChoice(userModel.displayName, userModel.username, userModel.emailAddress)); + } + } + return sortByDisplayName(teamUsers); + } + + private List<UserChoice> sortByDisplayName(List<UserChoice> teamUsers) { + Collections.sort(teamUsers, new Comparator<UserChoice>() { + + @Override + public int compare(UserChoice o1, UserChoice o2) { + return o1.getDisplayNameOrUserId().compareTo(o2.getDisplayNameOrUserId()); + } + }); + return teamUsers; + } } -- Gitblit v1.9.1