Skip to content

Commit

Permalink
Entity log doesn't show entities were created by user with tenant jmi…
Browse files Browse the repository at this point in the history
  • Loading branch information
dtaimanov committed Oct 4, 2022
1 parent 9ccc6a5 commit 8fb19c8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import io.jmix.core.security.EntityOp;
import io.jmix.data.AttributeChangesProvider;
import io.jmix.data.AuditInfoProvider;
import io.jmix.data.impl.EntityEventManager;
import io.jmix.data.impl.JpaLifecycleListener;
import org.apache.commons.lang3.BooleanUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -87,6 +88,8 @@ public class EntityLogImpl implements EntityLog, JpaLifecycleListener {
protected DatatypeRegistry datatypeRegistry;
@Autowired
protected AttributeChangesProvider attributeChangesProvider;
@Autowired
protected EntityEventManager entityEventManager;

@PersistenceContext
protected EntityManager entityManager;
Expand Down Expand Up @@ -252,6 +255,8 @@ protected EntityLogAttr getAttrToSave(EntityLogAttr entityLogAttr, EntityLogItem

protected void saveItem(EntityLogItem item) {
String storeName = metadata.getClass(item.getEntity()).getStore().getName();

entityEventManager.publishEntitySavingEvent(item, true);
if (item.getDbGeneratedIdEntity() == null) {
if (Stores.isMain(storeName)) {
entityManager.persist(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
import com.haulmont.cuba.core.sys.events.AppContextStoppedEvent;
import io.jmix.core.TimeSource;
import io.jmix.core.security.SystemAuthenticator;
import io.jmix.data.impl.EntityEventManager;
import org.apache.commons.lang3.BooleanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -87,6 +89,9 @@ public class RunnerBean implements Runner {
@Inject
protected Configuration configuration;

@Autowired
protected EntityEventManager entityEventManager;

@PostConstruct
public void init() {
int nThreads = configuration.getConfig(SchedulingConfig.class).getSchedulingThreadPoolSize();
Expand Down Expand Up @@ -165,6 +170,8 @@ protected ScheduledExecution registerExecutionStart(ScheduledTask task, long now
execution.setStartTime(new Date(now));
execution.setServer(serverInfo.getServerId());


entityEventManager.publishEntitySavingEvent(execution, true);
em.persist(execution);
tx.commit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.jmix.core.*;
import io.jmix.data.PersistenceHints;
import io.jmix.data.impl.EntityEventManager;
import io.jmix.email.EmailDataProvider;
import io.jmix.email.EmailerProperties;
import io.jmix.email.SendingStatus;
Expand Down Expand Up @@ -73,6 +74,9 @@ public class EmailDataProviderImpl implements EmailDataProvider {
@Autowired
protected FileStorageLocator fileStorageLocator;

@Autowired
protected EntityEventManager entityEventManager;

@Autowired
protected void setTransactionManager(PlatformTransactionManager transactionManager) {
transaction = new TransactionTemplate(transactionManager);
Expand Down Expand Up @@ -258,6 +262,7 @@ protected void persistSendingMessage(SendingMessage message, MessagePersistingCo
message.setContentText(null);
}

entityEventManager.publishEntitySavingEvent(message, true);
entityManager.persist(message);

message.getAttachments().forEach(attachment -> {
Expand All @@ -267,6 +272,7 @@ protected void persistSendingMessage(SendingMessage message, MessagePersistingCo
attachment.setContent(null);
}

entityEventManager.publishEntitySavingEvent(attachment, true);
entityManager.persist(attachment);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.jmix.core.security.AccessDeniedException;
import io.jmix.core.security.CurrentAuthentication;
import io.jmix.core.security.event.UserRemovedEvent;
import io.jmix.data.impl.EntityEventManager;
import io.jmix.ui.settings.UserSettingService;
import io.jmix.uidata.entity.UiSetting;
import io.jmix.uidata.entity.UiTablePresentation;
Expand Down Expand Up @@ -63,6 +64,8 @@ public class UserSettingServiceImpl implements UserSettingService {

@Autowired
protected AccessManager accessManager;
@Autowired
protected EntityEventManager entityEventManager;

@PersistenceContext
protected EntityManager entityManager;
Expand Down Expand Up @@ -98,7 +101,7 @@ public void saveSetting(String name, @Nullable String value) {
us.setUsername(authentication.getUser().getUsername());
us.setName(name);
us.setValue(value);

entityEventManager.publishEntitySavingEvent(us, true);
entityManager.persist(us);
} else {
us.setValue(value);
Expand Down Expand Up @@ -170,6 +173,7 @@ public void copySettings(UserDetails fromUser, UserDetails toUser) {
} catch (Exception e) {
newSetting.setValue(currSetting.getValue());
}
entityEventManager.publishEntitySavingEvent(newSetting, true);
entityManager.persist(newSetting);
}
});
Expand Down Expand Up @@ -231,6 +235,7 @@ protected Map<UUID, UiTablePresentation> copyPresentations(UserDetails fromUser,
newPresentation.setName(presentation.getName());
newPresentation.setSettings(presentation.getSettings());
presentationMap.put(presentation.getId(), newPresentation);
entityEventManager.publishEntitySavingEvent(newPresentation, true);
entityManager.persist(newPresentation);
}
return presentationMap;
Expand Down

0 comments on commit 8fb19c8

Please sign in to comment.