Search in sources :

Example 1 with FormPermissions

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\""));
}
Also used : FormPermissions(org.activityinfo.model.form.FormPermissions) FormTree(org.activityinfo.model.formTree.FormTree) NfiForm(org.activityinfo.store.testing.NfiForm) Test(org.junit.Test)

Example 2 with FormPermissions

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);
    }
}
Also used : FormPermissions(org.activityinfo.model.form.FormPermissions) ColumnView(org.activityinfo.model.query.ColumnView) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) FormulaNode(org.activityinfo.model.formula.FormulaNode) FormTree(org.activityinfo.model.formTree.FormTree)

Example 3 with FormPermissions

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);
}
Also used : FormPermissions(org.activityinfo.model.form.FormPermissions) FormStorage(org.activityinfo.store.spi.FormStorage)

Aggregations

FormPermissions (org.activityinfo.model.form.FormPermissions)3 FormTree (org.activityinfo.model.formTree.FormTree)2 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)1 FormulaNode (org.activityinfo.model.formula.FormulaNode)1 ColumnView (org.activityinfo.model.query.ColumnView)1 FormStorage (org.activityinfo.store.spi.FormStorage)1 NfiForm (org.activityinfo.store.testing.NfiForm)1 Test (org.junit.Test)1