From: James Moger Date: Mon, 6 Aug 2012 21:34:44 +0000 (-0400) Subject: Restore original team or user object on failure to update (issue 118) X-Git-Tag: v1.1.0~35 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2987f602e112d37ff7db522c3cd9e653847a9865;p=gitblit.git Restore original team or user object on failure to update (issue 118) --- diff --git a/docs/04_releases.mkd b/docs/04_releases.mkd index b2a373c9..ac3b31e9 100644 --- a/docs/04_releases.mkd +++ b/docs/04_releases.mkd @@ -11,6 +11,7 @@ If you are updating from an earlier release AND you have indexed branches with t #### fixes +- Restore original user or team object on failure to update (issue 118) - Repository URL uses `X-Forwarded-Proto` and `X-Forwarded-Port`, if available, for reverse proxy configurations (issue 115) - Fixes to relative path determination in repository searh algorithm for symlinks (issue 116) - Output real RAW content, not simulated RAW content (issue 114) diff --git a/src/com/gitblit/ConfigUserService.java b/src/com/gitblit/ConfigUserService.java index 9b0cf571..959c1bca 100644 --- a/src/com/gitblit/ConfigUserService.java +++ b/src/com/gitblit/ConfigUserService.java @@ -279,9 +279,10 @@ public class ConfigUserService implements IUserService { */ @Override public boolean updateUserModel(String username, UserModel model) { + UserModel originalUser = null; try { read(); - UserModel oldUser = users.remove(username.toLowerCase()); + originalUser = users.remove(username.toLowerCase()); users.put(model.username.toLowerCase(), model); // null check on "final" teams because JSON-sourced UserModel // can have a null teams object @@ -301,8 +302,8 @@ public class ConfigUserService implements IUserService { } // check for implicit team removal - if (oldUser != null) { - for (TeamModel team : oldUser.teams) { + if (originalUser != null) { + for (TeamModel team : originalUser.teams) { if (!model.isTeamMember(team.name)) { team.removeUser(username); } @@ -312,6 +313,10 @@ public class ConfigUserService implements IUserService { write(); return true; } catch (Throwable t) { + if (originalUser != null) { + // restore original user + users.put(originalUser.username, originalUser); + } logger.error(MessageFormat.format("Failed to update user model {0}!", model.username), t); } @@ -499,13 +504,18 @@ public class ConfigUserService implements IUserService { */ @Override public boolean updateTeamModel(String teamname, TeamModel model) { + TeamModel original = null; try { read(); - teams.remove(teamname.toLowerCase()); + original = teams.remove(teamname.toLowerCase()); teams.put(model.name.toLowerCase(), model); write(); return true; } catch (Throwable t) { + if (original != null) { + // restore original team + teams.put(original.name, original); + } logger.error(MessageFormat.format("Failed to update team model {0}!", model.name), t); } return false;