use of io.jmix.core.accesscontext.InMemoryCrudEntityContext in project jmix by jmix-framework.
the class DataStoreInMemoryCrudListener method entitySaving.
@Override
public void entitySaving(DataStoreEntitySavingEvent event) {
SaveContext context = event.getSaveContext();
for (Object entity : event.getEntities()) {
MetaClass metaClass = metadata.getClass(entity);
InMemoryCrudEntityContext entityContext = new InMemoryCrudEntityContext(metaClass, applicationContext);
accessManager.applyConstraints(entityContext, context.getAccessConstraints());
if (isNew(context, entity)) {
if (!entityContext.isCreatePermitted(entity)) {
throw new AccessDeniedException("entity", entity.toString(), "create");
}
} else {
if (!entityContext.isUpdatePermitted(entity)) {
throw new AccessDeniedException("entity", entity.toString(), "update");
}
}
}
}
use of io.jmix.core.accesscontext.InMemoryCrudEntityContext in project jmix by jmix-framework.
the class DataStoreInMemoryCrudListener method hasInMemoryRead.
protected boolean hasInMemoryRead(LoadContext<?> context) {
return collectEntityClasses(context).stream().anyMatch(entityClass -> {
InMemoryCrudEntityContext crudContext = new InMemoryCrudEntityContext(entityClass, applicationContext);
accessManager.applyConstraints(crudContext, context.getAccessConstraints());
return crudContext.readPredicate() != null;
});
}
use of io.jmix.core.accesscontext.InMemoryCrudEntityContext 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.core.accesscontext.InMemoryCrudEntityContext 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.core.accesscontext.InMemoryCrudEntityContext in project jmix by jmix-framework.
the class DeclarativeTrackingAction method isPermitted.
@Override
protected boolean isPermitted() {
if (target == null) {
return false;
}
Object singleSelected = target.getSingleSelected();
if (singleSelected == null) {
return false;
}
if (constraintEntityOp != null) {
MetaClass metaClass = metadata.getClass(singleSelected.getClass());
InMemoryCrudEntityContext context = new InMemoryCrudEntityContext(metaClass, applicationContext);
accessManager.applyRegisteredConstraints(context);
if (constraintEntityOp == EntityOp.CREATE) {
return context.isCreatePermitted(singleSelected);
} else if (constraintEntityOp == EntityOp.READ) {
return context.isReadPermitted(singleSelected);
} else if (constraintEntityOp == EntityOp.UPDATE) {
return context.isUpdatePermitted(singleSelected);
} else if (constraintEntityOp == EntityOp.DELETE) {
return context.isDeletePermitted(singleSelected);
} else {
return false;
}
}
return super.isPermitted();
}
Aggregations