From c3f64728597864a605f4e684a9519e50d016b40f Mon Sep 17 00:00:00 2001 From: Josep Llort Date: Mon, 22 Apr 2019 11:27:07 +0200 Subject: [PATCH] In login stage userId is not shown in the activity log fix #5 --- .../openkm/automation/action/TimeControl.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/openkm/automation/action/TimeControl.java b/src/main/java/com/openkm/automation/action/TimeControl.java index 5bec529..fd572f6 100644 --- a/src/main/java/com/openkm/automation/action/TimeControl.java +++ b/src/main/java/com/openkm/automation/action/TimeControl.java @@ -33,6 +33,7 @@ import com.openkm.dao.bean.Automation; import com.openkm.module.db.stuff.DbSessionManager; import com.openkm.util.PathUtils; +import com.openkm.util.UserActivity; import net.xeoh.plugins.base.annotations.PluginImplementation; import org.apache.commons.io.IOUtils; @@ -82,14 +83,13 @@ public void executePre(Map env, Object... params) throws Excepti Document document = null; try { - String systemToken = DbSessionManager.getInstance().getSystemToken(); - String controlDocPath = getControlDocPath(systemToken, env); - document = OKMDocument.getInstance().getProperties(systemToken, controlDocPath); + String controlDocPath = getControlDocPath(null, env); + document = OKMDocument.getInstance().getProperties(null, controlDocPath); String logoutId = logoutIdFormat.format(new Date()); // Get content of the file to be able to modify it - is = OKMDocument.getInstance().getContent(systemToken, document.getUuid(), false); + is = OKMDocument.getInstance().getContent(null, document.getUuid(), false); if (is != null) { String body = IOUtils.toString(is, StandardCharsets.UTF_8); if (body.contains("")) { @@ -99,8 +99,8 @@ public void executePre(Map env, Object... params) throws Excepti // Upload new document is.close(); is = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8)); - OKMDocument.getInstance().checkout(systemToken, document.getUuid()); - OKMDocument.getInstance().checkin(systemToken, document.getUuid(), is, ""); + OKMDocument.getInstance().checkout(null, document.getUuid()); + OKMDocument.getInstance().checkin(null, document.getUuid(), is, ""); is.close(); } } @@ -117,6 +117,7 @@ public void executePre(Map env, Object... params) throws Excepti public void executePost(Map env, Object... params) throws Exception { InputStream is = null; Document document = null; + String userId = AutomationUtils.getUser(env); try { String systemToken = DbSessionManager.getInstance().getSystemToken(); @@ -155,6 +156,9 @@ public void executePost(Map env, Object... params) throws Except is = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8)); OKMDocument.getInstance().checkout(systemToken, document.getUuid()); OKMDocument.getInstance().checkin(systemToken, document.getUuid(), is, ""); + document = OKMDocument.getInstance().getProperties(systemToken, document.getUuid()); + // Activity log + UserActivity.log(userId, "CHECKIN_DOCUMENT", document.getUuid(), document.getPath(), document.getActualVersion().getSize() + ", Modified by user system in name of " + userId); is.close(); } }