From 3820f76d27f5c8fd70ca525adb90de08c04e100d Mon Sep 17 00:00:00 2001 From: ZEROM22 Date: Fri, 3 Nov 2023 09:14:41 +0300 Subject: [PATCH 001/346] nodejs: added page for forgotten files --- web/documentserver-example/nodejs/app.js | 63 +++++++ .../nodejs/public/stylesheets/stylesheet.css | 6 +- .../nodejs/views/forgotten.ejs | 156 ++++++++++++++++++ .../nodejs/views/index.ejs | 1 + 4 files changed, 225 insertions(+), 1 deletion(-) create mode 100644 web/documentserver-example/nodejs/views/forgotten.ejs diff --git a/web/documentserver-example/nodejs/app.js b/web/documentserver-example/nodejs/app.js index 1a0378e4b..955311665 100755 --- a/web/documentserver-example/nodejs/app.js +++ b/web/documentserver-example/nodejs/app.js @@ -108,6 +108,69 @@ app.get('/', (req, res) => { // define a handler for default page } }); +app.get('/forgotten', async (req, res) => { + function getForgottenList() { + return new Promise((resolve, reject) => { + documentService.commandRequest('getForgottenList', '', (err, data, ress) => { + if (err) { + reject(err); + } + else { + resolve(JSON.parse(ress.data)); + } + }); + }); + } + + function getForgottenFile(key) { + return new Promise((resolve, reject) => { + documentService.commandRequest('getForgotten', key, (err, data) => { + if (err) { + reject(err); + } else { + const parsedData = JSON.parse(data); + resolve({ + name: parsedData.key, + documentType: fileUtility.getFileType(parsedData.url), + url: parsedData.url, + }); + } + }); + }); + } + + try { + const forgottenListResponse = await getForgottenList(); + + const keys = forgottenListResponse.keys; + const forgottenFiles = await Promise.all(keys.map(getForgottenFile)); + + req.DocManager = new DocManager(req, res); + res.render('forgotten', { forgottenFiles }); + } catch (error) { + console.error(error); + res.status(500).render('error', { message: 'Server error' }); + } +}); + +app.delete('/forgotten', (req, res) => { // define a handler for removing forgotten file + try { + let fileName = req.query.filename; + if (fileName) { // if the forgotten file name is defined + const result = function result(err, data, ress) { + res.write('{"success":true}'); + res.end(); + }; + documentService.commandRequest('deleteForgotten', fileName, result); + } else { + // TODO: add delete all forgotten files + } + } catch (ex) { + console.log(ex); + res.write('Server error'); + } +}); + app.get('/download', (req, res) => { // define a handler for downloading files req.DocManager = new DocManager(req, res); diff --git a/web/documentserver-example/nodejs/public/stylesheets/stylesheet.css b/web/documentserver-example/nodejs/public/stylesheets/stylesheet.css index 30d16c52a..7f74ba366 100644 --- a/web/documentserver-example/nodejs/public/stylesheets/stylesheet.css +++ b/web/documentserver-example/nodejs/public/stylesheets/stylesheet.css @@ -264,6 +264,10 @@ label .checkbox { padding: 16px 0; } +.links-panel a { + display: block; +} + .upload-panel, .create-panel { width: 100%; @@ -750,7 +754,7 @@ html { .tableRow td:first-child { display: flex; flex-grow: 1; - max-width: 25%; + max-width: 24%; } .tableHeaderCellFileName { diff --git a/web/documentserver-example/nodejs/views/forgotten.ejs b/web/documentserver-example/nodejs/views/forgotten.ejs new file mode 100644 index 000000000..2900d884c --- /dev/null +++ b/web/documentserver-example/nodejs/views/forgotten.ejs @@ -0,0 +1,156 @@ + + + + + + + + + ONLYOFFICE Document Editors + + + + + + + +
+
+ + ONLYOFFICE + +
+
+
+ + + + + + + +
+ + +
+
+ Forgotten documents + + + + + + + + + + +
FilenameDownloadRemove
+
+ + + <% for (var i = 0; i < forgottenFiles.length; i++) { %> + + + + + + + + + + + + + + + <% } %> + +
+ + <%= forgottenFiles[i].name %> + + + + Download + + + Delete +
+
+
+
+
+
+ + + + + + + diff --git a/web/documentserver-example/nodejs/views/index.ejs b/web/documentserver-example/nodejs/views/index.ejs index 6e3326340..e5799f2b0 100755 --- a/web/documentserver-example/nodejs/views/index.ejs +++ b/web/documentserver-example/nodejs/views/index.ejs @@ -108,6 +108,7 @@ From ec596753c65cc83d29795ddf9cdea3d6997239ef Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Tue, 5 Dec 2023 14:58:24 +0300 Subject: [PATCH 002/346] java-spring: remove historyClose and restore --- .../java/com/onlyoffice/integration/ExampleData.java | 4 +++- .../java-spring/src/main/resources/templates/editor.html | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/ExampleData.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/ExampleData.java index 1a0cd806a..54559aa31 100644 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/ExampleData.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/ExampleData.java @@ -92,7 +92,9 @@ public void init() { "Can create a file from an editor", "Can see the information about Group2 users", "Can view chat", - "Can’t submit forms" + "Can’t submit forms", + "Can't close history", + "Can't restore the file version" ); // create user 1 with the specified parameters diff --git a/web/documentserver-example/java-spring/src/main/resources/templates/editor.html b/web/documentserver-example/java-spring/src/main/resources/templates/editor.html index 5b600ff4a..afece6e70 100755 --- a/web/documentserver-example/java-spring/src/main/resources/templates/editor.html +++ b/web/documentserver-example/java-spring/src/main/resources/templates/editor.html @@ -276,10 +276,15 @@ "onRequestInsertImage": onRequestInsertImage, "onRequestSelectDocument": onRequestSelectDocument, "onRequestSelectSpreadsheet": onRequestSelectSpreadsheet, - "onRequestRestore": onRequestRestore, "onRequestHistory": onRequestHistory, "onRequestHistoryData": onRequestHistoryData, - "onRequestHistoryClose": onRequestHistoryClose + "onRequestHistoryClose": onRequestHistoryClose, + "onRequestRestore": onRequestRestore + }; + + if(config.editorConfig.user.id == 3){ + config.events["onRequestHistoryClose"] = null; + config.events["onRequestRestore"] = null; }; var usersForMentions = [[${usersForMentions}]]; From e02744e56b42dc5d7b5928ff82569d300c278243 Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Tue, 5 Dec 2023 14:59:14 +0300 Subject: [PATCH 003/346] nodejs: remove historyClose and restore --- web/documentserver-example/nodejs/helpers/users.js | 2 ++ web/documentserver-example/nodejs/views/editor.ejs | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/web/documentserver-example/nodejs/helpers/users.js b/web/documentserver-example/nodejs/helpers/users.js index 0461b9392..544be2693 100644 --- a/web/documentserver-example/nodejs/helpers/users.js +++ b/web/documentserver-example/nodejs/helpers/users.js @@ -80,6 +80,8 @@ const descrUser3 = [ 'Can create new files from the editor', 'Can see the information about Group2 users', 'Can’t submit forms', + 'Can’t close history', + 'Can’t restore the file version', ]; const descrUser0 = [ diff --git a/web/documentserver-example/nodejs/views/editor.ejs b/web/documentserver-example/nodejs/views/editor.ejs index e0924562b..cd9ac60ad 100644 --- a/web/documentserver-example/nodejs/views/editor.ejs +++ b/web/documentserver-example/nodejs/views/editor.ejs @@ -384,6 +384,11 @@ config.events.onRequestReferenceSource = onRequestReferenceSource; } + if (<%- JSON.stringify(editor.userid) %> == "uid-3") { + config.events["onRequestHistoryClose"] = null; + config.events["onRequestRestore"] = null; + } + if (config.editorConfig.createUrl) { config.events.onRequestSaveAs = onRequestSaveAs; } From 6598aa585aef212b1c379373e8f224ccd8fcd26d Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Tue, 5 Dec 2023 15:25:05 +0300 Subject: [PATCH 004/346] java: remove historyClose and restore --- .../java/src/main/java/helpers/Users.java | 2 ++ .../java/src/main/webapp/editor.jsp | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/web/documentserver-example/java/src/main/java/helpers/Users.java b/web/documentserver-example/java/src/main/java/helpers/Users.java index 65aa8cbbf..511ecc02d 100755 --- a/web/documentserver-example/java/src/main/java/helpers/Users.java +++ b/web/documentserver-example/java/src/main/java/helpers/Users.java @@ -64,6 +64,8 @@ public final class Users { add("Can create new files from the editor"); add("Can see the information about Group2 users"); add("Can’t submit forms"); + add("Can't close history"); + add("Can't restore the file version"); }}; private static List descriptionUserZero = new ArrayList() {{ diff --git a/web/documentserver-example/java/src/main/webapp/editor.jsp b/web/documentserver-example/java/src/main/webapp/editor.jsp index fabf0d148..67518a80d 100644 --- a/web/documentserver-example/java/src/main/webapp/editor.jsp +++ b/web/documentserver-example/java/src/main/webapp/editor.jsp @@ -275,10 +275,15 @@ "onRequestInsertImage": onRequestInsertImage, "onRequestSelectDocument": onRequestSelectDocument, "onRequestSelectSpreadsheet": onRequestSelectSpreadsheet, - "onRequestRestore": onRequestRestore, "onRequestHistory": onRequestHistory, "onRequestHistoryData": onRequestHistoryData, - "onRequestHistoryClose": onRequestHistoryClose + "onRequestHistoryClose": onRequestHistoryClose, + "onRequestRestore": onRequestRestore + }; + + if (config.editorConfig.user.id == "uid-3"){ + config.events['onRequestHistoryClose'] = null; + config.events['onRequestRestore'] = null; }; <% From 3243a04a1b046bbb0261a7d865dfe05ff8e253f9 Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Tue, 5 Dec 2023 15:25:20 +0300 Subject: [PATCH 005/346] php: remove historyClose and restore --- .../php/src/helpers/ExampleUsers.php | 4 +++- .../php/src/views/DocEditorView.php | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/web/documentserver-example/php/src/helpers/ExampleUsers.php b/web/documentserver-example/php/src/helpers/ExampleUsers.php index 99a377d4d..43cab5b07 100644 --- a/web/documentserver-example/php/src/helpers/ExampleUsers.php +++ b/web/documentserver-example/php/src/helpers/ExampleUsers.php @@ -62,7 +62,9 @@ public function __construct() "Can’t print the file", "Can create new files from the editor", "Can see the information about Group2 users", - "Can’t submit forms" + "Can’t submit forms", + "Can't close history", + "Can't restore the file version" ]; $this->user0Description = [ "The name is requested when the editor is opened", diff --git a/web/documentserver-example/php/src/views/DocEditorView.php b/web/documentserver-example/php/src/views/DocEditorView.php index 92b734fe0..a33332397 100644 --- a/web/documentserver-example/php/src/views/DocEditorView.php +++ b/web/documentserver-example/php/src/views/DocEditorView.php @@ -246,6 +246,14 @@ public function __construct($request, $tempName = "docEditor") } $historyLayout = ""; + + if ($user -> id == "uid-3") { + $historyLayout .= " + config.events['onRequestHistoryClose'] = null; + config.events['onRequestRestore'] = null; + "; + } + if ($user->id != "uid-0") { $historyLayout .= "// add mentions for not anonymous users config.events['onRequestUsers'] = function (event) { From f74f34504fffe90f2c3cf227d3ebce4426cbd6f0 Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Tue, 5 Dec 2023 16:08:29 +0300 Subject: [PATCH 006/346] python: remove historyClose and restore --- web/documentserver-example/python/src/utils/users.py | 4 +++- web/documentserver-example/python/templates/editor.html | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/web/documentserver-example/python/src/utils/users.py b/web/documentserver-example/python/src/utils/users.py index 1ffb62348..7df7e3988 100644 --- a/web/documentserver-example/python/src/utils/users.py +++ b/web/documentserver-example/python/src/utils/users.py @@ -70,7 +70,9 @@ def __init__(self, uid, name, email, group, reviewGroups, commentGroups, userInf "Can’t print the file", "Can create new files from the editor", "Can see the information about Group2 users", - "Can’t submit forms" + "Can’t submit forms", + "Can't close history", + "Can't restore the file version" ] descr_user_0 = [ diff --git a/web/documentserver-example/python/templates/editor.html b/web/documentserver-example/python/templates/editor.html index 5c4f45756..a62788804 100755 --- a/web/documentserver-example/python/templates/editor.html +++ b/web/documentserver-example/python/templates/editor.html @@ -280,6 +280,10 @@ }; + if (config.editorConfig.user.id == "uid-3"){ + config.events["onRequestHistoryClose"] = null; + config.events["onRequestRestore"] = null; + }; if (config.editorConfig.user.id) { From bde236075cd6ef706efc370c725d9fc1d1f5bbba Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Tue, 5 Dec 2023 16:08:45 +0300 Subject: [PATCH 007/346] ruby: remove historyClose and restore --- web/documentserver-example/ruby/app/models/users.rb | 2 ++ .../ruby/app/views/home/editor.html.erb | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/web/documentserver-example/ruby/app/models/users.rb b/web/documentserver-example/ruby/app/models/users.rb index e52dafdd2..0f39d9695 100644 --- a/web/documentserver-example/ruby/app/models/users.rb +++ b/web/documentserver-example/ruby/app/models/users.rb @@ -70,6 +70,8 @@ class Users "Can create new files from the editor", "Can see the information about Group2 users", "Can't submit forms", + "Can't close history", + "Can't restore the file version", ]; @@descr_user_0 = [ diff --git a/web/documentserver-example/ruby/app/views/home/editor.html.erb b/web/documentserver-example/ruby/app/views/home/editor.html.erb index 43a9bc4a4..f64a36234 100755 --- a/web/documentserver-example/ruby/app/views/home/editor.html.erb +++ b/web/documentserver-example/ruby/app/views/home/editor.html.erb @@ -261,6 +261,11 @@ <% usersMentions = @file.get_users_mentions %> + if (config.editorConfig.user.id == "uid-3"){ + config.events["onRequestHistoryClose"] = null; + config.events["onRequestRestore"] = null; + }; + if (config.editorConfig.user.id) { // add mentions for not anonymous users config.events['onRequestUsers'] = function (event) { From a9063af6e1ad112992d4f964eaba23bb098cb018 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Wed, 6 Dec 2023 12:55:09 +0300 Subject: [PATCH 008/346] fix sr-Latn-RS --- CHANGELOG.md | 2 +- web/documentserver-example/csharp-mvc/web.appsettings.config | 2 +- web/documentserver-example/csharp/settings.config | 2 +- .../java-spring/src/main/resources/application.properties | 2 +- .../java/src/main/resources/settings.properties | 2 +- web/documentserver-example/nodejs/config/default.json | 2 +- .../php/src/configuration/ConfigurationManager.php | 2 +- .../python/src/configuration/configuration.py | 2 +- .../ruby/app/configuration/configuration.rb | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a52074a61..c5efa2a90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Change Log - version number to page meta -- sr-Latn-CS skin languages +- sr-Latn-RS skin languages - getting history via api - using a repo with a list of formats - convert after uploading only tagged formats diff --git a/web/documentserver-example/csharp-mvc/web.appsettings.config b/web/documentserver-example/csharp-mvc/web.appsettings.config index 2a6a645ce..4f97fd1e4 100644 --- a/web/documentserver-example/csharp-mvc/web.appsettings.config +++ b/web/documentserver-example/csharp-mvc/web.appsettings.config @@ -15,7 +15,7 @@ - + diff --git a/web/documentserver-example/csharp/settings.config b/web/documentserver-example/csharp/settings.config index d6dc3238a..b418c690a 100644 --- a/web/documentserver-example/csharp/settings.config +++ b/web/documentserver-example/csharp/settings.config @@ -14,7 +14,7 @@ - + diff --git a/web/documentserver-example/java-spring/src/main/resources/application.properties b/web/documentserver-example/java-spring/src/main/resources/application.properties index b5e420d15..b64f2d610 100755 --- a/web/documentserver-example/java-spring/src/main/resources/application.properties +++ b/web/documentserver-example/java-spring/src/main/resources/application.properties @@ -25,7 +25,7 @@ files.docservice.token-use-for-request=true files.docservice.verify-peer-off=true -files.docservice.languages=en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (Simplified)|zh-TW:Chinese (Traditional)|cs:Czech|da:Danish|nl:Dutch|fi:Finnish|fr:French|gl:Galego|de:German|el:Greek|hu:Hungarian|id:Indonesian|it:Italian|ja:Japanese|ko:Korean|lo:Lao|lv:Latvian|ms:Malay (Malaysia)|no:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|sr-Latn-CS:Serbian|si:Sinhala (Sri Lanka)|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese|aa-AA:Test Language +files.docservice.languages=en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (Simplified)|zh-TW:Chinese (Traditional)|cs:Czech|da:Danish|nl:Dutch|fi:Finnish|fr:French|gl:Galego|de:German|el:Greek|hu:Hungarian|id:Indonesian|it:Italian|ja:Japanese|ko:Korean|lo:Lao|lv:Latvian|ms:Malay (Malaysia)|no:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|sr-Latn-RS:Serbian|si:Sinhala (Sri Lanka)|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese|aa-AA:Test Language spring.datasource.url=jdbc:h2:mem:usersdb spring.datasource.driverClassName=org.h2.Driver diff --git a/web/documentserver-example/java/src/main/resources/settings.properties b/web/documentserver-example/java/src/main/resources/settings.properties index d3cdb116c..444a869a1 100644 --- a/web/documentserver-example/java/src/main/resources/settings.properties +++ b/web/documentserver-example/java/src/main/resources/settings.properties @@ -13,7 +13,7 @@ files.docservice.url.api=web-apps/apps/api/documents/api.js files.docservice.url.preloader=web-apps/apps/api/documents/cache-scripts.html files.docservice.url.example= -files.docservice.languages=en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (Simplified)|zh-TW:Chinese (Traditional)|cs:Czech|da:Danish|nl:Dutch|fi:Finnish|fr:French|gl:Galego|de:German|el:Greek|hu:Hungarian|id:Indonesian|it:Italian|ja:Japanese|ko:Korean|lo:Lao|lv:Latvian|ms:Malay (Malaysia)|no:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|sr-Latn-CS:Serbian|si:Sinhala (Sri Lanka)|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese|aa-AA:Test Language +files.docservice.languages=en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (Simplified)|zh-TW:Chinese (Traditional)|cs:Czech|da:Danish|nl:Dutch|fi:Finnish|fr:French|gl:Galego|de:German|el:Greek|hu:Hungarian|id:Indonesian|it:Italian|ja:Japanese|ko:Korean|lo:Lao|lv:Latvian|ms:Malay (Malaysia)|no:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|sr-Latn-RS:Serbian|si:Sinhala (Sri Lanka)|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese|aa-AA:Test Language files.docservice.secret= files.docservice.header=Authorization diff --git a/web/documentserver-example/nodejs/config/default.json b/web/documentserver-example/nodejs/config/default.json index afff46cc6..e69f16bef 100644 --- a/web/documentserver-example/nodejs/config/default.json +++ b/web/documentserver-example/nodejs/config/default.json @@ -69,7 +69,7 @@ "pt-PT": "Portuguese (Portugal)", "ro": "Romanian", "ru": "Russian", - "sr-Latn-CS": "Serbian", + "sr-Latn-RS": "Serbian", "si": "Sinhala (Sri Lanka)", "sk": "Slovak", "sl": "Slovenian", diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManager.php b/web/documentserver-example/php/src/configuration/ConfigurationManager.php index f76a75476..5e2b65fd7 100644 --- a/web/documentserver-example/php/src/configuration/ConfigurationManager.php +++ b/web/documentserver-example/php/src/configuration/ConfigurationManager.php @@ -194,7 +194,7 @@ public function languages(): array 'pt-PT' => 'Portuguese (Portugal)', 'ro' => 'Romanian', 'ru' => 'Russian', - 'sr-Latn-CS' => 'Serbian', + 'sr-Latn-RS' => 'Serbian', 'si' => 'Sinhala (Sri Lanka)', 'sk' => 'Slovak', 'sl' => 'Slovenian', diff --git a/web/documentserver-example/python/src/configuration/configuration.py b/web/documentserver-example/python/src/configuration/configuration.py index ec15bbac6..3c93ddefa 100644 --- a/web/documentserver-example/python/src/configuration/configuration.py +++ b/web/documentserver-example/python/src/configuration/configuration.py @@ -154,7 +154,7 @@ def languages(self) -> dict[str, str]: 'pt-PT': 'Portuguese (Portugal)', 'ro': 'Romanian', 'ru': 'Russian', - 'sr-Latn-CS': 'Serbian', + 'sr-Latn-RS': 'Serbian', 'si': 'Sinhala (Sri Lanka)', 'sk': 'Slovak', 'sl': 'Slovenian', diff --git a/web/documentserver-example/ruby/app/configuration/configuration.rb b/web/documentserver-example/ruby/app/configuration/configuration.rb index b09443aa6..01c0b7c99 100644 --- a/web/documentserver-example/ruby/app/configuration/configuration.rb +++ b/web/documentserver-example/ruby/app/configuration/configuration.rb @@ -172,7 +172,7 @@ def languages 'pt-PT': 'Portuguese (Portugal)', ro: 'Romanian', ru: 'Russian', - 'sr-Latn-CS': 'Serbian', + 'sr-Latn-RS': 'Serbian', si: 'Sinhala (Sri Lanka)', sk: 'Slovak', sl: 'Slovenian', From 435b8013f640b7b0bed71ed7917b1a02ff4cf96c Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Thu, 7 Dec 2023 10:10:36 +0300 Subject: [PATCH 009/346] style: updates to styling --- .../java-spring/src/main/resources/templates/editor.html | 8 ++++---- .../java/src/main/webapp/editor.jsp | 6 +++--- web/documentserver-example/nodejs/views/editor.ejs | 2 +- .../php/src/views/DocEditorView.php | 8 +++----- web/documentserver-example/python/templates/editor.html | 4 ++-- .../ruby/app/views/home/editor.html.erb | 4 ++-- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/web/documentserver-example/java-spring/src/main/resources/templates/editor.html b/web/documentserver-example/java-spring/src/main/resources/templates/editor.html index afece6e70..979937c7d 100755 --- a/web/documentserver-example/java-spring/src/main/resources/templates/editor.html +++ b/web/documentserver-example/java-spring/src/main/resources/templates/editor.html @@ -276,15 +276,15 @@ "onRequestInsertImage": onRequestInsertImage, "onRequestSelectDocument": onRequestSelectDocument, "onRequestSelectSpreadsheet": onRequestSelectSpreadsheet, + "onRequestRestore": onRequestRestore, "onRequestHistory": onRequestHistory, "onRequestHistoryData": onRequestHistoryData, - "onRequestHistoryClose": onRequestHistoryClose, - "onRequestRestore": onRequestRestore + "onRequestHistoryClose": onRequestHistoryClose }; - if(config.editorConfig.user.id == 3){ + if (config.editorConfig.user.id == 3) { config.events["onRequestHistoryClose"] = null; - config.events["onRequestRestore"] = null; + config.events["onRequestRestore"] = null; }; var usersForMentions = [[${usersForMentions}]]; diff --git a/web/documentserver-example/java/src/main/webapp/editor.jsp b/web/documentserver-example/java/src/main/webapp/editor.jsp index 67518a80d..8325b33de 100644 --- a/web/documentserver-example/java/src/main/webapp/editor.jsp +++ b/web/documentserver-example/java/src/main/webapp/editor.jsp @@ -275,13 +275,13 @@ "onRequestInsertImage": onRequestInsertImage, "onRequestSelectDocument": onRequestSelectDocument, "onRequestSelectSpreadsheet": onRequestSelectSpreadsheet, + "onRequestRestore": onRequestRestore, "onRequestHistory": onRequestHistory, "onRequestHistoryData": onRequestHistoryData, - "onRequestHistoryClose": onRequestHistoryClose, - "onRequestRestore": onRequestRestore + "onRequestHistoryClose": onRequestHistoryClose }; - if (config.editorConfig.user.id == "uid-3"){ + if (config.editorConfig.user.id == "uid-3") { config.events['onRequestHistoryClose'] = null; config.events['onRequestRestore'] = null; }; diff --git a/web/documentserver-example/nodejs/views/editor.ejs b/web/documentserver-example/nodejs/views/editor.ejs index cd9ac60ad..1559a413c 100644 --- a/web/documentserver-example/nodejs/views/editor.ejs +++ b/web/documentserver-example/nodejs/views/editor.ejs @@ -386,7 +386,7 @@ if (<%- JSON.stringify(editor.userid) %> == "uid-3") { config.events["onRequestHistoryClose"] = null; - config.events["onRequestRestore"] = null; + config.events["onRequestRestore"] = null; } if (config.editorConfig.createUrl) { diff --git a/web/documentserver-example/php/src/views/DocEditorView.php b/web/documentserver-example/php/src/views/DocEditorView.php index a33332397..a605eb2af 100644 --- a/web/documentserver-example/php/src/views/DocEditorView.php +++ b/web/documentserver-example/php/src/views/DocEditorView.php @@ -247,11 +247,9 @@ public function __construct($request, $tempName = "docEditor") $historyLayout = ""; - if ($user -> id == "uid-3") { - $historyLayout .= " - config.events['onRequestHistoryClose'] = null; - config.events['onRequestRestore'] = null; - "; + if ($user->id == "uid-3") { + $historyLayout .= "config.events['onRequestHistoryClose'] = null; + config.events['onRequestRestore'] = null;"; } if ($user->id != "uid-0") { diff --git a/web/documentserver-example/python/templates/editor.html b/web/documentserver-example/python/templates/editor.html index a62788804..6d0fa3db4 100755 --- a/web/documentserver-example/python/templates/editor.html +++ b/web/documentserver-example/python/templates/editor.html @@ -280,9 +280,9 @@ }; - if (config.editorConfig.user.id == "uid-3"){ + if (config.editorConfig.user.id == "uid-3") { config.events["onRequestHistoryClose"] = null; - config.events["onRequestRestore"] = null; + config.events["onRequestRestore"] = null; }; if (config.editorConfig.user.id) { diff --git a/web/documentserver-example/ruby/app/views/home/editor.html.erb b/web/documentserver-example/ruby/app/views/home/editor.html.erb index f64a36234..3fb10182a 100755 --- a/web/documentserver-example/ruby/app/views/home/editor.html.erb +++ b/web/documentserver-example/ruby/app/views/home/editor.html.erb @@ -261,9 +261,9 @@ <% usersMentions = @file.get_users_mentions %> - if (config.editorConfig.user.id == "uid-3"){ + if (config.editorConfig.user.id == "uid-3") { config.events["onRequestHistoryClose"] = null; - config.events["onRequestRestore"] = null; + config.events["onRequestRestore"] = null; }; if (config.editorConfig.user.id) { From 78a8b56b487819c8045148706d92bf04fc3a90b8 Mon Sep 17 00:00:00 2001 From: Aleksandr Fedorov Date: Thu, 7 Dec 2023 13:47:25 +0300 Subject: [PATCH 010/346] java: delete spaces from editor.jsp --- web/documentserver-example/java/src/main/webapp/editor.jsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/documentserver-example/java/src/main/webapp/editor.jsp b/web/documentserver-example/java/src/main/webapp/editor.jsp index 8325b33de..86136efc2 100644 --- a/web/documentserver-example/java/src/main/webapp/editor.jsp +++ b/web/documentserver-example/java/src/main/webapp/editor.jsp @@ -280,7 +280,7 @@ "onRequestHistoryData": onRequestHistoryData, "onRequestHistoryClose": onRequestHistoryClose }; - + if (config.editorConfig.user.id == "uid-3") { config.events['onRequestHistoryClose'] = null; config.events['onRequestRestore'] = null; From 01618fee173186a3e359d99628219006328a5f8c Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Mon, 11 Dec 2023 11:50:51 +0300 Subject: [PATCH 011/346] java: add onRequestUsers and onRequestSendNotify in editor.jsp --- .../java/src/main/webapp/editor.jsp | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/web/documentserver-example/java/src/main/webapp/editor.jsp b/web/documentserver-example/java/src/main/webapp/editor.jsp index fabf0d148..6ce149ff6 100644 --- a/web/documentserver-example/java/src/main/webapp/editor.jsp +++ b/web/documentserver-example/java/src/main/webapp/editor.jsp @@ -262,6 +262,43 @@ document.location.reload(); }; + var onRequestUsers = function (event) { + if (event && event.data) { + var c = event.data.c; + } + + switch (c) { + case "info": + users = []; + var allUsers = <%=(String) request.getAttribute("usersInfo")%>; + for (var i = 0; i < event.data.id.length; i++) { + for (var j = 0; j < allUsers.length; j++) { + if (allUsers[j].id == event.data.id[i]) { + users.push(allUsers[j]); + break; + } + } + } + break; + case "protect": + var users = <%=(String) request.getAttribute("usersForProtect")%>; + break; + default: + users = <%=(String) request.getAttribute("usersForMentions")%>; + } + + docEditor.setUsers({ + "c": c, + "users": users, + }); + }; + + var onRequestSendNotify = function(event) { // the user is mentioned in a comment + event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink)); + var data = JSON.stringify(event.data); + innerAlert("onRequestSendNotify: " + data); + }; + config = JSON.parse('<%= FileModel.serialize(Model) %>'); config.width = "100%"; config.height = "100%"; @@ -281,48 +318,11 @@ "onRequestHistoryClose": onRequestHistoryClose }; - <% - String usersForMentions = (String) request.getAttribute("usersForMentions"); - String usersInfo = (String) request.getAttribute("usersInfo"); - String usersForProtect = (String) request.getAttribute("usersForProtect"); - %> - if (config.editorConfig.user.id) { // add mentions for not anonymous users - config.events['onRequestUsers'] = function (event) { - if (event && event.data){ - var c = event.data.c; - } - switch (c) { - case "info": - users = []; - var allUsers = <%=usersInfo%>; - for (var i = 0; i < event.data.id.length; i++) { - for (var j = 0; j < allUsers.length; j++) { - if (allUsers[j].id == event.data.id[i]) { - users.push(allUsers[j]); - break; - } - } - } - break; - case "protect": - var users = <%=usersForProtect%>; - break; - default: - users = <%=usersForMentions%>; - } - docEditor.setUsers({ - "c": c, - "users": users, - }); - }; + config.events['onRequestUsers'] = onRequestUsers; // the user is mentioned in a comment - config.events['onRequestSendNotify'] = function (event) { - event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink)); - var data = JSON.stringify(event.data); - innerAlert("onRequestSendNotify: " + data); - }; + config.events['onRequestSendNotify'] = onRequestSendNotify; // prevent file renaming for anonymous users config.events['onRequestRename'] = onRequestRename; config.events['onRequestReferenceData'] = onRequestReferenceData; From 75ca703f8a5a2ff9a703bc06ce8e5e5c0c03c094 Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Mon, 11 Dec 2023 11:59:52 +0300 Subject: [PATCH 012/346] java-spring: add onRequestUsers and onRequestSendNotify in editor.html --- .../src/main/resources/templates/editor.html | 78 ++++++++++--------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/web/documentserver-example/java-spring/src/main/resources/templates/editor.html b/web/documentserver-example/java-spring/src/main/resources/templates/editor.html index 5b600ff4a..18e0d5d6f 100755 --- a/web/documentserver-example/java-spring/src/main/resources/templates/editor.html +++ b/web/documentserver-example/java-spring/src/main/resources/templates/editor.html @@ -262,7 +262,44 @@ innerAlert(response.error); } } - } + }; + + var onRequestUsers = function (event) { + if (event && event.data) { + var c = event.data.c; + } + + switch (c) { + case "info": + users = []; + var allUsers = [[${usersInfo}]]; + for (var i = 0; i < event.data.id.length; i++) { + for (var j = 0; j < allUsers.length; j++) { + if (allUsers[j].id == event.data.id[i]) { + users.push(allUsers[j]); + break; + } + } + } + break; + case "protect": + var users = [[${usersForProtect}]]; + break; + default: + users = [[${usersForMentions}]]; + } + + docEditor.setUsers({ + "c": c, + "users": users, + }); + }; + + var onRequestSendNotify = function(event) { // the user is mentioned in a comment + event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink)); + var data = JSON.stringify(event.data); + innerAlert("onRequestSendNotify: " + data); + }; config.width = "100%"; config.height = "100%"; @@ -282,46 +319,11 @@ "onRequestHistoryClose": onRequestHistoryClose }; - var usersForMentions = [[${usersForMentions}]]; - var usersInfo = [[${usersInfo}]]; - var usersForProtect = [[${usersForProtect}]]; - if (config.editorConfig.user.id != 4) { // add mentions for not anonymous users - config.events['onRequestUsers'] = function (event) { - if (event && event.data){ - var c = event.data.c; - } - switch (c) { - case "info": - users = []; - var allUsers = usersInfo; - for (var i = 0; i < event.data.id.length; i++) { - for (var j = 0; j < allUsers.length; j++) { - if (allUsers[j].id == event.data.id[i]) { - users.push(allUsers[j]); - break; - } - } - } - break; - case "protect": - var users = usersForProtect; - break; - default: - users = usersForMentions; - } - docEditor.setUsers({ - "c": c, - "users": users, - }); - }; + config.events['onRequestUsers'] = onRequestUsers; // the user is mentioned in a comment - config.events['onRequestSendNotify'] = function (event) { - event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink)); - var data = JSON.stringify(event.data); - innerAlert("onRequestSendNotify: " + data); - }; + config.events['onRequestSendNotify'] = onRequestSendNotify; // prevent file renaming for anonymous users config.events['onRequestRename'] = onRequestRename; config.events['onRequestReferenceData'] = onRequestReferenceData; From d97291719ab19685bd2042f14b176afbac23e033 Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Mon, 11 Dec 2023 12:41:40 +0300 Subject: [PATCH 013/346] php: add onRequestUsers and onRequestSendNotify in docEditor.tpl --- .../php/src/views/DocEditorView.php | 35 +--------------- .../php/templates/docEditor.tpl | 40 ++++++++++++++++++- 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/web/documentserver-example/php/src/views/DocEditorView.php b/web/documentserver-example/php/src/views/DocEditorView.php index 92b734fe0..c6bdab0af 100644 --- a/web/documentserver-example/php/src/views/DocEditorView.php +++ b/web/documentserver-example/php/src/views/DocEditorView.php @@ -248,40 +248,9 @@ public function __construct($request, $tempName = "docEditor") $historyLayout = ""; if ($user->id != "uid-0") { $historyLayout .= "// add mentions for not anonymous users - config.events['onRequestUsers'] = function (event) { - if (event && event.data){ - var c = event.data.c; - } - switch (c) { - case \"info\": - users = []; - var allUsers = {usersInfo}; - for (var i = 0; i < event.data.id.length; i++) { - for (var j = 0; j < allUsers.length; j++) { - if (allUsers[j].id == event.data.id[i]) { - users.push(allUsers[j]); - break; - } - } - } - break; - case \"protect\": - var users = {usersForProtect}; - break; - default: - users = {usersForMentions}; - } - docEditor.setUsers({ - \"c\": c, - \"users\": users, - }); - }; + config.events['onRequestUsers'] = onRequestUsers; // the user is mentioned in a comment - config.events['onRequestSendNotify'] = function (event) { - event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink)); - var data = JSON.stringify(event.data); - innerAlert(\"onRequestSendNotify: \" + data); - }; + config.events['onRequestSendNotify'] = onRequestSendNotify; // prevent file renaming for anonymous users config.events['onRequestRename'] = onRequestRename; // prevent switch the document from the viewing into the editing mode for anonymous users diff --git a/web/documentserver-example/php/templates/docEditor.tpl b/web/documentserver-example/php/templates/docEditor.tpl index dcb8e50c7..3259c604b 100644 --- a/web/documentserver-example/php/templates/docEditor.tpl +++ b/web/documentserver-example/php/templates/docEditor.tpl @@ -275,6 +275,44 @@ } } + // add mentions for not anonymous users + var onRequestUsers = function (event) { + if (event && event.data){ + var c = event.data.c; + } + + switch (c) { + case "info": + users = []; + var allUsers = {usersInfo}; + for (var i = 0; i < event.data.id.length; i++) { + for (var j = 0; j < allUsers.length; j++) { + if (allUsers[j].id == event.data.id[i]) { + users.push(allUsers[j]); + break; + } + } + } + break; + case "protect": + var users = {usersForProtect}; + break; + default: + users = {usersForMentions}; + } + + docEditor.setUsers({ + "c": c, + "users": users, + }); + }; + + var onRequestSendNotify = function (event) { + event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink)); + var data = JSON.stringify(event.data); + innerAlert(\"onRequestSendNotify: \" + data); + }; + var сonnectEditor = function () { {fileNotFoundAlert} @@ -297,7 +335,7 @@ 'onRequestRestore': onRequestRestore, 'onRequestHistoryData': onRequestHistoryData, 'onRequestHistory': onRequestHistory, - 'onRequestHistoryClose': onRequestHistoryClose + 'onRequestHistoryClose': onRequestHistoryClose, "onRequestOpen": onRequestOpen, }; From 0b0e0dad8cff9674ee96dc82d59752d0302c1e2c Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Mon, 11 Dec 2023 12:55:06 +0300 Subject: [PATCH 014/346] python: add onRequestUsers and onRequestSendNotify in editor.html --- .../python/templates/editor.html | 72 ++++++++++--------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/web/documentserver-example/python/templates/editor.html b/web/documentserver-example/python/templates/editor.html index 5c4f45756..3031d6b50 100755 --- a/web/documentserver-example/python/templates/editor.html +++ b/web/documentserver-example/python/templates/editor.html @@ -258,6 +258,43 @@ document.location.reload(); } + var onRequestUsers = function (event) { + if (event && event.data){ + var c = event.data.c; + } + + switch (c) { + case "protect": + var users = {{ usersForProtect | safe }}; + break; + case "info": + users = []; + var allUsers = {{ usersInfo | safe }}; + for (var i = 0; i < event.data.id.length; i++) { + for (var j = 0; j < allUsers.length; j++) { + if (allUsers[j].id == event.data.id[i]) { + users.push(allUsers[j]); + break; + } + } + } + break; + default: + users = {{ usersForMentions | safe }}; + } + + docEditor.setUsers({ + "c": c, + "users": users, + }); + }; + + var onRequestSendNotify = function(event) { // the user is mentioned in a comment + event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink)); + var data = JSON.stringify(event.data); + innerAlert("onRequestSendNotify: " + data); + }; + var connectEditor = function () { config = {{ cfg | safe }} @@ -284,40 +321,9 @@ if (config.editorConfig.user.id) { // add mentions for not anonymous users - config.events['onRequestUsers'] = function (event) { - if (event && event.data){ - var c = event.data.c; - } - switch (c) { - case "info": - users = []; - var allUsers = {{ usersInfo | safe }}; - for (var i = 0; i < event.data.id.length; i++) { - for (var j = 0; j < allUsers.length; j++) { - if (allUsers[j].id == event.data.id[i]) { - users.push(allUsers[j]); - break; - } - } - } - break; - case "protect": - var users = {{ usersForProtect | safe }}; - break; - default: - users = {{ usersForMentions | safe }}; - } - docEditor.setUsers({ - "c": c, - "users": users, - }) - }; + config.events['onRequestUsers'] = onRequestUsers; // the user is mentioned in a comment - config.events['onRequestSendNotify'] = function (event) { - event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink)); - var data = JSON.stringify(event.data); - innerAlert("onRequestSendNotify: " + data); - }; + config.events['onRequestSendNotify'] = onRequestSendNotify; // prevent file renaming for anonymous users config.events['onRequestRename'] = onRequestRename; config.events['onRequestReferenceData'] = onRequestReferenceData; From cf097501c6985068948665b232462921b32a94c5 Mon Sep 17 00:00:00 2001 From: Sergey Linnik Date: Mon, 11 Dec 2023 15:32:19 +0300 Subject: [PATCH 015/346] Fix Bug 34620 - resize on mobile This reverts commit d3a08acec3a6ca1c9e93488798922874ab195051. --- .../nodejs/views/editor.ejs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/web/documentserver-example/nodejs/views/editor.ejs b/web/documentserver-example/nodejs/views/editor.ejs index e0924562b..36eceeb3d 100644 --- a/web/documentserver-example/nodejs/views/editor.ejs +++ b/web/documentserver-example/nodejs/views/editor.ejs @@ -349,9 +349,7 @@ }; var onDocumentReady = function(){ - if (config.type === "mobile") { - document.getElementsByTagName("iframe")[0].style.height = window.innerHeight + "px"; - } + fixSize(); }; config = { @@ -405,6 +403,20 @@ } docEditor = new DocsAPI.DocEditor("iframeEditor", config); + fixSize(); + }; + + // get the editor sizes + var fixSize = function () { + if (config.type !== "mobile") { + return; + } + var wrapEl = document.getElementsByClassName("form"); + if (wrapEl.length) { + wrapEl[0].style.height = screen.availHeight + "px"; + window.scrollTo(0, -1); + wrapEl[0].style.height = window.innerHeight + "px"; + } }; const getFileExt = function (fileName) { @@ -416,8 +428,10 @@ if (window.addEventListener) { window.addEventListener("load", connectEditor); + window.addEventListener("resize", fixSize); } else if (window.attachEvent) { window.attachEvent("onload", connectEditor); + window.attachEvent("onresize", fixSize); } From 0967c1c3aceb4b6be98311ab7501a9c7b0c8b33b Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Tue, 12 Dec 2023 10:14:18 +0300 Subject: [PATCH 016/346] java-spring: remove history methods for anonymous users (bc5393e28cf1bfa346f9029f6875ef138fd2ec63) old commit: bc5393e28cf1bfa346f9029f6875ef138fd2ec63 --- .../src/main/resources/templates/editor.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/web/documentserver-example/java-spring/src/main/resources/templates/editor.html b/web/documentserver-example/java-spring/src/main/resources/templates/editor.html index 5b600ff4a..91e7036c9 100755 --- a/web/documentserver-example/java-spring/src/main/resources/templates/editor.html +++ b/web/documentserver-example/java-spring/src/main/resources/templates/editor.html @@ -275,11 +275,7 @@ "onMetaChange": onMetaChange, "onRequestInsertImage": onRequestInsertImage, "onRequestSelectDocument": onRequestSelectDocument, - "onRequestSelectSpreadsheet": onRequestSelectSpreadsheet, - "onRequestRestore": onRequestRestore, - "onRequestHistory": onRequestHistory, - "onRequestHistoryData": onRequestHistoryData, - "onRequestHistoryClose": onRequestHistoryClose + "onRequestSelectSpreadsheet": onRequestSelectSpreadsheet }; var usersForMentions = [[${usersForMentions}]]; @@ -328,6 +324,10 @@ // prevent switch the document from the viewing into the editing mode for anonymous users config.events['onRequestEditRights'] = onRequestEditRights; config.events['onRequestOpen'] = onRequestOpen; + config.events['onRequestRestore'] = onRequestRestore; + config.events['onRequestHistory'] = onRequestHistory; + config.events['onRequestHistoryData'] = onRequestHistoryData; + config.events['onRequestHistoryClose'] = onRequestHistoryClose; } if (config.editorConfig.createUrl) { From 7051437928bb23a72a24b4bfe3231f75a264f9bd Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Tue, 12 Dec 2023 10:25:45 +0300 Subject: [PATCH 017/346] java: remove history methods for anonymous users (52a722cf892f09428c99e18f1beb700fa93e0cdf) old commit: 52a722cf892f09428c99e18f1beb700fa93e0cdf --- .../java/src/main/webapp/editor.jsp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/web/documentserver-example/java/src/main/webapp/editor.jsp b/web/documentserver-example/java/src/main/webapp/editor.jsp index fabf0d148..3b57f3594 100644 --- a/web/documentserver-example/java/src/main/webapp/editor.jsp +++ b/web/documentserver-example/java/src/main/webapp/editor.jsp @@ -274,11 +274,7 @@ "onMetaChange": onMetaChange, "onRequestInsertImage": onRequestInsertImage, "onRequestSelectDocument": onRequestSelectDocument, - "onRequestSelectSpreadsheet": onRequestSelectSpreadsheet, - "onRequestRestore": onRequestRestore, - "onRequestHistory": onRequestHistory, - "onRequestHistoryData": onRequestHistoryData, - "onRequestHistoryClose": onRequestHistoryClose + "onRequestSelectSpreadsheet": onRequestSelectSpreadsheet }; <% @@ -329,6 +325,10 @@ // prevent switch the document from the viewing into the editing mode for anonymous users config.events['onRequestEditRights'] = onRequestEditRights; config.events['onRequestOpen'] = onRequestOpen; + config.events['onRequestRestore'] = onRequestRestore; + config.events['onRequestHistory'] = onRequestHistory; + config.events['onRequestHistoryData'] = onRequestHistoryData; + config.events['onRequestHistoryClose'] = onRequestHistoryClose; } if (config.editorConfig.createUrl) { From 91f32c1387af0b2179911e1b4a930e2989667b65 Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Tue, 12 Dec 2023 10:30:42 +0300 Subject: [PATCH 018/346] php: remove history methods for anonymous users (39820cec0aadb45d1f43b0533a2e02873b04b9e1) old commit: 39820cec0aadb45d1f43b0533a2e02873b04b9e1 --- web/documentserver-example/php/src/views/DocEditorView.php | 6 +++++- web/documentserver-example/php/templates/docEditor.tpl | 4 ---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/web/documentserver-example/php/src/views/DocEditorView.php b/web/documentserver-example/php/src/views/DocEditorView.php index 92b734fe0..c817533ff 100644 --- a/web/documentserver-example/php/src/views/DocEditorView.php +++ b/web/documentserver-example/php/src/views/DocEditorView.php @@ -285,7 +285,11 @@ public function __construct($request, $tempName = "docEditor") // prevent file renaming for anonymous users config.events['onRequestRename'] = onRequestRename; // prevent switch the document from the viewing into the editing mode for anonymous users - config.events['onRequestEditRights'] = onRequestEditRights;"; + config.events['onRequestEditRights'] = onRequestEditRights; + config.events['onRequestRestore'] = onRequestRestore; + config.events['onRequestHistory'] = onRequestHistory; + config.events['onRequestHistoryData'] = onRequestHistoryData; + config.events['onRequestHistoryClose'] = onRequestHistoryClose;"; } $this->tagsValues = [ "docType" => getDocumentType($filename), diff --git a/web/documentserver-example/php/templates/docEditor.tpl b/web/documentserver-example/php/templates/docEditor.tpl index dcb8e50c7..72698cb04 100644 --- a/web/documentserver-example/php/templates/docEditor.tpl +++ b/web/documentserver-example/php/templates/docEditor.tpl @@ -294,10 +294,6 @@ 'onRequestSelectDocument': onRequestSelectDocument, 'onRequestSelectSpreadsheet': onRequestSelectSpreadsheet, 'onRequestReferenceData': onRequestReferenceData, - 'onRequestRestore': onRequestRestore, - 'onRequestHistoryData': onRequestHistoryData, - 'onRequestHistory': onRequestHistory, - 'onRequestHistoryClose': onRequestHistoryClose "onRequestOpen": onRequestOpen, }; From ee951fbfbc77482e3af335c541e299b85532e521 Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Tue, 12 Dec 2023 10:32:42 +0300 Subject: [PATCH 019/346] python: remove history methods for anonymous users (18cf21efe4cab4c096847c6ac0872810c51b16f3) old commit: 18cf21efe4cab4c096847c6ac0872810c51b16f3 --- .../python/templates/editor.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/web/documentserver-example/python/templates/editor.html b/web/documentserver-example/python/templates/editor.html index 5c4f45756..27fbfb55f 100755 --- a/web/documentserver-example/python/templates/editor.html +++ b/web/documentserver-example/python/templates/editor.html @@ -272,11 +272,7 @@ 'onMetaChange': onMetaChange, 'onRequestInsertImage': onRequestInsertImage, 'onRequestSelectDocument': onRequestSelectDocument, - "onRequestSelectSpreadsheet": onRequestSelectSpreadsheet, - 'onRequestRestore': onRequestRestore, - 'onRequestHistory': onRequestHistory, - 'onRequestHistoryData': onRequestHistoryData, - 'onRequestHistoryClose': onRequestHistoryClose + "onRequestSelectSpreadsheet": onRequestSelectSpreadsheet }; @@ -325,6 +321,10 @@ // prevent switch the document from the viewing into the editing mode for anonymous users config.events['onRequestEditRights'] = onRequestEditRights; config.events['onRequestOpen'] = onRequestOpen; + config.events['onRequestRestore'] = onRequestRestore; + config.events['onRequestHistory'] = onRequestHistory; + config.events['onRequestHistoryData'] = onRequestHistoryData; + config.events['onRequestHistoryClose'] = onRequestHistoryClose; } if (config.editorConfig.createUrl) { From 7f678c9ed876a5652aeb43c6ac9ee98eca4b746e Mon Sep 17 00:00:00 2001 From: Taygunova Rina Date: Tue, 12 Dec 2023 10:35:35 +0300 Subject: [PATCH 020/346] ruby: remove history methods for anonymous users (fe352ebad1ceb46facc3ad778052f09165982195) old commit: fe352ebad1ceb46facc3ad778052f09165982195 --- .../ruby/app/views/home/editor.html.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/web/documentserver-example/ruby/app/views/home/editor.html.erb b/web/documentserver-example/ruby/app/views/home/editor.html.erb index 1e98f2546..de8393e6e 100755 --- a/web/documentserver-example/ruby/app/views/home/editor.html.erb +++ b/web/documentserver-example/ruby/app/views/home/editor.html.erb @@ -251,11 +251,7 @@ 'onMetaChange': onMetaChange, 'onRequestInsertImage': onRequestInsertImage, 'onRequestSelectDocument': onRequestSelectDocument, - 'onRequestSelectSpreadsheet': onRequestSelectSpreadsheet, - 'onRequestRestore': onRequestRestore, - 'onRequestHistory': onRequestHistory, - 'onRequestHistoryData': onRequestHistoryData, - 'onRequestHistoryClose': onRequestHistoryClose + 'onRequestSelectSpreadsheet': onRequestSelectSpreadsheet }; <% @@ -303,6 +299,10 @@ // prevent switch the document from the viewing into the editing mode for anonymous users config.events['onRequestEditRights'] = onRequestEditRights; config.events['onRequestOpen'] = onRequestOpen; + config.events['onRequestRestore'] = onRequestRestore; + config.events['onRequestHistory'] = onRequestHistory; + config.events['onRequestHistoryData'] = onRequestHistoryData; + config.events['onRequestHistoryClose'] = onRequestHistoryClose; } if (config.editorConfig.createUrl) { From d1a67fa322911a5c4ac8aa97a3c92c26f55479e9 Mon Sep 17 00:00:00 2001 From: Aleksandr Fedorov Date: Wed, 13 Dec 2023 14:42:41 +0300 Subject: [PATCH 021/346] add: dependency com.onlyoffice.docs-intagration-sdk --- web/documentserver-example/java-spring/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web/documentserver-example/java-spring/pom.xml b/web/documentserver-example/java-spring/pom.xml index ba4ac4d32..27e987b7e 100644 --- a/web/documentserver-example/java-spring/pom.xml +++ b/web/documentserver-example/java-spring/pom.xml @@ -76,6 +76,11 @@ modelmapper 2.4.2 + + com.onlyoffice + docs-integration-sdk + 0.0.1 + From c2c14dd2f4190f71c526b96c68d73d3b2273fb9a Mon Sep 17 00:00:00 2001 From: Aleksandr Fedorov Date: Wed, 13 Dec 2023 14:43:49 +0300 Subject: [PATCH 022/346] add: implementations sdk managers (DocumentMangerImpl, SettingsManagerImpl, UrlManagerImpl) --- .../sdk/manager/DocumentMangerImpl.java | 65 ++++++++++++++++++ .../sdk/manager/SettingsManagerImpl.java | 57 ++++++++++++++++ .../sdk/manager/UrlManagerImpl.java | 67 +++++++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/manager/DocumentMangerImpl.java create mode 100644 web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/manager/SettingsManagerImpl.java create mode 100644 web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/manager/UrlManagerImpl.java diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/manager/DocumentMangerImpl.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/manager/DocumentMangerImpl.java new file mode 100644 index 000000000..50c27ba5f --- /dev/null +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/manager/DocumentMangerImpl.java @@ -0,0 +1,65 @@ +/** + * + * (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. + * + */ + +package com.onlyoffice.integration.sdk.manager; + +import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder; +import com.onlyoffice.manager.document.DefaultDocumentManager; +import com.onlyoffice.manager.settings.SettingsManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.io.File; + +import static com.onlyoffice.integration.documentserver.util.Constants.MAX_KEY_LENGTH; + +@Component +public class DocumentMangerImpl extends DefaultDocumentManager { + + @Autowired + private FileStoragePathBuilder storagePathBuilder; + + public DocumentMangerImpl(final SettingsManager settingsManager) { + super(settingsManager); + } + + @Override + public String getDocumentKey(final String fileId, final boolean embedded) { + String expectedKey = storagePathBuilder.getStorageLocation() + + "/" + fileId + "/" + + new File(storagePathBuilder.getFileLocation(fileId)).lastModified(); + + String formatKey = expectedKey.length() > MAX_KEY_LENGTH + ? Integer.toString(expectedKey.hashCode()) : expectedKey; + String key = formatKey.replace("[^0-9-.a-zA-Z_=]", "_"); + key = key.substring(0, Math.min(key.length(), MAX_KEY_LENGTH)); + + return embedded ? key + "_embedded" : key; + } + + @Override + public String getDocumentName(final String fileId) { + File file = new File(storagePathBuilder.getFileLocation(fileId)); + + if (file.exists()) { + return file.getName(); + } + + return null; + } +} diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/manager/SettingsManagerImpl.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/manager/SettingsManagerImpl.java new file mode 100644 index 000000000..4f43c679c --- /dev/null +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/manager/SettingsManagerImpl.java @@ -0,0 +1,57 @@ +/** + * + * (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. + * + */ + +package com.onlyoffice.integration.sdk.manager; + +import com.onlyoffice.manager.settings.DefaultSettingsManager; +import org.springframework.stereotype.Component; + +import java.io.InputStream; +import java.util.Properties; + +@Component +public class SettingsManagerImpl extends DefaultSettingsManager { + private static final String SETTINGS_PREFIX = "docservice"; + + private static Properties properties; + + public SettingsManagerImpl() { + init(); + } + + @Override + public String getSetting(final String name) { + return properties.getProperty(SETTINGS_PREFIX + "." + name); + } + + @Override + public void setSetting(final String name, final String value) { + properties.put(SETTINGS_PREFIX + "." + name, value); + } + + protected static void init() { + try { + properties = new Properties(); + InputStream stream = Thread.currentThread().getContextClassLoader() + .getResourceAsStream("docservice.properties"); + properties.load(stream); + } catch (Exception e) { + properties = null; + } + } +} diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/manager/UrlManagerImpl.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/manager/UrlManagerImpl.java new file mode 100644 index 000000000..46a24f1fa --- /dev/null +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/manager/UrlManagerImpl.java @@ -0,0 +1,67 @@ +/** + * + * (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. + * + */ + +package com.onlyoffice.integration.sdk.manager; + +import com.onlyoffice.integration.documentserver.managers.document.DocumentManager; +import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder; +import com.onlyoffice.manager.settings.SettingsManager; +import com.onlyoffice.manager.url.DefaultUrlManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class UrlManagerImpl extends DefaultUrlManager { + @Autowired + private FileStoragePathBuilder storagePathBuilder; + + @Value("${url.index}") + private String indexMapping; + + @Autowired + private DocumentManager documentManager; + + public UrlManagerImpl(final SettingsManager settingsManager) { + super(settingsManager); + } + + @Override + public String getFileUrl(final String fileId) { + return documentManager.getDownloadUrl(fileId, true); + } + + @Override + public String getDirectFileUrl(final String fileId) { + return documentManager.getDownloadUrl(fileId, false); + } + + public String getCreateUrl(final String fileId) { + return documentManager.getCreateUrl(fileId, false); + } + + @Override + public String getCallbackUrl(final String fileId) { + return documentManager.getCallback(fileId); + } + + @Override + public String getGobackUrl(final String fileId) { + return storagePathBuilder.getServerUrl(false) + indexMapping; + } +} From 9fe8701718cd103ac9537d80d578ef3a15361f35 Mon Sep 17 00:00:00 2001 From: Aleksandr Fedorov Date: Wed, 13 Dec 2023 14:57:30 +0300 Subject: [PATCH 023/346] add: sdk managers (JwtManager, RequestManager) to spring context --- .../integration/IntegrationConfiguration.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/IntegrationConfiguration.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/IntegrationConfiguration.java index d9d752014..ffd1b838a 100644 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/IntegrationConfiguration.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/IntegrationConfiguration.java @@ -20,6 +20,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder; +import com.onlyoffice.manager.request.DefaultRequestManager; +import com.onlyoffice.manager.request.RequestManager; +import com.onlyoffice.manager.security.DefaultJwtManager; +import com.onlyoffice.manager.security.JwtManager; +import com.onlyoffice.manager.settings.SettingsManager; +import com.onlyoffice.manager.url.UrlManager; import org.json.simple.parser.JSONParser; import org.modelmapper.ModelMapper; import org.modelmapper.convention.MatchingStrategies; @@ -84,4 +90,16 @@ public void init() { // initialize the storage path builder public ObjectMapper objectMapper() { // create the object mapper return new ObjectMapper(); } + + @Bean + public JwtManager jwtManager(final SettingsManager settingsManager) { + return new DefaultJwtManager(settingsManager); + } + + @Bean + public RequestManager requestManager(final UrlManager urlManager, final JwtManager jwtManager, + final SettingsManager settingsManager) { + return new DefaultRequestManager(urlManager, jwtManager, settingsManager); + } + } From 2e55bf1cfc2fbb27fae876c8a35f2dded6e7890e Mon Sep 17 00:00:00 2001 From: Aleksandr Fedorov Date: Wed, 13 Dec 2023 14:45:37 +0300 Subject: [PATCH 024/346] add: docservice.properties file --- .../java-spring/src/main/resources/docservice.properties | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 web/documentserver-example/java-spring/src/main/resources/docservice.properties diff --git a/web/documentserver-example/java-spring/src/main/resources/docservice.properties b/web/documentserver-example/java-spring/src/main/resources/docservice.properties new file mode 100644 index 000000000..7ef02c921 --- /dev/null +++ b/web/documentserver-example/java-spring/src/main/resources/docservice.properties @@ -0,0 +1,3 @@ +docservice.url=http://documentserver/ +docservice.security.key= + From 892d390fff965b7a966f96abe6455b8bf107c69d Mon Sep 17 00:00:00 2001 From: Aleksandr Fedorov Date: Wed, 13 Dec 2023 14:46:05 +0300 Subject: [PATCH 025/346] add: method getCurrentUser to UserServices --- .../integration/services/UserServices.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/services/UserServices.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/services/UserServices.java index 13f76b704..f576609b6 100755 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/services/UserServices.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/services/UserServices.java @@ -24,7 +24,11 @@ import com.onlyoffice.integration.repositories.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; import java.util.List; import java.util.Optional; @@ -92,4 +96,29 @@ public User createUser(final String name, final String email, return newUser; } + + public User getCurrentUser() { + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) + .getRequest(); + + Cookie[] cookies = request.getCookies(); + + String uid = null; + + if (cookies != null) { + for (Cookie cookie : cookies) { + if (cookie.getName().equals("uid")) { + uid = cookie.getValue(); + } + } + } + + if (uid == null || uid.isEmpty()) { + return null; + } + + Optional optionalUser = this.findUserById(Integer.parseInt(uid)); + + return optionalUser.get(); + } } From b9137b1d86f5a963a946e5c74471fe27bb1c1939 Mon Sep 17 00:00:00 2001 From: Aleksandr Fedorov Date: Wed, 13 Dec 2023 14:46:29 +0300 Subject: [PATCH 026/346] add: sdk service (ConfigService) --- .../sdk/service/ConfigService.java | 27 ++ .../sdk/service/ConfigServiceImpl.java | 364 ++++++++++++++++++ 2 files changed, 391 insertions(+) create mode 100644 web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/service/ConfigService.java create mode 100644 web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/service/ConfigServiceImpl.java diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/service/ConfigService.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/service/ConfigService.java new file mode 100644 index 000000000..2b7a6e2bd --- /dev/null +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/service/ConfigService.java @@ -0,0 +1,27 @@ +/** + * + * (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. + * + */ + +package com.onlyoffice.integration.sdk.service; + +import com.onlyoffice.integration.documentserver.models.enums.Action; +import com.onlyoffice.model.documenteditor.Config; +import com.onlyoffice.model.documenteditor.config.document.Type; + +public interface ConfigService extends com.onlyoffice.service.documenteditor.config.ConfigService { + Config createConfig(String fileId, Action action, Type type); +} diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/service/ConfigServiceImpl.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/service/ConfigServiceImpl.java new file mode 100644 index 000000000..d8033d3bb --- /dev/null +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/sdk/service/ConfigServiceImpl.java @@ -0,0 +1,364 @@ +/** + * + * (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. + * + */ + +package com.onlyoffice.integration.sdk.service; + +import com.google.gson.Gson; +import com.onlyoffice.integration.documentserver.managers.template.TemplateManager; +import com.onlyoffice.integration.documentserver.models.enums.Action; +import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder; +import com.onlyoffice.integration.entities.Group; +import com.onlyoffice.integration.entities.Permission; +import com.onlyoffice.integration.services.UserServices; +import com.onlyoffice.manager.document.DocumentManager; +import com.onlyoffice.manager.security.JwtManager; +import com.onlyoffice.manager.settings.SettingsManager; +import com.onlyoffice.manager.url.UrlManager; +import com.onlyoffice.model.common.User; +import com.onlyoffice.model.documenteditor.Config; +import com.onlyoffice.model.documenteditor.config.document.Info; +import com.onlyoffice.model.documenteditor.config.document.Permissions; +import com.onlyoffice.model.documenteditor.config.document.ReferenceData; +import com.onlyoffice.model.documenteditor.config.document.Type; +import com.onlyoffice.model.documenteditor.config.document.permissions.CommentGroups; +import com.onlyoffice.model.documenteditor.config.editorconfig.CoEditing; +import com.onlyoffice.model.documenteditor.config.editorconfig.Customization; +import com.onlyoffice.model.documenteditor.config.editorconfig.Embedded; +import com.onlyoffice.model.documenteditor.config.editorconfig.Mode; +import com.onlyoffice.model.documenteditor.config.editorconfig.Template; +import com.onlyoffice.model.documenteditor.config.editorconfig.customization.Goback; +import com.onlyoffice.model.documenteditor.config.editorconfig.embedded.Toolbar; +import com.onlyoffice.service.documenteditor.config.DefaultConfigService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +import java.io.File; +import java.net.InetAddress; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.stream.Collectors; + +@Component +public class ConfigServiceImpl extends DefaultConfigService implements ConfigService { + + @Autowired + private UserServices userService; + + @Autowired + private FileStoragePathBuilder storagePathBuilder; + + @Autowired + @Qualifier("sample") + private TemplateManager templateManager; + + + public ConfigServiceImpl(final DocumentManager documentManager, final UrlManager urlManager, + final JwtManager jwtManager, final SettingsManager settingsManager) { + super(documentManager, urlManager, jwtManager, settingsManager); + } + + @Override + public Config createConfig(final String fileId, final Action action, final Type type) { + com.onlyoffice.integration.entities.User appUser = userService.getCurrentUser(); + Action currentAction = action; + String fileName = getDocumentManager().getDocumentName(fileId); + + Boolean isEditable = getDocumentManager().isEditable(fileName); + if ((!isEditable && action.equals(Action.edit) || action.equals(Action.fillForms)) && getDocumentManager() + .isFillable(fileName)) { + isEditable = true; + currentAction = Action.fillForms; + } + + Mode mode = isEditable && !currentAction.equals(Action.view) ? Mode.EDIT : Mode.VIEW; + + Config config = super.createConfig(fileId, mode, type); + + Permissions permissions = config.getDocument().getPermissions(); + permissions = updatePermissions(permissions, action, isEditable); + + config.getDocument().setPermissions(permissions); + + if (appUser.getName().equals("Anonymous")) { + config.getEditorConfig().setCreateUrl(null); + } + + if (getSettingsManager().isSecurityEnabled()) { + config.setToken(getJwtManager().createToken(config)); + } + + return config; + } + + @Override + public ReferenceData getReferenceData(final String fileId) { + Gson gson = new Gson(); + + HashMap fileKey = new HashMap<>(); + fileKey.put("fileName", getDocumentManager().getDocumentName(fileId)); + try { + fileKey.put("userAddress", InetAddress.getLocalHost().getHostAddress()); + } catch (Exception e) { + e.printStackTrace(); + } + ReferenceData referenceData = ReferenceData.builder() + .instanceId(storagePathBuilder.getServerUrl(true)) + .fileKey(gson.toJson(fileKey)) + .build(); + + return referenceData; + } + + @Override + public Info getInfo(final String fileId) { + com.onlyoffice.integration.entities.User appUser = userService.getCurrentUser(); + + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE MMM dd yyyy", Locale.US); + + return Info.builder() + .owner("Me") + .favorite(appUser.getFavorite()) + .uploaded(simpleDateFormat.format(new Date( + new File(storagePathBuilder.getFileLocation(fileId)).lastModified()) + )) + .build(); + } + + @Override + public Permissions getPermissions(final String fileId) { + com.onlyoffice.integration.entities.User appUser = userService.getCurrentUser(); + + if (appUser == null) { + return null; + } + + Permission userPermissions = appUser.getPermissions(); + + return Permissions.builder() + .chat(userPermissions.getChat()) + .comment(userPermissions.getComment()) + .commentGroups(getCommentGroups(userPermissions)) + .copy(userPermissions.getCopy()) + .download(userPermissions.getDownload()) + .edit(userPermissions.getEdit()) + .fillForms(userPermissions.getFillForms()) + .modifyContentControl(userPermissions.getModifyContentControl()) + .modifyFilter(userPermissions.getModifyFilter()) + .print(userPermissions.getPrint()) + .protect(userPermissions.getProtect()) + .review(userPermissions.getReview()) + .reviewGroups(getReviewGroups(userPermissions)) + .userInfoGroups(getUserInfoGroups(userPermissions)) + .build(); + } + + @Override + public List