Search in sources :

Example 1 with PolicyStore

use of io.jmix.security.constraint.PolicyStore in project jmix by jmix-framework.

the class EntityLogBrowser method onInstancePickerLookup.

@Subscribe("instancePicker.lookup")
public void onInstancePickerLookup(Action.ActionPerformedEvent event) {
    final MetaClass metaClass = instancePicker.getMetaClass();
    if (instancePicker.isEditable()) {
        if (metaClass == null) {
            throw new IllegalStateException("Please specify metaclass or property for PickerField");
        }
        if (!secureOperations.isEntityReadPermitted(metaClass, policyStore)) {
            notifications.create(Notifications.NotificationType.ERROR).withCaption(messages.getMessage(EntityLogBrowser.class, "entityAccessDeniedMessage")).show();
            return;
        }
        try {
            Screen lookup = screenBuilders.lookup(instancePicker).withSelectHandler(items -> {
                if (!items.isEmpty()) {
                    Object item = items.iterator().next();
                    instancePicker.setValue(item);
                }
            }).build();
            lookup.addAfterCloseListener(afterCloseEvent -> instancePicker.focus());
            lookup.show();
        } catch (AccessDeniedException ex) {
            notifications.create(Notifications.NotificationType.ERROR).withCaption(messages.getMessage(EntityLogBrowser.class, "entityScreenAccessDeniedMessage")).show();
            return;
        }
    }
}
Also used : EntityLogItem(io.jmix.audit.entity.EntityLogItem) MetaClass(io.jmix.core.metamodel.model.MetaClass) CollectionLoader(io.jmix.ui.model.CollectionLoader) java.util(java.util) PolicyStore(io.jmix.security.constraint.PolicyStore) Autowired(org.springframework.beans.factory.annotation.Autowired) io.jmix.core(io.jmix.core) EntityLog(io.jmix.audit.EntityLog) SecureOperations(io.jmix.security.constraint.SecureOperations) StringUtils(org.apache.commons.lang3.StringUtils) AccessDeniedException(io.jmix.core.security.AccessDeniedException) LookupComponent(io.jmix.ui.screen.LookupComponent) Action(io.jmix.ui.action.Action) UserDetails(org.springframework.security.core.userdetails.UserDetails) Range(io.jmix.core.metamodel.model.Range) DialogAction(io.jmix.ui.action.DialogAction) io.jmix.ui(io.jmix.ui) Nullable(javax.annotation.Nullable) EntityLogAttr(io.jmix.audit.entity.EntityLogAttr) DataContext(io.jmix.ui.model.DataContext) LoggedEntity(io.jmix.audit.entity.LoggedEntity) CollectionContainer(io.jmix.ui.model.CollectionContainer) Collectors(java.util.stream.Collectors) DateUtils(org.apache.commons.lang3.time.DateUtils) UserRepository(io.jmix.core.security.UserRepository) LoggedAttribute(io.jmix.audit.entity.LoggedAttribute) EnumClass(io.jmix.core.metamodel.datatype.impl.EnumClass) io.jmix.ui.screen(io.jmix.ui.screen) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) io.jmix.ui.component(io.jmix.ui.component) AccessDeniedException(io.jmix.core.security.AccessDeniedException) MetaClass(io.jmix.core.metamodel.model.MetaClass)

Aggregations

EntityLog (io.jmix.audit.EntityLog)1 EntityLogAttr (io.jmix.audit.entity.EntityLogAttr)1 EntityLogItem (io.jmix.audit.entity.EntityLogItem)1 LoggedAttribute (io.jmix.audit.entity.LoggedAttribute)1 LoggedEntity (io.jmix.audit.entity.LoggedEntity)1 io.jmix.core (io.jmix.core)1 EnumClass (io.jmix.core.metamodel.datatype.impl.EnumClass)1 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1 Range (io.jmix.core.metamodel.model.Range)1 AccessDeniedException (io.jmix.core.security.AccessDeniedException)1 UserRepository (io.jmix.core.security.UserRepository)1 PolicyStore (io.jmix.security.constraint.PolicyStore)1 SecureOperations (io.jmix.security.constraint.SecureOperations)1 io.jmix.ui (io.jmix.ui)1 Action (io.jmix.ui.action.Action)1 DialogAction (io.jmix.ui.action.DialogAction)1 io.jmix.ui.component (io.jmix.ui.component)1 CollectionContainer (io.jmix.ui.model.CollectionContainer)1 CollectionLoader (io.jmix.ui.model.CollectionLoader)1