Merge "When resolving an account by ID check that it actually exists"
This commit is contained in:
@@ -71,11 +71,21 @@ public class AccountResolver {
|
||||
public Set<Account.Id> findAll(String nameOrEmail) throws OrmException {
|
||||
Matcher m = Pattern.compile("^.* \\(([1-9][0-9]*)\\)$").matcher(nameOrEmail);
|
||||
if (m.matches()) {
|
||||
return Collections.singleton(Account.Id.parse(m.group(1)));
|
||||
Account.Id id = Account.Id.parse(m.group(1));
|
||||
if (exists(id)) {
|
||||
return Collections.singleton(id);
|
||||
} else {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
if (nameOrEmail.matches("^[1-9][0-9]*$")) {
|
||||
return Collections.singleton(Account.Id.parse(nameOrEmail));
|
||||
Account.Id id = Account.Id.parse(nameOrEmail);
|
||||
if (exists(id)) {
|
||||
return Collections.singleton(id);
|
||||
} else {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
if (nameOrEmail.matches(Account.USER_NAME_PATTERN)) {
|
||||
@@ -88,6 +98,10 @@ public class AccountResolver {
|
||||
return findAllByNameOrEmail(nameOrEmail);
|
||||
}
|
||||
|
||||
private boolean exists(Account.Id id) throws OrmException {
|
||||
return schema.get().accounts().get(id) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate exactly one account matching the name or name/email string.
|
||||
*
|
||||
|
Reference in New Issue
Block a user