Merge "AccountManager: Don't try to change username that is already set"

This commit is contained in:
Edwin Kempin
2016-08-16 06:43:33 +00:00
committed by Gerrit Code Review

View File

@@ -142,7 +142,7 @@ public class AccountManager {
update(db, who, id);
return new AuthResult(id.getAccountId(), key, false);
}
} catch (OrmException | NameAlreadyUsedException | InvalidUserNameException e) {
} catch (OrmException e) {
throw new AccountException("Authentication error", e);
}
}
@@ -181,8 +181,7 @@ public class AccountManager {
}
private void update(ReviewDb db, AuthRequest who, AccountExternalId extId)
throws OrmException, NameAlreadyUsedException, InvalidUserNameException,
IOException {
throws OrmException, IOException {
IdentifiedUser user = userFactory.create(extId.getAccountId());
Account toUpdate = null;
@@ -212,7 +211,8 @@ public class AccountManager {
if (!realm.allowsEdit(Account.FieldName.USER_NAME)
&& who.getUserName() != null
&& !eq(user.getUserName(), who.getUserName())) {
changeUserNameFactory.create(db, user, who.getUserName()).call();
log.warn(String.format("Not changing already set username %s to %s",
user.getUserName(), who.getUserName()));
}
if (toUpdate != null) {
@@ -378,12 +378,7 @@ public class AccountManager {
if (!extId.getAccountId().equals(to)) {
throw new AccountException("Identity in use by another account");
}
try {
update(db, who, extId);
} catch (NameAlreadyUsedException | InvalidUserNameException e) {
throw new AccountException("Account update failed", e);
}
update(db, who, extId);
} else {
extId = createId(to, who);
extId.setEmailAddress(who.getEmailAddress());