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); update(db, who, id);
return new AuthResult(id.getAccountId(), key, false); return new AuthResult(id.getAccountId(), key, false);
} }
} catch (OrmException | NameAlreadyUsedException | InvalidUserNameException e) { } catch (OrmException e) {
throw new AccountException("Authentication error", e); throw new AccountException("Authentication error", e);
} }
} }
@@ -181,8 +181,7 @@ public class AccountManager {
} }
private void update(ReviewDb db, AuthRequest who, AccountExternalId extId) private void update(ReviewDb db, AuthRequest who, AccountExternalId extId)
throws OrmException, NameAlreadyUsedException, InvalidUserNameException, throws OrmException, IOException {
IOException {
IdentifiedUser user = userFactory.create(extId.getAccountId()); IdentifiedUser user = userFactory.create(extId.getAccountId());
Account toUpdate = null; Account toUpdate = null;
@@ -212,7 +211,8 @@ public class AccountManager {
if (!realm.allowsEdit(Account.FieldName.USER_NAME) if (!realm.allowsEdit(Account.FieldName.USER_NAME)
&& who.getUserName() != null && who.getUserName() != null
&& !eq(user.getUserName(), who.getUserName())) { && !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) { if (toUpdate != null) {
@@ -378,12 +378,7 @@ 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);
extId.setEmailAddress(who.getEmailAddress()); extId.setEmailAddress(who.getEmailAddress());