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