diff options
author | James Moger <james.moger@gitblit.com> | 2014-02-19 09:04:55 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-02-19 09:04:55 -0500 |
commit | b2775fefaafb0ce89094bdd4bb5308dbb90f487b (patch) | |
tree | 4f5398a3bdbaecca25a1a5b0858cb90ac3b63383 /src/main/java/com/gitblit | |
parent | 0648b33b882a5bb2ddef3cad7c16df15158af8a0 (diff) | |
parent | 37d5b7cda27ae7da5690f0b0ce0dee4421624810 (diff) | |
download | gitblit-b2775fefaafb0ce89094bdd4bb5308dbb90f487b.tar.gz gitblit-b2775fefaafb0ce89094bdd4bb5308dbb90f487b.zip |
Merge commit 'refs/tickets/08/8/3' of https://dev.gitblit.com/r/gitblit
Diffstat (limited to 'src/main/java/com/gitblit')
3 files changed, 166 insertions, 12 deletions
diff --git a/src/main/java/com/gitblit/models/UserChoice.java b/src/main/java/com/gitblit/models/UserChoice.java new file mode 100644 index 00000000..845ab7c7 --- /dev/null +++ b/src/main/java/com/gitblit/models/UserChoice.java @@ -0,0 +1,112 @@ +/* + * Copyright 2014 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.models; + +import java.io.Serializable; + +import com.gitblit.utils.StringUtils; + +/** + * @author Alfred Schmid + * @author James Moger + * + */ +public class UserChoice implements Serializable { + + private static final long serialVersionUID = 1L; + + private final String displayName; + private final String userId; + private final String email; + + /** + * Create a UserChoice without email and displayName. + * + * @param userId + * the unique id of the user (in most cases the unique username + * from user store). Can never be null or empty string. + * + */ + public UserChoice(String userId) { + this(null, userId, null); + } + + /** + * Create a UserChoice without email. + * + * @param displayName + * the display name for the user. Can be null or empty string. + * @param userId + * the unique id of the user (in most cases the unique username + * from user store). Can never be null or empty string. + * + */ + public UserChoice(String displayName, String userId) { + this(displayName, userId, null); + } + + /** + * Create a UserChoice with email and displayName. + * + * @param displayName + * the display name for the user. Can be null or empty string. + * @param userId + * the unique id of the user (in most cases the unique username + * from user store). Can never be null or empty string. + * @param email + * the email from the user. Can be null or empty string. + * + */ + public UserChoice(String displayName, String userId, String email) { + if (userId == null) { + throw new IllegalArgumentException("The argument userId can't be null!"); + } + if ("".equals(userId)) { + throw new IllegalArgumentException("The argument userId can't be an empty String!"); + } + this.displayName = displayName; + this.userId = userId; + this.email = email; + } + + public String getDisplayName() { + return displayName; + } + + public String getDisplayNameOrUserId() { + if (StringUtils.isEmpty(displayName)) { + return userId; + } + return displayName; + } + + public String getUserId() { + return userId; + } + + public String getEmail() { + return email; + } + + @Override + public String toString() { + String dn = getDisplayNameOrUserId(); + if (dn.equals(userId)) { + return dn; + } + return dn + " (" + userId + ")"; + } +} diff --git a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java index a986fd53..bb166101 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -36,6 +36,7 @@ import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label;
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.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
@@ -59,6 +60,7 @@ import com.gitblit.GitBlitException; import com.gitblit.Keys;
import com.gitblit.models.RegistrantAccessPermission;
import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.UserChoice;
import com.gitblit.models.UserModel;
import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.StringUtils;
@@ -172,10 +174,26 @@ public class EditRepositoryPage extends RootSubPage { RegistrantType.TEAM, app().users().getAllTeamNames(), repositoryTeams, getAccessPermissions());
// owners palette
- List<String> owners = new ArrayList<String>(repositoryModel.owners);
- List<String> persons = app().users().getAllUsernames();
- final Palette<String> ownersPalette = new Palette<String>("owners", new ListModel<String>(owners), new CollectionModel<String>(
- persons), new StringChoiceRenderer(), 12, true);
+ List<UserChoice> owners = new ArrayList<UserChoice>();
+ for (String owner : repositoryModel.owners) {
+ UserModel o = app().users().getUserModel(owner);
+ if (o != null) {
+ owners.add(new UserChoice(o.getDisplayName(), o.username, o.emailAddress));
+ } else {
+ owners.add(new UserChoice(owner));
+ }
+ }
+ List<UserChoice> persons = new ArrayList<UserChoice>();
+ for (String person : app().users().getAllUsernames()) {
+ UserModel o = app().users().getUserModel(person);
+ if (o != null) {
+ persons.add(new UserChoice(o.getDisplayName(), o.username, o.emailAddress));
+ } else {
+ persons.add(new UserChoice(person));
+ }
+ }
+ final Palette<UserChoice> ownersPalette = new Palette<UserChoice>("owners", new ListModel<UserChoice>(owners), new CollectionModel<UserChoice>(
+ persons), new ChoiceRenderer<UserChoice>(null, "userId"), 12, true);
// indexed local branches palette
List<String> allLocalBranches = new ArrayList<String>();
@@ -358,9 +376,9 @@ public class EditRepositoryPage extends RootSubPage { // owners
repositoryModel.owners.clear();
- Iterator<String> owners = ownersPalette.getSelectedChoices();
+ Iterator<UserChoice> owners = ownersPalette.getSelectedChoices();
while (owners.hasNext()) {
- repositoryModel.addOwner(owners.next());
+ repositoryModel.addOwner(owners.next().getUserId());
}
// pre-receive scripts
diff --git a/src/main/java/com/gitblit/wicket/pages/EditTeamPage.java b/src/main/java/com/gitblit/wicket/pages/EditTeamPage.java index 82b28fc4..a0d11a05 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 @@ package com.gitblit.wicket.pages; 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.behavior.SimpleAttributeModifier; 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.GitBlitException; 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 @@ public class EditTeamPage extends RootSubPage { 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 @@ public class EditTeamPage extends RootSubPage { 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 @@ public class EditTeamPage extends RootSubPage { 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);
@@ -255,4 +257,26 @@ public class EditTeamPage extends RootSubPage { 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;
+ }
}
|