use of org.activityinfo.store.mysql.metadata.UserPermission 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();
}
}
Aggregations