Merge "Remove unused dbProvider field from IdentifiedUser"
This commit is contained in:
@@ -81,7 +81,6 @@ import com.google.gwtorm.server.OrmException;
|
|||||||
import com.google.gwtorm.server.SchemaFactory;
|
import com.google.gwtorm.server.SchemaFactory;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.util.Providers;
|
|
||||||
|
|
||||||
import org.eclipse.jgit.api.Git;
|
import org.eclipse.jgit.api.Git;
|
||||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||||
@@ -532,7 +531,7 @@ public abstract class AbstractDaemonTest {
|
|||||||
|
|
||||||
private Context newRequestContext(TestAccount account) {
|
private Context newRequestContext(TestAccount account) {
|
||||||
return atrScope.newContext(reviewDbProvider, new SshSession(server, account),
|
return atrScope.newContext(reviewDbProvider, new SshSession(server, account),
|
||||||
identifiedUserFactory.create(Providers.of(db), account.getId()));
|
identifiedUserFactory.create(account.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Context setApiUser(TestAccount account) {
|
protected Context setApiUser(TestAccount account) {
|
||||||
@@ -717,7 +716,7 @@ public abstract class AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected IdentifiedUser user(TestAccount testAccount) {
|
protected IdentifiedUser user(TestAccount testAccount) {
|
||||||
return identifiedUserFactory.create(Providers.of(db), testAccount.getId());
|
return identifiedUserFactory.create(testAccount.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RevisionResource parseCurrentRevisionResource(String changeId)
|
protected RevisionResource parseCurrentRevisionResource(String changeId)
|
||||||
|
@@ -38,7 +38,6 @@ import com.google.gerrit.server.project.ProjectControl;
|
|||||||
import com.google.gerrit.server.project.Util;
|
import com.google.gerrit.server.project.Util;
|
||||||
import com.google.gerrit.testutil.DisabledReviewDb;
|
import com.google.gerrit.testutil.DisabledReviewDb;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.util.Providers;
|
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
import org.eclipse.jgit.lib.Ref;
|
import org.eclipse.jgit.lib.Ref;
|
||||||
@@ -272,7 +271,7 @@ public class VisibleRefFilterIT extends AbstractDaemonTest {
|
|||||||
AcceptanceTestRequestScope.Context ctx = disableDb();
|
AcceptanceTestRequestScope.Context ctx = disableDb();
|
||||||
try (Repository repo = repoManager.openRepository(project)) {
|
try (Repository repo = repoManager.openRepository(project)) {
|
||||||
ProjectControl ctl = projectControlFactory.controlFor(project,
|
ProjectControl ctl = projectControlFactory.controlFor(project,
|
||||||
identifiedUserFactory.create(Providers.of(db), user.getId()));
|
identifiedUserFactory.create(user.getId()));
|
||||||
VisibleRefFilter filter = new VisibleRefFilter(
|
VisibleRefFilter filter = new VisibleRefFilter(
|
||||||
tagCache, changeCache, repo, ctl, new DisabledReviewDb(), true);
|
tagCache, changeCache, repo, ctl, new DisabledReviewDb(), true);
|
||||||
Map<String, Ref> all = repo.getAllRefs();
|
Map<String, Ref> all = repo.getAllRefs();
|
||||||
|
@@ -169,7 +169,7 @@ public class GerritPublicKeyChecker extends PublicKeyChecker {
|
|||||||
if (extId == null) {
|
if (extId == null) {
|
||||||
return CheckResult.bad("Key is not associated with any users");
|
return CheckResult.bad("Key is not associated with any users");
|
||||||
}
|
}
|
||||||
IdentifiedUser user = userFactory.create(db, extId.getAccountId());
|
IdentifiedUser user = userFactory.create(extId.getAccountId());
|
||||||
Set<String> allowedUserIds = getAllowedUserIds(user);
|
Set<String> allowedUserIds = getAllowedUserIds(user);
|
||||||
if (allowedUserIds.isEmpty()) {
|
if (allowedUserIds.isEmpty()) {
|
||||||
return CheckResult.bad("No identities found for user");
|
return CheckResult.bad("No identities found for user");
|
||||||
|
@@ -151,12 +151,12 @@ public class GerritPublicKeyCheckerTest {
|
|||||||
private IdentifiedUser addUser(String name) throws Exception {
|
private IdentifiedUser addUser(String name) throws Exception {
|
||||||
AuthRequest req = AuthRequest.forUser(name);
|
AuthRequest req = AuthRequest.forUser(name);
|
||||||
Account.Id id = accountManager.authenticate(req).getAccountId();
|
Account.Id id = accountManager.authenticate(req).getAccountId();
|
||||||
return userFactory.create(Providers.of(db), id);
|
return userFactory.create(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IdentifiedUser reloadUser() {
|
private IdentifiedUser reloadUser() {
|
||||||
accountCache.evict(userId);
|
accountCache.evict(userId);
|
||||||
user = userFactory.create(Providers.of(db), userId);
|
user = userFactory.create(userId);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,7 +20,6 @@ import com.google.common.collect.Sets;
|
|||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
|
||||||
import com.google.gerrit.server.account.AccountCache;
|
import com.google.gerrit.server.account.AccountCache;
|
||||||
import com.google.gerrit.server.account.AccountState;
|
import com.google.gerrit.server.account.AccountState;
|
||||||
import com.google.gerrit.server.account.CapabilityControl;
|
import com.google.gerrit.server.account.CapabilityControl;
|
||||||
@@ -90,29 +89,20 @@ public class IdentifiedUser extends CurrentUser {
|
|||||||
this.disableReverseDnsLookup = disableReverseDnsLookup;
|
this.disableReverseDnsLookup = disableReverseDnsLookup;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IdentifiedUser create(final Account.Id id) {
|
public IdentifiedUser create(Account.Id id) {
|
||||||
return create((SocketAddress) null, id);
|
return create((SocketAddress) null, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IdentifiedUser create(Provider<ReviewDb> db, Account.Id id) {
|
|
||||||
return new IdentifiedUser(capabilityControlFactory, starredChangesUtil,
|
|
||||||
authConfig, realm, anonymousCowardName, canonicalUrl, accountCache,
|
|
||||||
groupBackend, disableReverseDnsLookup, null, db, id, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IdentifiedUser create(SocketAddress remotePeer, Account.Id id) {
|
public IdentifiedUser create(SocketAddress remotePeer, Account.Id id) {
|
||||||
return new IdentifiedUser(capabilityControlFactory, starredChangesUtil,
|
return runAs(remotePeer, id, null);
|
||||||
authConfig, realm, anonymousCowardName, canonicalUrl, accountCache,
|
|
||||||
groupBackend, disableReverseDnsLookup, Providers.of(remotePeer), null,
|
|
||||||
id, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CurrentUser runAs(SocketAddress remotePeer, Account.Id id,
|
public IdentifiedUser runAs(SocketAddress remotePeer, Account.Id id,
|
||||||
@Nullable CurrentUser caller) {
|
@Nullable CurrentUser caller) {
|
||||||
return new IdentifiedUser(capabilityControlFactory, starredChangesUtil,
|
return new IdentifiedUser(capabilityControlFactory, starredChangesUtil,
|
||||||
authConfig, realm, anonymousCowardName, canonicalUrl, accountCache,
|
authConfig, realm, anonymousCowardName, canonicalUrl, accountCache,
|
||||||
groupBackend, disableReverseDnsLookup, Providers.of(remotePeer), null,
|
groupBackend, disableReverseDnsLookup, Providers.of(remotePeer), id,
|
||||||
id, caller);
|
caller);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,23 +123,20 @@ public class IdentifiedUser extends CurrentUser {
|
|||||||
private final AccountCache accountCache;
|
private final AccountCache accountCache;
|
||||||
private final GroupBackend groupBackend;
|
private final GroupBackend groupBackend;
|
||||||
private final Boolean disableReverseDnsLookup;
|
private final Boolean disableReverseDnsLookup;
|
||||||
|
|
||||||
private final Provider<SocketAddress> remotePeerProvider;
|
private final Provider<SocketAddress> remotePeerProvider;
|
||||||
private final Provider<ReviewDb> dbProvider;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RequestFactory(
|
RequestFactory(
|
||||||
CapabilityControl.Factory capabilityControlFactory,
|
CapabilityControl.Factory capabilityControlFactory,
|
||||||
@Nullable StarredChangesUtil starredChangesUtil,
|
@Nullable StarredChangesUtil starredChangesUtil,
|
||||||
final AuthConfig authConfig,
|
AuthConfig authConfig,
|
||||||
Realm realm,
|
Realm realm,
|
||||||
@AnonymousCowardName final String anonymousCowardName,
|
@AnonymousCowardName String anonymousCowardName,
|
||||||
@CanonicalWebUrl final Provider<String> canonicalUrl,
|
@CanonicalWebUrl Provider<String> canonicalUrl,
|
||||||
final AccountCache accountCache,
|
AccountCache accountCache,
|
||||||
final GroupBackend groupBackend,
|
GroupBackend groupBackend,
|
||||||
@DisableReverseDnsLookup final Boolean disableReverseDnsLookup,
|
@DisableReverseDnsLookup Boolean disableReverseDnsLookup,
|
||||||
@RemotePeer final Provider<SocketAddress> remotePeerProvider,
|
@RemotePeer Provider<SocketAddress> remotePeerProvider) {
|
||||||
final Provider<ReviewDb> dbProvider) {
|
|
||||||
this.capabilityControlFactory = capabilityControlFactory;
|
this.capabilityControlFactory = capabilityControlFactory;
|
||||||
this.starredChangesUtil = starredChangesUtil;
|
this.starredChangesUtil = starredChangesUtil;
|
||||||
this.authConfig = authConfig;
|
this.authConfig = authConfig;
|
||||||
@@ -160,21 +147,19 @@ public class IdentifiedUser extends CurrentUser {
|
|||||||
this.groupBackend = groupBackend;
|
this.groupBackend = groupBackend;
|
||||||
this.disableReverseDnsLookup = disableReverseDnsLookup;
|
this.disableReverseDnsLookup = disableReverseDnsLookup;
|
||||||
this.remotePeerProvider = remotePeerProvider;
|
this.remotePeerProvider = remotePeerProvider;
|
||||||
this.dbProvider = dbProvider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IdentifiedUser create(Account.Id id) {
|
public IdentifiedUser create(Account.Id id) {
|
||||||
return new IdentifiedUser(capabilityControlFactory, starredChangesUtil,
|
return new IdentifiedUser(capabilityControlFactory, starredChangesUtil,
|
||||||
authConfig, realm, anonymousCowardName, canonicalUrl, accountCache,
|
authConfig, realm, anonymousCowardName, canonicalUrl, accountCache,
|
||||||
groupBackend, disableReverseDnsLookup, remotePeerProvider, dbProvider,
|
groupBackend, disableReverseDnsLookup, remotePeerProvider, id, null);
|
||||||
id, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IdentifiedUser runAs(Account.Id id, CurrentUser caller) {
|
public IdentifiedUser runAs(Account.Id id, CurrentUser caller) {
|
||||||
return new IdentifiedUser(capabilityControlFactory, starredChangesUtil,
|
return new IdentifiedUser(capabilityControlFactory, starredChangesUtil,
|
||||||
authConfig, realm, anonymousCowardName, canonicalUrl, accountCache,
|
authConfig, realm, anonymousCowardName, canonicalUrl, accountCache,
|
||||||
groupBackend, disableReverseDnsLookup, remotePeerProvider, dbProvider,
|
groupBackend, disableReverseDnsLookup, remotePeerProvider, id,
|
||||||
id, caller);
|
caller);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,12 +181,7 @@ public class IdentifiedUser extends CurrentUser {
|
|||||||
private final Set<String> validEmails =
|
private final Set<String> validEmails =
|
||||||
Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
|
Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private final Provider<SocketAddress> remotePeerProvider;
|
private final Provider<SocketAddress> remotePeerProvider;
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private final Provider<ReviewDb> dbProvider;
|
|
||||||
|
|
||||||
private final Account.Id accountId;
|
private final Account.Id accountId;
|
||||||
|
|
||||||
private AccountState state;
|
private AccountState state;
|
||||||
@@ -224,7 +204,6 @@ public class IdentifiedUser extends CurrentUser {
|
|||||||
final GroupBackend groupBackend,
|
final GroupBackend groupBackend,
|
||||||
final Boolean disableReverseDnsLookup,
|
final Boolean disableReverseDnsLookup,
|
||||||
@Nullable final Provider<SocketAddress> remotePeerProvider,
|
@Nullable final Provider<SocketAddress> remotePeerProvider,
|
||||||
@Nullable final Provider<ReviewDb> dbProvider,
|
|
||||||
final Account.Id id,
|
final Account.Id id,
|
||||||
@Nullable CurrentUser realUser) {
|
@Nullable CurrentUser realUser) {
|
||||||
super(capabilityControlFactory);
|
super(capabilityControlFactory);
|
||||||
@@ -237,7 +216,6 @@ public class IdentifiedUser extends CurrentUser {
|
|||||||
this.anonymousCowardName = anonymousCowardName;
|
this.anonymousCowardName = anonymousCowardName;
|
||||||
this.disableReverseDnsLookup = disableReverseDnsLookup;
|
this.disableReverseDnsLookup = disableReverseDnsLookup;
|
||||||
this.remotePeerProvider = remotePeerProvider;
|
this.remotePeerProvider = remotePeerProvider;
|
||||||
this.dbProvider = dbProvider;
|
|
||||||
this.accountId = id;
|
this.accountId = id;
|
||||||
this.realUser = realUser != null ? realUser : this;
|
this.realUser = realUser != null ? realUser : this;
|
||||||
}
|
}
|
||||||
@@ -386,14 +364,11 @@ public class IdentifiedUser extends CurrentUser {
|
|||||||
user = user + "|" + "account-" + ua.getId().toString();
|
user = user + "|" + "account-" + ua.getId().toString();
|
||||||
|
|
||||||
String host = null;
|
String host = null;
|
||||||
if (remotePeerProvider != null) {
|
SocketAddress remotePeer = remotePeerProvider.get();
|
||||||
final SocketAddress remotePeer = remotePeerProvider.get();
|
if (remotePeer instanceof InetSocketAddress) {
|
||||||
if (remotePeer instanceof InetSocketAddress) {
|
InetSocketAddress sa = (InetSocketAddress) remotePeer;
|
||||||
final InetSocketAddress sa = (InetSocketAddress) remotePeer;
|
InetAddress in = sa.getAddress();
|
||||||
final InetAddress in = sa.getAddress();
|
host = in != null ? getHost(in) : sa.getHostName();
|
||||||
|
|
||||||
host = in != null ? getHost(in) : sa.getHostName();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (host == null || host.isEmpty()) {
|
if (host == null || host.isEmpty()) {
|
||||||
host = "unknown";
|
host = "unknown";
|
||||||
|
@@ -967,7 +967,7 @@ public class ChangeJson {
|
|||||||
if (in.getPushCertificate() != null) {
|
if (in.getPushCertificate() != null) {
|
||||||
out.pushCertificate = gpgApi.checkPushCertificate(
|
out.pushCertificate = gpgApi.checkPushCertificate(
|
||||||
in.getPushCertificate(),
|
in.getPushCertificate(),
|
||||||
userFactory.create(db, in.getUploader()));
|
userFactory.create(in.getUploader()));
|
||||||
} else {
|
} else {
|
||||||
out.pushCertificate = new PushCertificateInfo();
|
out.pushCertificate = new PushCertificateInfo();
|
||||||
}
|
}
|
||||||
|
@@ -64,8 +64,7 @@ public class SuggestChangeReviewers extends SuggestReviewers
|
|||||||
return new VisibilityControl() {
|
return new VisibilityControl() {
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisibleTo(Account.Id account) throws OrmException {
|
public boolean isVisibleTo(Account.Id account) throws OrmException {
|
||||||
IdentifiedUser who =
|
IdentifiedUser who = identifiedUserFactory.create(account);
|
||||||
identifiedUserFactory.create(dbProvider, account);
|
|
||||||
// we can't use changeControl directly as it won't suggest reviewers
|
// we can't use changeControl directly as it won't suggest reviewers
|
||||||
// to drafts
|
// to drafts
|
||||||
return rsrc.getControl().forUser(who).isRefVisible();
|
return rsrc.getControl().forUser(who).isRefVisible();
|
||||||
|
@@ -112,8 +112,7 @@ public class EmailMerge implements Runnable, RequestContext {
|
|||||||
@Override
|
@Override
|
||||||
public CurrentUser getUser() {
|
public CurrentUser getUser() {
|
||||||
if (submitter != null) {
|
if (submitter != null) {
|
||||||
return identifiedUserFactory.create(
|
return identifiedUserFactory.create(submitter).getRealUser();
|
||||||
getReviewDbProvider(), submitter).getRealUser();
|
|
||||||
}
|
}
|
||||||
throw new OutOfScopeException("No user on email thread");
|
throw new OutOfScopeException("No user on email thread");
|
||||||
}
|
}
|
||||||
|
@@ -174,8 +174,7 @@ public class ProjectWatch {
|
|||||||
|
|
||||||
private boolean add(Watchers matching, AccountProjectWatch w, NotifyType type)
|
private boolean add(Watchers matching, AccountProjectWatch w, NotifyType type)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
IdentifiedUser user =
|
IdentifiedUser user = args.identifiedUserFactory.create(w.getAccountId());
|
||||||
args.identifiedUserFactory.create(args.db, w.getAccountId());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (filterMatch(user, w.getFilter())) {
|
if (filterMatch(user, w.getFilter())) {
|
||||||
|
@@ -301,7 +301,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
|||||||
} catch (ProvisionException e) {
|
} catch (ProvisionException e) {
|
||||||
// Doesn't match current user, continue.
|
// Doesn't match current user, continue.
|
||||||
}
|
}
|
||||||
return asUser(userFactory.create(db, otherId));
|
return asUser(userFactory.create(otherId));
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentifiedUser getIdentifiedUser() throws QueryParseException {
|
IdentifiedUser getIdentifiedUser() throws QueryParseException {
|
||||||
@@ -736,7 +736,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
|||||||
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) {
|
||||||
return visibleto(args.userFactory.create(args.db, id));
|
return visibleto(args.userFactory.create(id));
|
||||||
}
|
}
|
||||||
return Predicate.or(p);
|
return Predicate.or(p);
|
||||||
}
|
}
|
||||||
@@ -791,7 +791,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
|||||||
if (g == null) {
|
if (g == null) {
|
||||||
throw error("Group " + group + " not found");
|
throw error("Group " + group + " not found");
|
||||||
}
|
}
|
||||||
return new OwnerinPredicate(args.db, args.userFactory, g.getUUID());
|
return new OwnerinPredicate(args.userFactory, g.getUUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operator
|
@Operator
|
||||||
@@ -818,7 +818,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
|||||||
if (g == null) {
|
if (g == null) {
|
||||||
throw error("Group " + group + " not found");
|
throw error("Group " + group + " not found");
|
||||||
}
|
}
|
||||||
return new ReviewerinPredicate(args.db, args.userFactory, g.getUUID());
|
return new ReviewerinPredicate(args.userFactory, g.getUUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operator
|
@Operator
|
||||||
|
@@ -112,7 +112,7 @@ class EqualsLabelPredicate extends IndexPredicate<ChangeData> {
|
|||||||
if (psVal == expVal) {
|
if (psVal == expVal) {
|
||||||
// Double check the value is still permitted for the user.
|
// Double check the value is still permitted for the user.
|
||||||
//
|
//
|
||||||
IdentifiedUser reviewer = userFactory.create(dbProvider, approver);
|
IdentifiedUser reviewer = userFactory.create(approver);
|
||||||
try {
|
try {
|
||||||
ChangeControl cc =
|
ChangeControl cc =
|
||||||
ccFactory.controlFor(dbProvider.get(), change, reviewer);
|
ccFactory.controlFor(dbProvider.get(), change, reviewer);
|
||||||
|
@@ -16,21 +16,17 @@ package com.google.gerrit.server.query.change;
|
|||||||
|
|
||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
import com.google.gerrit.server.query.OperatorPredicate;
|
import com.google.gerrit.server.query.OperatorPredicate;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Provider;
|
|
||||||
|
|
||||||
class OwnerinPredicate extends OperatorPredicate<ChangeData> {
|
class OwnerinPredicate extends OperatorPredicate<ChangeData> {
|
||||||
private final Provider<ReviewDb> dbProvider;
|
|
||||||
private final IdentifiedUser.GenericFactory userFactory;
|
private final IdentifiedUser.GenericFactory userFactory;
|
||||||
private final AccountGroup.UUID uuid;
|
private final AccountGroup.UUID uuid;
|
||||||
|
|
||||||
OwnerinPredicate(Provider<ReviewDb> dbProvider,
|
OwnerinPredicate(IdentifiedUser.GenericFactory userFactory,
|
||||||
IdentifiedUser.GenericFactory userFactory, AccountGroup.UUID uuid) {
|
AccountGroup.UUID uuid) {
|
||||||
super(ChangeQueryBuilder.FIELD_OWNERIN, uuid.toString());
|
super(ChangeQueryBuilder.FIELD_OWNERIN, uuid.toString());
|
||||||
this.dbProvider = dbProvider;
|
|
||||||
this.userFactory = userFactory;
|
this.userFactory = userFactory;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
}
|
}
|
||||||
@@ -45,8 +41,7 @@ class OwnerinPredicate extends OperatorPredicate<ChangeData> {
|
|||||||
if (change == null) {
|
if (change == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final IdentifiedUser owner = userFactory.create(dbProvider,
|
final IdentifiedUser owner = userFactory.create(change.getOwner());
|
||||||
change.getOwner());
|
|
||||||
return owner.getEffectiveGroups().contains(uuid);
|
return owner.getEffectiveGroups().contains(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,21 +16,17 @@ package com.google.gerrit.server.query.change;
|
|||||||
|
|
||||||
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.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
import com.google.gerrit.server.query.OperatorPredicate;
|
import com.google.gerrit.server.query.OperatorPredicate;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Provider;
|
|
||||||
|
|
||||||
class ReviewerinPredicate extends OperatorPredicate<ChangeData> {
|
class ReviewerinPredicate extends OperatorPredicate<ChangeData> {
|
||||||
private final Provider<ReviewDb> dbProvider;
|
|
||||||
private final IdentifiedUser.GenericFactory userFactory;
|
private final IdentifiedUser.GenericFactory userFactory;
|
||||||
private final AccountGroup.UUID uuid;
|
private final AccountGroup.UUID uuid;
|
||||||
|
|
||||||
ReviewerinPredicate(Provider<ReviewDb> dbProvider,
|
ReviewerinPredicate(IdentifiedUser.GenericFactory userFactory,
|
||||||
IdentifiedUser.GenericFactory userFactory, AccountGroup.UUID uuid) {
|
AccountGroup.UUID uuid) {
|
||||||
super(ChangeQueryBuilder.FIELD_REVIEWERIN, uuid.toString());
|
super(ChangeQueryBuilder.FIELD_REVIEWERIN, uuid.toString());
|
||||||
this.dbProvider = dbProvider;
|
|
||||||
this.userFactory = userFactory;
|
this.userFactory = userFactory;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
}
|
}
|
||||||
@@ -42,7 +38,7 @@ class ReviewerinPredicate extends OperatorPredicate<ChangeData> {
|
|||||||
@Override
|
@Override
|
||||||
public boolean match(final ChangeData object) throws OrmException {
|
public boolean match(final ChangeData object) throws OrmException {
|
||||||
for (Account.Id accountId : object.reviewers().values()) {
|
for (Account.Id accountId : object.reviewers().values()) {
|
||||||
IdentifiedUser reviewer = userFactory.create(dbProvider, accountId);
|
IdentifiedUser reviewer = userFactory.create(accountId);
|
||||||
if (reviewer.getEffectiveGroups().contains(uuid)) {
|
if (reviewer.getEffectiveGroups().contains(uuid)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -17,12 +17,10 @@ package gerrit;
|
|||||||
import static com.googlecode.prolog_cafe.lang.SymbolTerm.intern;
|
import static com.googlecode.prolog_cafe.lang.SymbolTerm.intern;
|
||||||
|
|
||||||
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.rules.PrologEnvironment;
|
import com.google.gerrit.rules.PrologEnvironment;
|
||||||
import com.google.gerrit.rules.StoredValues;
|
import com.google.gerrit.rules.StoredValues;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
import com.google.inject.util.Providers;
|
|
||||||
|
|
||||||
import com.googlecode.prolog_cafe.exceptions.IllegalTypeException;
|
import com.googlecode.prolog_cafe.exceptions.IllegalTypeException;
|
||||||
import com.googlecode.prolog_cafe.exceptions.PInstantiationException;
|
import com.googlecode.prolog_cafe.exceptions.PInstantiationException;
|
||||||
@@ -90,14 +88,8 @@ class PRED_current_user_2 extends Predicate.P2 {
|
|||||||
Account.Id accountId = new Account.Id(((IntegerTerm) idTerm).intValue());
|
Account.Id accountId = new Account.Id(((IntegerTerm) idTerm).intValue());
|
||||||
user = cache.get(accountId);
|
user = cache.get(accountId);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
ReviewDb db = StoredValues.REVIEW_DB.getOrNull(engine);
|
|
||||||
IdentifiedUser.GenericFactory userFactory = userFactory(engine);
|
IdentifiedUser.GenericFactory userFactory = userFactory(engine);
|
||||||
IdentifiedUser who;
|
IdentifiedUser who = userFactory.create(accountId);
|
||||||
if (db != null) {
|
|
||||||
who = userFactory.create(Providers.of(db), accountId);
|
|
||||||
} else {
|
|
||||||
who = userFactory.create(accountId);
|
|
||||||
}
|
|
||||||
cache.put(accountId, who);
|
cache.put(accountId, who);
|
||||||
user = who;
|
user = who;
|
||||||
}
|
}
|
||||||
|
@@ -90,7 +90,7 @@ public class LabelNormalizerTest {
|
|||||||
schemaCreator.create(db);
|
schemaCreator.create(db);
|
||||||
userId = accountManager.authenticate(AuthRequest.forUser("user"))
|
userId = accountManager.authenticate(AuthRequest.forUser("user"))
|
||||||
.getAccountId();
|
.getAccountId();
|
||||||
user = userFactory.create(Providers.of(db), userId);
|
user = userFactory.create(userId);
|
||||||
|
|
||||||
requestContext.setContext(new RequestContext() {
|
requestContext.setContext(new RequestContext() {
|
||||||
@Override
|
@Override
|
||||||
|
@@ -79,7 +79,7 @@ public class ProjectControlTest {
|
|||||||
schemaCreator.create(db);
|
schemaCreator.create(db);
|
||||||
Account.Id userId = accountManager.authenticate(AuthRequest.forUser("user"))
|
Account.Id userId = accountManager.authenticate(AuthRequest.forUser("user"))
|
||||||
.getAccountId();
|
.getAccountId();
|
||||||
user = userFactory.create(Providers.of(db), userId);
|
user = userFactory.create(userId);
|
||||||
|
|
||||||
Project.NameKey name = new Project.NameKey("project");
|
Project.NameKey name = new Project.NameKey("project");
|
||||||
InMemoryRepository inMemoryRepo = repoManager.createRepository(name);
|
InMemoryRepository inMemoryRepo = repoManager.createRepository(name);
|
||||||
|
@@ -156,13 +156,13 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
Account userAccount = db.accounts().get(userId);
|
Account userAccount = db.accounts().get(userId);
|
||||||
userAccount.setPreferredEmail("user@example.com");
|
userAccount.setPreferredEmail("user@example.com");
|
||||||
db.accounts().update(ImmutableList.of(userAccount));
|
db.accounts().update(ImmutableList.of(userAccount));
|
||||||
user = userFactory.create(Providers.of(db), userId);
|
user = userFactory.create(userId);
|
||||||
requestContext.setContext(newRequestContext(userAccount.getId()));
|
requestContext.setContext(newRequestContext(userAccount.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RequestContext newRequestContext(Account.Id requestUserId) {
|
protected RequestContext newRequestContext(Account.Id requestUserId) {
|
||||||
final CurrentUser requestUser =
|
final CurrentUser requestUser =
|
||||||
userFactory.create(Providers.of(db), requestUserId);
|
userFactory.create(requestUserId);
|
||||||
return new RequestContext() {
|
return new RequestContext() {
|
||||||
@Override
|
@Override
|
||||||
public CurrentUser getUser() {
|
public CurrentUser getUser() {
|
||||||
@@ -1540,7 +1540,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
Project.NameKey project = new Project.NameKey(
|
Project.NameKey project = new Project.NameKey(
|
||||||
repo.getRepository().getDescription().getRepositoryName());
|
repo.getRepository().getDescription().getRepositoryName());
|
||||||
Account.Id ownerId = owner != null ? owner : userId;
|
Account.Id ownerId = owner != null ? owner : userId;
|
||||||
IdentifiedUser user = userFactory.create(Providers.of(db), ownerId);
|
IdentifiedUser user = userFactory.create(ownerId);
|
||||||
try (BatchUpdate bu =
|
try (BatchUpdate bu =
|
||||||
updateFactory.create(db, project, user, TimeUtil.nowTs())) {
|
updateFactory.create(db, project, user, TimeUtil.nowTs())) {
|
||||||
bu.insertChange(ins);
|
bu.insertChange(ins);
|
||||||
|
Reference in New Issue
Block a user