Search in sources :

Example 1 with PermissionBackendCondition

use of com.google.gerrit.server.permissions.PermissionBackendCondition in project gerrit by GerritCodeReview.

the class UiActionsTest method permissionBackendConditionEvaluationDeduplicatesAndBackfills.

@Test
public void permissionBackendConditionEvaluationDeduplicatesAndBackfills() throws Exception {
    FakeForProject forProject = new FakeForProject();
    // Create three conditions, two of which are identical
    PermissionBackendCondition cond1 = (PermissionBackendCondition) forProject.testCond(ProjectPermission.CREATE_CHANGE);
    PermissionBackendCondition cond2 = (PermissionBackendCondition) forProject.testCond(ProjectPermission.READ);
    PermissionBackendCondition cond3 = (PermissionBackendCondition) forProject.testCond(ProjectPermission.CREATE_CHANGE);
    // Set up the Mock to expect a call of bulkEvaluateTest to only contain cond{1,2} since cond3
    // needs to be identified as duplicate and not called out explicitly.
    PermissionBackend permissionBackendMock = mock(PermissionBackend.class);
    UiActions.evaluatePermissionBackendConditions(permissionBackendMock, ImmutableList.of(cond1, cond2, cond3));
    // Disallow queries for value to ensure that cond3 (previously left behind) is backfilled with
    // the value of cond1 and issues no additional call to PermissionBackend.
    forProject.disallowValueQueries();
    verify(permissionBackendMock, only()).bulkEvaluateTest(ImmutableSet.of(cond1, cond2));
    // Assert the values of all conditions
    assertThat(cond1.value()).isFalse();
    assertThat(cond2.value()).isTrue();
    assertThat(cond3.value()).isFalse();
}
Also used : PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) PermissionBackendCondition(com.google.gerrit.server.permissions.PermissionBackendCondition) Test(org.junit.Test)

Example 2 with PermissionBackendCondition

use of com.google.gerrit.server.permissions.PermissionBackendCondition in project gerrit by GerritCodeReview.

the class UiActions method evaluatePermissionBackendConditions.

@VisibleForTesting
static void evaluatePermissionBackendConditions(PermissionBackend perm, List<PermissionBackendCondition> conds) {
    Map<PermissionBackendCondition, PermissionBackendCondition> dedupedConds = new HashMap<>(conds.size());
    for (PermissionBackendCondition cond : conds) {
        dedupedConds.put(cond, cond);
    }
    perm.bulkEvaluateTest(dedupedConds.keySet());
    for (PermissionBackendCondition cond : conds) {
        cond.set(dedupedConds.get(cond).value());
    }
}
Also used : HashMap(java.util.HashMap) PermissionBackendCondition(com.google.gerrit.server.permissions.PermissionBackendCondition) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

PermissionBackendCondition (com.google.gerrit.server.permissions.PermissionBackendCondition)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1