Fix issue with querying inactive user changes
Introduce the custom account activity predicate to allow customise the way of resolving accounts during the search. Current implementation filters out inactive users during the change data query but changes from inactive user should be visible. Bug: Issue 11367 Change-Id: Ib8cfcf3e7c4f21a0207f801c111c5359716bda9c
This commit is contained in:
committed by
Luca Milanesio
parent
d722ffc7cb
commit
de3662444a
@@ -162,6 +162,23 @@ public class AccountResolverTest extends GerritBaseTests {
|
||||
assertThat(filteredInactiveIds(result)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUseCustomAccountActivityPredicate() throws Exception {
|
||||
TestSearcher searcher1 = new TestSearcher("foo", false, newInactiveAccount(1));
|
||||
searcher1.setCallerShouldFilterOutInactiveCandidates();
|
||||
TestSearcher searcher2 = new TestSearcher("f.*", false, newInactiveAccount(2));
|
||||
searcher2.setCallerShouldFilterOutInactiveCandidates();
|
||||
ImmutableList<Searcher<?>> searchers = ImmutableList.of(searcher1, searcher2);
|
||||
|
||||
Result result = search("foo", searchers, allVisible(), (a) -> true);
|
||||
// Searchers always short-circuit when finding a non-empty result list,
|
||||
// and this one didn't filter out inactive results,
|
||||
// so the second searcher never ran.
|
||||
assertThat(result.asIdSet()).containsExactlyElementsIn(ids(1));
|
||||
assertThat(getOnlyElement(result.asList()).getAccount().isActive()).isFalse();
|
||||
assertThat(filteredInactiveIds(result)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterInactiveEventuallyFindingResults() throws Exception {
|
||||
TestSearcher searcher1 = new TestSearcher("foo", false, newInactiveAccount(1));
|
||||
@@ -324,7 +341,16 @@ public class AccountResolverTest extends GerritBaseTests {
|
||||
ImmutableList<Searcher<?>> searchers,
|
||||
Supplier<Predicate<AccountState>> visibilitySupplier)
|
||||
throws Exception {
|
||||
return newAccountResolver().searchImpl(input, searchers, visibilitySupplier);
|
||||
return search(input, searchers, visibilitySupplier, activityPrediate());
|
||||
}
|
||||
|
||||
private Result search(
|
||||
String input,
|
||||
ImmutableList<Searcher<?>> searchers,
|
||||
Supplier<Predicate<AccountState>> visibilitySupplier,
|
||||
Predicate<AccountState> activityPredicate)
|
||||
throws Exception {
|
||||
return newAccountResolver().searchImpl(input, searchers, visibilitySupplier, activityPredicate);
|
||||
}
|
||||
|
||||
private static AccountResolver newAccountResolver() {
|
||||
@@ -350,6 +376,10 @@ public class AccountResolverTest extends GerritBaseTests {
|
||||
return () -> a -> true;
|
||||
}
|
||||
|
||||
private Predicate<AccountState> activityPrediate() {
|
||||
return (AccountState accountState) -> accountState.getAccount().isActive();
|
||||
}
|
||||
|
||||
private static Supplier<Predicate<AccountState>> only(int... ids) {
|
||||
ImmutableSet<Account.Id> idSet =
|
||||
Arrays.stream(ids).mapToObj(Account.Id::new).collect(toImmutableSet());
|
||||
|
||||
Reference in New Issue
Block a user