From: James Moger Date: Sat, 22 Oct 2011 13:48:17 +0000 (-0400) Subject: Fixed collision error on rename repository or user X-Git-Tag: v0.7.0~58 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=16038ce2adf5f06f75230150f75d110a804414c1;p=gitblit.git Fixed collision error on rename repository or user --- diff --git a/docs/00_index.mkd b/docs/00_index.mkd index 6a2d0d18..f34fd559 100644 --- a/docs/00_index.mkd +++ b/docs/00_index.mkd @@ -40,6 +40,7 @@ Gitblit requires a Java 6 Runtime Environment (JRE) or a Java 6 Development Kit - added: Gitblit Manager (Java/Swing Application) for remote administration of a Gitblit server. - fixed: federation protocol timestamps. dates are now serialized to the [iso8601](http://en.wikipedia.org/wiki/ISO_8601) standard. **This breaks 0.6.0 federation clients/servers.** +- fixed: collision on rename for repositories and users - fixed: Gitblit can now browse the Linux kernel repository (issue 25) - fixed: Gitblit now runs on Servlet 3.0 webservers (e.g. Tomcat 7, Jetty 8) (issue 23) - fixed: Set the RSS content type for Firefox 4 (issue 22) diff --git a/docs/04_releases.mkd b/docs/04_releases.mkd index ba09075f..4b538ba9 100644 --- a/docs/04_releases.mkd +++ b/docs/04_releases.mkd @@ -14,6 +14,7 @@ - added: Gitblit Manager (Java/Swing Application) for remote administration of a Gitblit server. - fixed: federation protocol timestamps. dates are now serialized to the [iso8601](http://en.wikipedia.org/wiki/ISO_8601) standard. **This breaks 0.6.0 federation clients/servers.** +- fixed: collision on rename for repositories and users - fixed: Gitblit can now browse the Linux kernel repository (issue 25) - fixed: Gitblit now runs on Servlet 3.0 webservers (e.g. Tomcat 7, Jetty 8) (issue 23) - fixed: Set the RSS content type for Firefox 4 (issue 22) diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index eaf6a957..6f537ec6 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -440,6 +440,14 @@ public class GitBlit implements ServletContextListener { */ public void updateUserModel(String username, UserModel user, boolean isCreate) throws GitBlitException { + if (!username.equalsIgnoreCase(user.username)) { + if (userService.getUserModel(user.username) != null) { + throw new GitBlitException( + MessageFormat + .format("Failed to rename ''{0}'' because ''{1}'' already exists.", + username, user.username)); + } + } if (!userService.updateUserModel(username, user)) { throw new GitBlitException(isCreate ? "Failed to add user!" : "Failed to update user!"); } @@ -722,6 +730,16 @@ public class GitBlit implements ServletContextListener { } else { // rename repository if (!repositoryName.equalsIgnoreCase(repository.name)) { + if (!repository.name.toLowerCase().endsWith( + org.eclipse.jgit.lib.Constants.DOT_GIT_EXT)) { + repository.name += org.eclipse.jgit.lib.Constants.DOT_GIT_EXT; + } + if (new File(repositoriesFolder, repository.name).exists()) { + throw new GitBlitException( + MessageFormat + .format("Failed to rename ''{0}'' because ''{1}'' already exists.", + repositoryName, repository.name)); + } closeRepository(repositoryName); File folder = new File(repositoriesFolder, repositoryName); File destFolder = new File(repositoriesFolder, repository.name); diff --git a/src/com/gitblit/client/EditRepositoryDialog.java b/src/com/gitblit/client/EditRepositoryDialog.java index 93330cd1..c2d8f672 100644 --- a/src/com/gitblit/client/EditRepositoryDialog.java +++ b/src/com/gitblit/client/EditRepositoryDialog.java @@ -63,6 +63,8 @@ public class EditRepositoryDialog extends JDialog { private static final long serialVersionUID = 1L; + private final String repositoryName; + private final RepositoryModel repository; private boolean isCreate; @@ -105,6 +107,7 @@ public class EditRepositoryDialog extends JDialog { public EditRepositoryDialog(RepositoryModel aRepository) { super(); + this.repositoryName = aRepository.name; this.repository = new RepositoryModel(); this.repositoryNames = new HashSet(); this.isCreate = false; @@ -114,7 +117,7 @@ public class EditRepositoryDialog extends JDialog { setTitle(Translation.get("gb.edit") + ": " + aRepository.name); setIconImage(new ImageIcon(getClass().getResource("/gitblt-favicon.png")).getImage()); } - + @Override protected JRootPane createRootPane() { KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); @@ -175,7 +178,8 @@ public class EditRepositoryDialog extends JDialog { fieldsPanel .add(newFieldPanel(Translation.get("gb.showRemoteBranches"), showRemoteBranches)); fieldsPanel.add(newFieldPanel(Translation.get("gb.showReadme"), showReadme)); - fieldsPanel.add(newFieldPanel(Translation.get("gb.skipSizeCalculation"), skipSizeCalculation)); + fieldsPanel.add(newFieldPanel(Translation.get("gb.skipSizeCalculation"), + skipSizeCalculation)); fieldsPanel.add(newFieldPanel(Translation.get("gb.isFrozen"), isFrozen)); usersPalette = new JPalette(); @@ -292,6 +296,16 @@ public class EditRepositoryDialog extends JDialog { "Can not create repository ''{0}'' because it already exists.", rname)); return false; } + } else { + // check rename collision + if (!repositoryName.equalsIgnoreCase(rname)) { + if (repositoryNames.contains(rname.toLowerCase())) { + error(MessageFormat.format( + "Failed to rename ''{0}'' because ''{1}'' already exists.", + repositoryName, rname)); + return false; + } + } } if (accessRestriction.getSelectedItem() == null) { diff --git a/src/com/gitblit/client/EditUserDialog.java b/src/com/gitblit/client/EditUserDialog.java index 988f8fb0..c77713a8 100644 --- a/src/com/gitblit/client/EditUserDialog.java +++ b/src/com/gitblit/client/EditUserDialog.java @@ -55,6 +55,8 @@ public class EditUserDialog extends JDialog { private static final long serialVersionUID = 1L; + private final String username; + private final UserModel user; private final ServerSettings settings; @@ -85,6 +87,7 @@ public class EditUserDialog extends JDialog { public EditUserDialog(UserModel anUser, ServerSettings settings) { super(); + this.username = anUser.username; this.user = new UserModel(""); this.settings = settings; this.usernames = new HashSet(); @@ -194,6 +197,16 @@ public class EditUserDialog extends JDialog { error(MessageFormat.format("Username ''{0}'' is unavailable.", uname)); return false; } + } else { + // check rename collision + if (!username.equalsIgnoreCase(uname)) { + if (usernames.contains(uname.toLowerCase())) { + error(MessageFormat.format( + "Failed to rename ''{0}'' because ''{1}'' already exists.", username, + uname)); + return false; + } + } } int minLength = settings.get(Keys.realm.minPasswordLength).getInteger(5); diff --git a/src/com/gitblit/client/GitblitPanel.java b/src/com/gitblit/client/GitblitPanel.java index e4c6e76c..5737c15c 100644 --- a/src/com/gitblit/client/GitblitPanel.java +++ b/src/com/gitblit/client/GitblitPanel.java @@ -656,6 +656,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { List usernames = gitblit.getUsernames(); List members = gitblit.getPermittedUsernames(repository); dialog.setUsers(repository.owner, usernames, members); + dialog.setRepositories(gitblit.getRepositories()); dialog.setFederationSets(gitblit.getFederationSets(), repository.federationSets); dialog.setVisible(true); final RepositoryModel revisedRepository = dialog.getRepository(); @@ -798,6 +799,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { protected void editUser(final UserModel user) { EditUserDialog dialog = new EditUserDialog(user, gitblit.getSettings()); dialog.setLocationRelativeTo(GitblitPanel.this); + dialog.setUsers(gitblit.getUsers()); dialog.setRepositories(gitblit.getRepositories(), new ArrayList(user.repositories)); dialog.setVisible(true); final UserModel revisedUser = dialog.getUser();