Search in sources :

Example 1 with UserPermission

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();
    }
}
Also used : SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode) ConstantNode(org.activityinfo.model.formula.ConstantNode) UserPermission(org.activityinfo.store.mysql.metadata.UserPermission)

Aggregations

ConstantNode (org.activityinfo.model.formula.ConstantNode)1 FormulaNode (org.activityinfo.model.formula.FormulaNode)1 SymbolNode (org.activityinfo.model.formula.SymbolNode)1 UserPermission (org.activityinfo.store.mysql.metadata.UserPermission)1