summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlfred Schmid <A.Schmid@ff-muenchen.de>2014-02-13 09:47:53 +0100
committerJames Moger <james.moger@gitblit.com>2014-02-19 09:01:34 -0500
commit37d5b7cda27ae7da5690f0b0ce0dee4421624810 (patch)
tree4f5398a3bdbaecca25a1a5b0858cb90ac3b63383
parent0648b33b882a5bb2ddef3cad7c16df15158af8a0 (diff)
downloadgitblit-37d5b7cda27ae7da5690f0b0ce0dee4421624810.tar.gz
gitblit-37d5b7cda27ae7da5690f0b0ce0dee4421624810.zip
Show "Displayname (username)" in palettes for edit team and repository pages
-rw-r--r--releases.moxie1
-rw-r--r--src/main/java/com/gitblit/models/UserChoice.java112
-rw-r--r--src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java30
-rw-r--r--src/main/java/com/gitblit/wicket/pages/EditTeamPage.java36
-rw-r--r--src/main/resources/gitblit.css5
-rw-r--r--src/test/java/com/gitblit/tests/GitBlitSuite.java1
-rw-r--r--src/test/java/com/gitblit/tests/UserChoiceTest.java63
-rw-r--r--src/test/java/com/gitblit/tests/UserModelTest.java52
8 files changed, 288 insertions, 12 deletions
diff --git a/releases.moxie b/releases.moxie
index 116fca95..66643cf9 100644
--- a/releases.moxie
+++ b/releases.moxie
@@ -33,6 +33,7 @@ r20: {
- Reversed line links in blob view (issue-309)
- Dashboard and Activity pages now obey the web.generateActivityGraph setting (issue-310)
- Do not log passwords on failed authentication attempts (issue-316)
+ - Show displayname and username in palettes (issue-364)
- Updated default binary and Lucene ignore extensions
- Change the WAR baseFolder context parameter to a JNDI env-entry to improve enterprise deployments
- Removed internal Gitblit ref exclusions in the upload pack
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;
+ }
}
diff --git a/src/main/resources/gitblit.css b/src/main/resources/gitblit.css
index 58c0aed5..91825f7e 100644
--- a/src/main/resources/gitblit.css
+++ b/src/main/resources/gitblit.css
@@ -1291,6 +1291,11 @@ table.palette td.header {
}
table.palette td.pane {
padding: 0px;
+ width: 250px !important;
+}
+
+table.palette td.pane select {
+ width: 250px !important;
}
table.gitnotes {
diff --git a/src/test/java/com/gitblit/tests/GitBlitSuite.java b/src/test/java/com/gitblit/tests/GitBlitSuite.java
index 81180276..7b38c183 100644
--- a/src/test/java/com/gitblit/tests/GitBlitSuite.java
+++ b/src/test/java/com/gitblit/tests/GitBlitSuite.java
@@ -56,6 +56,7 @@ import com.gitblit.utils.JGitUtils;
@RunWith(Suite.class)
@SuiteClasses({ ArrayUtilsTest.class, FileUtilsTest.class, TimeUtilsTest.class,
StringUtilsTest.class, Base64Test.class, JsonUtilsTest.class, ByteFormatTest.class,
+ UserModelTest.class, UserChoiceTest.class,
ObjectCacheTest.class, PermissionsTest.class, UserServiceTest.class, LdapAuthenticationTest.class,
MarkdownUtilsTest.class, JGitUtilsTest.class, SyndicationUtilsTest.class,
DiffUtilsTest.class, MetricUtilsTest.class, X509UtilsTest.class,
diff --git a/src/test/java/com/gitblit/tests/UserChoiceTest.java b/src/test/java/com/gitblit/tests/UserChoiceTest.java
new file mode 100644
index 00000000..b0effcd1
--- /dev/null
+++ b/src/test/java/com/gitblit/tests/UserChoiceTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.tests;
+
+import org.junit.Test;
+
+import com.gitblit.models.UserChoice;
+
+/**
+ * Test behavior of UserChoice class.
+ *
+ * @author Alfred Schmid
+ *
+ */
+public class UserChoiceTest extends GitblitUnitTest {
+
+ @Test(expected=IllegalArgumentException.class)
+ public void creatingUserChoiceWithNullAsUserIdIsImpossible() {
+ new UserChoice(null);
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void creatingUserChoiceWithEmptyStringAsUserIdIsImpossible() {
+ new UserChoice("");
+ }
+
+ @Test
+ public void toStringPrintsPlainUserIdWhenDisplayNameIsNull() {
+ String userId = "runnerr";
+ UserChoice userChoice = new UserChoice(userId);
+ assertEquals("", userId, userChoice.toString());
+ }
+
+ @Test
+ public void toStringPrintsPlainUserIdWhenDisplayNameIsEmpty() {
+ String userId = "runnerr";
+ UserChoice userChoice = new UserChoice("", userId);
+ assertEquals("", userId, userChoice.toString());
+ }
+
+ @Test
+ public void toStringPrintsDisplaNameWithUserIdInBracketsWhenDisplayNameIsSet() {
+ String userId = "runnerr";
+ String displayName = "The Road Runner";
+ UserChoice userChoice = new UserChoice(displayName, userId);
+ assertEquals(
+ "displayName + userId have to be concatenated to: displayName (userId)",
+ displayName + " (" + userId + ")", userChoice.toString());
+ }
+}
diff --git a/src/test/java/com/gitblit/tests/UserModelTest.java b/src/test/java/com/gitblit/tests/UserModelTest.java
new file mode 100644
index 00000000..0de02d57
--- /dev/null
+++ b/src/test/java/com/gitblit/tests/UserModelTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.tests;
+
+import org.junit.Test;
+
+import com.gitblit.models.UserModel;
+
+/**
+ * @author Alfred Schmid
+ *
+ */
+public class UserModelTest extends GitblitUnitTest {
+
+ @Test
+ public void whenDisplayNameIsEmptyUsernameIsUsed() {
+ String username = "test";
+ UserModel userModel = new UserModel(username);
+ userModel.displayName = "";
+ assertEquals("When displayName is empty the username has to be returnd from getDisplayName().", username, userModel.getDisplayName());
+ }
+
+ @Test
+ public void whenDisplayNameIsNullUsernameIsUsed() {
+ String username = "test";
+ UserModel userModel = new UserModel(username);
+ userModel.displayName = null;
+ assertEquals("When displayName is null the username has to be returnd from getDisplayName().", username, userModel.getDisplayName());
+ }
+
+ @Test
+ public void whenDisplayNameIsNotEmptyDisplayNameIsUsed() {
+ String displayName = "Test User";
+ UserModel userModel = new UserModel("test");
+ userModel.displayName = displayName;
+ assertEquals("When displayName is not empty its value has to be returnd from getDisplayName().", displayName, userModel.getDisplayName());
+ }
+
+}