]> source.dussan.org Git - gitblit.git/commitdiff
Restore original team or user object on failure to update (issue 118)
authorJames Moger <james.moger@gitblit.com>
Mon, 6 Aug 2012 21:34:44 +0000 (17:34 -0400)
committerJames Moger <james.moger@gitblit.com>
Mon, 6 Aug 2012 21:34:44 +0000 (17:34 -0400)
docs/04_releases.mkd
src/com/gitblit/ConfigUserService.java

index b2a373c94abfa6056f9e2a45b0d6e49cb79f236c..ac3b31e9824f7c0f11c00482da671b98e7340c6e 100644 (file)
@@ -11,6 +11,7 @@ If you are updating from an earlier release AND you have indexed branches with t
 \r
 #### fixes\r
 \r
+- Restore original user or team object on failure to update (issue 118)\r
 - Repository URL uses `X-Forwarded-Proto` and `X-Forwarded-Port`, if available, for reverse proxy configurations (issue 115)\r
 - Fixes to relative path determination in repository searh algorithm for symlinks (issue 116)\r
 - Output real RAW content, not simulated RAW content (issue 114)\r
index 9b0cf571311cf6250b32b23bc49b01590a19989b..959c1bca0e33f208eab5f7e30ab9e4e58a442bec 100644 (file)
@@ -279,9 +279,10 @@ public class ConfigUserService implements IUserService {
         */\r
        @Override\r
        public boolean updateUserModel(String username, UserModel model) {\r
+               UserModel originalUser = null;\r
                try {\r
                        read();\r
-                       UserModel oldUser = users.remove(username.toLowerCase());\r
+                       originalUser = users.remove(username.toLowerCase());\r
                        users.put(model.username.toLowerCase(), model);\r
                        // null check on "final" teams because JSON-sourced UserModel\r
                        // can have a null teams object\r
@@ -301,8 +302,8 @@ public class ConfigUserService implements IUserService {
                                }\r
 \r
                                // check for implicit team removal\r
-                               if (oldUser != null) {\r
-                                       for (TeamModel team : oldUser.teams) {\r
+                               if (originalUser != null) {\r
+                                       for (TeamModel team : originalUser.teams) {\r
                                                if (!model.isTeamMember(team.name)) {\r
                                                        team.removeUser(username);\r
                                                }\r
@@ -312,6 +313,10 @@ public class ConfigUserService implements IUserService {
                        write();\r
                        return true;\r
                } catch (Throwable t) {\r
+                       if (originalUser != null) {\r
+                               // restore original user\r
+                               users.put(originalUser.username, originalUser);\r
+                       }\r
                        logger.error(MessageFormat.format("Failed to update user model {0}!", model.username),\r
                                        t);\r
                }\r
@@ -499,13 +504,18 @@ public class ConfigUserService implements IUserService {
         */\r
        @Override\r
        public boolean updateTeamModel(String teamname, TeamModel model) {\r
+               TeamModel original = null;\r
                try {\r
                        read();\r
-                       teams.remove(teamname.toLowerCase());\r
+                       original = teams.remove(teamname.toLowerCase());\r
                        teams.put(model.name.toLowerCase(), model);\r
                        write();\r
                        return true;\r
                } catch (Throwable t) {\r
+                       if (original != null) {\r
+                               // restore original team\r
+                               teams.put(original.name, original);\r
+                       }\r
                        logger.error(MessageFormat.format("Failed to update team model {0}!", model.name), t);\r
                }\r
                return false;\r