-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from ONLYOFFICE/develop
Release/4.1.0
- Loading branch information
Showing
23 changed files
with
251 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/onlyoffice/conditions/confluence/previews/plugin/OnlyofficeButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule app_data
updated
78 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/resources/css/confluence-previews-plugin/onlyoffice-button.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions
5
src/main/resources/images/confluence-previews-plugin/onlyoffice-button.svg
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.
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.
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.
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.
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.
91 changes: 91 additions & 0 deletions
91
src/main/resources/js/confluence-previews-plugin/onlyoffice-button.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})(); |
10 changes: 10 additions & 0 deletions
10
src/main/resources/templates/confluence-previews-plugin/onlyoffice-button.soy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |