Throw an exception when a referenced group is not found
Change-Id: Id3c61dcf70492ba05475df4656fd89bad40c9324
This commit is contained in:
@@ -20,6 +20,7 @@ import com.google.gerrit.common.data.AccessSection;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.common.errors.NameAlreadyUsedException;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.extensions.client.AccountFieldName;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
@@ -125,7 +126,8 @@ public class AccountManager {
|
||||
* @param who identity of the user, with any details we received about them.
|
||||
* @return the result of authenticating the user.
|
||||
* @throws AccountException the account does not exist, and cannot be created, or exists, but
|
||||
* cannot be located, or is inactive.
|
||||
* cannot be located, or is inactive, or cannot be added to the admin group (only for the
|
||||
* first account).
|
||||
*/
|
||||
public AuthResult authenticate(AuthRequest who) throws AccountException, IOException {
|
||||
who = realm.authenticate(who);
|
||||
@@ -264,7 +266,11 @@ public class AccountManager {
|
||||
GroupsUpdate groupsUpdate = groupsUpdateProvider.get();
|
||||
// The user initiated this request by logging in. -> Attribute all modifications to that user.
|
||||
groupsUpdate.setCurrentUser(user);
|
||||
groupsUpdate.addGroupMember(db, uuid, newId);
|
||||
try {
|
||||
groupsUpdate.addGroupMember(db, uuid, newId);
|
||||
} catch (NoSuchGroupException e) {
|
||||
throw new AccountException(String.format("Group %s not found", uuid));
|
||||
}
|
||||
}
|
||||
|
||||
if (who.getUserName() != null) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.common.data.GroupDescriptions;
|
||||
import com.google.gerrit.common.errors.InvalidSshKeyException;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.api.accounts.AccountInput;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
@@ -186,7 +187,11 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn
|
||||
});
|
||||
|
||||
for (AccountGroup.UUID groupUuid : groups) {
|
||||
groupsUpdate.get().addGroupMember(db, groupUuid, id);
|
||||
try {
|
||||
groupsUpdate.get().addGroupMember(db, groupUuid, id);
|
||||
} catch (NoSuchGroupException e) {
|
||||
throw new UnprocessableEntityException(String.format("Group %s not found", groupUuid));
|
||||
}
|
||||
}
|
||||
|
||||
if (input.sshKey != null) {
|
||||
|
||||
@@ -187,7 +187,7 @@ public class GroupCacheImpl implements GroupCache {
|
||||
@Override
|
||||
public Optional<AccountGroup> load(AccountGroup.Id key) throws Exception {
|
||||
try (ReviewDb db = schema.open()) {
|
||||
return groups.get(db, key);
|
||||
return groups.getGroup(db, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,7 +205,7 @@ public class GroupCacheImpl implements GroupCache {
|
||||
@Override
|
||||
public Optional<AccountGroup> load(String name) throws Exception {
|
||||
try (ReviewDb db = schema.open()) {
|
||||
return groups.get(db, new AccountGroup.NameKey(name));
|
||||
return groups.getGroup(db, new AccountGroup.NameKey(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -223,7 +223,7 @@ public class GroupCacheImpl implements GroupCache {
|
||||
@Override
|
||||
public Optional<AccountGroup> load(String uuid) throws Exception {
|
||||
try (ReviewDb db = schema.open()) {
|
||||
return groups.get(db, new AccountGroup.UUID(uuid));
|
||||
return groups.getGroup(db, new AccountGroup.UUID(uuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class GroupDetailFactory implements Callable<GroupDetail> {
|
||||
return new GroupDetail(members, includes);
|
||||
}
|
||||
|
||||
private ImmutableSet<Account.Id> loadMembers() throws OrmException {
|
||||
private ImmutableSet<Account.Id> loadMembers() throws OrmException, NoSuchGroupException {
|
||||
return groups.getMembers(db, groupUuid).filter(control::canSeeMember).collect(toImmutableSet());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.cache.CacheModule;
|
||||
@@ -146,7 +147,8 @@ public class GroupIncludeCacheImpl implements GroupIncludeCache {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<AccountGroup.UUID> load(AccountGroup.UUID key) throws OrmException {
|
||||
public ImmutableList<AccountGroup.UUID> load(AccountGroup.UUID key)
|
||||
throws OrmException, NoSuchGroupException {
|
||||
try (ReviewDb db = schema.open()) {
|
||||
return groups.getIncludes(db, key).collect(toImmutableList());
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.google.gerrit.server.account;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.common.data.ContributorAgreement;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.extensions.common.AgreementInput;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
@@ -43,7 +44,6 @@ import org.eclipse.jgit.lib.Config;
|
||||
@Singleton
|
||||
public class PutAgreement implements RestModifyView<AccountResource, AgreementInput> {
|
||||
private final ProjectCache projectCache;
|
||||
private final GroupCache groupCache;
|
||||
private final Provider<IdentifiedUser> self;
|
||||
private final AgreementSignup agreementSignup;
|
||||
private final AddMembers addMembers;
|
||||
@@ -52,13 +52,11 @@ public class PutAgreement implements RestModifyView<AccountResource, AgreementIn
|
||||
@Inject
|
||||
PutAgreement(
|
||||
ProjectCache projectCache,
|
||||
GroupCache groupCache,
|
||||
Provider<IdentifiedUser> self,
|
||||
AgreementSignup agreementSignup,
|
||||
AddMembers addMembers,
|
||||
@GerritServerConfig Config config) {
|
||||
this.projectCache = projectCache;
|
||||
this.groupCache = groupCache;
|
||||
this.self = self;
|
||||
this.agreementSignup = agreementSignup;
|
||||
this.addMembers = addMembers;
|
||||
@@ -92,13 +90,12 @@ public class PutAgreement implements RestModifyView<AccountResource, AgreementIn
|
||||
throw new ResourceConflictException("autoverify group uuid not found");
|
||||
}
|
||||
|
||||
AccountGroup group = groupCache.get(uuid);
|
||||
if (group == null) {
|
||||
Account account = self.get().getAccount();
|
||||
try {
|
||||
addMembers.addMembers(uuid, ImmutableList.of(account.getId()));
|
||||
} catch (NoSuchGroupException e) {
|
||||
throw new ResourceConflictException("autoverify group not found");
|
||||
}
|
||||
|
||||
Account account = self.get().getAccount();
|
||||
addMembers.addMembers(group.getGroupUUID(), ImmutableList.of(account.getId()));
|
||||
agreementSignup.fire(account, agreementName);
|
||||
|
||||
return Response.ok(agreementName);
|
||||
|
||||
Reference in New Issue
Block a user