Accounts: Load AccountState instead of Account

This allows to get a consistent view on an account. So far we loaded
account properties, external IDs, generel preferences and project
watches separately and it was possible that the account was updated in
between.

Change-Id: Ie4feae69274bc4dc58c91e1ecce43206a5d1c819
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2018-01-08 15:19:44 +01:00
parent 7bea8e2e0b
commit 246c7ad643
7 changed files with 49 additions and 69 deletions

View File

@@ -18,10 +18,12 @@ import com.google.common.base.Strings;
import com.google.common.collect.ComparisonChain;
import com.google.gerrit.extensions.client.ProjectWatchInfo;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountResource;
import com.google.gerrit.server.account.AccountState;
import com.google.gerrit.server.account.Accounts;
import com.google.gerrit.server.account.WatchConfig.NotifyType;
import com.google.gerrit.server.account.WatchConfig.ProjectWatchKey;
@@ -58,15 +60,18 @@ public class GetWatchedProjects implements RestReadView<AccountResource> {
@Override
public List<ProjectWatchInfo> apply(AccountResource rsrc)
throws OrmException, AuthException, IOException, ConfigInvalidException,
PermissionBackendException {
PermissionBackendException, ResourceNotFoundException {
if (self.get() != rsrc.getUser()) {
permissionBackend.user(self).check(GlobalPermission.ADMINISTRATE_SERVER);
}
Account.Id accountId = rsrc.getUser().getAccountId();
AccountState account = accounts.get(accountId);
if (account == null) {
throw new ResourceNotFoundException();
}
List<ProjectWatchInfo> projectWatchInfos = new ArrayList<>();
for (Map.Entry<ProjectWatchKey, Set<NotifyType>> e :
accounts.getProjectWatches(accountId).entrySet()) {
for (Map.Entry<ProjectWatchKey, Set<NotifyType>> e : account.getProjectWatches().entrySet()) {
ProjectWatchInfo pwi = new ProjectWatchInfo();
pwi.filter = e.getKey().filter();
pwi.project = e.getKey().project().get();