Search in sources :

Example 16 with CrudEntityContext

use of io.jmix.core.accesscontext.CrudEntityContext in project jmix by jmix-framework.

the class DataStoreCrudListener method evaluateCrudAccess.

protected CrudEntityContext evaluateCrudAccess(MetaClass metaClass, Collection<AccessConstraint<?>> accessConstraints) {
    CrudEntityContext entityContext = new CrudEntityContext(metaClass);
    accessManager.applyConstraints(entityContext, accessConstraints);
    return entityContext;
}
Also used : CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext)

Example 17 with CrudEntityContext

use of io.jmix.core.accesscontext.CrudEntityContext in project jmix by jmix-framework.

the class CategoryEdit method setupFieldsLock.

protected void setupFieldsLock() {
    CrudEntityContext crudEntityContext = new CrudEntityContext(categoryDc.getEntityMetaClass());
    accessManager.applyRegisteredConstraints(crudEntityContext);
    if (!crudEntityContext.isUpdatePermitted()) {
        entityTypeField.setEnabled(false);
    }
}
Also used : CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext)

Example 18 with CrudEntityContext

use of io.jmix.core.accesscontext.CrudEntityContext in project jmix by jmix-framework.

the class CategoryEdit method initAttributeLocationTab.

protected void initAttributeLocationTab() {
    CrudEntityContext crudEntityContext = new CrudEntityContext(categoryDc.getEntityMetaClass());
    accessManager.applyRegisteredConstraints(crudEntityContext);
    VBoxLayout attributesLocationTabComponent = (VBoxLayout) tabSheet.getTabComponent(ATTRIBUTES_LOCATION_TAB);
    attributeLocationFragment = fragments.create(this, AttributeLocationFragment.class);
    attributeLocationFragment.setEnabled(crudEntityContext.isUpdatePermitted());
    Fragment fragment = attributeLocationFragment.getFragment();
    fragment.setWidth(Component.FULL_SIZE);
    attributesLocationTabComponent.add(fragment);
    attributesLocationTabComponent.expand(fragment);
}
Also used : AttributeLocationFragment(io.jmix.dynattrui.screen.location.AttributeLocationFragment) CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext) AttributeLocalizationFragment(io.jmix.dynattrui.screen.localization.AttributeLocalizationFragment) CategoryAttrsFragment(io.jmix.dynattrui.screen.categoryattr.CategoryAttrsFragment) AttributeLocationFragment(io.jmix.dynattrui.screen.location.AttributeLocationFragment)

Example 19 with CrudEntityContext

use of io.jmix.core.accesscontext.CrudEntityContext in project jmix by jmix-framework.

the class PermissionDataFetcher method getPermissions.

protected PermissionConfig getPermissions(boolean entities, boolean entityAttrs, boolean specifics) {
    PermissionConfig PermissionConfig = new PermissionConfig();
    List<ShortPermissionInfo> entityPermissions = new ArrayList<>();
    List<ShortPermissionInfo> entityAttributePermissions = new ArrayList<>();
    List<ShortPermissionInfo> specificPermissions = new ArrayList<>();
    PermissionConfig.setEntities(entityPermissions);
    PermissionConfig.setEntityAttributes(entityAttributePermissions);
    PermissionConfig.setSpecifics(specificPermissions);
    for (MetaClass metaClass : metadata.getSession().getClasses()) {
        CrudEntityContext entityContext = new CrudEntityContext(metaClass);
        accessManager.applyRegisteredConstraints(entityContext);
        if (entities) {
            if (entityContext.isCreatePermitted()) {
                entityPermissions.add(new ShortPermissionInfo(getEntityTarget(metaClass, "create"), ALLOWED_CRUD_PERMISSION));
            }
            if (entityContext.isReadPermitted()) {
                entityPermissions.add(new ShortPermissionInfo(getEntityTarget(metaClass, "read"), ALLOWED_CRUD_PERMISSION));
            }
            if (entityContext.isUpdatePermitted()) {
                entityPermissions.add(new ShortPermissionInfo(getEntityTarget(metaClass, "update"), ALLOWED_CRUD_PERMISSION));
            }
            if (entityContext.isDeletePermitted()) {
                entityPermissions.add(new ShortPermissionInfo(getEntityTarget(metaClass, "delete"), ALLOWED_CRUD_PERMISSION));
            }
        }
        if (entityAttrs) {
            for (MetaProperty metaProperty : metaClass.getProperties()) {
                EntityAttributeContext attributeContext = new EntityAttributeContext(metaClass, metaProperty.getName());
                accessManager.applyRegisteredConstraints(attributeContext);
                if (attributeContext.canModify()) {
                    entityAttributePermissions.add(new ShortPermissionInfo(getEntityAttributeTarget(metaClass, metaProperty), MODIFY_ATTRIBUTE_PERMISSION));
                } else if (attributeContext.canView()) {
                    entityAttributePermissions.add(new ShortPermissionInfo(getEntityAttributeTarget(metaClass, metaProperty), VIEW_ATTRIBUTE_PERMISSION));
                }
            }
        }
    }
    if (specifics) {
        GraphQLAccessContext downloadContext = new GraphQLAccessContext(GRAPHQL_FILE_DOWNLOAD_ENABLED);
        accessManager.applyRegisteredConstraints(downloadContext);
        if (downloadContext.isPermitted()) {
            specificPermissions.add(new ShortPermissionInfo(downloadContext.getName(), 1));
        } else {
            specificPermissions.add(new ShortPermissionInfo(downloadContext.getName(), 0));
        }
        GraphQLAccessContext uploadContext = new GraphQLAccessContext(GRAPHQL_FILE_UPLOAD_ENABLED);
        accessManager.applyRegisteredConstraints(uploadContext);
        if (uploadContext.isPermitted()) {
            specificPermissions.add(new ShortPermissionInfo(uploadContext.getName(), 1));
        } else {
            specificPermissions.add(new ShortPermissionInfo(uploadContext.getName(), 0));
        }
    }
    return PermissionConfig;
}
Also used : PermissionConfig(io.jmix.graphql.schema.permission.PermissionConfig) MetaClass(io.jmix.core.metamodel.model.MetaClass) CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext) GraphQLAccessContext(io.jmix.graphql.accesscontext.GraphQLAccessContext) EntityAttributeContext(io.jmix.core.accesscontext.EntityAttributeContext) ArrayList(java.util.ArrayList) ShortPermissionInfo(io.jmix.graphql.schema.permission.ShortPermissionInfo) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 20 with CrudEntityContext

use of io.jmix.core.accesscontext.CrudEntityContext in project jmix by jmix-framework.

the class EntityMutationDataFetcher method checkCanDeleteEntity.

protected void checkCanDeleteEntity(MetaClass metaClass) {
    CrudEntityContext entityContext = new CrudEntityContext(metaClass);
    accessManager.applyRegisteredConstraints(entityContext);
    if (!entityContext.isDeletePermitted()) {
        throw new PersistenceException(String.format("Deletion of the %s is forbidden", metaClass.getName()));
    }
}
Also used : CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext) PersistenceException(javax.persistence.PersistenceException)

Aggregations

CrudEntityContext (io.jmix.core.accesscontext.CrudEntityContext)26 MetaClass (io.jmix.core.metamodel.model.MetaClass)9 EntityAttributeContext (io.jmix.core.accesscontext.EntityAttributeContext)4 AttributeLocalizationFragment (io.jmix.dynattrui.screen.localization.AttributeLocalizationFragment)4 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)3 AccessDeniedException (io.jmix.core.security.AccessDeniedException)3 ArrayList (java.util.ArrayList)3 CategoryAttrsFragment (io.jmix.dynattrui.screen.categoryattr.CategoryAttrsFragment)2 AttributeLocationFragment (io.jmix.dynattrui.screen.location.AttributeLocationFragment)2 UiSetting (io.jmix.uidata.entity.UiSetting)2 UiTablePresentation (io.jmix.uidata.entity.UiTablePresentation)2 UUID (java.util.UUID)2 Query (javax.persistence.Query)2 TypedQuery (javax.persistence.TypedQuery)2 Attribute (org.dom4j.Attribute)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)1 AccessManager (io.jmix.core.AccessManager)1 Metadata (io.jmix.core.Metadata)1