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;
}
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);
}
}
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);
}
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;
}
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()));
}
}
Aggregations