Move most methods from AccountsCollection to AccountResolver
Leave only the restapi-specific method to create an AccountResource. Change-Id: If02b64a0c842555f2475365bf8472855368f2c8c
This commit is contained in:
@@ -19,7 +19,13 @@ import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.AnonymousUser;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.externalids.ExternalId;
|
||||
import com.google.gerrit.server.query.account.InternalAccountQuery;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
@@ -38,22 +44,31 @@ import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
|
||||
@Singleton
|
||||
public class AccountResolver {
|
||||
private final Provider<CurrentUser> self;
|
||||
private final Realm realm;
|
||||
private final Accounts accounts;
|
||||
private final AccountCache byId;
|
||||
private final IdentifiedUser.GenericFactory userFactory;
|
||||
private final AccountControl.Factory accountControlFactory;
|
||||
private final Provider<InternalAccountQuery> accountQueryProvider;
|
||||
private final Emails emails;
|
||||
|
||||
@Inject
|
||||
AccountResolver(
|
||||
Provider<CurrentUser> self,
|
||||
Realm realm,
|
||||
Accounts accounts,
|
||||
AccountCache byId,
|
||||
IdentifiedUser.GenericFactory userFactory,
|
||||
AccountControl.Factory accountControlFactory,
|
||||
Provider<InternalAccountQuery> accountQueryProvider,
|
||||
Emails emails) {
|
||||
this.self = self;
|
||||
this.realm = realm;
|
||||
this.accounts = accounts;
|
||||
this.byId = byId;
|
||||
this.userFactory = userFactory;
|
||||
this.accountControlFactory = accountControlFactory;
|
||||
this.accountQueryProvider = accountQueryProvider;
|
||||
this.emails = emails;
|
||||
}
|
||||
@@ -197,4 +212,74 @@ public class AccountResolver {
|
||||
.map(a -> a.getAccount().getId())
|
||||
.collect(toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a account ID from a request body and returns the user.
|
||||
*
|
||||
* @param id ID of the account, can be a string of the format "{@code Full Name
|
||||
* <email@example.com>}", just the email address, a full name if it is unique, an account ID,
|
||||
* a user name or "{@code self}" for the calling user
|
||||
* @return the user, never null.
|
||||
* @throws UnprocessableEntityException thrown if the account ID cannot be resolved or if the
|
||||
* account is not visible to the calling user
|
||||
*/
|
||||
public IdentifiedUser parse(String id)
|
||||
throws AuthException, UnprocessableEntityException, OrmException, IOException,
|
||||
ConfigInvalidException {
|
||||
return parseOnBehalfOf(null, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an account ID and returns the user without making any permission check whether the
|
||||
* current user can see the account.
|
||||
*
|
||||
* @param id ID of the account, can be a string of the format "{@code Full Name
|
||||
* <email@example.com>}", just the email address, a full name if it is unique, an account ID,
|
||||
* a user name or "{@code self}" for the calling user
|
||||
* @return the user, null if no user is found for the given account ID
|
||||
* @throws AuthException thrown if 'self' is used as account ID and the current user is not
|
||||
* authenticated
|
||||
* @throws OrmException
|
||||
* @throws ConfigInvalidException
|
||||
* @throws IOException
|
||||
*/
|
||||
public IdentifiedUser parseId(String id)
|
||||
throws AuthException, OrmException, IOException, ConfigInvalidException {
|
||||
return parseIdOnBehalfOf(null, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@link #parse(String)}, but also sets the {@link CurrentUser#getRealUser()} on the result.
|
||||
*/
|
||||
public IdentifiedUser parseOnBehalfOf(@Nullable CurrentUser caller, String id)
|
||||
throws AuthException, UnprocessableEntityException, OrmException, IOException,
|
||||
ConfigInvalidException {
|
||||
IdentifiedUser user = parseIdOnBehalfOf(caller, id);
|
||||
if (user == null || !accountControlFactory.get().canSee(user.getAccount())) {
|
||||
throw new UnprocessableEntityException(
|
||||
String.format("Account '%s' is not found or ambiguous", id));
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
private IdentifiedUser parseIdOnBehalfOf(@Nullable CurrentUser caller, String id)
|
||||
throws AuthException, OrmException, IOException, ConfigInvalidException {
|
||||
if (id.equals("self")) {
|
||||
CurrentUser user = self.get();
|
||||
if (user.isIdentifiedUser()) {
|
||||
return user.asIdentifiedUser();
|
||||
} else if (user instanceof AnonymousUser) {
|
||||
throw new AuthException("Authentication required");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Account match = find(id);
|
||||
if (match == null) {
|
||||
return null;
|
||||
}
|
||||
CurrentUser realUser = caller != null ? caller.getRealUser() : null;
|
||||
return userFactory.runAs(null, match.getId(), realUser);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.server.account.AccountResolver;
|
||||
import com.google.gerrit.server.group.GroupResolver;
|
||||
import com.google.gerrit.server.permissions.GlobalPermission;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||
import com.google.gerrit.server.project.ProjectResource;
|
||||
import com.google.gerrit.server.restapi.account.AccountsCollection;
|
||||
import com.google.gerrit.server.restapi.group.CreateGroup;
|
||||
import com.google.gerrit.server.restapi.group.GroupsCollection;
|
||||
import com.google.gerrit.server.restapi.group.ListGroups;
|
||||
@@ -44,7 +44,7 @@ import java.util.SortedMap;
|
||||
|
||||
@Singleton
|
||||
class GroupsImpl implements Groups {
|
||||
private final AccountsCollection accounts;
|
||||
private final AccountResolver accountResolver;
|
||||
private final GroupsCollection groups;
|
||||
private final GroupResolver groupResolver;
|
||||
private final ProjectsCollection projects;
|
||||
@@ -56,7 +56,7 @@ class GroupsImpl implements Groups {
|
||||
|
||||
@Inject
|
||||
GroupsImpl(
|
||||
AccountsCollection accounts,
|
||||
AccountResolver accountResolver,
|
||||
GroupsCollection groups,
|
||||
GroupResolver groupResolver,
|
||||
ProjectsCollection projects,
|
||||
@@ -65,7 +65,7 @@ class GroupsImpl implements Groups {
|
||||
PermissionBackend permissionBackend,
|
||||
CreateGroup createGroup,
|
||||
GroupApiImpl.Factory api) {
|
||||
this.accounts = accounts;
|
||||
this.accountResolver = accountResolver;
|
||||
this.groups = groups;
|
||||
this.groupResolver = groupResolver;
|
||||
this.projects = projects;
|
||||
@@ -141,7 +141,7 @@ class GroupsImpl implements Groups {
|
||||
|
||||
if (req.getUser() != null) {
|
||||
try {
|
||||
list.setUser(accounts.parse(req.getUser()).getAccountId());
|
||||
list.setUser(accountResolver.parse(req.getUser()).getAccountId());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Error looking up user " + req.getUser(), e);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.server.restapi.account;
|
||||
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
@@ -22,10 +21,6 @@ import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestCollection;
|
||||
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.server.AnonymousUser;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountControl;
|
||||
import com.google.gerrit.server.account.AccountResolver;
|
||||
@@ -39,25 +34,19 @@ import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
|
||||
@Singleton
|
||||
public class AccountsCollection implements RestCollection<TopLevelResource, AccountResource> {
|
||||
private final Provider<CurrentUser> self;
|
||||
private final AccountResolver resolver;
|
||||
private final AccountResolver accountResolver;
|
||||
private final AccountControl.Factory accountControlFactory;
|
||||
private final IdentifiedUser.GenericFactory userFactory;
|
||||
private final Provider<QueryAccounts> list;
|
||||
private final DynamicMap<RestView<AccountResource>> views;
|
||||
|
||||
@Inject
|
||||
public AccountsCollection(
|
||||
Provider<CurrentUser> self,
|
||||
AccountResolver resolver,
|
||||
AccountResolver accountResolver,
|
||||
AccountControl.Factory accountControlFactory,
|
||||
IdentifiedUser.GenericFactory userFactory,
|
||||
Provider<QueryAccounts> list,
|
||||
DynamicMap<RestView<AccountResource>> views) {
|
||||
this.self = self;
|
||||
this.resolver = resolver;
|
||||
this.accountResolver = accountResolver;
|
||||
this.accountControlFactory = accountControlFactory;
|
||||
this.userFactory = userFactory;
|
||||
this.list = list;
|
||||
this.views = views;
|
||||
}
|
||||
@@ -66,7 +55,7 @@ public class AccountsCollection implements RestCollection<TopLevelResource, Acco
|
||||
public AccountResource parse(TopLevelResource root, IdString id)
|
||||
throws ResourceNotFoundException, AuthException, OrmException, IOException,
|
||||
ConfigInvalidException {
|
||||
IdentifiedUser user = parseId(id.get());
|
||||
IdentifiedUser user = accountResolver.parseId(id.get());
|
||||
if (user == null || !accountControlFactory.get().canSee(user.getAccount())) {
|
||||
throw new ResourceNotFoundException(
|
||||
String.format("Account '%s' is not found or ambiguous", id));
|
||||
@@ -74,76 +63,6 @@ public class AccountsCollection implements RestCollection<TopLevelResource, Acco
|
||||
return new AccountResource(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a account ID from a request body and returns the user.
|
||||
*
|
||||
* @param id ID of the account, can be a string of the format "{@code Full Name
|
||||
* <email@example.com>}", just the email address, a full name if it is unique, an account ID,
|
||||
* a user name or "{@code self}" for the calling user
|
||||
* @return the user, never null.
|
||||
* @throws UnprocessableEntityException thrown if the account ID cannot be resolved or if the
|
||||
* account is not visible to the calling user
|
||||
*/
|
||||
public IdentifiedUser parse(String id)
|
||||
throws AuthException, UnprocessableEntityException, OrmException, IOException,
|
||||
ConfigInvalidException {
|
||||
return parseOnBehalfOf(null, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an account ID and returns the user without making any permission check whether the
|
||||
* current user can see the account.
|
||||
*
|
||||
* @param id ID of the account, can be a string of the format "{@code Full Name
|
||||
* <email@example.com>}", just the email address, a full name if it is unique, an account ID,
|
||||
* a user name or "{@code self}" for the calling user
|
||||
* @return the user, null if no user is found for the given account ID
|
||||
* @throws AuthException thrown if 'self' is used as account ID and the current user is not
|
||||
* authenticated
|
||||
* @throws OrmException
|
||||
* @throws ConfigInvalidException
|
||||
* @throws IOException
|
||||
*/
|
||||
public IdentifiedUser parseId(String id)
|
||||
throws AuthException, OrmException, IOException, ConfigInvalidException {
|
||||
return parseIdOnBehalfOf(null, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@link #parse(String)}, but also sets the {@link CurrentUser#getRealUser()} on the result.
|
||||
*/
|
||||
public IdentifiedUser parseOnBehalfOf(@Nullable CurrentUser caller, String id)
|
||||
throws AuthException, UnprocessableEntityException, OrmException, IOException,
|
||||
ConfigInvalidException {
|
||||
IdentifiedUser user = parseIdOnBehalfOf(caller, id);
|
||||
if (user == null || !accountControlFactory.get().canSee(user.getAccount())) {
|
||||
throw new UnprocessableEntityException(
|
||||
String.format("Account '%s' is not found or ambiguous", id));
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
private IdentifiedUser parseIdOnBehalfOf(@Nullable CurrentUser caller, String id)
|
||||
throws AuthException, OrmException, IOException, ConfigInvalidException {
|
||||
if (id.equals("self")) {
|
||||
CurrentUser user = self.get();
|
||||
if (user.isIdentifiedUser()) {
|
||||
return user.asIdentifiedUser();
|
||||
} else if (user instanceof AnonymousUser) {
|
||||
throw new AuthException("Authentication required");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Account match = resolver.find(id);
|
||||
if (match == null) {
|
||||
return null;
|
||||
}
|
||||
CurrentUser realUser = caller != null ? caller.getRealUser() : null;
|
||||
return userFactory.runAs(null, match.getId(), realUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestView<TopLevelResource> list() throws ResourceNotFoundException {
|
||||
return list.get();
|
||||
|
||||
@@ -88,6 +88,7 @@ import com.google.gerrit.server.OutputFormat;
|
||||
import com.google.gerrit.server.PatchSetUtil;
|
||||
import com.google.gerrit.server.PublishCommentUtil;
|
||||
import com.google.gerrit.server.ReviewerSet;
|
||||
import com.google.gerrit.server.account.AccountResolver;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.EmailReviewComments;
|
||||
import com.google.gerrit.server.change.NotifyUtil;
|
||||
@@ -110,7 +111,6 @@ import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.project.ProjectState;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.restapi.account.AccountsCollection;
|
||||
import com.google.gerrit.server.restapi.change.ReviewerAdder.ReviewerAddition;
|
||||
import com.google.gerrit.server.update.BatchUpdate;
|
||||
import com.google.gerrit.server.update.BatchUpdateOp;
|
||||
@@ -167,7 +167,7 @@ public class PostReview
|
||||
private final PublishCommentUtil publishCommentUtil;
|
||||
private final PatchSetUtil psUtil;
|
||||
private final PatchListCache patchListCache;
|
||||
private final AccountsCollection accounts;
|
||||
private final AccountResolver accountResolver;
|
||||
private final EmailReviewComments.Factory email;
|
||||
private final CommentAdded commentAdded;
|
||||
private final ReviewerAdder reviewerAdder;
|
||||
@@ -192,7 +192,7 @@ public class PostReview
|
||||
PublishCommentUtil publishCommentUtil,
|
||||
PatchSetUtil psUtil,
|
||||
PatchListCache patchListCache,
|
||||
AccountsCollection accounts,
|
||||
AccountResolver accountResolver,
|
||||
EmailReviewComments.Factory email,
|
||||
CommentAdded commentAdded,
|
||||
ReviewerAdder reviewerAdder,
|
||||
@@ -213,7 +213,7 @@ public class PostReview
|
||||
this.patchListCache = patchListCache;
|
||||
this.approvalsUtil = approvalsUtil;
|
||||
this.cmUtil = cmUtil;
|
||||
this.accounts = accounts;
|
||||
this.accountResolver = accountResolver;
|
||||
this.email = email;
|
||||
this.commentAdded = commentAdded;
|
||||
this.reviewerAdder = reviewerAdder;
|
||||
@@ -503,7 +503,7 @@ public class PostReview
|
||||
String.format("label required to post review on behalf of \"%s\"", in.onBehalfOf));
|
||||
}
|
||||
|
||||
IdentifiedUser reviewer = accounts.parseOnBehalfOf(caller, in.onBehalfOf);
|
||||
IdentifiedUser reviewer = accountResolver.parseOnBehalfOf(caller, in.onBehalfOf);
|
||||
try {
|
||||
permissionBackend
|
||||
.user(reviewer)
|
||||
|
||||
@@ -28,12 +28,12 @@ import com.google.gerrit.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountLoader;
|
||||
import com.google.gerrit.server.account.AccountResolver;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.SetAssigneeOp;
|
||||
import com.google.gerrit.server.permissions.ChangePermission;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.restapi.account.AccountsCollection;
|
||||
import com.google.gerrit.server.restapi.change.ReviewerAdder.ReviewerAddition;
|
||||
import com.google.gerrit.server.update.BatchUpdate;
|
||||
import com.google.gerrit.server.update.RetryHelper;
|
||||
@@ -51,7 +51,7 @@ import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
public class PutAssignee extends RetryingRestModifyView<ChangeResource, AssigneeInput, AccountInfo>
|
||||
implements UiAction<ChangeResource> {
|
||||
|
||||
private final AccountsCollection accounts;
|
||||
private final AccountResolver accountResolver;
|
||||
private final SetAssigneeOp.Factory assigneeFactory;
|
||||
private final Provider<ReviewDb> db;
|
||||
private final ReviewerAdder reviewerAdder;
|
||||
@@ -60,7 +60,7 @@ public class PutAssignee extends RetryingRestModifyView<ChangeResource, Assignee
|
||||
|
||||
@Inject
|
||||
PutAssignee(
|
||||
AccountsCollection accounts,
|
||||
AccountResolver accountResolver,
|
||||
SetAssigneeOp.Factory assigneeFactory,
|
||||
RetryHelper retryHelper,
|
||||
Provider<ReviewDb> db,
|
||||
@@ -68,7 +68,7 @@ public class PutAssignee extends RetryingRestModifyView<ChangeResource, Assignee
|
||||
AccountLoader.Factory accountLoaderFactory,
|
||||
PermissionBackend permissionBackend) {
|
||||
super(retryHelper);
|
||||
this.accounts = accounts;
|
||||
this.accountResolver = accountResolver;
|
||||
this.assigneeFactory = assigneeFactory;
|
||||
this.db = db;
|
||||
this.reviewerAdder = reviewerAdder;
|
||||
@@ -88,7 +88,7 @@ public class PutAssignee extends RetryingRestModifyView<ChangeResource, Assignee
|
||||
throw new BadRequestException("missing assignee field");
|
||||
}
|
||||
|
||||
IdentifiedUser assignee = accounts.parse(input.assignee);
|
||||
IdentifiedUser assignee = accountResolver.parse(input.assignee);
|
||||
if (!assignee.getAccount().isActive()) {
|
||||
throw new UnprocessableEntityException(input.assignee + " is not active");
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ import com.google.gerrit.server.AnonymousUser;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountLoader;
|
||||
import com.google.gerrit.server.account.AccountResolver;
|
||||
import com.google.gerrit.server.account.GroupMembers;
|
||||
import com.google.gerrit.server.change.ChangeMessages;
|
||||
import com.google.gerrit.server.change.NotifyUtil;
|
||||
@@ -65,7 +66,6 @@ import com.google.gerrit.server.permissions.RefPermission;
|
||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.restapi.account.AccountsCollection;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
@@ -81,7 +81,7 @@ public class ReviewerAdder {
|
||||
public static final int DEFAULT_MAX_REVIEWERS_WITHOUT_CHECK = 10;
|
||||
public static final int DEFAULT_MAX_REVIEWERS = 20;
|
||||
|
||||
private final AccountsCollection accounts;
|
||||
private final AccountResolver accountResolver;
|
||||
private final PermissionBackend permissionBackend;
|
||||
private final GroupResolver groupResolver;
|
||||
private final GroupMembers groupMembers;
|
||||
@@ -98,7 +98,7 @@ public class ReviewerAdder {
|
||||
|
||||
@Inject
|
||||
ReviewerAdder(
|
||||
AccountsCollection accounts,
|
||||
AccountResolver accountResolver,
|
||||
PermissionBackend permissionBackend,
|
||||
GroupResolver groupResolver,
|
||||
GroupMembers groupMembers,
|
||||
@@ -112,7 +112,7 @@ public class ReviewerAdder {
|
||||
Provider<AnonymousUser> anonymousProvider,
|
||||
PostReviewersOp.Factory postReviewersOpFactory,
|
||||
OutgoingEmailValidator validator) {
|
||||
this.accounts = accounts;
|
||||
this.accountResolver = accountResolver;
|
||||
this.permissionBackend = permissionBackend;
|
||||
this.groupResolver = groupResolver;
|
||||
this.groupMembers = groupMembers;
|
||||
@@ -220,7 +220,7 @@ public class ReviewerAdder {
|
||||
IdentifiedUser reviewerUser;
|
||||
boolean exactMatchFound = false;
|
||||
try {
|
||||
reviewerUser = accounts.parse(reviewer);
|
||||
reviewerUser = accountResolver.parse(reviewer);
|
||||
if (reviewer.equalsIgnoreCase(reviewerUser.getName())
|
||||
|| reviewer.equals(String.valueOf(reviewerUser.getAccountId()))) {
|
||||
exactMatchFound = true;
|
||||
|
||||
@@ -42,6 +42,7 @@ import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.PatchSetUtil;
|
||||
import com.google.gerrit.server.ProjectUtil;
|
||||
import com.google.gerrit.server.account.AccountResolver;
|
||||
import com.google.gerrit.server.change.ChangeJson;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.RevisionResource;
|
||||
@@ -55,7 +56,6 @@ import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gerrit.server.query.change.InternalChangeQuery;
|
||||
import com.google.gerrit.server.restapi.account.AccountsCollection;
|
||||
import com.google.gerrit.server.submit.ChangeSet;
|
||||
import com.google.gerrit.server.submit.MergeOp;
|
||||
import com.google.gerrit.server.submit.MergeSuperSet;
|
||||
@@ -114,7 +114,7 @@ public class Submit
|
||||
private final ChangeNotes.Factory changeNotesFactory;
|
||||
private final Provider<MergeOp> mergeOpProvider;
|
||||
private final Provider<MergeSuperSet> mergeSuperSet;
|
||||
private final AccountsCollection accounts;
|
||||
private final AccountResolver accountResolver;
|
||||
private final String label;
|
||||
private final String labelWithParents;
|
||||
private final ParameterizedString titlePattern;
|
||||
@@ -135,7 +135,7 @@ public class Submit
|
||||
ChangeNotes.Factory changeNotesFactory,
|
||||
Provider<MergeOp> mergeOpProvider,
|
||||
Provider<MergeSuperSet> mergeSuperSet,
|
||||
AccountsCollection accounts,
|
||||
AccountResolver accountResolver,
|
||||
@GerritServerConfig Config cfg,
|
||||
Provider<InternalChangeQuery> queryProvider,
|
||||
PatchSetUtil psUtil,
|
||||
@@ -147,7 +147,7 @@ public class Submit
|
||||
this.changeNotesFactory = changeNotesFactory;
|
||||
this.mergeOpProvider = mergeOpProvider;
|
||||
this.mergeSuperSet = mergeSuperSet;
|
||||
this.accounts = accounts;
|
||||
this.accountResolver = accountResolver;
|
||||
this.label =
|
||||
MoreObjects.firstNonNull(
|
||||
Strings.emptyToNull(cfg.getString("change", null, "submitLabel")), "Submit");
|
||||
@@ -472,7 +472,7 @@ public class Submit
|
||||
perm.check(ChangePermission.SUBMIT_AS);
|
||||
|
||||
CurrentUser caller = rsrc.getUser();
|
||||
IdentifiedUser submitter = accounts.parseOnBehalfOf(caller, in.onBehalfOf);
|
||||
IdentifiedUser submitter = accountResolver.parseOnBehalfOf(caller, in.onBehalfOf);
|
||||
try {
|
||||
permissionBackend
|
||||
.user(submitter)
|
||||
|
||||
@@ -47,7 +47,6 @@ import com.google.gerrit.server.group.MemberResource;
|
||||
import com.google.gerrit.server.group.db.GroupsUpdate;
|
||||
import com.google.gerrit.server.group.db.InternalGroupUpdate;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.restapi.account.AccountsCollection;
|
||||
import com.google.gerrit.server.restapi.group.AddMembers.Input;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
@@ -90,7 +89,6 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
|
||||
|
||||
private final AccountManager accountManager;
|
||||
private final AuthType authType;
|
||||
private final AccountsCollection accounts;
|
||||
private final AccountResolver accountResolver;
|
||||
private final AccountCache accountCache;
|
||||
private final AccountLoader.Factory infoFactory;
|
||||
@@ -100,14 +98,12 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
|
||||
AddMembers(
|
||||
AccountManager accountManager,
|
||||
AuthConfig authConfig,
|
||||
AccountsCollection accounts,
|
||||
AccountResolver accountResolver,
|
||||
AccountCache accountCache,
|
||||
AccountLoader.Factory infoFactory,
|
||||
@UserInitiated Provider<GroupsUpdate> groupsUpdateProvider) {
|
||||
this.accountManager = accountManager;
|
||||
this.authType = authConfig.getAuthType();
|
||||
this.accounts = accounts;
|
||||
this.accountResolver = accountResolver;
|
||||
this.accountCache = accountCache;
|
||||
this.infoFactory = infoFactory;
|
||||
@@ -151,7 +147,7 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
|
||||
throws AuthException, UnprocessableEntityException, OrmException, IOException,
|
||||
ConfigInvalidException {
|
||||
try {
|
||||
return accounts.parse(nameOrEmailOrId).getAccount();
|
||||
return accountResolver.parse(nameOrEmailOrId).getAccount();
|
||||
} catch (UnprocessableEntityException e) {
|
||||
// might be because the account does not exist or because the account is
|
||||
// not visible
|
||||
|
||||
@@ -26,12 +26,12 @@ import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.server.UserInitiated;
|
||||
import com.google.gerrit.server.account.AccountResolver;
|
||||
import com.google.gerrit.server.account.GroupControl;
|
||||
import com.google.gerrit.server.group.GroupResource;
|
||||
import com.google.gerrit.server.group.MemberResource;
|
||||
import com.google.gerrit.server.group.db.GroupsUpdate;
|
||||
import com.google.gerrit.server.group.db.InternalGroupUpdate;
|
||||
import com.google.gerrit.server.restapi.account.AccountsCollection;
|
||||
import com.google.gerrit.server.restapi.group.AddMembers.Input;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
@@ -44,13 +44,13 @@ import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
|
||||
@Singleton
|
||||
public class DeleteMembers implements RestModifyView<GroupResource, Input> {
|
||||
private final AccountsCollection accounts;
|
||||
private final AccountResolver accountResolver;
|
||||
private final Provider<GroupsUpdate> groupsUpdateProvider;
|
||||
|
||||
@Inject
|
||||
DeleteMembers(
|
||||
AccountsCollection accounts, @UserInitiated Provider<GroupsUpdate> groupsUpdateProvider) {
|
||||
this.accounts = accounts;
|
||||
AccountResolver accountResolver, @UserInitiated Provider<GroupsUpdate> groupsUpdateProvider) {
|
||||
this.accountResolver = accountResolver;
|
||||
this.groupsUpdateProvider = groupsUpdateProvider;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class DeleteMembers implements RestModifyView<GroupResource, Input> {
|
||||
|
||||
Set<Account.Id> membersToRemove = new HashSet<>();
|
||||
for (String nameOrEmail : input.members) {
|
||||
Account a = accounts.parse(nameOrEmail).getAccount();
|
||||
Account a = accountResolver.parse(nameOrEmail).getAccount();
|
||||
membersToRemove.add(a.getId());
|
||||
}
|
||||
AccountGroup.UUID groupUuid = internalGroup.getGroupUUID();
|
||||
|
||||
Reference in New Issue
Block a user