use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.
the class AppSettingsEntityScreen method readPermitted.
protected boolean readPermitted(MetaClass metaClass) {
UiEntityContext entityContext = new UiEntityContext(metaClass);
accessManager.applyRegisteredConstraints(entityContext);
return entityContext.isViewPermitted();
}
use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.
the class EntityInspectorBrowser method readPermitted.
protected boolean readPermitted(MetaClass metaClass) {
UiEntityContext entityContext = new UiEntityContext(metaClass);
accessManager.applyRegisteredConstraints(entityContext);
return entityContext.isViewPermitted();
}
use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.
the class InspectorFormBuilder method addField.
/**
* Adds field to the specified form.
* If the field should be custom, adds it to the specified customFields collection
* which can be used later to create fieldGenerators
*
* @param metaProperty meta property of the item's property which field is creating
* @param form field group to which created field will be added
*/
protected void addField(InstanceContainer container, Form form, MetaProperty metaProperty, boolean isReadonly) {
MetaClass metaClass = container.getEntityMetaClass();
Range range = metaProperty.getRange();
boolean isRequired = isRequired(metaProperty);
UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, metaProperty.getName());
accessManager.applyRegisteredConstraints(attributeContext);
if (!attributeContext.canView())
return;
if (range.isClass()) {
UiEntityContext entityContext = new UiEntityContext(range.asClass());
accessManager.applyRegisteredConstraints(entityContext);
if (!entityContext.isViewPermitted()) {
return;
}
}
ValueSource valueSource = new ContainerValueSource<>(container, metaProperty.getName());
ComponentGenerationContext componentContext = new ComponentGenerationContext(metaClass, metaProperty.getName());
componentContext.setValueSource(valueSource);
Field field = (Field) uiComponentsGenerator.generate(componentContext);
if (requireTextArea(metaProperty, getItem(), MAX_TEXTFIELD_STRING_LENGTH)) {
field = uiComponents.create(TextArea.NAME);
}
if (isBoolean(metaProperty)) {
field = createBooleanField();
}
if (range.isClass()) {
EntityPicker pickerField = uiComponents.create(EntityPicker.class);
EntityLookupAction lookupAction = actions.create(EntityLookupAction.class);
lookupAction.setScreenClass(EntityInspectorBrowser.class);
lookupAction.setScreenOptionsSupplier(() -> new MapScreenOptions(ParamsMap.of("entity", metaProperty.getRange().asClass().getName())));
lookupAction.setOpenMode(OpenMode.THIS_TAB);
pickerField.addAction(lookupAction);
pickerField.addAction(actions.create(EntityClearAction.class));
field = pickerField;
}
field.setValueSource(valueSource);
field.setCaption(getPropertyCaption(metaClass, metaProperty));
field.setRequired(isRequired);
isReadonly = isReadonly || (disabledProperties != null && disabledProperties.contains(metaProperty.getName()));
if (range.isClass() && !metadataTools.isEmbedded(metaProperty)) {
field.setEditable(metadataTools.isOwningSide(metaProperty) && !isReadonly);
} else {
field.setEditable(!isReadonly);
}
field.setWidth(fieldWidth);
if (isRequired) {
field.setRequiredMessage(messageTools.getDefaultRequiredMessage(metaClass, metaProperty.getName()));
}
form.add(field);
}
use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.
the class BaseEmbeddingStrategy method checkPermissions.
protected boolean checkPermissions(AttributeDefinition attributeDefinition, MetaClass entityMetaClass) {
UiEntityAttributeContext uiEntityAttributeContext = new UiEntityAttributeContext(metadataTools.resolveMetaPropertyPath(entityMetaClass, DynAttrUtils.getPropertyFromAttributeCode(attributeDefinition.getCode())));
accessManager.applyRegisteredConstraints(uiEntityAttributeContext);
if (uiEntityAttributeContext.canView()) {
if (attributeDefinition.getDataType() == AttributeType.ENTITY) {
MetaClass referenceEntityClass = metadata.getClass(attributeDefinition.getJavaType());
UiEntityContext uiEntityContext = new UiEntityContext(referenceEntityClass);
accessManager.applyRegisteredConstraints(uiEntityContext);
return uiEntityContext.isViewPermitted();
}
return true;
}
return false;
}
use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.
the class CreateAction method isPermitted.
@Override
protected boolean isPermitted() {
if (target == null || !(target.getItems() instanceof EntityDataUnit)) {
return false;
}
MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
if (metaClass == null) {
return true;
}
UiEntityContext entityContext = new UiEntityContext(metaClass);
accessManager.applyRegisteredConstraints(entityContext);
if (!entityContext.isCreatePermitted()) {
return false;
}
return super.isPermitted();
}
Aggregations