Skip to content

Commit

Permalink
Merge pull request #6 from openkm/issue/5
Browse files Browse the repository at this point in the history
In login stage userId is not shown in the activity log
  • Loading branch information
darkman97i authored Apr 22, 2019
2 parents e37da91 + c3f6472 commit 5b3d5b2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/java/com/openkm/automation/action/TimeControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -82,14 +83,13 @@ public void executePre(Map<String, Object> 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("<td id='logout-" + logoutId + "'>")) {
Expand All @@ -99,8 +99,8 @@ public void executePre(Map<String, Object> 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();
}
}
Expand All @@ -117,6 +117,7 @@ public void executePre(Map<String, Object> env, Object... params) throws Excepti
public void executePost(Map<String, Object> env, Object... params) throws Exception {
InputStream is = null;
Document document = null;
String userId = AutomationUtils.getUser(env);

try {
String systemToken = DbSessionManager.getInstance().getSystemToken();
Expand Down Expand Up @@ -155,6 +156,9 @@ public void executePost(Map<String, Object> 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();
}
}
Expand Down

0 comments on commit 5b3d5b2

Please sign in to comment.