Skip to content

Commit

Permalink
Merge pull request #83 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Release/4.1.0
  • Loading branch information
LinneyS authored Aug 15, 2022
2 parents d1b03c7 + 459c86b commit 26bf3e9
Show file tree
Hide file tree
Showing 23 changed files with 251 additions and 5 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.1.0
## Added
- button ONLYOFFICE in confluence preview

## Changed
- compatible with Confluence 7.19.0

## 4.0.0
## Added
- review display settings
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.0.0</version>
<version>4.1.0</version>

<organization>
<name>Ascensio System SIA</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/app_data
Submodule app_data updated 78 files
+ az-Latn-AZ/new.docx
+ az-Latn-AZ/new.docxf
+ az-Latn-AZ/new.pptx
+ az-Latn-AZ/new.xlsx
+ bg-BG/new.pptx
+ bg-BG/new.xlsx
+ de-DE/new.pptx
+ de-DE/new.xlsx
+ el-GR/new.pptx
+ el-GR/new.xlsx
+ en-GB/new.pptx
+ en-GB/new.xlsx
+ en-US/new.pptx
+ en-US/new.xlsx
+ es-ES/new.docxf
+ es-ES/new.pptx
+ es-ES/new.xlsx
+ eu-ES/new.docx
+ eu-ES/new.docxf
+ eu-ES/new.pptx
+ eu-ES/new.xlsx
+ fr-FR/new.pptx
+ fr-FR/new.xlsx
+ gl-ES/new.pptx
+ gl-ES/new.xlsx
+ hy-AM/new.docx
+ hy-AM/new.docxf
+ hy-AM/new.pptx
+ hy-AM/new.xlsx
+ it-IT/new.pptx
+ it-IT/new.xlsx
+ ja-JP/new.docx
+ ja-JP/new.docxf
+ ja-JP/new.pptx
+ ja-JP/new.xlsx
+ ko-KR/new.pptx
+ ko-KR/new.xlsx
+ lv-LV/new.pptx
+ lv-LV/new.xlsx
+ ms-MY/new.docx
+ ms-MY/new.docxf
+ ms-MY/new.pptx
+ ms-MY/new.xlsx
+ nl-NL/new.pptx
+ nl-NL/new.xlsx
+ pl-PL/new.pptx
+ pl-PL/new.xlsx
+ pt-BR/new.docx
+ pt-BR/new.docxf
+ pt-BR/new.pptx
+ pt-BR/new.xlsx
+ pt-PT/new.docx
+ pt-PT/new.docxf
+ pt-PT/new.pptx
+ pt-PT/new.xlsx
+ ru-RU/new.pptx
+ ru-RU/new.xlsx
+ sk-SK/new.docx
+ sk-SK/new.docxf
+ sk-SK/new.pptx
+ sk-SK/new.xlsx
+ sv-SE/new.docx
+ sv-SE/new.docxf
+ sv-SE/new.pptx
+ sv-SE/new.xlsx
+ tr-TR/new.docxf
+ tr-TR/new.pptx
+ tr-TR/new.xlsx
+ uk-UA/new.pptx
+ uk-UA/new.xlsx
+ vi-VN/new.pptx
+ vi-VN/new.xlsx
+ zh-CN/new.pptx
+ zh-CN/new.xlsx
+ zh-TW/new.docx
+ zh-TW/new.docxf
+ zh-TW/new.pptx
+ zh-TW/new.xlsx
4 changes: 2 additions & 2 deletions src/main/resources/atlassian-plugin-marketing.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<atlassian-plugin-marketing>
<compatibility>
<product name="confluence" min="6.13.1" max="7.18.3" />
<product name="confluence" min="6.13.1" max="7.19.0" />
</compatibility>

<logo image="images/144.png"/>
<banner image="images/banner.jpg"/>
<banner image="images/banner.png"/>

<highlights>
<highlight image="images/hss1.png" cropped="images/hss1c.png"/>
Expand Down
21 changes: 21 additions & 0 deletions src/main/resources/atlassian-plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@
<context>page</context>
</web-resource>

<web-resource key="onlyoffice-confluence-previews-plugin" name="Button ONLYOFFICE for confluence preview lightbox">
<transformation extension="js">
<transformer key="jsI18n"/>
</transformation>
<transformation extension="soy">
<transformer key="soyTransformer"/>
</transformation>

<dependency>com.atlassian.confluence.plugins.confluence-previews:confluence-previews-resources</dependency>

<resource type="download" name="cp-onlyoffice-button.soy.js" location="/templates/confluence-previews-plugin/onlyoffice-button.soy"/>
<resource type="download" name="cp-onlyoffice-button-plugin.js" location="/js/confluence-previews-plugin/onlyoffice-button.js"/>
<resource type="download" name="cp-onlyoffice-button.css" location="/css/confluence-previews-plugin/onlyoffice-button.css"/>
<resource type="download" name="cp-onlyoffice-button.svg" location="images/confluence-previews-plugin/onlyoffice-button.svg"/>
<context>media-viewer</context>
</web-resource>

<web-resource key="onlyoffice-confluence-plugin-resources-editor" name="Web Resources container for the editor page">
<dependency>com.atlassian.confluence.editor:page-editor-js</dependency>
<dependency>com.atlassian.confluence.plugins.drag-and-drop:editor-drop-handler</dependency>
Expand Down Expand Up @@ -141,4 +158,8 @@
<description>ONLYOFFICE API Handler.</description>
<url-pattern>/onlyoffice/api</url-pattern>
</servlet>
<servlet key="OnlyOfficeButtonCondition" class="onlyoffice.conditions.confluence.previews.plugin.OnlyofficeButton" name="ONLYOFFICE Button Condition">
<description>Conditions for displaying ONLYOFFICE button in confluence preview.</description>
<url-pattern>/onlyoffice/confluence/previews/plugin/access</url-pattern>
</servlet>
</atlassian-plugin>
Original file line number Diff line number Diff line change
@@ -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);
}
Binary file modified src/main/resources/images/144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/resources/images/banner.jpg
Binary file not shown.
Binary file added src/main/resources/images/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/images/hss1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/images/hss1c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/images/hss2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/images/hss2c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/images/hss3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/images/hss3c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/images/ss1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/images/ss2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/images/ss3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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);
})();
Original file line number Diff line number Diff line change
@@ -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}
<a role="button" target="_blank" tabindex=58" aria-haspopup="true" id="cp-control-panel-onlyoffice" href="/plugins/servlet/onlyoffice/doceditor?attachmentId={$attachmentId}" title="{$title}" class="cp-icon"></a>
{/template}

0 comments on commit 26bf3e9

Please sign in to comment.