]> source.dussan.org Git - gitblit.git/commitdiff
Show "Displayname (username)" in palettes for edit team and repository pages 08/8/3
authorAlfred Schmid <A.Schmid@ff-muenchen.de>
Thu, 13 Feb 2014 08:47:53 +0000 (09:47 +0100)
committerJames Moger <james.moger@gitblit.com>
Wed, 19 Feb 2014 14:01:34 +0000 (09:01 -0500)
releases.moxie
src/main/java/com/gitblit/models/UserChoice.java [new file with mode: 0644]
src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java
src/main/java/com/gitblit/wicket/pages/EditTeamPage.java
src/main/resources/gitblit.css
src/test/java/com/gitblit/tests/GitBlitSuite.java
src/test/java/com/gitblit/tests/UserChoiceTest.java [new file with mode: 0644]
src/test/java/com/gitblit/tests/UserModelTest.java [new file with mode: 0644]

index 116fca950c6d76a210eb950c4e9bdbe2bd2b4cb1..66643cf9b91a3e7c281857e8092c75240c784a7b 100644 (file)
@@ -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 (file)
index 0000000..845ab7c
--- /dev/null
@@ -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 + ")";
+       }
+}
index a986fd53f5985608308f8f91ddc0d598494c2904..bb1661013679939239263a7a3c2e6b11f72bf047 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.basic.Label;\r
 import org.apache.wicket.markup.html.form.Button;\r
 import org.apache.wicket.markup.html.form.CheckBox;\r
+import org.apache.wicket.markup.html.form.ChoiceRenderer;\r
 import org.apache.wicket.markup.html.form.DropDownChoice;\r
 import org.apache.wicket.markup.html.form.Form;\r
 import org.apache.wicket.markup.html.form.IChoiceRenderer;\r
@@ -59,6 +60,7 @@ import com.gitblit.GitBlitException;
 import com.gitblit.Keys;\r
 import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.RepositoryModel;\r
+import com.gitblit.models.UserChoice;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.ArrayUtils;\r
 import com.gitblit.utils.StringUtils;\r
@@ -172,10 +174,26 @@ public class EditRepositoryPage extends RootSubPage {
                                RegistrantType.TEAM, app().users().getAllTeamNames(), repositoryTeams, getAccessPermissions());\r
 \r
                // owners palette\r
-               List<String> owners = new ArrayList<String>(repositoryModel.owners);\r
-               List<String> persons = app().users().getAllUsernames();\r
-               final Palette<String> ownersPalette = new Palette<String>("owners", new ListModel<String>(owners), new CollectionModel<String>(\r
-                     persons), new StringChoiceRenderer(), 12, true);\r
+               List<UserChoice> owners = new ArrayList<UserChoice>();\r
+               for (String owner : repositoryModel.owners) {\r
+                       UserModel o = app().users().getUserModel(owner);\r
+                       if (o != null) {\r
+                               owners.add(new UserChoice(o.getDisplayName(), o.username, o.emailAddress));\r
+                       } else {\r
+                               owners.add(new UserChoice(owner));\r
+                       }\r
+               }\r
+               List<UserChoice> persons = new ArrayList<UserChoice>();\r
+               for (String person : app().users().getAllUsernames()) {\r
+                       UserModel o = app().users().getUserModel(person);\r
+                       if (o != null) {\r
+                               persons.add(new UserChoice(o.getDisplayName(), o.username, o.emailAddress));\r
+                       } else {\r
+                               persons.add(new UserChoice(person));\r
+                       }\r
+               }\r
+               final Palette<UserChoice> ownersPalette = new Palette<UserChoice>("owners", new ListModel<UserChoice>(owners), new CollectionModel<UserChoice>(\r
+                     persons), new ChoiceRenderer<UserChoice>(null, "userId"), 12, true);\r
 \r
                // indexed local branches palette\r
                List<String> allLocalBranches = new ArrayList<String>();\r
@@ -358,9 +376,9 @@ public class EditRepositoryPage extends RootSubPage {
 \r
                                        // owners\r
                                        repositoryModel.owners.clear();\r
-                                       Iterator<String> owners = ownersPalette.getSelectedChoices();\r
+                                       Iterator<UserChoice> owners = ownersPalette.getSelectedChoices();\r
                                        while (owners.hasNext()) {\r
-                                               repositoryModel.addOwner(owners.next());\r
+                                               repositoryModel.addOwner(owners.next().getUserId());\r
                                        }\r
 \r
                                        // pre-receive scripts\r
index 82b28fc4526b95f1a5eeeab23402e2eac4928f1b..a0d11a057929fe6f12428afeadf665671b817f8a 100644 (file)
@@ -18,6 +18,7 @@ package com.gitblit.wicket.pages;
 import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
 import java.util.Collections;\r
+import java.util.Comparator;\r
 import java.util.HashSet;\r
 import java.util.Iterator;\r
 import java.util.List;\r
@@ -28,6 +29,7 @@ import org.apache.wicket.behavior.SimpleAttributeModifier;
 import org.apache.wicket.extensions.markup.html.form.palette.Palette;\r
 import org.apache.wicket.markup.html.form.Button;\r
 import org.apache.wicket.markup.html.form.CheckBox;\r
+import org.apache.wicket.markup.html.form.ChoiceRenderer;\r
 import org.apache.wicket.markup.html.form.Form;\r
 import org.apache.wicket.markup.html.form.TextField;\r
 import org.apache.wicket.model.CompoundPropertyModel;\r
@@ -41,6 +43,8 @@ import com.gitblit.GitBlitException;
 import com.gitblit.Keys;\r
 import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.TeamModel;\r
+import com.gitblit.models.UserChoice;\r
+import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.RequiresAdminRole;\r
 import com.gitblit.wicket.StringChoiceRenderer;\r
@@ -97,7 +101,6 @@ public class EditTeamPage extends RootSubPage {
                List<String> repos = getAccessRestrictedRepositoryList(true, null);\r
 \r
                List<String> teamUsers = new ArrayList<String>(teamModel.users);\r
-               Collections.sort(teamUsers);\r
                List<String> preReceiveScripts = new ArrayList<String>();\r
                List<String> postReceiveScripts = new ArrayList<String>();\r
 \r
@@ -105,9 +108,8 @@ public class EditTeamPage extends RootSubPage {
                final List<RegistrantAccessPermission> permissions = teamModel.getRepositoryPermissions();\r
 \r
                // users palette\r
-               final Palette<String> users = new Palette<String>("users", new ListModel<String>(\r
-                               new ArrayList<String>(teamUsers)), new CollectionModel<String>(app().users()\r
-                               .getAllUsernames()), new StringChoiceRenderer(), 10, false);\r
+               final Palette<UserChoice> users = new Palette<UserChoice>("users", new ListModel<UserChoice>(\r
+                               getTeamUsers(teamUsers)), new CollectionModel<UserChoice>(sortByDisplayName(getTeamUsers(app().users().getAllUsernames()))), new ChoiceRenderer<UserChoice>(null, "userId"), 10, false);\r
 \r
                // pre-receive palette\r
                if (teamModel.preReceiveScripts != null) {\r
@@ -155,10 +157,10 @@ public class EditTeamPage extends RootSubPage {
                                        teamModel.setRepositoryPermission(repositoryPermission.registrant, repositoryPermission.permission);\r
                                }\r
 \r
-                               Iterator<String> selectedUsers = users.getSelectedChoices();\r
+                               Iterator<UserChoice> selectedUsers = users.getSelectedChoices();\r
                                List<String> members = new ArrayList<String>();\r
                                while (selectedUsers.hasNext()) {\r
-                                       members.add(selectedUsers.next().toLowerCase());\r
+                                       members.add(selectedUsers.next().getUserId().toLowerCase());\r
                                }\r
                                teamModel.users.clear();\r
                                teamModel.users.addAll(members);\r
@@ -255,4 +257,26 @@ public class EditTeamPage extends RootSubPage {
 \r
                add(form);\r
        }\r
+\r
+       private List<UserChoice> getTeamUsers(List<String> teamUserIds) {\r
+               List<UserChoice> teamUsers = new ArrayList<UserChoice>();\r
+               for (String teamUserId : teamUserIds) {\r
+                       UserModel userModel = app().users().getUserModel(teamUserId);\r
+                       if (userModel!=null) {\r
+                               teamUsers.add(new UserChoice(userModel.displayName, userModel.username, userModel.emailAddress));\r
+                       }\r
+               }\r
+               return sortByDisplayName(teamUsers);\r
+       }\r
+\r
+       private List<UserChoice> sortByDisplayName(List<UserChoice> teamUsers) {\r
+               Collections.sort(teamUsers, new Comparator<UserChoice>() {\r
+\r
+                       @Override\r
+                       public int compare(UserChoice o1, UserChoice o2) {\r
+                               return o1.getDisplayNameOrUserId().compareTo(o2.getDisplayNameOrUserId());\r
+                       }\r
+               });\r
+               return teamUsers;\r
+       }\r
 }\r
index 58c0aed59eabb34e7f96988cb5ef77b4504f2c65..91825f7e3e991e4ac3062e1d839a4a511e35d940 100644 (file)
@@ -1291,6 +1291,11 @@ table.palette td.header {
 }\r
 table.palette td.pane {\r
        padding: 0px;\r
+       width: 250px !important;\r
+}\r
+\r
+table.palette td.pane select {\r
+       width: 250px !important;\r
 }\r
 \r
 table.gitnotes {               \r
index 81180276ff5fab79ce414f6d0ddc7459723d4439..7b38c18351d060550dfd17f7a9a95403a775f50e 100644 (file)
@@ -56,6 +56,7 @@ import com.gitblit.utils.JGitUtils;
 @RunWith(Suite.class)\r
 @SuiteClasses({ ArrayUtilsTest.class, FileUtilsTest.class, TimeUtilsTest.class,\r
                StringUtilsTest.class, Base64Test.class, JsonUtilsTest.class, ByteFormatTest.class,\r
+               UserModelTest.class, UserChoiceTest.class,\r
                ObjectCacheTest.class, PermissionsTest.class, UserServiceTest.class, LdapAuthenticationTest.class,\r
                MarkdownUtilsTest.class, JGitUtilsTest.class, SyndicationUtilsTest.class,\r
                DiffUtilsTest.class, MetricUtilsTest.class, X509UtilsTest.class,\r
diff --git a/src/test/java/com/gitblit/tests/UserChoiceTest.java b/src/test/java/com/gitblit/tests/UserChoiceTest.java
new file mode 100644 (file)
index 0000000..b0effcd
--- /dev/null
@@ -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 (file)
index 0000000..0de02d5
--- /dev/null
@@ -0,0 +1,52 @@
+/*\r
+ * Copyright 2014 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.tests;\r
+\r
+import org.junit.Test;\r
+\r
+import com.gitblit.models.UserModel;\r
+\r
+/**\r
+ * @author Alfred Schmid\r
+ *\r
+ */\r
+public class UserModelTest extends GitblitUnitTest {\r
+\r
+       @Test\r
+       public void whenDisplayNameIsEmptyUsernameIsUsed() {\r
+               String username = "test";\r
+               UserModel userModel = new UserModel(username);\r
+               userModel.displayName = "";\r
+               assertEquals("When displayName is empty the username has to be returnd from getDisplayName().", username, userModel.getDisplayName());\r
+       }\r
+\r
+       @Test\r
+       public void whenDisplayNameIsNullUsernameIsUsed() {\r
+               String username = "test";\r
+               UserModel userModel = new UserModel(username);\r
+               userModel.displayName = null;\r
+               assertEquals("When displayName is null the username has to be returnd from getDisplayName().", username, userModel.getDisplayName());\r
+       }\r
+\r
+       @Test\r
+       public void whenDisplayNameIsNotEmptyDisplayNameIsUsed() {\r
+               String displayName = "Test User";\r
+               UserModel userModel = new UserModel("test");\r
+               userModel.displayName = displayName;\r
+               assertEquals("When displayName is not empty its value has to be returnd from getDisplayName().", displayName, userModel.getDisplayName());\r
+       }\r
+\r
+}\r