Merge "Fix updating of username from AccountManager"

This commit is contained in:
Edwin Kempin
2015-08-04 12:51:25 +00:00
committed by Gerrit Code Review

View File

@@ -125,13 +125,13 @@ public class AccountManager {
} }
} }
} catch (OrmException e) { } catch (OrmException | NameAlreadyUsedException | InvalidUserNameException e) {
throw new AccountException("Authentication error", e); throw new AccountException("Authentication error", e);
} }
} }
private void update(ReviewDb db, AuthRequest who, AccountExternalId extId) private void update(ReviewDb db, AuthRequest who, AccountExternalId extId)
throws OrmException { throws OrmException, NameAlreadyUsedException, InvalidUserNameException {
IdentifiedUser user = userFactory.create(extId.getAccountId()); IdentifiedUser user = userFactory.create(extId.getAccountId());
Account toUpdate = null; Account toUpdate = null;
@@ -159,7 +159,7 @@ public class AccountManager {
if (!realm.allowsEdit(Account.FieldName.USER_NAME) if (!realm.allowsEdit(Account.FieldName.USER_NAME)
&& !eq(user.getUserName(), who.getUserName())) { && !eq(user.getUserName(), who.getUserName())) {
changeUserNameFactory.create(db, user, who.getUserName()); changeUserNameFactory.create(db, user, who.getUserName()).call();
} }
if (toUpdate != null) { if (toUpdate != null) {
@@ -327,7 +327,11 @@ public class AccountManager {
if (!extId.getAccountId().equals(to)) { if (!extId.getAccountId().equals(to)) {
throw new AccountException("Identity in use by another account"); throw new AccountException("Identity in use by another account");
} }
try {
update(db, who, extId); update(db, who, extId);
} catch(NameAlreadyUsedException | InvalidUserNameException e) {
throw new AccountException("Account update failed", e);
}
} else { } else {
extId = createId(to, who); extId = createId(to, who);