Search in sources :

Example 1 with BooleanCondition

use of com.google.gerrit.extensions.conditions.BooleanCondition in project gerrit by GerritCodeReview.

the class UiActions method describe.

@Nullable
private <R extends RestResource> UiAction.Description describe(Extension<RestView<R>> e, R resource) {
    int d = e.getExportName().indexOf('.');
    if (d < 0) {
        return null;
    }
    RestView<R> view;
    try {
        view = e.getProvider().get();
    } catch (RuntimeException err) {
        logger.atSevere().withCause(err).log("error creating view %s.%s", e.getPluginName(), e.getExportName());
        return null;
    }
    if (!(view instanceof UiAction)) {
        return null;
    }
    String name = e.getExportName().substring(d + 1);
    UiAction.Description dsc = null;
    try (Timer1.Context<String> ignored = uiActionLatency.start(name)) {
        dsc = ((UiAction<R>) view).getDescription(resource);
    } catch (Exception ex) {
        logger.atSevere().withCause(ex).log("Unable to render UIAction. Will omit from actions");
    }
    if (dsc == null) {
        return null;
    }
    Set<GlobalOrPluginPermission> globalRequired;
    try {
        globalRequired = GlobalPermission.fromAnnotation(e.getPluginName(), view.getClass());
    } catch (PermissionBackendException err) {
        logger.atSevere().withCause(err).log("exception testing view %s.%s", e.getPluginName(), e.getExportName());
        return null;
    }
    if (!globalRequired.isEmpty()) {
        PermissionBackend.WithUser withUser = permissionBackend.currentUser();
        Iterator<GlobalOrPluginPermission> i = globalRequired.iterator();
        BooleanCondition p = withUser.testCond(i.next());
        while (i.hasNext()) {
            p = or(p, withUser.testCond(i.next()));
        }
        dsc.setVisible(and(p, dsc.getVisibleCondition()));
    }
    PrivateInternals_UiActionDescription.setMethod(dsc, e.getExportName().substring(0, d));
    PrivateInternals_UiActionDescription.setId(dsc, PluginName.GERRIT.equals(e.getPluginName()) ? name : e.getPluginName() + '~' + name);
    return dsc;
}
Also used : BooleanCondition(com.google.gerrit.extensions.conditions.BooleanCondition) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) Description(com.google.gerrit.extensions.webui.UiAction.Description) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) UiAction(com.google.gerrit.extensions.webui.UiAction) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) Timer1(com.google.gerrit.metrics.Timer1) GlobalOrPluginPermission(com.google.gerrit.extensions.api.access.GlobalOrPluginPermission) Nullable(com.google.gerrit.common.Nullable)

Example 2 with BooleanCondition

use of com.google.gerrit.extensions.conditions.BooleanCondition in project gerrit by GerritCodeReview.

the class PermissionBackendConditionIT method projectPermissions_sameResourceDifferentUserDoesNotEqual.

@Test
public void projectPermissions_sameResourceDifferentUserDoesNotEqual() throws Exception {
    BooleanCondition cond1 = pb.user(user()).project(project).testCond(ProjectPermission.READ);
    BooleanCondition cond2 = pb.user(admin()).project(project).testCond(ProjectPermission.READ);
    assertNotEquals(cond1, cond2);
    assertNotEquals(cond1.hashCode(), cond2.hashCode());
}
Also used : BooleanCondition(com.google.gerrit.extensions.conditions.BooleanCondition) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with BooleanCondition

use of com.google.gerrit.extensions.conditions.BooleanCondition in project gerrit by GerritCodeReview.

the class PermissionBackendConditionIT method globalPermissions_differentPermissionDoesNotEquals.

@Test
public void globalPermissions_differentPermissionDoesNotEquals() throws Exception {
    BooleanCondition cond1 = pb.user(user()).testCond(GlobalPermission.CREATE_GROUP);
    BooleanCondition cond2 = pb.user(user()).testCond(GlobalPermission.ACCESS_DATABASE);
    assertNotEquals(cond1, cond2);
    assertNotEquals(cond1.hashCode(), cond2.hashCode());
}
Also used : BooleanCondition(com.google.gerrit.extensions.conditions.BooleanCondition) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with BooleanCondition

use of com.google.gerrit.extensions.conditions.BooleanCondition in project gerrit by GerritCodeReview.

the class PermissionBackendConditionIT method projectPermissions_sameResourceAndUserEquals.

@Test
public void projectPermissions_sameResourceAndUserEquals() throws Exception {
    BooleanCondition cond1 = pb.user(user()).project(project).testCond(ProjectPermission.READ);
    BooleanCondition cond2 = pb.user(user()).project(project).testCond(ProjectPermission.READ);
    assertEquals(cond1, cond2);
    assertEquals(cond1.hashCode(), cond2.hashCode());
}
Also used : BooleanCondition(com.google.gerrit.extensions.conditions.BooleanCondition) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with BooleanCondition

use of com.google.gerrit.extensions.conditions.BooleanCondition in project gerrit by GerritCodeReview.

the class PermissionBackendConditionIT method refPermissions_sameResourceAndUserEquals.

@Test
public void refPermissions_sameResourceAndUserEquals() throws Exception {
    BranchNameKey branch = BranchNameKey.create(project, "branch");
    BooleanCondition cond1 = pb.user(user()).ref(branch).testCond(RefPermission.READ);
    BooleanCondition cond2 = pb.user(user()).ref(branch).testCond(RefPermission.READ);
    assertEquals(cond1, cond2);
    assertEquals(cond1.hashCode(), cond2.hashCode());
}
Also used : BranchNameKey(com.google.gerrit.entities.BranchNameKey) BooleanCondition(com.google.gerrit.extensions.conditions.BooleanCondition) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

BooleanCondition (com.google.gerrit.extensions.conditions.BooleanCondition)14 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)13 Test (org.junit.Test)13 BranchNameKey (com.google.gerrit.entities.BranchNameKey)4 ChangeData (com.google.gerrit.server.query.change.ChangeData)3 Nullable (com.google.gerrit.common.Nullable)1 Project (com.google.gerrit.entities.Project)1 GlobalOrPluginPermission (com.google.gerrit.extensions.api.access.GlobalOrPluginPermission)1 UiAction (com.google.gerrit.extensions.webui.UiAction)1 Description (com.google.gerrit.extensions.webui.UiAction.Description)1 Timer1 (com.google.gerrit.metrics.Timer1)1 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1