Support anonymous account queries
Change-Id: Ie2d42ccf2e0364d740d6d190f29fe7bc7fea95ca Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -123,11 +123,14 @@ public class AccountQueryBuilder extends QueryBuilder<AccountState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Predicate<AccountState> defaultField(String query)
|
public Predicate<AccountState> defaultField(String query) {
|
||||||
throws QueryParseException {
|
|
||||||
List<Predicate<AccountState>> preds = Lists.newArrayListWithCapacity(4);
|
List<Predicate<AccountState>> preds = Lists.newArrayListWithCapacity(4);
|
||||||
if ("self".equalsIgnoreCase(query)) {
|
if ("self".equalsIgnoreCase(query)) {
|
||||||
preds.add(AccountPredicates.id(self()));
|
try {
|
||||||
|
preds.add(AccountPredicates.id(self()));
|
||||||
|
} catch (QueryParseException e) {
|
||||||
|
// Skip.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Integer id = Ints.tryParse(query);
|
Integer id = Ints.tryParse(query);
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import com.google.gerrit.extensions.restapi.RestApiException;
|
|||||||
import com.google.gerrit.lifecycle.LifecycleManager;
|
import com.google.gerrit.lifecycle.LifecycleManager;
|
||||||
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.reviewdb.server.ReviewDb;
|
||||||
|
import com.google.gerrit.server.AnonymousUser;
|
||||||
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.gerrit.server.account.AccountCache;
|
import com.google.gerrit.server.account.AccountCache;
|
||||||
@@ -82,6 +83,9 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
|||||||
@Inject
|
@Inject
|
||||||
protected IdentifiedUser.GenericFactory userFactory;
|
protected IdentifiedUser.GenericFactory userFactory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Provider<AnonymousUser> anonymousUser;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected InMemoryDatabase schemaFactory;
|
protected InMemoryDatabase schemaFactory;
|
||||||
|
|
||||||
@@ -134,6 +138,20 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setAnonymous() {
|
||||||
|
requestContext.setContext(new RequestContext() {
|
||||||
|
@Override
|
||||||
|
public CurrentUser getUser() {
|
||||||
|
return anonymousUser.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Provider<ReviewDb> getReviewDbProvider() {
|
||||||
|
return Providers.of(db);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDownInjector() {
|
public void tearDownInjector() {
|
||||||
if (lifecycle != null) {
|
if (lifecycle != null) {
|
||||||
@@ -325,6 +343,16 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
|
|||||||
.containsExactlyElementsIn(Arrays.asList(secondaryEmails)).inOrder();
|
.containsExactlyElementsIn(Arrays.asList(secondaryEmails)).inOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void asAnonymous() throws Exception {
|
||||||
|
AccountInfo user1 = newAccount("user1");
|
||||||
|
|
||||||
|
setAnonymous();
|
||||||
|
assertQuery("9999999");
|
||||||
|
assertQuery("self");
|
||||||
|
assertQuery("username:" + user1.username, user1);
|
||||||
|
}
|
||||||
|
|
||||||
protected AccountInfo newAccount(String username) throws Exception {
|
protected AccountInfo newAccount(String username) throws Exception {
|
||||||
return newAccountWithEmail(username, null);
|
return newAccountWithEmail(username, null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user