use of org.activityinfo.model.formula.ConstantNode in project activityinfo by bedatadriven.
the class SiteFormStorage method getPermissions.
@Override
public FormPermissions getPermissions(int userId) {
if (activity.getOwnerUserId() == userId) {
return FormPermissions.owner();
} else {
UserPermission databasePermission = permissionsCache.getPermission(userId, activity.getDatabaseId());
FormPermissions.Builder permissions = FormPermissions.builder();
FormulaNode partnerFilter = Formulas.equals(new SymbolNode(CuidAdapter.partnerField(activity.getId())), new ConstantNode(CuidAdapter.partnerRecordId(databasePermission.getPartnerId()).asString()));
if (databasePermission.isViewAll()) {
permissions.allowView();
} else if (databasePermission.isView()) {
permissions.allowFilteredView(partnerFilter.asExpression());
}
if (databasePermission.isEditAll()) {
permissions.allowEdit();
} else if (databasePermission.isEdit()) {
permissions.allowFilteredEdit(partnerFilter.asExpression());
}
if (databasePermission.isDesign()) {
permissions.allowSchemaUpdate();
}
// published property of activity overrides user permissions
if (activity.isPublished()) {
permissions.allowUnfilteredView();
}
return permissions.build();
}
}
use of org.activityinfo.model.formula.ConstantNode in project activityinfo by bedatadriven.
the class SubFormDeletionTest method deleteParent.
@Test
public void deleteParent() {
QueryModel queryModel = new QueryModel(ReferralSubForm.FORM_ID);
queryModel.selectResourceId().as("id");
queryModel.selectExpr(new CompoundExpr(IncidentForm.FORM_ID, ColumnModel.ID_SYMBOL)).as("parent");
queryModel.selectExpr(new ConstantNode(1)).as("count");
ColumnSet columnSet = query(queryModel);
assertThat(columnSet.getNumRows(), equalTo(ReferralSubForm.ROW_COUNT));
System.out.println(columnSet.getColumnView("parent"));
// Now delete a number of parent records
delete(IncidentForm.FORM_ID, "c528");
// The query results should reflect the change
columnSet = query(queryModel);
assertThat(columnSet.getNumRows(), equalTo(ReferralSubForm.ROW_COUNT - 2));
}
use of org.activityinfo.model.formula.ConstantNode in project activityinfo by bedatadriven.
the class FormStoreTest method serialNumberOffline.
@Test
public void serialNumberOffline() {
TestSetup setup = new TestSetup();
IntakeForm intakeForm = setup.getCatalog().getIntakeForm();
// Synchronize the intake form
setup.setConnected(true);
setup.getFormStore().setFormOffline(intakeForm.getFormId(), true);
setup.runScheduled();
// Go offline
setup.setConnected(false);
// Create a new intake record
FormInstance newRecord = intakeForm.getGenerator().get();
newRecord.set(intakeForm.getProtectionCodeFieldId(), (FieldValue) null);
Promise<Void> update = setup.getFormStore().updateRecords(new RecordTransactionBuilder().create(newRecord).build());
assertThat(update.getState(), equalTo(Promise.State.FULFILLED));
// Verify that we can read the new record offline
QueryModel queryModel = new QueryModel(intakeForm.getFormId());
queryModel.selectResourceId().as("id");
queryModel.selectField(intakeForm.getProtectionCodeFieldId()).as("serial");
queryModel.setFilter(Formulas.equals(new SymbolNode("_id"), new ConstantNode(newRecord.getId().asString())));
Connection<ColumnSet> view = setup.connect(setup.getFormStore().query(queryModel));
assertThat(view.assertLoaded().getNumRows(), equalTo(1));
assertThat(view.assertLoaded().getColumnView("serial").getString(0), nullValue());
// Now go online...
setup.setConnected(true);
setup.getOfflineStore().syncChanges();
;
setup.runScheduled();
// Check that the serial number has been updated with the value from the server
assertThat(view.assertLoaded().getColumnView("serial").getString(0), not(nullValue()));
}
Aggregations