use of org.activityinfo.model.form.FormPermissions in project activityinfo by bedatadriven.
the class OperationFiltersTest method simpleRootFieldTest.
@Test
public void simpleRootFieldTest() {
NfiForm nfiForm = setup.getCatalog().getNfiForm();
FormTree formTree = setup.getCatalog().getFormTree(nfiForm.getFormId());
FormPermissions permissions = new FormPermissions.Builder().allowFilteredView(nfiForm.getVillageField().getId() + " == 'g12345'").allowFilteredEdit(nfiForm.getVillageField().getId() + "=='g12345'").build();
PermissionFilters filters = new PermissionFilters(formTree, permissions);
assertThat(filters.getReferenceBaseFilter(nfiForm.getVillageField().getId()).get().asExpression(), equalTo("[_id] == \"g12345\""));
}
use of org.activityinfo.model.form.FormPermissions in project activityinfo by bedatadriven.
the class FormScanBatch method computePermissionFilter.
private Slot<TableFilter> computePermissionFilter(ResourceId formId) {
FormPermissions permissions = supervisor.getFormPermissions(formId);
if (!permissions.isVisible()) {
return new PendingSlot<>(TableFilter.NONE_SELECTED);
}
if (!permissions.hasVisibilityFilter()) {
return new PendingSlot<>(TableFilter.ALL_SELECTED);
}
// Otherwise apply per-record permissions
try {
FormTreeBuilder formTreeBuilder = new FormTreeBuilder(formClassProvider);
FormTree formTree = formTreeBuilder.queryTree(formId);
FormulaNode formula = FormulaParser.parse(permissions.getViewFilter());
QueryEvaluator evaluator = new QueryEvaluator(FilterLevel.NONE, formTree, this);
Slot<ColumnView> filterView = evaluator.evaluateExpression(formula);
return new MemoizedSlot<>(filterView, new Function<ColumnView, TableFilter>() {
@Override
public TableFilter apply(ColumnView columnView) {
return new TableFilter(columnView);
}
});
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to parse visibility filter", e);
LOGGER.severe("Error parsing visibility filter '" + permissions.getViewFilter() + " in form " + formId + ": " + e.getMessage() + ". " + "For security reasons, no results will be shown");
return new PendingSlot<>(TableFilter.NONE_SELECTED);
}
}
use of org.activityinfo.model.form.FormPermissions in project activityinfo by bedatadriven.
the class FormSourceSyncImpl method getFormMetadata.
public FormMetadata getFormMetadata(ResourceId formId) {
Optional<FormStorage> storage = formCatalog.getForm(formId);
if (!storage.isPresent()) {
return FormMetadata.notFound(formId);
}
FormPermissions permissions = storage.get().getPermissions(userId);
if (!permissions.isVisible()) {
return FormMetadata.forbidden(formId);
}
return FormMetadata.of(storage.get().cacheVersion(), storage.get().getFormClass(), permissions);
}
Aggregations