Remove unused ReviewDb from AccountResolver
Change-Id: Ie0df178fc89f25e24f87ea836eb3b788b3d73e11
This commit is contained in:
@@ -17,7 +17,6 @@ package com.google.gerrit.server.account;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.query.account.InternalAccountQuery;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
@@ -63,9 +62,8 @@ public class AccountResolver {
|
||||
* @return the single account that matches; null if no account matches or there are multiple
|
||||
* candidates.
|
||||
*/
|
||||
public Account find(ReviewDb db, String nameOrEmail)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
Set<Account.Id> r = findAll(db, nameOrEmail);
|
||||
public Account find(String nameOrEmail) throws OrmException, IOException, ConfigInvalidException {
|
||||
Set<Account.Id> r = findAll(nameOrEmail);
|
||||
if (r.size() == 1) {
|
||||
return byId.get(r.iterator().next()).getAccount();
|
||||
}
|
||||
@@ -87,13 +85,12 @@ public class AccountResolver {
|
||||
/**
|
||||
* Find all accounts matching the name or name/email string.
|
||||
*
|
||||
* @param db open database handle.
|
||||
* @param nameOrEmail a string of the format "Full Name <email@example>", just the email
|
||||
* address ("email@example"), a full name ("Full Name"), an account id ("18419") or an user
|
||||
* name ("username").
|
||||
* @return the accounts that match, empty collection if none. Never null.
|
||||
*/
|
||||
public Set<Account.Id> findAll(ReviewDb db, String nameOrEmail)
|
||||
public Set<Account.Id> findAll(String nameOrEmail)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
Matcher m = Pattern.compile("^.* \\(([1-9][0-9]*)\\)$").matcher(nameOrEmail);
|
||||
if (m.matches()) {
|
||||
@@ -119,34 +116,30 @@ public class AccountResolver {
|
||||
}
|
||||
}
|
||||
|
||||
return findAllByNameOrEmail(db, nameOrEmail);
|
||||
return findAllByNameOrEmail(nameOrEmail);
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate exactly one account matching the name or name/email string.
|
||||
*
|
||||
* @param db open database handle.
|
||||
* @param nameOrEmail a string of the format "Full Name <email@example>", just the email
|
||||
* address ("email@example"), a full name ("Full Name").
|
||||
* @return the single account that matches; null if no account matches or there are multiple
|
||||
* candidates.
|
||||
*/
|
||||
public Account findByNameOrEmail(ReviewDb db, String nameOrEmail)
|
||||
throws OrmException, IOException {
|
||||
Set<Account.Id> r = findAllByNameOrEmail(db, nameOrEmail);
|
||||
public Account findByNameOrEmail(String nameOrEmail) throws OrmException, IOException {
|
||||
Set<Account.Id> r = findAllByNameOrEmail(nameOrEmail);
|
||||
return r.size() == 1 ? byId.get(r.iterator().next()).getAccount() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate exactly one account matching the name or name/email string.
|
||||
*
|
||||
* @param db open database handle.
|
||||
* @param nameOrEmail a string of the format "Full Name <email@example>", just the email
|
||||
* address ("email@example"), a full name ("Full Name").
|
||||
* @return the accounts that match, empty collection if none. Never null.
|
||||
*/
|
||||
public Set<Account.Id> findAllByNameOrEmail(ReviewDb db, String nameOrEmail)
|
||||
throws OrmException, IOException {
|
||||
public Set<Account.Id> findAllByNameOrEmail(String nameOrEmail) throws OrmException, IOException {
|
||||
int lt = nameOrEmail.indexOf('<');
|
||||
int gt = nameOrEmail.indexOf('>');
|
||||
if (lt >= 0 && gt > lt && nameOrEmail.contains("@")) {
|
||||
|
@@ -25,7 +25,6 @@ import com.google.gerrit.extensions.restapi.RestView;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.AnonymousUser;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
@@ -39,7 +38,6 @@ import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
@Singleton
|
||||
public class AccountsCollection
|
||||
implements RestCollection<TopLevelResource, AccountResource>, AcceptsCreate<TopLevelResource> {
|
||||
private final Provider<ReviewDb> db;
|
||||
private final Provider<CurrentUser> self;
|
||||
private final AccountResolver resolver;
|
||||
private final AccountControl.Factory accountControlFactory;
|
||||
@@ -50,7 +48,6 @@ public class AccountsCollection
|
||||
|
||||
@Inject
|
||||
AccountsCollection(
|
||||
Provider<ReviewDb> db,
|
||||
Provider<CurrentUser> self,
|
||||
AccountResolver resolver,
|
||||
AccountControl.Factory accountControlFactory,
|
||||
@@ -58,7 +55,6 @@ public class AccountsCollection
|
||||
Provider<QueryAccounts> list,
|
||||
DynamicMap<RestView<AccountResource>> views,
|
||||
CreateAccount.Factory createAccountFactory) {
|
||||
this.db = db;
|
||||
this.self = self;
|
||||
this.resolver = resolver;
|
||||
this.accountControlFactory = accountControlFactory;
|
||||
@@ -144,7 +140,7 @@ public class AccountsCollection
|
||||
}
|
||||
}
|
||||
|
||||
Account match = resolver.find(db.get(), id);
|
||||
Account match = resolver.find(id);
|
||||
if (match == null) {
|
||||
return null;
|
||||
}
|
||||
|
@@ -16,7 +16,6 @@ package com.google.gerrit.server.args4j;
|
||||
|
||||
import com.google.gerrit.extensions.client.AuthType;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.account.AccountException;
|
||||
import com.google.gerrit.server.account.AccountManager;
|
||||
import com.google.gerrit.server.account.AccountResolver;
|
||||
@@ -24,7 +23,6 @@ import com.google.gerrit.server.account.AuthRequest;
|
||||
import com.google.gerrit.server.config.AuthConfig;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.io.IOException;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
@@ -36,14 +34,12 @@ import org.kohsuke.args4j.spi.Parameters;
|
||||
import org.kohsuke.args4j.spi.Setter;
|
||||
|
||||
public class AccountIdHandler extends OptionHandler<Account.Id> {
|
||||
private final Provider<ReviewDb> db;
|
||||
private final AccountResolver accountResolver;
|
||||
private final AccountManager accountManager;
|
||||
private final AuthType authType;
|
||||
|
||||
@Inject
|
||||
public AccountIdHandler(
|
||||
Provider<ReviewDb> db,
|
||||
AccountResolver accountResolver,
|
||||
AccountManager accountManager,
|
||||
AuthConfig authConfig,
|
||||
@@ -51,7 +47,6 @@ public class AccountIdHandler extends OptionHandler<Account.Id> {
|
||||
@Assisted OptionDef option,
|
||||
@Assisted Setter<Account.Id> setter) {
|
||||
super(parser, option, setter);
|
||||
this.db = db;
|
||||
this.accountResolver = accountResolver;
|
||||
this.accountManager = accountManager;
|
||||
this.authType = authConfig.getAuthType();
|
||||
@@ -62,7 +57,7 @@ public class AccountIdHandler extends OptionHandler<Account.Id> {
|
||||
String token = params.getParameter(0);
|
||||
Account.Id accountId;
|
||||
try {
|
||||
Account a = accountResolver.find(db.get(), token);
|
||||
Account a = accountResolver.find(token);
|
||||
if (a != null) {
|
||||
accountId = a.getId();
|
||||
} else {
|
||||
|
@@ -25,11 +25,9 @@ import com.google.gerrit.extensions.api.changes.NotifyInfo;
|
||||
import com.google.gerrit.extensions.api.changes.RecipientType;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.account.AccountResolver;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -40,12 +38,10 @@ import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
|
||||
@Singleton
|
||||
public class NotifyUtil {
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final AccountResolver accountResolver;
|
||||
|
||||
@Inject
|
||||
NotifyUtil(Provider<ReviewDb> dbProvider, AccountResolver accountResolver) {
|
||||
this.dbProvider = dbProvider;
|
||||
NotifyUtil(AccountResolver accountResolver) {
|
||||
this.accountResolver = accountResolver;
|
||||
}
|
||||
|
||||
@@ -90,19 +86,19 @@ public class NotifyUtil {
|
||||
if (m == null) {
|
||||
m = MultimapBuilder.hashKeys().arrayListValues().build();
|
||||
}
|
||||
m.putAll(e.getKey(), find(dbProvider.get(), accounts));
|
||||
m.putAll(e.getKey(), find(accounts));
|
||||
}
|
||||
}
|
||||
|
||||
return m != null ? m : ImmutableListMultimap.of();
|
||||
}
|
||||
|
||||
private List<Account.Id> find(ReviewDb db, List<String> nameOrEmails)
|
||||
private List<Account.Id> find(List<String> nameOrEmails)
|
||||
throws OrmException, BadRequestException, IOException, ConfigInvalidException {
|
||||
List<String> missing = new ArrayList<>(nameOrEmails.size());
|
||||
List<Account.Id> r = new ArrayList<>(nameOrEmails.size());
|
||||
for (String nameOrEmail : nameOrEmails) {
|
||||
Account a = accountResolver.find(db, nameOrEmail);
|
||||
Account a = accountResolver.find(nameOrEmail);
|
||||
if (a != null) {
|
||||
r.add(a.getId());
|
||||
} else {
|
||||
|
@@ -2126,7 +2126,7 @@ class ReceiveCommits {
|
||||
checkNotNull(magicBranch);
|
||||
recipients.add(magicBranch.getMailRecipients());
|
||||
approvals = magicBranch.labels;
|
||||
recipients.add(getRecipientsFromFooters(db, accountResolver, footerLines));
|
||||
recipients.add(getRecipientsFromFooters(accountResolver, footerLines));
|
||||
recipients.remove(me);
|
||||
StringBuilder msg =
|
||||
new StringBuilder(
|
||||
|
@@ -291,7 +291,7 @@ public class ReplaceOp implements BatchUpdateOp {
|
||||
psDescription);
|
||||
|
||||
update.setPsDescription(psDescription);
|
||||
recipients.add(getRecipientsFromFooters(ctx.getDb(), accountResolver, commit.getFooterLines()));
|
||||
recipients.add(getRecipientsFromFooters(accountResolver, commit.getFooterLines()));
|
||||
recipients.remove(ctx.getAccountId());
|
||||
ChangeData cd = changeDataFactory.create(ctx.getDb(), ctx.getNotes());
|
||||
MailRecipients oldRecipients = getRecipientsFromReviewers(cd.reviewers());
|
||||
|
@@ -152,7 +152,7 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
|
||||
case HTTP_LDAP:
|
||||
case CLIENT_SSL_CERT_LDAP:
|
||||
case LDAP:
|
||||
if (accountResolver.find(db.get(), nameOrEmailOrId) == null) {
|
||||
if (accountResolver.find(nameOrEmailOrId) == null) {
|
||||
// account does not exist, try to create it
|
||||
Account a = createAccountByLdap(nameOrEmailOrId);
|
||||
if (a != null) {
|
||||
|
@@ -20,7 +20,6 @@ import static com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER;
|
||||
import com.google.gerrit.common.FooterConstants;
|
||||
import com.google.gerrit.common.errors.NoSuchAccountException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.ReviewerSet;
|
||||
import com.google.gerrit.server.account.AccountResolver;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
@@ -39,15 +38,15 @@ public class MailUtil {
|
||||
DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss ZZZ");
|
||||
|
||||
public static MailRecipients getRecipientsFromFooters(
|
||||
ReviewDb db, AccountResolver accountResolver, List<FooterLine> footerLines)
|
||||
AccountResolver accountResolver, List<FooterLine> footerLines)
|
||||
throws OrmException, IOException {
|
||||
MailRecipients recipients = new MailRecipients();
|
||||
for (FooterLine footerLine : footerLines) {
|
||||
try {
|
||||
if (isReviewer(footerLine)) {
|
||||
recipients.reviewers.add(toAccountId(db, accountResolver, footerLine.getValue().trim()));
|
||||
recipients.reviewers.add(toAccountId(accountResolver, footerLine.getValue().trim()));
|
||||
} else if (footerLine.matches(FooterKey.CC)) {
|
||||
recipients.cc.add(toAccountId(db, accountResolver, footerLine.getValue().trim()));
|
||||
recipients.cc.add(toAccountId(accountResolver, footerLine.getValue().trim()));
|
||||
}
|
||||
} catch (NoSuchAccountException e) {
|
||||
continue;
|
||||
@@ -63,10 +62,9 @@ public class MailUtil {
|
||||
return recipients;
|
||||
}
|
||||
|
||||
private static Account.Id toAccountId(
|
||||
ReviewDb db, AccountResolver accountResolver, String nameOrEmail)
|
||||
private static Account.Id toAccountId(AccountResolver accountResolver, String nameOrEmail)
|
||||
throws OrmException, NoSuchAccountException, IOException {
|
||||
Account a = accountResolver.findByNameOrEmail(db, nameOrEmail);
|
||||
Account a = accountResolver.findByNameOrEmail(nameOrEmail);
|
||||
if (a == null) {
|
||||
throw new NoSuchAccountException("\"" + nameOrEmail + "\" is not registered");
|
||||
}
|
||||
|
@@ -24,7 +24,6 @@ import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountResolver;
|
||||
import com.google.gerrit.server.permissions.GlobalPermission;
|
||||
@@ -34,7 +33,6 @@ import com.google.gerrit.server.permissions.ProjectPermission;
|
||||
import com.google.gerrit.server.permissions.RefPermission;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -43,18 +41,15 @@ import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
@Singleton
|
||||
public class CheckAccess implements RestModifyView<ProjectResource, AccessCheckInput> {
|
||||
private final AccountResolver accountResolver;
|
||||
private final Provider<ReviewDb> db;
|
||||
private final IdentifiedUser.GenericFactory userFactory;
|
||||
private final PermissionBackend permissionBackend;
|
||||
|
||||
@Inject
|
||||
CheckAccess(
|
||||
AccountResolver resolver,
|
||||
Provider<ReviewDb> db,
|
||||
IdentifiedUser.GenericFactory userFactory,
|
||||
PermissionBackend permissionBackend) {
|
||||
this.accountResolver = resolver;
|
||||
this.db = db;
|
||||
this.userFactory = userFactory;
|
||||
this.permissionBackend = permissionBackend;
|
||||
}
|
||||
@@ -72,7 +67,7 @@ public class CheckAccess implements RestModifyView<ProjectResource, AccessCheckI
|
||||
throw new BadRequestException("input requires 'account'");
|
||||
}
|
||||
|
||||
Account match = accountResolver.find(db.get(), input.account);
|
||||
Account match = accountResolver.find(input.account);
|
||||
if (match == null) {
|
||||
throw new UnprocessableEntityException(
|
||||
String.format("cannot find account %s", input.account));
|
||||
|
@@ -901,7 +901,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
||||
if (isSelf(who)) {
|
||||
return is_visible();
|
||||
}
|
||||
Set<Account.Id> m = args.accountResolver.findAll(args.db.get(), who);
|
||||
Set<Account.Id> m = args.accountResolver.findAll(who);
|
||||
if (!m.isEmpty()) {
|
||||
List<Predicate<ChangeData>> p = Lists.newArrayListWithCapacity(m.size());
|
||||
for (Account.Id id : m) {
|
||||
@@ -1258,7 +1258,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
||||
if (isSelf(who)) {
|
||||
return Collections.singleton(self());
|
||||
}
|
||||
Set<Account.Id> matches = args.accountResolver.findAll(args.db.get(), who);
|
||||
Set<Account.Id> matches = args.accountResolver.findAll(who);
|
||||
if (matches.isEmpty()) {
|
||||
throw error("User " + who + " not found");
|
||||
}
|
||||
|
@@ -27,7 +27,6 @@ import com.google.gerrit.index.query.QueryBuilder;
|
||||
import com.google.gerrit.index.query.QueryParseException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.account.AccountResolver;
|
||||
import com.google.gerrit.server.account.GroupBackend;
|
||||
import com.google.gerrit.server.account.GroupBackends;
|
||||
@@ -38,7 +37,6 @@ import com.google.gerrit.server.index.group.GroupIndex;
|
||||
import com.google.gerrit.server.index.group.GroupIndexCollection;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -58,7 +56,6 @@ public class GroupQueryBuilder extends QueryBuilder<InternalGroup> {
|
||||
new QueryBuilder.Definition<>(GroupQueryBuilder.class);
|
||||
|
||||
public static class Arguments {
|
||||
final Provider<ReviewDb> db;
|
||||
final GroupIndex groupIndex;
|
||||
final GroupCache groupCache;
|
||||
final GroupBackend groupBackend;
|
||||
@@ -66,12 +63,10 @@ public class GroupQueryBuilder extends QueryBuilder<InternalGroup> {
|
||||
|
||||
@Inject
|
||||
Arguments(
|
||||
Provider<ReviewDb> db,
|
||||
GroupIndexCollection groupIndexCollection,
|
||||
GroupCache groupCache,
|
||||
GroupBackend groupBackend,
|
||||
AccountResolver accountResolver) {
|
||||
this.db = db;
|
||||
this.groupIndex = groupIndexCollection.getSearchIndex();
|
||||
this.groupCache = groupCache;
|
||||
this.groupBackend = groupBackend;
|
||||
@@ -189,7 +184,7 @@ public class GroupQueryBuilder extends QueryBuilder<InternalGroup> {
|
||||
|
||||
private Set<Account.Id> parseAccount(String nameOrEmail)
|
||||
throws QueryParseException, OrmException, IOException, ConfigInvalidException {
|
||||
Set<Account.Id> foundAccounts = args.accountResolver.findAll(args.db.get(), nameOrEmail);
|
||||
Set<Account.Id> foundAccounts = args.accountResolver.findAll(nameOrEmail);
|
||||
if (foundAccounts.isEmpty()) {
|
||||
throw error("User " + nameOrEmail + " not found");
|
||||
}
|
||||
|
Reference in New Issue
Block a user