Remove access of groups related db tables from CreateAccount
Change-Id: I445d268e24cd68549f704661513b77717d05dd74
This commit is contained in:
		@@ -16,7 +16,6 @@ package com.google.gerrit.server.account;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_MAILTO;
 | 
					import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_MAILTO;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.gerrit.audit.AuditService;
 | 
					 | 
				
			||||||
import com.google.gerrit.common.Nullable;
 | 
					import com.google.gerrit.common.Nullable;
 | 
				
			||||||
import com.google.gerrit.common.data.GlobalCapability;
 | 
					import com.google.gerrit.common.data.GlobalCapability;
 | 
				
			||||||
import com.google.gerrit.common.data.GroupDescriptions;
 | 
					import com.google.gerrit.common.data.GroupDescriptions;
 | 
				
			||||||
@@ -33,7 +32,6 @@ 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.client.AccountGroup;
 | 
					import com.google.gerrit.reviewdb.client.AccountGroup;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.AccountGroupMember;
 | 
					 | 
				
			||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
 | 
					import com.google.gerrit.reviewdb.server.ReviewDb;
 | 
				
			||||||
import com.google.gerrit.server.IdentifiedUser;
 | 
					import com.google.gerrit.server.IdentifiedUser;
 | 
				
			||||||
import com.google.gerrit.server.Sequences;
 | 
					import com.google.gerrit.server.Sequences;
 | 
				
			||||||
@@ -42,6 +40,8 @@ import com.google.gerrit.server.account.externalids.ExternalIds;
 | 
				
			|||||||
import com.google.gerrit.server.account.externalids.ExternalIdsUpdate;
 | 
					import com.google.gerrit.server.account.externalids.ExternalIdsUpdate;
 | 
				
			||||||
import com.google.gerrit.server.api.accounts.AccountExternalIdCreator;
 | 
					import com.google.gerrit.server.api.accounts.AccountExternalIdCreator;
 | 
				
			||||||
import com.google.gerrit.server.group.GroupsCollection;
 | 
					import com.google.gerrit.server.group.GroupsCollection;
 | 
				
			||||||
 | 
					import com.google.gerrit.server.group.GroupsUpdate;
 | 
				
			||||||
 | 
					import com.google.gerrit.server.group.UserInitiated;
 | 
				
			||||||
import com.google.gerrit.server.mail.send.OutgoingEmailValidator;
 | 
					import com.google.gerrit.server.mail.send.OutgoingEmailValidator;
 | 
				
			||||||
import com.google.gerrit.server.ssh.SshKeyCache;
 | 
					import com.google.gerrit.server.ssh.SshKeyCache;
 | 
				
			||||||
import com.google.gwtorm.server.OrmDuplicateKeyException;
 | 
					import com.google.gwtorm.server.OrmDuplicateKeyException;
 | 
				
			||||||
@@ -51,7 +51,6 @@ 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 java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.Collections;
 | 
					 | 
				
			||||||
import java.util.HashSet;
 | 
					import java.util.HashSet;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.Set;
 | 
					import java.util.Set;
 | 
				
			||||||
@@ -65,7 +64,6 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  private final ReviewDb db;
 | 
					  private final ReviewDb db;
 | 
				
			||||||
  private final Sequences seq;
 | 
					  private final Sequences seq;
 | 
				
			||||||
  private final Provider<IdentifiedUser> currentUser;
 | 
					 | 
				
			||||||
  private final GroupsCollection groupsCollection;
 | 
					  private final GroupsCollection groupsCollection;
 | 
				
			||||||
  private final VersionedAuthorizedKeys.Accessor authorizedKeys;
 | 
					  private final VersionedAuthorizedKeys.Accessor authorizedKeys;
 | 
				
			||||||
  private final SshKeyCache sshKeyCache;
 | 
					  private final SshKeyCache sshKeyCache;
 | 
				
			||||||
@@ -74,9 +72,9 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn
 | 
				
			|||||||
  private final AccountByEmailCache byEmailCache;
 | 
					  private final AccountByEmailCache byEmailCache;
 | 
				
			||||||
  private final AccountLoader.Factory infoLoader;
 | 
					  private final AccountLoader.Factory infoLoader;
 | 
				
			||||||
  private final DynamicSet<AccountExternalIdCreator> externalIdCreators;
 | 
					  private final DynamicSet<AccountExternalIdCreator> externalIdCreators;
 | 
				
			||||||
  private final AuditService auditService;
 | 
					 | 
				
			||||||
  private final ExternalIds externalIds;
 | 
					  private final ExternalIds externalIds;
 | 
				
			||||||
  private final ExternalIdsUpdate.User externalIdsUpdateFactory;
 | 
					  private final ExternalIdsUpdate.User externalIdsUpdateFactory;
 | 
				
			||||||
 | 
					  private final Provider<GroupsUpdate> groupsUpdate;
 | 
				
			||||||
  private final OutgoingEmailValidator validator;
 | 
					  private final OutgoingEmailValidator validator;
 | 
				
			||||||
  private final String username;
 | 
					  private final String username;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -93,14 +91,13 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn
 | 
				
			|||||||
      AccountByEmailCache byEmailCache,
 | 
					      AccountByEmailCache byEmailCache,
 | 
				
			||||||
      AccountLoader.Factory infoLoader,
 | 
					      AccountLoader.Factory infoLoader,
 | 
				
			||||||
      DynamicSet<AccountExternalIdCreator> externalIdCreators,
 | 
					      DynamicSet<AccountExternalIdCreator> externalIdCreators,
 | 
				
			||||||
      AuditService auditService,
 | 
					 | 
				
			||||||
      ExternalIds externalIds,
 | 
					      ExternalIds externalIds,
 | 
				
			||||||
      ExternalIdsUpdate.User externalIdsUpdateFactory,
 | 
					      ExternalIdsUpdate.User externalIdsUpdateFactory,
 | 
				
			||||||
 | 
					      @UserInitiated Provider<GroupsUpdate> groupsUpdate,
 | 
				
			||||||
      OutgoingEmailValidator validator,
 | 
					      OutgoingEmailValidator validator,
 | 
				
			||||||
      @Assisted String username) {
 | 
					      @Assisted String username) {
 | 
				
			||||||
    this.db = db;
 | 
					    this.db = db;
 | 
				
			||||||
    this.seq = seq;
 | 
					    this.seq = seq;
 | 
				
			||||||
    this.currentUser = currentUser;
 | 
					 | 
				
			||||||
    this.groupsCollection = groupsCollection;
 | 
					    this.groupsCollection = groupsCollection;
 | 
				
			||||||
    this.authorizedKeys = authorizedKeys;
 | 
					    this.authorizedKeys = authorizedKeys;
 | 
				
			||||||
    this.sshKeyCache = sshKeyCache;
 | 
					    this.sshKeyCache = sshKeyCache;
 | 
				
			||||||
@@ -109,9 +106,9 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn
 | 
				
			|||||||
    this.byEmailCache = byEmailCache;
 | 
					    this.byEmailCache = byEmailCache;
 | 
				
			||||||
    this.infoLoader = infoLoader;
 | 
					    this.infoLoader = infoLoader;
 | 
				
			||||||
    this.externalIdCreators = externalIdCreators;
 | 
					    this.externalIdCreators = externalIdCreators;
 | 
				
			||||||
    this.auditService = auditService;
 | 
					 | 
				
			||||||
    this.externalIds = externalIds;
 | 
					    this.externalIds = externalIds;
 | 
				
			||||||
    this.externalIdsUpdateFactory = externalIdsUpdateFactory;
 | 
					    this.externalIdsUpdateFactory = externalIdsUpdateFactory;
 | 
				
			||||||
 | 
					    this.groupsUpdate = groupsUpdate;
 | 
				
			||||||
    this.validator = validator;
 | 
					    this.validator = validator;
 | 
				
			||||||
    this.username = username;
 | 
					    this.username = username;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -189,10 +186,7 @@ public class CreateAccount implements RestModifyView<TopLevelResource, AccountIn
 | 
				
			|||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (AccountGroup.Id groupId : groups) {
 | 
					    for (AccountGroup.Id groupId : groups) {
 | 
				
			||||||
      AccountGroupMember m = new AccountGroupMember(new AccountGroupMember.Key(id, groupId));
 | 
					      groupsUpdate.get().addGroupMember(db, groupId, id);
 | 
				
			||||||
      auditService.dispatchAddAccountsToGroup(
 | 
					 | 
				
			||||||
          currentUser.get().getAccountId(), Collections.singleton(m));
 | 
					 | 
				
			||||||
      db.accountGroupMembers().insert(Collections.singleton(m));
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (input.sshKey != null) {
 | 
					    if (input.sshKey != null) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -93,6 +93,11 @@ public class GroupsUpdate {
 | 
				
			|||||||
    addGroupMembers(db, group, ImmutableSet.of(accountId));
 | 
					    addGroupMembers(db, group, ImmutableSet.of(accountId));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public void addGroupMember(ReviewDb db, AccountGroup.Id groupId, Account.Id accountId)
 | 
				
			||||||
 | 
					      throws OrmException, IOException {
 | 
				
			||||||
 | 
					    addGroupMembers(db, groupId, ImmutableSet.of(accountId));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public void addGroupMembers(ReviewDb db, AccountGroup.Id groupId, Set<Account.Id> accountIds)
 | 
					  public void addGroupMembers(ReviewDb db, AccountGroup.Id groupId, Set<Account.Id> accountIds)
 | 
				
			||||||
      throws OrmException, IOException {
 | 
					      throws OrmException, IOException {
 | 
				
			||||||
    Optional<AccountGroup> foundGroup = groups.get(db, groupId);
 | 
					    Optional<AccountGroup> foundGroup = groups.get(db, groupId);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user