diff --git a/CHANGELOG.md b/CHANGELOG.md index 42901ebd..56c18af8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## 4.1.0 +## Added +- button ONLYOFFICE in confluence preview + +## Changed +- compatible with Confluence 7.19.0 + ## 4.0.0 ## Added - review display settings diff --git a/pom.xml b/pom.xml index 99fdb9df..05a80b6a 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ 4.0.0 onlyoffice onlyoffice-confluence-plugin - 4.0.0 + 4.1.0 Ascensio System SIA diff --git a/src/main/java/onlyoffice/conditions/confluence/previews/plugin/OnlyofficeButton.java b/src/main/java/onlyoffice/conditions/confluence/previews/plugin/OnlyofficeButton.java new file mode 100644 index 00000000..e7ff810e --- /dev/null +++ b/src/main/java/onlyoffice/conditions/confluence/previews/plugin/OnlyofficeButton.java @@ -0,0 +1,91 @@ +/** + * + * (c) Copyright Ascensio System SIA 2022 + * + * 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. + * + */ + +package onlyoffice.conditions.confluence.previews.plugin; + +import com.atlassian.confluence.pages.Attachment; +import com.atlassian.confluence.pages.AttachmentManager; +import com.atlassian.confluence.user.AuthenticatedUserThreadLocal; +import com.atlassian.confluence.user.ConfluenceUser; +import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport; +import onlyoffice.managers.document.DocumentManager; +import onlyoffice.utils.attachment.AttachmentUtil; +import onlyoffice.utils.parsing.ParsingUtil; +import org.json.JSONObject; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; + +public class OnlyofficeButton extends HttpServlet { + @ComponentImport + AttachmentManager attachmentManager; + + private final ParsingUtil parsingUtil; + private final AttachmentUtil attachmentUtil; + private final DocumentManager documentManager; + + @Inject + public OnlyofficeButton(AttachmentManager attachmentManager, ParsingUtil parsingUtil, AttachmentUtil attachmentUtil, DocumentManager documentManager) { + this.attachmentManager = attachmentManager; + this.parsingUtil = parsingUtil; + this.attachmentUtil = attachmentUtil; + this.documentManager = documentManager; + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + InputStream requestStream = request.getInputStream(); + String body = parsingUtil.getBody(requestStream); + + try { + JSONObject bodyJson = new JSONObject(body); + String attachmentIdString = bodyJson.getString("attachmentId"); + Long attachmentId = Long.parseLong(attachmentIdString); + Attachment attachment = attachmentManager.getAttachment(attachmentId); + + ConfluenceUser user = AuthenticatedUserThreadLocal.get(); + boolean accessEdit = attachmentUtil.checkAccess(attachment, user, true); + boolean accessView = attachmentUtil.checkAccess(attachment, user, false); + + String ext = attachment.getFileExtension(); + String access = null; + + if (accessEdit && documentManager.isEditable(ext)) { + access = "edit"; + } else if (accessEdit && documentManager.isFillForm(ext)) { + access = "fillform"; + } else if (accessView && documentManager.isViewable(ext) && + !(accessEdit && (documentManager.isEditable(ext) || documentManager.isFillForm(ext)))) { + access = "view"; + } + + response.setContentType("application/json"); + PrintWriter writer = response.getWriter(); + writer.write("{\"access\":\"" + access + "\"}"); + + } catch (Exception e) { + throw new IOException(e.getMessage()); + } + } +} diff --git a/src/main/java/onlyoffice/utils/attachment/AttachmentUtilImpl.java b/src/main/java/onlyoffice/utils/attachment/AttachmentUtilImpl.java index cd381a9e..4dc64635 100644 --- a/src/main/java/onlyoffice/utils/attachment/AttachmentUtilImpl.java +++ b/src/main/java/onlyoffice/utils/attachment/AttachmentUtilImpl.java @@ -107,7 +107,7 @@ public boolean checkAccess(Attachment attachment, User user, boolean forEdit) { if (forEdit) { boolean create = checkAccessCreate(user, attachment.getContainer().getId()); boolean access = permissionManager.hasPermission(user, Permission.EDIT, attachment); - return create && access; + return create && access && attachment.isLatestVersion(); } else { boolean access = permissionManager.hasPermission(user, Permission.VIEW, attachment); return access; diff --git a/src/main/resources/app_data b/src/main/resources/app_data index 01a35499..4b96e283 160000 --- a/src/main/resources/app_data +++ b/src/main/resources/app_data @@ -1 +1 @@ -Subproject commit 01a35499a3cfb4013d990100e119a7f47f02616f +Subproject commit 4b96e283924e0481299b6400520829649634c23e diff --git a/src/main/resources/atlassian-plugin-marketing.xml b/src/main/resources/atlassian-plugin-marketing.xml index bd200d3f..f3047af5 100644 --- a/src/main/resources/atlassian-plugin-marketing.xml +++ b/src/main/resources/atlassian-plugin-marketing.xml @@ -1,10 +1,10 @@ - + - + diff --git a/src/main/resources/atlassian-plugin.xml b/src/main/resources/atlassian-plugin.xml index af41f755..64fa18e5 100644 --- a/src/main/resources/atlassian-plugin.xml +++ b/src/main/resources/atlassian-plugin.xml @@ -51,6 +51,23 @@ page + + + + + + + + + com.atlassian.confluence.plugins.confluence-previews:confluence-previews-resources + + + + + + media-viewer + + com.atlassian.confluence.editor:page-editor-js com.atlassian.confluence.plugins.drag-and-drop:editor-drop-handler @@ -141,4 +158,8 @@ ONLYOFFICE API Handler. /onlyoffice/api + + Conditions for displaying ONLYOFFICE button in confluence preview. + /onlyoffice/confluence/previews/plugin/access + \ No newline at end of file diff --git a/src/main/resources/css/confluence-previews-plugin/onlyoffice-button.css b/src/main/resources/css/confluence-previews-plugin/onlyoffice-button.css new file mode 100644 index 00000000..aa51cb82 --- /dev/null +++ b/src/main/resources/css/confluence-previews-plugin/onlyoffice-button.css @@ -0,0 +1,21 @@ +/** + * + * (c) Copyright Ascensio System SIA 2022 + * + * 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. + * + */ + +#cp-control-panel-onlyoffice { + background-image: url(cp-onlyoffice-button.svg); +} \ No newline at end of file diff --git a/src/main/resources/images/144.png b/src/main/resources/images/144.png index 3de79e2e..fd62f576 100644 Binary files a/src/main/resources/images/144.png and b/src/main/resources/images/144.png differ diff --git a/src/main/resources/images/banner.jpg b/src/main/resources/images/banner.jpg deleted file mode 100644 index ef2a0646..00000000 Binary files a/src/main/resources/images/banner.jpg and /dev/null differ diff --git a/src/main/resources/images/banner.png b/src/main/resources/images/banner.png new file mode 100644 index 00000000..31b5bac9 Binary files /dev/null and b/src/main/resources/images/banner.png differ diff --git a/src/main/resources/images/confluence-previews-plugin/onlyoffice-button.svg b/src/main/resources/images/confluence-previews-plugin/onlyoffice-button.svg new file mode 100644 index 00000000..3bf28d2d --- /dev/null +++ b/src/main/resources/images/confluence-previews-plugin/onlyoffice-button.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/images/hss1.png b/src/main/resources/images/hss1.png index c4e5602b..e7de35d0 100644 Binary files a/src/main/resources/images/hss1.png and b/src/main/resources/images/hss1.png differ diff --git a/src/main/resources/images/hss1c.png b/src/main/resources/images/hss1c.png index b7e517ec..ab622a05 100644 Binary files a/src/main/resources/images/hss1c.png and b/src/main/resources/images/hss1c.png differ diff --git a/src/main/resources/images/hss2.png b/src/main/resources/images/hss2.png index 69945404..803cae1d 100644 Binary files a/src/main/resources/images/hss2.png and b/src/main/resources/images/hss2.png differ diff --git a/src/main/resources/images/hss2c.png b/src/main/resources/images/hss2c.png index 670fd1ed..438078d2 100644 Binary files a/src/main/resources/images/hss2c.png and b/src/main/resources/images/hss2c.png differ diff --git a/src/main/resources/images/hss3.png b/src/main/resources/images/hss3.png index d21ff440..6de14d90 100644 Binary files a/src/main/resources/images/hss3.png and b/src/main/resources/images/hss3.png differ diff --git a/src/main/resources/images/hss3c.png b/src/main/resources/images/hss3c.png index 321bc926..42362f75 100644 Binary files a/src/main/resources/images/hss3c.png and b/src/main/resources/images/hss3c.png differ diff --git a/src/main/resources/images/ss1.png b/src/main/resources/images/ss1.png index a23042b1..cce7072f 100644 Binary files a/src/main/resources/images/ss1.png and b/src/main/resources/images/ss1.png differ diff --git a/src/main/resources/images/ss2.png b/src/main/resources/images/ss2.png index e9737229..d1ccd8d1 100644 Binary files a/src/main/resources/images/ss2.png and b/src/main/resources/images/ss2.png differ diff --git a/src/main/resources/images/ss3.png b/src/main/resources/images/ss3.png index d9fd1b20..a2640150 100644 Binary files a/src/main/resources/images/ss3.png and b/src/main/resources/images/ss3.png differ diff --git a/src/main/resources/js/confluence-previews-plugin/onlyoffice-button.js b/src/main/resources/js/confluence-previews-plugin/onlyoffice-button.js new file mode 100644 index 00000000..a3a49c91 --- /dev/null +++ b/src/main/resources/js/confluence-previews-plugin/onlyoffice-button.js @@ -0,0 +1,91 @@ +/** + * + * (c) Copyright Ascensio System SIA 2022 + * + * 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. + * + */ + +define('cp/component/onlyoffice-button', [ + 'jquery', + 'ajs', + 'backbone', + 'core/template-store-singleton' +], function ($, + AJS, + Backbone, + templateStore) { + 'use strict'; + + var OnlyofficeButtonView = Backbone.View.extend({ + tagName: 'span', + + initialize: function (options) { + this._mediaViewer = options.mediaViewer; + }, + + render: function () { + var attachmentId = this._mediaViewer.getCurrentFile().get('id'); + + var xhr = new XMLHttpRequest(); + + xhr.open("POST", "/plugins/servlet/onlyoffice/confluence/previews/plugin/access", false); + xhr.send(JSON.stringify({ + attachmentId: attachmentId + })); + + var title; + + if (xhr.status == 200) { + var response = JSON.parse(xhr.responseText); + + if (response.access == "edit") { + title = AJS.I18n.getText('onlyoffice.editor.editlink'); + } else if (response.access == "view") { + title = AJS.I18n.getText('onlyoffice.editor.viewlink'); + } else if (response.access == "fillform") { + title = AJS.I18n.getText('onlyoffice.editor.fillFormlink'); + } + } + + if (title) { + this.$el.html(templateStore.get('controlOnlyofficeButton')({ + attachmentId: attachmentId, + title: title + })); + if ($.fn.tooltip) { + this.$('a').tooltip({gravity: 'n'}); + } + } + + return this; + } + }); + + var OnlyofficeButton = function (mediaViewer) { + mediaViewer.getView().fileControlsView.addLayerView('onlyofficeButton', OnlyofficeButtonView, { + weight: 1, + predicate: function (mediaViewer) { + return true; + } + }); + }; + + return OnlyofficeButton; +}); + +(function () { + var OnlyofficeButton = require('cp/component/onlyoffice-button'); + var MediaViewer = require('MediaViewer'); + MediaViewer.registerPlugin('onlyofficebutton', OnlyofficeButton); +})(); diff --git a/src/main/resources/templates/confluence-previews-plugin/onlyoffice-button.soy b/src/main/resources/templates/confluence-previews-plugin/onlyoffice-button.soy new file mode 100644 index 00000000..90e01700 --- /dev/null +++ b/src/main/resources/templates/confluence-previews-plugin/onlyoffice-button.soy @@ -0,0 +1,10 @@ +{namespace FileViewer.Templates} + +/** +* Onlyoffice button for opening editor. +* @param attachmentId The id attachment. +* @param title The title ONLYOFFICE button. +*/ +{template .controlOnlyofficeButton} + +{/template}