Skip to content

Commit

Permalink
Merge pull request #112 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Release/4.4.0
  • Loading branch information
LinneyS authored Oct 11, 2023
2 parents 2ab9d58 + 7ae3ef1 commit 6cde0ab
Show file tree
Hide file tree
Showing 23 changed files with 181 additions and 21 deletions.
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.4.0
## Added
- compatible with Confluence 8.6
- opening documents for viewing by an anonymous user
- edit button in ONLYOFFICE preview macro
- link to docs cloud

## 4.3.1
## Changed
- vulnerability dependency update
Expand Down
2 changes: 1 addition & 1 deletion 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>4.3.1</version>
<version>4.4.0</version>

<organization>
<name>Ascensio System SIA</name>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/onlyoffice/OnlyOfficeEditorServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ public OnlyOfficeEditorServlet(final I18nResolver i18n, final UrlManager urlMana
@Override
public void doGet(final HttpServletRequest request, final HttpServletResponse response)
throws ServletException, IOException {
if (!authContext.checkUserAuthorization(request, response)) {
return;
}

ConfluenceUser user = AuthenticatedUserThreadLocal.get();

String attachmentIdString = request.getParameter("attachmentId");
String actionDataString = request.getParameter("actionData");
String referer = request.getHeader("referer");

if (attachmentIdString == null || attachmentIdString.isEmpty()) {
if (!authContext.checkUserAuthorization(request, response)) {
return;
}

String fileName = request.getParameter("fileName");
String fileExt = request.getParameter("fileExt");
String pageId = request.getParameter("pageId");
Expand Down Expand Up @@ -118,7 +118,7 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re
}

if (!attachmentUtil.checkAccess(attachmentId, user, false)) {
response.sendRedirect(attachment.getContainer().getUrlPath());
response.sendRedirect(authContext.getLoginUrl(request));
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/onlyoffice/OnlyOfficeFileProviderServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re
throw new SecurityException("Invalid link token!");
}

String userKeyString = bodyFromToken.getString("userKey");
String userKeyString = bodyFromToken.has("userKey") ? bodyFromToken.getString("userKey") : null;
String attachmentIdString = bodyFromToken.getString("attachmentId");

UserAccessor userAccessor = (UserAccessor) ContainerManager.getComponent("userAccessor");

UserKey userKey = new UserKey(userKeyString);
UserKey userKey = userKeyString == null || userKeyString.equals("") ? null : new UserKey(userKeyString);
ConfluenceUser user = userAccessor.getUserByKey(userKey);
Long attachmentId = Long.parseLong(attachmentIdString);

Expand Down
24 changes: 22 additions & 2 deletions src/main/java/onlyoffice/macro/OnlyOfficePreviewMacro.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.atlassian.confluence.pages.Attachment;
import com.atlassian.confluence.pages.AttachmentManager;
import com.atlassian.confluence.plugin.services.VelocityHelperService;
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal;
import com.atlassian.confluence.util.HtmlUtil;
import onlyoffice.macro.components.ContentResolver;
import onlyoffice.managers.config.ConfigManager;
Expand All @@ -39,6 +40,7 @@
import onlyoffice.model.config.DocumentType;
import onlyoffice.model.config.Type;
import onlyoffice.model.config.editor.Mode;
import onlyoffice.utils.attachment.AttachmentUtil;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -62,18 +64,20 @@ public class OnlyOfficePreviewMacro implements Macro, EditorImagePlaceholder, Re
private final ConfigManager configManager;
private final UrlManager urlManager;
private final DocumentManager documentManager;
private final AttachmentUtil attachmentUtil;

public OnlyOfficePreviewMacro(final AttachmentManager attachmentManager,
final VelocityHelperService velocityHelperService,
final ContentResolver contentResolver,
final ConfigManager configManager, final UrlManager urlManager,
final DocumentManager documentManager) {
final DocumentManager documentManager, final AttachmentUtil attachmentUtil) {
this.attachmentManager = attachmentManager;
this.velocityHelperService = velocityHelperService;
this.contentResolver = contentResolver;
this.configManager = configManager;
this.urlManager = urlManager;
this.documentManager = documentManager;
this.attachmentUtil = attachmentUtil;
}

@Override
Expand Down Expand Up @@ -110,8 +114,24 @@ public String execute(final Map<String, String> args, final String s, final Conv
height
);

String extension = attachmentUtil.getFileExt(attachment.getId());
String action = "";

final boolean isPreview = conversionContext.getOutputType().equals("preview");

if (attachmentUtil.checkAccess(attachment.getId(), AuthenticatedUserThreadLocal.get(), true)
&& !isPreview) {
if (documentManager.isEditable(extension)) {
action = "edit";
} else if (documentManager.isFillForm(extension)) {
action = "fill";
}
}

final Map<String, Object> context = this.velocityHelperService.createDefaultVelocityContext();
context.put("id", documentManager.getKeyOfFile(attachment.getId(), true));
context.put("id", System.currentTimeMillis());
context.put("attachmentId", attachment.getId());
context.put("action", action);
context.put("docServiceApiUrl", urlManager.getDocServiceApiUrl());
context.put("configAsHtml", config);

Expand Down
1 change: 1 addition & 0 deletions src/main/java/onlyoffice/managers/auth/AuthContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

public interface AuthContext {
boolean checkUserAuthorization(HttpServletRequest request, HttpServletResponse response) throws IOException;
String getLoginUrl(HttpServletRequest request) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public boolean checkUserAuthorization(final HttpServletRequest request, final Ht
return true;
}

private String getLoginUrl(final HttpServletRequest request) throws IOException {
public String getLoginUrl(final HttpServletRequest request) throws IOException {
StringBuilder stringBuilder = new StringBuilder(request.getContextPath());
String fullUrl = stringBuilder.append("/login.action?permissionViolation=true&os_destination=")
.append("plugins%2Fservlet%2Fonlyoffice%2Fdoceditor").append("?")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public String getTargetExt(final String ext) {
if (format.getName().equals("docxf") && format.getConvert().contains("oform")) {
return "oform";
}
if (format.getName().equals("docx") && format.getConvert().contains("docxf")) {
return "docxf";
}
if (format.getConvert().contains("docx")) {
return "docx";
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/onlyoffice/managers/url/UrlManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ public String getFileUri(final Long attachmentId) {
ConfluenceUser user = AuthenticatedUserThreadLocal.get();

Map<String, String> params = new HashMap<>();
params.put("userKey", user.getKey().getStringValue());

if (user != null) {
params.put("userKey", user.getKey().getStringValue());
}
params.put("attachmentId", attachmentId.toString());
params.put("action", "download");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,12 @@ public Attachment getAttachmentByName(final String fileName, final Long pageId)
}

public boolean checkAccess(final Long attachmentId, final User user, final boolean forEdit) {
if (user == null) {
return false;
}

Attachment attachment = attachmentManager.getAttachment(attachmentId);

return checkAccess(attachment, user, forEdit);
}

public boolean checkAccess(final Attachment attachment, final User user, final boolean forEdit) {
if (user == null) {
return false;
}

PermissionManager permissionManager = (PermissionManager) ContainerManager.getComponent("permissionManager");

if (forEdit) {
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.4.0" />
<product name="confluence" min="7.12.0" max="8.6.0" />
</compatibility>

<logo image="images/144.png"/>
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/atlassian-plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
</web-resource>

<web-resource key="onlyoffice-confluence-plugin-resources-configure" name="Web Resources container for the configuration page">
<resource type="download" name="banner.css" location="css/banner/banner.css"/>
<resource type="download" name="background.svg" location="images/banner/background.svg"/>
<resource type="download" name="logo.svg" location="images/banner/logo.svg"/>
<resource type="download" name="configure.css" location="css/configure.css"/>
<resource type="download" name="icon_view.svg" location="images/icon_view.svg"/>
<resource type="download" name="icon_hide.svg" location="images/icon_hide.svg"/>
Expand All @@ -42,6 +45,7 @@
</transformation>
<resource type="download" name="onlyoffice-download-as.js" location="js/onlyoffice-download-as.js"/>
<context>page</context>
<context>blogpost</context>
</web-resource>

<web-resource key="onlyoffice-confluence-plugin-resources-filecreate" name="Web Resources container for the file creation dialog">
Expand Down
37 changes: 37 additions & 0 deletions src/main/resources/css/banner/banner.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
*
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

.onlyoffice-docs-cloud-banner-main {
align-items: center;
background: url(background.svg) no-repeat;
background-color: #f5f6f8;
display: flex;
height: 135px;
width: 500px;
margin: 30px 0 0;
}

.onlyoffice-docs-cloud-banner-section {
padding: 0 15px;
}

.onlyoffice-docs-cloud-banner-image {
background-image: url(logo.svg);
width: 82px;
height: 79px;
}
5 changes: 5 additions & 0 deletions src/main/resources/images/banner/background.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6cde0ab

Please sign in to comment.