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;
}
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());
}
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());
}
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());
}
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());
}
Aggregations