use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.
the class ResetPasswordAction 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.isEditPermitted()) {
return false;
}
return super.isPermitted();
}
use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.
the class EditAction method isPermitted.
@Override
protected boolean isPermitted() {
if (target == null || target.getSingleSelected() == 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);
InMemoryCrudEntityContext inMemoryCrudEntityContext = new InMemoryCrudEntityContext(metaClass, applicationContext);
accessManager.applyRegisteredConstraints(inMemoryCrudEntityContext);
if (!entityContext.isViewPermitted() && !entityContext.isEditPermitted()) {
return false;
}
if (inMemoryCrudEntityContext.updatePredicate() != null) {
return true;
}
return super.isPermitted();
}
use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.
the class EditAction method refreshState.
@Override
public void refreshState() {
super.refreshState();
if (target == null || !(target.getItems() instanceof EntityDataUnit)) {
return;
}
if (!captionInitialized) {
MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
UiEntityContext entityContext = new UiEntityContext(metaClass);
accessManager.applyRegisteredConstraints(entityContext);
InMemoryCrudEntityContext inMemoryContext = new InMemoryCrudEntityContext(metaClass, applicationContext);
accessManager.applyRegisteredConstraints(inMemoryContext);
if (metaClass != null) {
Object entity = target.getSingleSelected();
if (entityContext.isEditPermitted() && (inMemoryContext.updatePredicate() == null || entity != null && inMemoryContext.isUpdatePermitted(entity))) {
super.setCaption(messages.getMessage("actions.Edit"));
} else {
super.setCaption(messages.getMessage("actions.View"));
}
}
}
}
use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.
the class BulkEditorWindow method isRangeClassPermitted.
protected boolean isRangeClassPermitted(MetaProperty metaProperty) {
if (metaProperty.getRange().isClass()) {
MetaClass propertyMetaClass = metaProperty.getRange().asClass();
UiEntityContext entityContext = new UiEntityContext(propertyMetaClass);
accessManager.applyRegisteredConstraints(entityContext);
return !metadataTools.isSystemLevel(propertyMetaClass) && entityContext.isViewPermitted();
}
return true;
}
use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.
the class AbstractTable method setupColumnSettings.
protected void setupColumnSettings(EntityTableItems<E> entityTableSource) {
MetaClass metaClass = entityTableSource.getEntityMetaClass();
List<MetaPropertyPath> editableColumns = Collections.emptyList();
for (Map.Entry<Object, Column<E>> entry : this.columns.entrySet()) {
Object columnId = entry.getKey();
Column<E> column = entry.getValue();
String caption;
if (column != null) {
caption = getColumnCaption(columnId, column);
} else {
caption = StringUtils.capitalize(getColumnCaption(columnId));
}
setColumnHeader(columnId, caption);
if (column != null) {
if (column.isEditable() && (columnId instanceof MetaPropertyPath)) {
MetaPropertyPath propertyPath = ((MetaPropertyPath) columnId);
UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, propertyPath.toString());
accessManager.applyRegisteredConstraints(attributeContext);
if (attributeContext.canModify() && attributeContext.canView()) {
if (editableColumns.isEmpty()) {
editableColumns = new ArrayList<>();
}
editableColumns.add(propertyPath);
} else {
log.info("Editable column '{}' is not permitted to read or update", propertyPath.toString());
}
}
if (column.isCollapsed() && component.isColumnCollapsingAllowed()) {
UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, columnId.toString());
accessManager.applyRegisteredConstraints(attributeContext);
if (!(columnId instanceof MetaPropertyPath) || attributeContext.canView()) {
component.setColumnCollapsed(column.getId(), true);
}
}
if (column.getAggregation() != null) {
checkAggregation(column.getAggregation());
component.addContainerPropertyAggregation(column.getId(), WrapperUtils.convertAggregationType(column.getAggregation().getType()));
}
}
}
if (isEditable() && !editableColumns.isEmpty()) {
UiEntityContext entityContext = new UiEntityContext(metaClass);
accessManager.applyRegisteredConstraints(entityContext);
if (entityContext.isViewPermitted() && entityContext.isEditPermitted()) {
setEditableColumns(editableColumns);
} else {
log.info("Entity '{}' is not permitted to read or update", metaClass.getName());
}
}
}
Aggregations