Skip to content

Commit

Permalink
Merge pull request 'Release/v5.1.0' from develop into master
Browse files Browse the repository at this point in the history
  • Loading branch information
LinneyS committed Oct 23, 2024
2 parents 90d88dc + c7ad900 commit 62016f4
Show file tree
Hide file tree
Showing 36 changed files with 188 additions and 121 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Get Info
run: |
echo "version=$(awk '/<version>/,/<\/version>/' pom.xml | head -n 1 | sed 's/^[[:space:]]*//g' | sed -n 's:.*<version>\(.*\)</version>.*:\1:p')" >> $GITHUB_OUTPUT
echo "artifact=$(awk '/<artifactId>/,/<\/artifactId>/' pom.xml | head -n 1 | sed 's/^[[:space:]]*//g' | sed -n 's:.*<artifactId>\(.*\)</artifactId>.*:\1:p')" >> $GITHUB_OUTPUT
id: info
- name: Install Java 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
Expand All @@ -37,7 +37,7 @@ jobs:
cd ./target
mv ${{ steps.info.outputs.artifact }}-${{ steps.info.outputs.version }}.jar $cwd
- name: Upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ steps.info.outputs.artifact }}-${{ steps.info.outputs.version }}
path: ${{ steps.info.outputs.artifact }}-${{ steps.info.outputs.version }}.jar
9 changes: 5 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ name: Lint

on:
workflow_dispatch:
push:
branches: [master, develop]
pull_request:
types: [opened, reopened]
branches: [master]
branches: [master, develop]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Java 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Get Info
run: |
echo "version=$(awk '/<version>/,/<\/version>/' pom.xml | head -n 1 | sed 's/^[[:space:]]*//g' | sed -n 's:.*<version>\(.*\)</version>.*:\1:p')" >> $GITHUB_OUTPUT
echo "artifact=$(awk '/<artifactId>/,/<\/artifactId>/' pom.xml | head -n 1 | sed 's/^[[:space:]]*//g' | sed -n 's:.*<artifactId>\(.*\)</artifactId>.*:\1:p')" >> $GITHUB_OUTPUT
id: info
- name: Install Java 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 5.1.0
## Added
- compatible with Confluence 8.9.7
- creating pdf form
- button go to edit in editor
- pdf favicon

## 5.0.2
## Changed
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>onlyoffice</groupId>
<artifactId>onlyoffice-confluence-plugin</artifactId>
<version>5.0.2</version>
<version>5.1.0</version>

<organization>
<name>Ascensio System SIA</name>
Expand Down Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>com.onlyoffice</groupId>
<artifactId>docs-integration-sdk</artifactId>
<version>1.1.2</version>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand All @@ -71,7 +71,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.13.0</version>
<version>2.14.0</version>
<scope>provided</scope>
</dependency>

Expand Down
19 changes: 13 additions & 6 deletions src/main/java/onlyoffice/OnlyOfficeConvertServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.onlyoffice.model.common.Format;
import com.onlyoffice.model.convertservice.ConvertRequest;
import com.onlyoffice.model.convertservice.ConvertResponse;
import com.onlyoffice.model.convertservice.convertrequest.PDF;
import com.onlyoffice.service.convert.ConvertService;
import onlyoffice.managers.auth.AuthContext;
import onlyoffice.sdk.manager.document.DocumentManager;
Expand Down Expand Up @@ -84,6 +85,7 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re
}
String pageIdString = request.getParameter("pageId");
String newTitle = request.getParameter("newTitle");
Boolean createForm = Boolean.valueOf(request.getParameter("createForm"));

String attachmentIdString = request.getParameter("attachmentId");
Long attachmentId = Long.parseLong(attachmentIdString);
Expand All @@ -106,8 +108,8 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re
if (docx != null
&& extension.equals(docx.getName())
&& docx.getConvert() != null
&& docx.getConvert().contains("docxf")) {
newFileExtension = "docxf";
&& docx.getConvert().contains("pdf")) {
newFileExtension = "pdf";
}

String title = fileName.substring(0, fileName.lastIndexOf("."));
Expand All @@ -127,6 +129,7 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re
contextMap.put("attachmentId", attachmentIdString);
contextMap.put("oldName", fileName);
contextMap.put("newName", newName);
contextMap.put("createForm", createForm);
writer.write(getTemplate(contextMap));
}

Expand All @@ -142,11 +145,11 @@ public void doPost(final HttpServletRequest request, final HttpServletResponse r
}

String attachmentIdString = request.getParameter("attachmentId");
Boolean createForm = Boolean.valueOf(request.getParameter("createForm"));

ConfluenceUser user = null;
String errorMessage = null;
JSONObject json = null;


Long attachmentId = Long.parseLong(attachmentIdString);
log.info("attachmentId " + attachmentId);

Expand Down Expand Up @@ -183,8 +186,8 @@ public void doPost(final HttpServletRequest request, final HttpServletResponse r
if (docx != null
&& extension.equals(docx.getName())
&& docx.getConvert() != null
&& docx.getConvert().contains("docxf")) {
convertToExt = "docxf";
&& docx.getConvert().contains("pdf")) {
convertToExt = "pdf";
}

if (!attachmentUtil.checkAccess(attachmentId, user, false)
Expand All @@ -210,6 +213,10 @@ public void doPost(final HttpServletRequest request, final HttpServletResponse r
.region(region)
.build();

if (convertToExt.equals("pdf") && createForm) {
convertRequest.setPdf(new PDF(true));
}

ConvertResponse convertResponse = convertService.processConvert(convertRequest,
String.valueOf(attachmentId));

Expand Down
39 changes: 36 additions & 3 deletions src/main/java/onlyoffice/OnlyOfficeEditorServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
import com.atlassian.confluence.user.ConfluenceUser;
import com.atlassian.confluence.util.velocity.VelocityUtils;
import com.atlassian.sal.api.message.I18nResolver;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.onlyoffice.manager.settings.SettingsManager;
import com.onlyoffice.model.documenteditor.Config;
import com.onlyoffice.model.documenteditor.config.document.DocumentType;
Expand All @@ -34,6 +38,7 @@
import onlyoffice.managers.auth.AuthContext;
import com.atlassian.confluence.pages.Attachment;
import onlyoffice.sdk.manager.document.DocumentManager;
import onlyoffice.sdk.manager.security.JwtManager;
import onlyoffice.sdk.manager.url.UrlManager;
import onlyoffice.utils.attachment.AttachmentUtil;
import org.apache.log4j.LogManager;
Expand Down Expand Up @@ -64,20 +69,22 @@ public class OnlyOfficeEditorServlet extends HttpServlet {
private final AttachmentUtil attachmentUtil;
private final ConfigService configService;
private final SettingsManager settingsManager;
private final JwtManager jwtManager;

private final LocaleManager localeManager;

public OnlyOfficeEditorServlet(final I18nResolver i18n, final UrlManager urlManager, final AuthContext authContext,
final DocumentManager documentManager, final AttachmentUtil attachmentUtil,
final ConfigService configService, final SettingsManager settingsManager,
final LocaleManager localeManager) {
final JwtManager jwtManager, final LocaleManager localeManager) {
this.i18n = i18n;
this.urlManager = urlManager;
this.authContext = authContext;
this.documentManager = documentManager;
this.attachmentUtil = attachmentUtil;
this.configService = configService;
this.settingsManager = settingsManager;
this.jwtManager = jwtManager;
this.localeManager = localeManager;
}

Expand Down Expand Up @@ -107,7 +114,7 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re
String extension = fileExt == null
|| !fileExt.equals("xlsx")
&& !fileExt.equals("pptx")
&& !fileExt.equals("docxf")
&& !fileExt.equals("pdf")
? "docx" : fileExt.trim();

String name = fileName == null || fileName.equals("")
Expand Down Expand Up @@ -178,10 +185,21 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re
request.getHeader("USER-AGENT")
);

if (modeString != null
&& modeString.equals("fillForms")
&& config.getDocument().getPermissions().getFillForms()
) {
config.getDocument().getPermissions().setEdit(false);
}

config.getEditorConfig().setLang(localeManager.getLocale(user).toLanguageTag());
config.getEditorConfig().setActionLink(actionData);

ObjectMapper mapper = new ObjectMapper();
if (settingsManager.isSecurityEnabled()) {
config.setToken(jwtManager.createToken(config));
}

ObjectMapper mapper = createObjectMapper();

context.put("request", request);
context.put("configAsHtml", mapper.writeValueAsString(config));
Expand Down Expand Up @@ -210,4 +228,19 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re
throw new ServletException(e.getMessage(), e);
}
}

private ObjectMapper createObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(JSONObject.class, new JsonSerializer<JSONObject>() {
@Override
public void serialize(final JSONObject jsonObject, final JsonGenerator jsonGenerator,
final SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeObject(jsonObject.toMap());
}
});
objectMapper.registerModule(module);

return objectMapper;
}
}
18 changes: 3 additions & 15 deletions src/main/java/onlyoffice/conditions/IsOfficeFileAttachment.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

public class IsOfficeFileAttachment implements Condition {
private boolean forEdit;
private boolean form;
private DocumentManager documentManager;
private AttachmentUtil attachmentUtil;

Expand All @@ -41,13 +40,9 @@ public IsOfficeFileAttachment(final DocumentManager documentManager, final Attac

public void init(final Map<String, String> params) throws PluginParseException {
forEdit = false;
form = false;
if (params != null && !params.isEmpty() && params.get("forEdit") != null) {
forEdit = !params.get("forEdit").isEmpty();
}
if (params != null && !params.isEmpty() && params.get("form") != null) {
form = !params.get("form").isEmpty();
}
}

public boolean shouldDisplay(final Map<String, Object> context) {
Expand All @@ -65,19 +60,12 @@ public boolean shouldDisplay(final Map<String, Object> context) {
String fileName = attachment.getFileName();

if (forEdit) {
if (form) {
if (accessEdit && documentManager.isFillable(fileName)) {
return true;
}
} else {
if (accessEdit && documentManager.isEditable(fileName)) {
return true;
}
if (accessEdit && documentManager.isEditable(fileName)) {
return true;
}
} else {
if (accessView
&& documentManager.isViewable(fileName)
&& !(accessEdit && documentManager.isEditable(fileName))
&& documentManager.isViewable(fileName) && !(accessEdit && documentManager.isEditable(fileName))
) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public boolean shouldDisplay(final Map<String, Object> context) {
return false;
}

if ((form && !ext.equals("docxf")) || (!form && ext.equals("docxf"))) {
if (form && !ext.equals("docxf")) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public void doPost(final HttpServletRequest request, final HttpServletResponse r
String fileName = attachment.getFileName();
String access = null;

if (accessEdit && documentManager.isEditable(fileName)) {
if (accessEdit && documentManager.isFillable(fileName)) {
access = "fillForms";
} else if (accessEdit && documentManager.isEditable(fileName)) {
access = "edit";
} else if (accessEdit && documentManager.isFillable(fileName)) {
access = "fillform";
} else if (accessView && documentManager.isViewable(fileName)
&& !(accessEdit
&& (documentManager.isEditable(fileName) || documentManager.isFillable(fileName)))) {
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/onlyoffice/macro/OnlyOfficePreviewMacro.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ public String execute(final Map<String, String> args, final String s, final Conv

if (attachmentUtil.checkAccess(attachment.getId(), user, true)
&& !isPreview) {
if (documentManager.isEditable(fileName)) {
action = "edit";
} else if (documentManager.isFillable(fileName)) {
if (documentManager.isFillable(fileName)) {
action = "fill";
} else if (documentManager.isEditable(fileName)) {
action = "edit";
}
}

Expand Down Expand Up @@ -183,9 +183,6 @@ public ImagePlaceholder getImagePlaceholder(final Map<String, String> args,
String fileExt = name.substring(dotIdx + 1).toLowerCase();
if (documentManager.getDocumentType(name) != null) {
documentType = documentManager.getDocumentType(name).name().toLowerCase();
if (fileExt.equals("oform")) {
documentType = "form";
}
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/onlyoffice/sdk/manager/url/UrlManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ public String getCreateUrl(final String fileId) {
if (attachmentUtil.checkAccessCreate(user, pageId)) {
String fileName = documentManager.getDocumentName(fileId);
String extension = documentManager.getExtension(fileName);
DocumentType documentType = documentManager.getDocumentType(fileName);

if (!extension.equals("docxf")) {
extension = documentManager.getDefaultExtension(documentType);
}

return getConfluenceBaseUrl(false) + DOC_EDITOR_SERVLET + "?pageId=" + pageId + "&fileExt=" + extension;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/atlassian-plugin-marketing.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<atlassian-plugin-marketing>
<compatibility>
<product name="confluence" min="7.12.0" max="8.9.1" />
<product name="confluence" min="7.12.0" max="8.9.7" />
</compatibility>

<logo image="images/144.png"/>
Expand Down
Loading

0 comments on commit 62016f4

Please sign in to comment.