Skip to content

Commit 77f552b

Browse files
committed
Avoid altering the original PDF when filling the form
1 parent 031bad0 commit 77f552b

File tree

10 files changed

+136
-82
lines changed

10 files changed

+136
-82
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.logicaldoc.gui.common.client.util;
2+
3+
import java.util.List;
4+
5+
import com.google.gwt.user.client.rpc.AsyncCallback;
6+
import com.logicaldoc.gui.common.client.beans.GUIAccessControlEntry;
7+
import com.logicaldoc.gui.common.client.i18n.I18N;
8+
import com.logicaldoc.gui.common.client.log.GuiLog;
9+
import com.logicaldoc.gui.frontend.client.services.DocumentService;
10+
11+
/**
12+
* Some utility methods related to recurrent security operations
13+
*
14+
* @author Marco Meschieri - LogicalDOC
15+
* @since 9.0.1
16+
*/
17+
public class SecurityUtil {
18+
19+
private SecurityUtil() {
20+
// Not instantiable
21+
}
22+
23+
/**
24+
* Checks if the user has all the specified permissions on the selected
25+
* documents and runs the task
26+
*
27+
* @param docIds Identifier of the documents to check
28+
* @param requiredPermissions The permissions required on the documents
29+
* selection
30+
* @param task The task to run
31+
*/
32+
public static void checkPermissionsAndRun(List<Long> docIds, String[] requiredPermissions, Runnable task) {
33+
if (docIds == null || docIds.isEmpty())
34+
return;
35+
36+
DocumentService.Instance.get().getAllowedPermissions(docIds, new AsyncCallback<>() {
37+
@Override
38+
public void onFailure(Throwable caught) {
39+
GuiLog.serverError(caught);
40+
}
41+
42+
@Override
43+
public void onSuccess(GUIAccessControlEntry grantedPermissions) {
44+
for (String permission : requiredPermissions) {
45+
if (!grantedPermissions.isPermissionAllowed(permission.toLowerCase())) {
46+
GuiLog.warn(I18N.message("somedocsdonothaveperm", permission.toUpperCase()), null);
47+
return;
48+
}
49+
}
50+
task.run();
51+
}
52+
});
53+
}
54+
}

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/document/DocumentToolbar.java

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.logicaldoc.gui.common.client.services.SecurityService;
2424
import com.logicaldoc.gui.common.client.util.AwesomeFactory;
2525
import com.logicaldoc.gui.common.client.util.DocUtil;
26+
import com.logicaldoc.gui.common.client.util.SecurityUtil;
2627
import com.logicaldoc.gui.common.client.util.Util;
2728
import com.logicaldoc.gui.common.client.widgets.DropSpotPopup;
2829
import com.logicaldoc.gui.frontend.client.calendar.CalendarEventDialog;
@@ -33,7 +34,7 @@
3334
import com.logicaldoc.gui.frontend.client.document.stamp.StampDialog;
3435
import com.logicaldoc.gui.frontend.client.document.update.UpdateDialog;
3536
import com.logicaldoc.gui.frontend.client.folder.FolderNavigator;
36-
import com.logicaldoc.gui.frontend.client.services.DocumentService;
37+
import com.logicaldoc.gui.frontend.client.onlyoffice.OnlyOfficeEditor;
3738
import com.logicaldoc.gui.frontend.client.subscription.SubscriptionDialog;
3839
import com.smartgwt.client.types.SelectionType;
3940
import com.smartgwt.client.util.SC;
@@ -80,6 +81,8 @@ public class DocumentToolbar extends ToolStrip implements FolderObserver {
8081

8182
protected ToolStripButton office = AwesomeFactory.newToolStripButton("windows", "editwithoffice");
8283

84+
protected ToolStripButton onlyoffice = AwesomeFactory.newToolStripButton("windows", "editwithonlyoffice");
85+
8386
protected ToolStripButton bulkUpdate = AwesomeFactory.newToolStripButton("edit", "bulkupdate");
8487

8588
protected ToolStripButton stamp = AwesomeFactory.newToolStripButton("tint", "stamp");
@@ -133,6 +136,8 @@ protected void prepareButtons() {
133136

134137
addOffice();
135138

139+
addOnlyOffice();
140+
136141
addSeparator();
137142

138143
addUpload();
@@ -431,7 +436,7 @@ private void addForm() {
431436
if (!Feature.enabled(Feature.FORM))
432437
setFeatureDisabled(addForm);
433438

434-
addForm.addClickHandler(event -> new AddDocumentUsingForm().show());
439+
addForm.addClickHandler(click -> new AddDocumentUsingForm().show());
435440
}
436441
}
437442

@@ -441,7 +446,7 @@ private void addScan() {
441446
if (!Feature.enabled(Feature.SCAN))
442447
setFeatureDisabled(scan);
443448

444-
scan.addClickHandler(event -> Util.openScan());
449+
scan.addClickHandler(click -> Util.openScan());
445450
}
446451
}
447452

@@ -459,7 +464,7 @@ private void addDropSpot() {
459464
if (!Feature.enabled(Feature.DROP_SPOT))
460465
setFeatureDisabled(dropSpot);
461466

462-
dropSpot.addClickHandler(event -> DropSpotPopup.openDropSpot());
467+
dropSpot.addClickHandler(click -> DropSpotPopup.openDropSpot());
463468
}
464469
}
465470

@@ -471,22 +476,36 @@ private void addOffice() {
471476
if (!Feature.enabled(Feature.OFFICE))
472477
setFeatureDisabled(office);
473478

474-
office.addClickHandler(event -> checkPermissionsAndRun(
479+
office.addClickHandler(click -> checkPermissionsAndRun(
475480
new String[] { GUIAccessControlEntry.PERMISSION_DOWNLOAD, GUIAccessControlEntry.PERMISSION_WRITE },
476481
() -> Util.openEditWithOffice(document.getId())));
477482
}
478483
}
479484

485+
private void addOnlyOffice() {
486+
if (Feature.visible(Feature.ONLYOFFICE) && Menu.enabled(Menu.ONLYOFFICE)) {
487+
addButton(onlyoffice);
488+
onlyoffice.setTooltip(I18N.message("editwithonlyoffice"));
489+
onlyoffice.setTitle("<i class='fab fa-briefcase fa-lg fa-lg' aria-hidden='true'></i>");
490+
if (!Feature.enabled(Feature.OFFICE))
491+
setFeatureDisabled(office);
492+
493+
onlyoffice.addClickHandler(click -> checkPermissionsAndRun(
494+
new String[] { GUIAccessControlEntry.PERMISSION_DOWNLOAD, GUIAccessControlEntry.PERMISSION_WRITE },
495+
() -> new OnlyOfficeEditor(document).show()));
496+
}
497+
}
498+
480499
private void addConvert() {
481500
if (Feature.visible(Feature.FORMAT_CONVERSION)) {
482501
addButton(convert);
483502
convert.setTooltip(I18N.message("convert"));
484503
if (!Feature.enabled(Feature.PDF))
485504
setFeatureDisabled(convert);
486505

487-
convert.addClickHandler(event -> {
506+
convert.addClickHandler(click -> {
488507
new ConversionDialog(document).show();
489-
event.cancel();
508+
click.cancel();
490509
});
491510
}
492511
}
@@ -499,7 +518,7 @@ private void addPdf() {
499518
setFeatureDisabled(pdf);
500519

501520
pdf.addClickHandler(
502-
event -> checkPermissionsAndRun(new String[] { GUIAccessControlEntry.PERMISSION_DOWNLOAD }, () -> {
521+
click -> checkPermissionsAndRun(new String[] { GUIAccessControlEntry.PERMISSION_DOWNLOAD }, () -> {
503522
List<Long> selection = DocumentsPanel.get().getDocumentsGrid().getSelectedIds();
504523
if (selection.size() == 1) {
505524
DocUtil.downloadPdfConversion(document.getId(), document.getVersion());
@@ -549,28 +568,8 @@ private void addDownload() {
549568
* @param task The task to run
550569
*/
551570
private void checkPermissionsAndRun(String[] requiredPermissions, Runnable task) {
552-
DocumentsGrid grid = DocumentsPanel.get().getDocumentsGrid();
553-
if (grid.getSelectedCount() == 0)
554-
return;
555-
556-
DocumentService.Instance.get().getAllowedPermissions(grid.getSelectedIds(),
557-
new AsyncCallback<>() {
558-
@Override
559-
public void onFailure(Throwable caught) {
560-
GuiLog.serverError(caught);
561-
}
562-
563-
@Override
564-
public void onSuccess(GUIAccessControlEntry grantedPermissions) {
565-
for (String permission : requiredPermissions) {
566-
if (!grantedPermissions.isPermissionAllowed(permission.toLowerCase())) {
567-
GuiLog.warn(I18N.message("somedocsdonothaveperm", permission.toUpperCase()), null);
568-
return;
569-
}
570-
}
571-
task.run();
572-
}
573-
});
571+
SecurityUtil.checkPermissionsAndRun(DocumentsPanel.get().getDocumentsGrid().getSelectedIds(),
572+
requiredPermissions, task);
574573
}
575574

576575
private void addRefresh() {
@@ -610,6 +609,7 @@ public void update(GUIDocument document, GUIFolder folder) {
610609
stamp.setDisabled(true);
611610
sign.setDisabled(true);
612611
office.setDisabled(true);
612+
onlyoffice.setDisabled(true);
613613
addForm.setDisabled(true);
614614
readingRequest.setDisabled(true);
615615
}
@@ -693,10 +693,14 @@ else if (document.getType() != null)
693693

694694
office.setDisabled(
695695
!Feature.enabled(Feature.OFFICE) || !isOfficeFile || !document.isDownload() || !document.isWrite());
696+
onlyoffice.setDisabled(!Feature.enabled(Feature.OFFICE) || !Menu.enabled(Menu.ONLYOFFICE)
697+
|| !document.isDownload() || !document.isWrite());
696698
if (document.getStatus() != Constants.DOC_UNLOCKED && !Session.get().getUser().isMemberOf(Constants.GROUP_ADMIN)
697699
&& document.getLockUserId() != null
698-
&& Session.get().getUser().getId() != document.getLockUserId().longValue())
700+
&& Session.get().getUser().getId() != document.getLockUserId().longValue()) {
699701
office.setDisabled(true);
702+
onlyoffice.setDisabled(true);
703+
}
700704
}
701705

702706
@Override

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/menu/MainMenu.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.logicaldoc.gui.common.client.CookiesManager;
1515
import com.logicaldoc.gui.common.client.Feature;
1616
import com.logicaldoc.gui.common.client.Session;
17+
import com.logicaldoc.gui.common.client.beans.GUIAccessControlEntry;
1718
import com.logicaldoc.gui.common.client.beans.GUIDocument;
1819
import com.logicaldoc.gui.common.client.beans.GUIFolder;
1920
import com.logicaldoc.gui.common.client.beans.GUIParameter;
@@ -29,6 +30,7 @@
2930
import com.logicaldoc.gui.common.client.util.DocUtil;
3031
import com.logicaldoc.gui.common.client.util.ItemFactory;
3132
import com.logicaldoc.gui.common.client.util.LD;
33+
import com.logicaldoc.gui.common.client.util.SecurityUtil;
3234
import com.logicaldoc.gui.common.client.util.Util;
3335
import com.logicaldoc.gui.common.client.util.ValuesCallback;
3436
import com.logicaldoc.gui.common.client.util.WindowUtils;
@@ -564,8 +566,9 @@ private MenuItem getOnlyOfficeMenuItem(GUIFolder folder, final GUIDocument docum
564566
edit.addClickHandler(event -> {
565567
if (document == null)
566568
return;
567-
568-
new OnlyOfficeEditor(document).show();
569+
SecurityUtil.checkPermissionsAndRun(Arrays.asList(document.getId()),
570+
new String[] { GUIAccessControlEntry.PERMISSION_DOWNLOAD, GUIAccessControlEntry.PERMISSION_WRITE },
571+
() -> new OnlyOfficeEditor(document).show());
569572
});
570573

571574
final MenuItem create = new MenuItem(I18N.message("createdoc"));

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/onlyoffice/OnlyOfficeEditor.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,8 @@ public OnlyOfficeEditor(final GUIDocument document) {
5858
addItem(layout);
5959

6060
if ("fillForms".equals(document.getComment())) {
61-
// the document is not being edited just used to produce another PDF
62-
reloadBody();
63-
} else {
6461
// the document is being edited, so declare the editing
65-
OnlyOfficeService.Instance.get().startEditing(document.getId(), new AsyncCallback<Void>() {
62+
OnlyOfficeService.Instance.get().startFilling(document.getId(), new AsyncCallback<Void>() {
6663

6764
@Override
6865
public void onFailure(Throwable caught) {
@@ -74,16 +71,9 @@ public void onSuccess(Void result) {
7471
reloadBody();
7572
}
7673
});
77-
}
78-
}
79-
80-
private void onClose() {
81-
if ("fillForms".equals(document.getComment())) {
82-
// the document is not being edited just used to produce another PDF
83-
destroy();
8474
} else {
85-
// the document is being edited, so declare the end of editing
86-
OnlyOfficeService.Instance.get().endEditing(document.getId(), new AsyncCallback<Void>() {
75+
// the document is being edited, so declare the editing
76+
OnlyOfficeService.Instance.get().startEditing(document.getId(), new AsyncCallback<Void>() {
8777

8878
@Override
8979
public void onFailure(Throwable caught) {
@@ -92,12 +82,28 @@ public void onFailure(Throwable caught) {
9282

9383
@Override
9484
public void onSuccess(Void result) {
95-
destroy();
85+
reloadBody();
9686
}
9787
});
9888
}
9989
}
10090

91+
private void onClose() {
92+
// the document is being edited, so declare the end of editing
93+
OnlyOfficeService.Instance.get().endEditing(document.getId(), new AsyncCallback<Void>() {
94+
95+
@Override
96+
public void onFailure(Throwable caught) {
97+
GuiLog.serverError(caught);
98+
}
99+
100+
@Override
101+
public void onSuccess(Void result) {
102+
destroy();
103+
}
104+
});
105+
}
106+
101107
/**
102108
* Reloads a preview.
103109
*

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/onlyoffice/OnlyOfficeService.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package com.logicaldoc.gui.frontend.client.onlyoffice;
22

3-
import java.util.List;
4-
53
import com.google.gwt.core.client.GWT;
64
import com.google.gwt.user.client.rpc.RemoteService;
75
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
86
import com.google.gwt.user.client.rpc.ServiceDefTarget;
97
import com.logicaldoc.gui.common.client.LDRpcRequestBuilder;
108
import com.logicaldoc.gui.common.client.ServerException;
11-
import com.logicaldoc.gui.common.client.beans.GUIValue;
129

1310
/**
1411
* The client side stub for the OnlyOffice Service.
@@ -29,31 +26,22 @@ public interface OnlyOfficeService extends RemoteService {
2926
public void startEditing(long docId) throws ServerException;
3027

3128
/**
32-
* Starts the editing of a document with Only Office
29+
* Starts the filling of a form with Only Office
3330
*
34-
* @param docId ID of the document being edited
31+
* @param docId ID of the form to take as model
3532
*
3633
* @throws ServerException an error happened in the server application
3734
*/
38-
public void endEditing(long docId) throws ServerException;
35+
public void startFilling(long docId) throws ServerException;
3936

4037
/**
41-
* Loads the settings
42-
*
43-
* @returns the list of settings
44-
*
45-
* @throws ServerException an error happened in the server application
46-
*/
47-
public List<GUIValue> loadSettings() throws ServerException;
48-
49-
/**
50-
* Saves the settings
38+
* Starts the editing of a document with Only Office
5139
*
52-
* @param settings the list of settings
40+
* @param docId ID of the document being edited
5341
*
5442
* @throws ServerException an error happened in the server application
5543
*/
56-
public void saveSettings(List<GUIValue> settings) throws ServerException;
44+
public void endEditing(long docId) throws ServerException;
5745

5846
public static class Instance {
5947
private static OnlyOfficeServiceAsync inst;
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
package com.logicaldoc.gui.frontend.client.onlyoffice;
22

3-
import java.util.List;
4-
53
import com.google.gwt.user.client.rpc.AsyncCallback;
6-
import com.logicaldoc.gui.common.client.beans.GUIValue;
74

85
public interface OnlyOfficeServiceAsync {
96

107
void startEditing(long docId, AsyncCallback<Void> callback);
8+
9+
void startFilling(long docId, AsyncCallback<Void> callback);
1110

1211
void endEditing(long docId, AsyncCallback<Void> callback);
13-
14-
void loadSettings(AsyncCallback<List<GUIValue>> callback);
15-
16-
void saveSettings(List<GUIValue> settings, AsyncCallback<Void> callback);
1712
}

logicaldoc-i18n/src/main/resources/i18n/messages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2613,4 +2613,5 @@ apisecret = API Secret
26132613
customId = Custom ID
26142614
thisdocsecurityparent = This document does not define any security policy so <u>the policies of the folder will be used instead</u>
26152615
onlyoffice = OnlyOffice
2616-
allowclientid = Allow use of Client ID to hook session
2616+
allowclientid = Allow use of Client ID to hook session
2617+
editwithonlyoffice = Edit with OnlyOffice

0 commit comments

Comments
 (0)