Skip to content

Commit

Permalink
Merge pull request #75 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Release/4.3.0
  • Loading branch information
LinneyS authored Mar 18, 2021
2 parents 1b555bf + 7eac244 commit cef7de3
Show file tree
Hide file tree
Showing 68 changed files with 525 additions and 110 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "repo/src/main/resources/newdocs"]
path = repo/src/main/resources/newdocs
url = https://github.com/ONLYOFFICE/document-templates
branch = main/new
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## 4.3.0
## Added
- Opening not OOXML file formats for editing
- Empty file templates added in multiple new languages

## Fixed
- Fixed an issue where the file could not be saved by a user with permissions Collaborator

## 4.2.1
## Fixed
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.onlyoffice.alfresco</groupId>
<artifactId>onlyoffice-integration</artifactId>
<version>4.2.1</version>
<version>4.3.0</version>
<name>ONLYOFFICE Alfresco Integration</name>
<description>This Module integrates Alfresco Share with ONLYOFFICE</description>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion repo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.onlyoffice.alfresco</groupId>
<artifactId>onlyoffice-integration</artifactId>
<version>4.2.1</version>
<version>4.3.0</version>
</parent>

<properties>
Expand Down
51 changes: 39 additions & 12 deletions repo/src/main/java/com/parashift/onlyoffice/CallBack.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* Created by cetra on 20/10/15.
*/
/*
Copyright (c) Ascensio System SIA 2020. All rights reserved.
Copyright (c) Ascensio System SIA 2021. All rights reserved.
http://www.onlyoffice.com
*/
@Component(value = "webscript.onlyoffice.callback.post")
Expand Down Expand Up @@ -76,6 +76,9 @@ public class CallBack extends AbstractWebScript {
@Autowired
TransactionService transactionService;

@Autowired
Util util;

private Logger logger = LoggerFactory.getLogger(this.getClass());

@Override
Expand Down Expand Up @@ -183,35 +186,44 @@ private class ProccessRequestCallback implements RetryingTransactionCallback<Obj
public ProccessRequestCallback(JSONObject json, NodeRef node) {
callBackJSon = json;
nodeRef = node;
forcesave = configManager.getAsBoolean("forcesave");
forcesave = configManager.getAsBoolean("forcesave", "fasle");
}

@Override
public Object execute() throws Throwable {
NodeRef wc = cociService.getWorkingCopy(nodeRef);
String lockOwner = (String)nodeService.getProperty(wc, ContentModel.PROP_WORKING_COPY_OWNER);

//Status codes from here: https://api.onlyoffice.com/editors/editor
switch(callBackJSon.getInt("status")) {
case 0:
logger.error("ONLYOFFICE has reported that no doc with the specified key can be found");
cociService.cancelCheckout(cociService.getWorkingCopy(nodeRef));
AuthenticationUtil.setRunAsUser(AuthenticationUtil.getSystemUserName());
cociService.cancelCheckout(wc);
break;
case 1:
logger.debug("User has entered/exited ONLYOFFICE");
break;
case 2:
logger.debug("Document Updated, changing content");
updateNode(cociService.getWorkingCopy(nodeRef), callBackJSon.getString("url"));
cociService.checkin(cociService.getWorkingCopy(nodeRef), null, null);
updateNode(wc, callBackJSon.getString("url"));

logger.info("removing prop");
nodeService.removeProperty(nodeRef, Util.EditingHashAspect);
nodeService.removeProperty(nodeRef, Util.EditingKeyAspect);
nodeService.removeProperty(wc, Util.EditingHashAspect);
nodeService.removeProperty(wc, Util.EditingKeyAspect);

AuthenticationUtil.setRunAsUser(AuthenticationUtil.getSystemUserName());
cociService.checkin(wc, null, null);
break;
case 3:
logger.error("ONLYOFFICE has reported that saving the document has failed");
cociService.cancelCheckout(cociService.getWorkingCopy(nodeRef));
AuthenticationUtil.setRunAsUser(AuthenticationUtil.getSystemUserName());
cociService.cancelCheckout(wc);
break;
case 4:
logger.debug("No document updates, unlocking node");
cociService.cancelCheckout(cociService.getWorkingCopy(nodeRef));
AuthenticationUtil.setRunAsUser(AuthenticationUtil.getSystemUserName());
cociService.cancelCheckout(wc);
break;
case 6:
if (!forcesave) {
Expand All @@ -220,8 +232,22 @@ public Object execute() throws Throwable {
}

logger.debug("Forcesave request (type: " + callBackJSon.getString("forcesavetype") + ")");
updateNode(cociService.getWorkingCopy(nodeRef), callBackJSon.getString("url"));
cociService.checkin(cociService.getWorkingCopy(nodeRef), null, null, true);
updateNode(wc, callBackJSon.getString("url"));

String hash = (String) nodeService.getProperty(wc, Util.EditingHashAspect);
String key = (String) nodeService.getProperty(wc, Util.EditingKeyAspect);

nodeService.removeProperty(wc, Util.EditingHashAspect);
nodeService.removeProperty(wc, Util.EditingKeyAspect);

AuthenticationUtil.setRunAsUser(AuthenticationUtil.getSystemUserName());
cociService.checkin(wc, null, null, true);

AuthenticationUtil.clearCurrentSecurityContext();
AuthenticationUtil.setRunAsUser(lockOwner);

nodeService.setProperty(wc, Util.EditingHashAspect, hash);
nodeService.setProperty(wc, Util.EditingKeyAspect, key);
logger.debug("Forcesave complete");
break;
}
Expand All @@ -237,7 +263,8 @@ private void updateNode(NodeRef nodeRef, String url) throws Exception {
if (converterService.shouldConvertBack(mimeType)) {
try {
logger.debug("Should convert back");
url = converterService.convert(nodeRef.getId(), "docx", mimetypeService.getExtension(mimeType), url);
String downloadExt = util.getFileExtension(url).replace(".", "");
url = converterService.convert(util.getKey(nodeRef), downloadExt, mimetypeService.getExtension(mimeType), url);
} catch (Exception e) {
throw new Exception("Error while converting document back to original format: " + e.getMessage(), e);
}
Expand Down
19 changes: 13 additions & 6 deletions repo/src/main/java/com/parashift/onlyoffice/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.Map;

/*
Copyright (c) Ascensio System SIA 2020. All rights reserved.
Copyright (c) Ascensio System SIA 2021. All rights reserved.
http://www.onlyoffice.com
*/
@Component(value = "webscript.onlyoffice.onlyoffice-config.get")
Expand All @@ -27,16 +27,23 @@ protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, C
model.put("docinnerurl", configManager.getOrDefault("innerurl", ""));
model.put("alfurl", configManager.getOrDefault("alfurl", ""));

model.put("cert", getBoolAsAttribute("cert"));
model.put("forcesave", getBoolAsAttribute("forcesave"));
model.put("webpreview", getBoolAsAttribute("webpreview"));
model.put("cert", getBoolAsAttribute("cert", "false"));
model.put("forcesave", getBoolAsAttribute("forcesave", "false"));
model.put("webpreview", getBoolAsAttribute("webpreview", "false"));

model.put("jwtsecret", configManager.getOrDefault("jwtsecret", ""));

model.put("formatODT", getBoolAsAttribute("formatODT", "false"));
model.put("formatODS", getBoolAsAttribute("formatODS", "false"));
model.put("formatODP", getBoolAsAttribute("formatODP", "false"));
model.put("formatCSV", getBoolAsAttribute("formatCSV", "true"));
model.put("formatTXT", getBoolAsAttribute("formatTXT", "true"));
model.put("formatRTF", getBoolAsAttribute("formatRTF", "false"));
return model;
}

private String getBoolAsAttribute(String key) {
return configManager.getAsBoolean(key) ? "checked=\"\"" : "";
private String getBoolAsAttribute(String key, Object defaultValue) {
return configManager.getAsBoolean(key, defaultValue) ? "checked=\"\"" : "";
}
}

11 changes: 10 additions & 1 deletion repo/src/main/java/com/parashift/onlyoffice/ConfigCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.Properties;

/*
Copyright (c) Ascensio System SIA 2020. All rights reserved.
Copyright (c) Ascensio System SIA 2021. All rights reserved.
http://www.onlyoffice.com
*/
@Component(value = "webscript.onlyoffice.onlyoffice-config.post")
Expand Down Expand Up @@ -68,6 +68,8 @@ public void execute(WebScriptRequest request, WebScriptResponse response) throws
docInnerUrl = AppendSlash(docInnerUrl);
alfUrl = AppendSlash(alfUrl);

JSONObject formats = (JSONObject) data.get("formats");

configManager.set("url", docUrl);
configManager.set("innerurl", docInnerUrl);
configManager.set("alfurl", alfUrl);
Expand All @@ -76,6 +78,13 @@ public void execute(WebScriptRequest request, WebScriptResponse response) throws
configManager.set("webpreview", data.getString("webpreview"));
configManager.set("jwtsecret", jwtSecret);

configManager.set("formatODT", formats.getString("odt"));
configManager.set("formatODS", formats.getString("ods"));
configManager.set("formatODP", formats.getString("odp"));
configManager.set("formatCSV", formats.getString("csv"));
configManager.set("formatTXT", formats.getString("txt"));
configManager.set("formatRTF", formats.getString("rtf"));

String alfrescoProto = (String) globalProp.getOrDefault("alfresco.protocol", "http");

if (alfrescoProto == "https" && docUrl.toLowerCase().startsWith("http://")) {
Expand Down
33 changes: 30 additions & 3 deletions repo/src/main/java/com/parashift/onlyoffice/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Properties;
import java.util.Set;

/*
Copyright (c) Ascensio System SIA 2020. All rights reserved.
Copyright (c) Ascensio System SIA 2021. All rights reserved.
http://www.onlyoffice.com
*/
@Service
Expand Down Expand Up @@ -47,17 +49,42 @@ public Object getOrDefault(String key, Object defaultValue) {
return value;
}

public Boolean getAsBoolean(String key) {
public Boolean getAsBoolean(String key, Object defaultValue) {
String formedKey = formKey(key);
Object value = attributeService.getAttribute(formedKey);

if (value == null) {
value = globalProp.getOrDefault(formedKey, "");
value = globalProp.getOrDefault(formedKey, defaultValue);
}

return (value != null && ((String)value).equals("true")) ? true : false;
}

public Set<String> getEditableSet() {
Set<String> editableSet = new HashSet<>();
if (getAsBoolean("formatODT", "false")){
editableSet.add("application/vnd.oasis.opendocument.text");
}
if (getAsBoolean("formatODS", "false")){
editableSet.add("application/vnd.oasis.opendocument.spreadsheet");
}
if (getAsBoolean("formatODP", "false")){
editableSet.add("application/vnd.oasis.opendocument.presentation");
}
if (getAsBoolean("formatCSV", "true")){
editableSet.add("text/csv");
}
if (getAsBoolean("formatTXT", "true")){
editableSet.add("text/plain");
}
if (getAsBoolean("formatRTF", "false")){
editableSet.add("application/rtf");
editableSet.add("application/x-rtf");
editableSet.add("text/richtext");
}
return editableSet;
}

private String formKey(String key) {
return "onlyoffice." + key;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.springframework.beans.factory.annotation.Autowired;

/*
Copyright (c) Ascensio System SIA 2020. All rights reserved.
Copyright (c) Ascensio System SIA 2021. All rights reserved.
http://www.onlyoffice.com
*/

Expand Down
8 changes: 7 additions & 1 deletion repo/src/main/java/com/parashift/onlyoffice/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import javax.net.ssl.SSLSession;

/*
Copyright (c) Ascensio System SIA 2020. All rights reserved.
Copyright (c) Ascensio System SIA 2021. All rights reserved.
http://www.onlyoffice.com
*/

Expand Down Expand Up @@ -92,8 +92,14 @@ public class Converter extends AbstractContentTransformer2 {
}};

private static Set<String> ConvertBackList = new HashSet<String>() {{
add("application/vnd.oasis.opendocument.text");
add("application/vnd.oasis.opendocument.spreadsheet");
add("application/vnd.oasis.opendocument.presentation");
add("text/plain");
add("text/csv");
add("application/rtf");
add("application/x-rtf");
add("text/richtext");
}};

public String GetModernMimetype(String mimetype) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.stereotype.Component;

/*
Copyright (c) Ascensio System SIA 2020. All rights reserved.
Copyright (c) Ascensio System SIA 2021. All rights reserved.
http://www.onlyoffice.com
*/
@Component(value = "webscript.onlyoffice.converter.get")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.stereotype.Component;

/*
Copyright (c) Ascensio System SIA 2020. All rights reserved.
Copyright (c) Ascensio System SIA 2021. All rights reserved.
http://www.onlyoffice.com
*/
@Component(value = "webscript.onlyoffice.convertertest.get")
Expand Down
37 changes: 37 additions & 0 deletions repo/src/main/java/com/parashift/onlyoffice/EditableMimetypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.parashift.onlyoffice;

import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.extensions.webscripts.*;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Set;

/*
Copyright (c) Ascensio System SIA 2021. All rights reserved.
http://www.onlyoffice.com
*/
@Component(value = "webscript.onlyoffice.editablemimetypes.get")
public class EditableMimetypes extends AbstractWebScript {

@Autowired
ConfigManager configManager;

@Override
public void execute(WebScriptRequest request, WebScriptResponse response) throws IOException {
JSONObject responseJson = new JSONObject();
try {
Set<String> editableMimetypes = configManager.getEditableSet();
responseJson.put("mimetypes", editableMimetypes);

response.setContentType("application/json; charset=utf-8");
response.setContentEncoding("UTF-8");
response.getWriter().write(responseJson.toString());
} catch (JSONException e) {
throw new WebScriptException("Unable to serialize JSON: " + e.getMessage());
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import javax.crypto.Mac;

/*
Copyright (c) Ascensio System SIA 2020. All rights reserved.
Copyright (c) Ascensio System SIA 2021. All rights reserved.
http://www.onlyoffice.com
*/
@Service
Expand Down
Loading

0 comments on commit cef7de3

Please sign in to comment.