summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2012-08-06 17:34:44 -0400
committerJames Moger <james.moger@gitblit.com>2012-08-06 17:34:44 -0400
commit2987f602e112d37ff7db522c3cd9e653847a9865 (patch)
tree1057d7c75484d54a755bb9598cb3958e1112d605 /src
parentf3ff376a5eb945f15329b66bbb7d69ed3ca2ce3f (diff)
downloadgitblit-2987f602e112d37ff7db522c3cd9e653847a9865.tar.gz
gitblit-2987f602e112d37ff7db522c3cd9e653847a9865.zip
Restore original team or user object on failure to update (issue 118)
Diffstat (limited to 'src')
-rw-r--r--src/com/gitblit/ConfigUserService.java18
1 files changed, 14 insertions, 4 deletions
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;