]> source.dussan.org Git - gitblit.git/commitdiff
Fixed collision error on rename repository or user
authorJames Moger <james.moger@gitblit.com>
Sat, 22 Oct 2011 13:48:17 +0000 (09:48 -0400)
committerJames Moger <james.moger@gitblit.com>
Sat, 22 Oct 2011 13:48:17 +0000 (09:48 -0400)
docs/00_index.mkd
docs/04_releases.mkd
src/com/gitblit/GitBlit.java
src/com/gitblit/client/EditRepositoryDialog.java
src/com/gitblit/client/EditUserDialog.java
src/com/gitblit/client/GitblitPanel.java

index 6a2d0d18189920d79970b90bb6202ec2e587ec17..f34fd559827105407b00b64a59824c162ea5eba3 100644 (file)
@@ -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.\r
 - fixed: federation protocol timestamps.  dates are now serialized to the [iso8601](http://en.wikipedia.org/wiki/ISO_8601) standard.  \r
     **This breaks 0.6.0 federation clients/servers.**\r
+- fixed: collision on rename for repositories and users\r
 - fixed: Gitblit can now browse the Linux kernel repository (issue 25)\r
 - fixed: Gitblit now runs on Servlet 3.0 webservers (e.g. Tomcat 7, Jetty 8) (issue 23)\r
 - fixed: Set the RSS content type for Firefox 4 (issue 22)\r
index ba09075fbdef739fe3b82174bb1395fe564cebfd..4b538ba9a1aee48e47a601a0c9c678ab4a235696 100644 (file)
@@ -14,6 +14,7 @@
 - added: Gitblit Manager (Java/Swing Application) for remote administration of a Gitblit server.\r
 - fixed: federation protocol timestamps.  dates are now serialized to the [iso8601](http://en.wikipedia.org/wiki/ISO_8601) standard.  \r
     **This breaks 0.6.0 federation clients/servers.**\r
+- fixed: collision on rename for repositories and users\r
 - fixed: Gitblit can now browse the Linux kernel repository (issue 25)\r
 - fixed: Gitblit now runs on Servlet 3.0 webservers (e.g. Tomcat 7, Jetty 8) (issue 23)\r
 - fixed: Set the RSS content type for Firefox 4 (issue 22)\r
index eaf6a9576ae5c5733c5a91f77e98dc6d692b209d..6f537ec641954a2bf92bb394b87dda230656cfa5 100644 (file)
@@ -440,6 +440,14 @@ public class GitBlit implements ServletContextListener {
         */\r
        public void updateUserModel(String username, UserModel user, boolean isCreate)\r
                        throws GitBlitException {\r
+               if (!username.equalsIgnoreCase(user.username)) {\r
+                       if (userService.getUserModel(user.username) != null) {\r
+                               throw new GitBlitException(\r
+                                               MessageFormat\r
+                                                               .format("Failed to rename ''{0}'' because ''{1}'' already exists.",\r
+                                                                               username, user.username));\r
+                       }\r
+               }\r
                if (!userService.updateUserModel(username, user)) {\r
                        throw new GitBlitException(isCreate ? "Failed to add user!" : "Failed to update user!");\r
                }\r
@@ -722,6 +730,16 @@ public class GitBlit implements ServletContextListener {
                } else {\r
                        // rename repository\r
                        if (!repositoryName.equalsIgnoreCase(repository.name)) {\r
+                               if (!repository.name.toLowerCase().endsWith(\r
+                                               org.eclipse.jgit.lib.Constants.DOT_GIT_EXT)) {\r
+                                       repository.name += org.eclipse.jgit.lib.Constants.DOT_GIT_EXT;\r
+                               }\r
+                               if (new File(repositoriesFolder, repository.name).exists()) {\r
+                                       throw new GitBlitException(\r
+                                                       MessageFormat\r
+                                                                       .format("Failed to rename ''{0}'' because ''{1}'' already exists.",\r
+                                                                                       repositoryName, repository.name));\r
+                               }\r
                                closeRepository(repositoryName);\r
                                File folder = new File(repositoriesFolder, repositoryName);\r
                                File destFolder = new File(repositoriesFolder, repository.name);\r
index 93330cd1c44394250a4bab5f5bbb64c24c17b48f..c2d8f67212d0a81a80c3e12248d885bf7c0b027a 100644 (file)
@@ -63,6 +63,8 @@ public class EditRepositoryDialog extends JDialog {
 \r
        private static final long serialVersionUID = 1L;\r
 \r
+       private final String repositoryName;\r
+\r
        private final RepositoryModel repository;\r
 \r
        private boolean isCreate;\r
@@ -105,6 +107,7 @@ public class EditRepositoryDialog extends JDialog {
 \r
        public EditRepositoryDialog(RepositoryModel aRepository) {\r
                super();\r
+               this.repositoryName = aRepository.name;\r
                this.repository = new RepositoryModel();\r
                this.repositoryNames = new HashSet<String>();\r
                this.isCreate = false;\r
@@ -114,7 +117,7 @@ public class EditRepositoryDialog extends JDialog {
                setTitle(Translation.get("gb.edit") + ": " + aRepository.name);\r
                setIconImage(new ImageIcon(getClass().getResource("/gitblt-favicon.png")).getImage());\r
        }\r
-       \r
+\r
        @Override\r
        protected JRootPane createRootPane() {\r
                KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);\r
@@ -175,7 +178,8 @@ public class EditRepositoryDialog extends JDialog {
                fieldsPanel\r
                                .add(newFieldPanel(Translation.get("gb.showRemoteBranches"), showRemoteBranches));\r
                fieldsPanel.add(newFieldPanel(Translation.get("gb.showReadme"), showReadme));\r
-               fieldsPanel.add(newFieldPanel(Translation.get("gb.skipSizeCalculation"), skipSizeCalculation));\r
+               fieldsPanel.add(newFieldPanel(Translation.get("gb.skipSizeCalculation"),\r
+                               skipSizeCalculation));\r
                fieldsPanel.add(newFieldPanel(Translation.get("gb.isFrozen"), isFrozen));\r
 \r
                usersPalette = new JPalette<String>();\r
@@ -292,6 +296,16 @@ public class EditRepositoryDialog extends JDialog {
                                                "Can not create repository ''{0}'' because it already exists.", rname));\r
                                return false;\r
                        }\r
+               } else {\r
+                       // check rename collision\r
+                       if (!repositoryName.equalsIgnoreCase(rname)) {\r
+                               if (repositoryNames.contains(rname.toLowerCase())) {\r
+                                       error(MessageFormat.format(\r
+                                                       "Failed to rename ''{0}'' because ''{1}'' already exists.",\r
+                                                       repositoryName, rname));\r
+                                       return false;\r
+                               }\r
+                       }\r
                }\r
 \r
                if (accessRestriction.getSelectedItem() == null) {\r
index 988f8fb0c46bd74cd5a375b817d7514654a272d2..c77713a8e8a1ba639b751e8a28179d998691880e 100644 (file)
@@ -55,6 +55,8 @@ public class EditUserDialog extends JDialog {
 \r
        private static final long serialVersionUID = 1L;\r
 \r
+       private final String username;\r
+\r
        private final UserModel user;\r
 \r
        private final ServerSettings settings;\r
@@ -85,6 +87,7 @@ public class EditUserDialog extends JDialog {
 \r
        public EditUserDialog(UserModel anUser, ServerSettings settings) {\r
                super();\r
+               this.username = anUser.username;\r
                this.user = new UserModel("");\r
                this.settings = settings;\r
                this.usernames = new HashSet<String>();\r
@@ -194,6 +197,16 @@ public class EditUserDialog extends JDialog {
                                error(MessageFormat.format("Username ''{0}'' is unavailable.", uname));\r
                                return false;\r
                        }\r
+               } else {\r
+                       // check rename collision\r
+                       if (!username.equalsIgnoreCase(uname)) {\r
+                               if (usernames.contains(uname.toLowerCase())) {\r
+                                       error(MessageFormat.format(\r
+                                                       "Failed to rename ''{0}'' because ''{1}'' already exists.", username,\r
+                                                       uname));\r
+                                       return false;\r
+                               }\r
+                       }\r
                }\r
 \r
                int minLength = settings.get(Keys.realm.minPasswordLength).getInteger(5);\r
index e4c6e76c8d7593296c557135a5ef2916c6d7fb88..5737c15cac313a91e4fa79226f586c9a5605b8d6 100644 (file)
@@ -656,6 +656,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                List<String> usernames = gitblit.getUsernames();\r
                List<String> members = gitblit.getPermittedUsernames(repository);\r
                dialog.setUsers(repository.owner, usernames, members);\r
+               dialog.setRepositories(gitblit.getRepositories());\r
                dialog.setFederationSets(gitblit.getFederationSets(), repository.federationSets);\r
                dialog.setVisible(true);\r
                final RepositoryModel revisedRepository = dialog.getRepository();\r
@@ -798,6 +799,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
        protected void editUser(final UserModel user) {\r
                EditUserDialog dialog = new EditUserDialog(user, gitblit.getSettings());\r
                dialog.setLocationRelativeTo(GitblitPanel.this);\r
+               dialog.setUsers(gitblit.getUsers());\r
                dialog.setRepositories(gitblit.getRepositories(), new ArrayList<String>(user.repositories));\r
                dialog.setVisible(true);\r
                final UserModel revisedUser = dialog.getUser();\r