- 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
--- /dev/null
+/*
+ * 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 + ")";
+ }
+}
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
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
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
\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
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
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
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
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
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
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
\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
}\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
@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
--- /dev/null
+/*
+ * 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());
+ }
+}
--- /dev/null
+/*\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