From 60cbd477259cc69ced0b7ea537a18de8ff44262f Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 4 Feb 2021 12:39:56 +0300 Subject: [PATCH] Add new parameters to "permissions" section of config: editCommentAuthorOnly (can edit your own comments only if true), deleteCommentAuthorOnly (can delete your own comments only if true). Deprecate customization.commentAuthorOnly parameter. --- apps/api/documents/api.js | 6 +++-- apps/common/main/lib/controller/Comments.js | 13 +++++++---- apps/common/main/lib/model/Comment.js | 6 +++-- .../main/lib/template/Comments.template | 4 ++++ .../lib/template/CommentsPopover.template | 6 ++++- apps/common/main/lib/view/ReviewChanges.js | 4 ++-- .../mobile/lib/controller/Collaboration.js | 23 ++++++++++++------- apps/common/mobile/lib/view/Collaboration.js | 8 +++---- .../main/app/controller/Main.js | 8 ++++++- .../mobile/app/controller/Main.js | 8 ++++++- .../main/app/controller/Main.js | 8 ++++++- .../mobile/app/controller/Main.js | 8 ++++++- .../main/app/controller/Main.js | 8 ++++++- .../mobile/app/controller/Main.js | 8 ++++++- 14 files changed, 89 insertions(+), 29 deletions(-) diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js index 023f5f34a..588d38512 100644 --- a/apps/api/documents/api.js +++ b/apps/api/documents/api.js @@ -49,7 +49,9 @@ modifyFilter: // default = true modifyContentControl: // default = true fillForms: // default = edit || review, - copy: // default = true + copy: // default = true, + editCommentAuthorOnly: // default = false + deleteCommentAuthorOnly: // default = false } }, editorConfig: { @@ -140,7 +142,7 @@ statusBar: true, autosave: true, forcesave: false, - commentAuthorOnly: false, + commentAuthorOnly: false, // must be deprecated. use permissions.editCommentAuthorOnly and permissions.deleteCommentAuthorOnly instead showReviewChanges: false, help: true, compactHeader: false, diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index 11fbb89ec..f07c5b31c 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -237,7 +237,7 @@ define([ }, onRemoveComments: function (type) { if (this.api) { - this.api.asc_RemoveAllComments(type=='my' || !this.mode.canEditComments, type=='current');// 1 param = true if remove only my comments, 2 param - remove current comments + this.api.asc_RemoveAllComments(type=='my' || !this.mode.canDeleteComments, type=='current');// 1 param = true if remove only my comments, 2 param - remove current comments } }, onResolveComment: function (uid) { @@ -776,6 +776,8 @@ define([ comment.set('userdata', data.asc_getUserData()); comment.set('time', date.getTime()); comment.set('date', t.dateToLocaleTimeString(date)); + comment.set('editable', t.mode.canEditComments || (data.asc_getUserId() == t.currentUserId)); + comment.set('removable', t.mode.canDeleteComments || (data.asc_getUserId() == t.currentUserId)); replies = _.clone(comment.get('replys')); @@ -801,7 +803,8 @@ define([ editTextInPopover : false, showReplyInPopover : false, scope : t.view, - editable : t.mode.canEditComments || (data.asc_getReply(i).asc_getUserId() == t.currentUserId) + editable : t.mode.canEditComments || (data.asc_getReply(i).asc_getUserId() == t.currentUserId), + removable : t.mode.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == t.currentUserId) })); } @@ -1241,6 +1244,7 @@ define([ hideAddReply : !_.isUndefined(this.hidereply) ? this.hidereply : (this.showPopover ? true : false), scope : this.view, editable : this.mode.canEditComments || (data.asc_getUserId() == this.currentUserId), + removable : this.mode.canDeleteComments || (data.asc_getUserId() == this.currentUserId), hint : !this.mode.canComments, groupName : (groupname && groupname.length>1) ? groupname[1] : null }); @@ -1277,7 +1281,8 @@ define([ editTextInPopover : false, showReplyInPopover : false, scope : this.view, - editable : this.mode.canEditComments || (data.asc_getReply(i).asc_getUserId() == this.currentUserId) + editable : this.mode.canEditComments || (data.asc_getReply(i).asc_getUserId() == this.currentUserId), + removable : this.mode.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == this.currentUserId) })); } } @@ -1438,7 +1443,7 @@ define([ for (i = 0; i < comments.length; ++i) { comment = this.findComment(comments[i].asc_getId()); if (comment) { - comment.set('editTextInPopover', t.mode.canEditComments);// dont't edit comment when customization->commentAuthorOnly is true + comment.set('editTextInPopover', t.mode.canEditComments);// dont't edit comment when customization->commentAuthorOnly is true or when permissions.editCommentAuthorOnly is true comment.set('hint', false); this.popoverComments.push(comment); } diff --git a/apps/common/main/lib/model/Comment.js b/apps/common/main/lib/model/Comment.js index 0c64da83e..80c8667ba 100644 --- a/apps/common/main/lib/model/Comment.js +++ b/apps/common/main/lib/model/Comment.js @@ -79,7 +79,8 @@ define([ hide : false, hint : false, dummy : undefined, - editable : true + editable : true, + removable : true } }); Common.Models.Reply = Backbone.Model.extend({ @@ -96,7 +97,8 @@ define([ editText : false, editTextInPopover : false, scope : null, - editable : true + editable : true, + removable : true } }); }); diff --git a/apps/common/main/lib/template/Comments.template b/apps/common/main/lib/template/Comments.template index c5d8f0311..c9009b464 100644 --- a/apps/common/main/lib/template/Comments.template +++ b/apps/common/main/lib/template/Comments.template @@ -36,6 +36,8 @@
<% if (item.get("editable")) { %>
">
+ <% } %> + <% if (item.get("removable")) { %>
">
<% } %>
@@ -67,6 +69,8 @@
<% if (editable) { %>
+ <% } %> + <% if (removable) { %>
<% } %> <% if (resolved) { %> diff --git a/apps/common/main/lib/template/CommentsPopover.template b/apps/common/main/lib/template/CommentsPopover.template index 78f0d4a5a..6b5e23233 100644 --- a/apps/common/main/lib/template/CommentsPopover.template +++ b/apps/common/main/lib/template/CommentsPopover.template @@ -36,7 +36,9 @@
<% if (item.get("editable")) { %>
">
-
">
+ <%}%> + <% if (item.get("removable")) { %> +
">
<%}%>
<%}%> @@ -68,6 +70,8 @@
<% if (editable) { %>
+ <% } %> + <% if (removable) { %>
<% } %> <% if (resolved) { %> diff --git a/apps/common/main/lib/view/ReviewChanges.js b/apps/common/main/lib/view/ReviewChanges.js index 33cf281dd..0ff9da8cb 100644 --- a/apps/common/main/lib/view/ReviewChanges.js +++ b/apps/common/main/lib/view/ReviewChanges.js @@ -457,7 +457,7 @@ define([ if (me.btnCommentRemove) { var items = [ { - caption: config.canEditComments ? me.txtCommentRemCurrent : me.txtCommentRemMyCurrent, + caption: config.canDeleteComments ? me.txtCommentRemCurrent : me.txtCommentRemMyCurrent, value: 'current' }, { @@ -465,7 +465,7 @@ define([ value: 'my' } ]; - if (config.canEditComments) + if (config.canDeleteComments) items.push({ caption: me.txtCommentRemAll, value: 'all' diff --git a/apps/common/mobile/lib/controller/Collaboration.js b/apps/common/mobile/lib/controller/Collaboration.js index 731240568..5b8896eb9 100644 --- a/apps/common/mobile/lib/controller/Collaboration.js +++ b/apps/common/mobile/lib/controller/Collaboration.js @@ -1144,7 +1144,7 @@ define([ var me = this; _.delay(function () { var _menuItems = []; - _menuItems.push({ + comment.editable && _menuItems.push({ caption: me.textEdit, event: 'edit' }); @@ -1165,7 +1165,7 @@ define([ event: 'addreply' }); } - _menuItems.push({ + comment.removable && _menuItems.push({ caption: me.textDeleteComment, event: 'delete', color: 'red' @@ -1203,13 +1203,15 @@ define([ if (_.isNumber(idComment)) { idComment = idComment.toString(); } - _.delay(function () { + var comment = this.findComment(idComment); + var reply = comment && comment.replys ? comment.replys[ind] : null; + reply && _.delay(function () { var _menuItems = []; - _menuItems.push({ + reply.editable && _menuItems.push({ caption: me.textEdit, event: 'editreply' }); - _menuItems.push({ + reply.removable && _menuItems.push({ caption: me.textDeleteReply, event: 'deletereply', color: 'red' @@ -1555,7 +1557,8 @@ define([ reply : data.asc_getReply(i).asc_getText(), time : date.getTime(), userInitials : this.getInitials(username), - editable : this.appConfig.canEditComments || (data.asc_getReply(i).asc_getUserId() == _userId) + editable : this.appConfig.canEditComments || (data.asc_getReply(i).asc_getUserId() == _userId), + removable : this.appConfig.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == _userId) }); } } @@ -1584,7 +1587,8 @@ define([ replys : [], groupName : (groupname && groupname.length>1) ? groupname[1] : null, userInitials : this.getInitials(username), - editable : this.appConfig.canEditComments || (data.asc_getUserId() == _userId) + editable : this.appConfig.canEditComments || (data.asc_getUserId() == _userId), + removable : this.appConfig.canDeleteComments || (data.asc_getUserId() == _userId) }; if (comment) { var replies = this.readSDKReplies(data); @@ -1620,6 +1624,8 @@ define([ comment.quote = data.asc_getQuoteText(); comment.time = date.getTime(); comment.date = me.dateToLocaleTimeString(date); + comment.editable = me.appConfig.canEditComments || (data.asc_getUserId() == _userId); + comment.removable = me.appConfig.canDeleteComments || (data.asc_getUserId() == _userId); replies = _.clone(comment.replys); @@ -1644,7 +1650,8 @@ define([ reply : data.asc_getReply(i).asc_getText(), time : dateReply.getTime(), userInitials : me.getInitials(username), - editable : me.appConfig.canEditComments || (data.asc_getUserId() == _userId) + editable : me.appConfig.canEditComments || (data.asc_getReply(i).asc_getUserId() == _userId), + removable : me.appConfig.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == _userId) }); } comment.replys = replies; diff --git a/apps/common/mobile/lib/view/Collaboration.js b/apps/common/mobile/lib/view/Collaboration.js index b39f69ffb..eaccfe03f 100644 --- a/apps/common/mobile/lib/view/Collaboration.js +++ b/apps/common/mobile/lib/view/Collaboration.js @@ -183,7 +183,7 @@ define([ template += '
'; } template += '
'; - if (comment.editable && !me.viewmode) { + if (!me.viewmode) { template += '
' + '
' + '
' + @@ -208,7 +208,7 @@ define([ if (isAndroid) { template += '
'; } - if (reply.editable && !me.viewmode) { + if ((reply.editable || reply.removable) && !me.viewmode) { template += '
'; } template += '' + @@ -253,7 +253,7 @@ define([ '
<%= item.date %>
', '<% if (android) { %><% } %>', '', - '<% if (item.editable && !viewmode) { %>', + '<% if (!viewmode) { %>', '
', '
', '
', @@ -275,7 +275,7 @@ define([ '
<%= reply.date %>
', '
', '<% if (android) { %><% } %>', - '<% if (reply.editable && !viewmode) { %>', + '<% if ((reply.editable || reply.removable) && !viewmode) { %>', '
', '<% } %>', '', diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 65eb8a126..748c97bad 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -1277,7 +1277,13 @@ define([ this.appOptions.buildVersion = params.asc_getBuildVersion(); this.appOptions.canForcesave = this.appOptions.isEdit && !this.appOptions.isOffline && (typeof (this.editorConfig.customization) == 'object' && !!this.editorConfig.customization.forcesave); this.appOptions.forcesave = this.appOptions.canForcesave; - this.appOptions.canEditComments= this.appOptions.isOffline || !(typeof (this.editorConfig.customization) == 'object' && this.editorConfig.customization.commentAuthorOnly); + this.appOptions.canEditComments= this.appOptions.isOffline || !this.permissions.editCommentAuthorOnly; + this.appOptions.canDeleteComments= this.appOptions.isOffline || !this.permissions.deleteCommentAuthorOnly; + if ((typeof (this.editorConfig.customization) == 'object') && this.editorConfig.customization.commentAuthorOnly===true) { + console.log("Obsolete: The 'commentAuthorOnly' parameter of the 'customization' section is deprecated. Please use 'editCommentAuthorOnly' and 'deleteCommentAuthorOnly' parameters in the permissions instead."); + if (this.permissions.editCommentAuthorOnly===undefined && this.permissions.deleteCommentAuthorOnly===undefined) + this.appOptions.canEditComments = this.appOptions.canDeleteComments = this.appOptions.isOffline; + } this.appOptions.trialMode = params.asc_getLicenseMode(); this.appOptions.isBeta = params.asc_getIsBeta(); this.appOptions.isSignatureSupport= this.appOptions.isEdit && this.appOptions.isDesktopApp && this.appOptions.isOffline && this.api.asc_isSignaturesSupport(); diff --git a/apps/documenteditor/mobile/app/controller/Main.js b/apps/documenteditor/mobile/app/controller/Main.js index cff0f2662..b88aaa76c 100644 --- a/apps/documenteditor/mobile/app/controller/Main.js +++ b/apps/documenteditor/mobile/app/controller/Main.js @@ -812,7 +812,13 @@ define([ me.appOptions.canComments = me.appOptions.canLicense && (me.permissions.comment===undefined ? me.appOptions.isEdit : me.permissions.comment) && (me.editorConfig.mode !== 'view'); me.appOptions.canComments = me.appOptions.canComments && !((typeof (me.editorConfig.customization) == 'object') && me.editorConfig.customization.comments===false); me.appOptions.canViewComments = me.appOptions.canComments || !((typeof (me.editorConfig.customization) == 'object') && me.editorConfig.customization.comments===false); - me.appOptions.canEditComments = me.appOptions.isOffline || !(typeof (me.editorConfig.customization) == 'object' && me.editorConfig.customization.commentAuthorOnly); + me.appOptions.canEditComments= me.appOptions.isOffline || !me.permissions.editCommentAuthorOnly; + me.appOptions.canDeleteComments= me.appOptions.isOffline || !me.permissions.deleteCommentAuthorOnly; + if ((typeof (me.editorConfig.customization) == 'object') && me.editorConfig.customization.commentAuthorOnly===true) { + console.log("Obsolete: The 'commentAuthorOnly' parameter of the 'customization' section is deprecated. Please use 'editCommentAuthorOnly' and 'deleteCommentAuthorOnly' parameters in the permissions instead."); + if (me.permissions.editCommentAuthorOnly===undefined && me.permissions.deleteCommentAuthorOnly===undefined) + me.appOptions.canEditComments = me.appOptions.canDeleteComments = me.appOptions.isOffline; + } me.appOptions.canChat = me.appOptions.canLicense && !me.appOptions.isOffline && !((typeof (me.editorConfig.customization) == 'object') && me.editorConfig.customization.chat===false); me.appOptions.canEditStyles = me.appOptions.canLicense && me.appOptions.canEdit; me.appOptions.canPrint = (me.permissions.print !== false); diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index 8c977e9c8..172de55ea 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -1002,7 +1002,13 @@ define([ this.appOptions.canRename = this.editorConfig.canRename; this.appOptions.canForcesave = this.appOptions.isEdit && !this.appOptions.isOffline && (typeof (this.editorConfig.customization) == 'object' && !!this.editorConfig.customization.forcesave); this.appOptions.forcesave = this.appOptions.canForcesave; - this.appOptions.canEditComments= this.appOptions.isOffline || !(typeof (this.editorConfig.customization) == 'object' && this.editorConfig.customization.commentAuthorOnly); + this.appOptions.canEditComments= this.appOptions.isOffline || !this.permissions.editCommentAuthorOnly; + this.appOptions.canDeleteComments= this.appOptions.isOffline || !this.permissions.deleteCommentAuthorOnly; + if ((typeof (this.editorConfig.customization) == 'object') && this.editorConfig.customization.commentAuthorOnly===true) { + console.log("Obsolete: The 'commentAuthorOnly' parameter of the 'customization' section is deprecated. Please use 'editCommentAuthorOnly' and 'deleteCommentAuthorOnly' parameters in the permissions instead."); + if (this.permissions.editCommentAuthorOnly===undefined && this.permissions.deleteCommentAuthorOnly===undefined) + this.appOptions.canEditComments = this.appOptions.canDeleteComments = this.appOptions.isOffline; + } this.appOptions.buildVersion = params.asc_getBuildVersion(); this.appOptions.trialMode = params.asc_getLicenseMode(); this.appOptions.isBeta = params.asc_getIsBeta(); diff --git a/apps/presentationeditor/mobile/app/controller/Main.js b/apps/presentationeditor/mobile/app/controller/Main.js index efe2d2dd7..df3291f92 100644 --- a/apps/presentationeditor/mobile/app/controller/Main.js +++ b/apps/presentationeditor/mobile/app/controller/Main.js @@ -739,7 +739,13 @@ define([ me.appOptions.canComments = me.appOptions.canLicense && (me.permissions.comment===undefined ? me.appOptions.isEdit : me.permissions.comment) && (me.editorConfig.mode !== 'view'); me.appOptions.canComments = me.appOptions.canComments && !((typeof (me.editorConfig.customization) == 'object') && me.editorConfig.customization.comments===false); me.appOptions.canViewComments = me.appOptions.canComments || !((typeof (me.editorConfig.customization) == 'object') && me.editorConfig.customization.comments===false); - me.appOptions.canEditComments = me.appOptions.isOffline || !(typeof (me.editorConfig.customization) == 'object' && me.editorConfig.customization.commentAuthorOnly); + me.appOptions.canEditComments= me.appOptions.isOffline || !me.permissions.editCommentAuthorOnly; + me.appOptions.canDeleteComments= me.appOptions.isOffline || !me.permissions.deleteCommentAuthorOnly; + if ((typeof (this.editorConfig.customization) == 'object') && me.editorConfig.customization.commentAuthorOnly===true) { + console.log("Obsolete: The 'commentAuthorOnly' parameter of the 'customization' section is deprecated. Please use 'editCommentAuthorOnly' and 'deleteCommentAuthorOnly' parameters in the permissions instead."); + if (me.permissions.editCommentAuthorOnly===undefined && me.permissions.deleteCommentAuthorOnly===undefined) + me.appOptions.canEditComments = me.appOptions.canDeleteComments = me.appOptions.isOffline; + } me.appOptions.canChat = me.appOptions.canLicense && !me.appOptions.isOffline && !((typeof (me.editorConfig.customization) == 'object') && me.editorConfig.customization.chat===false); me.appOptions.canEditStyles = me.appOptions.canLicense && me.appOptions.canEdit; me.appOptions.canPrint = (me.permissions.print !== false); diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 95da87451..2dec09bb3 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -1087,7 +1087,13 @@ define([ this.appOptions.canForcesave = this.appOptions.isEdit && !this.appOptions.isOffline && !(this.appOptions.isEditDiagram || this.appOptions.isEditMailMerge) && (typeof (this.editorConfig.customization) == 'object' && !!this.editorConfig.customization.forcesave); this.appOptions.forcesave = this.appOptions.canForcesave; - this.appOptions.canEditComments= this.appOptions.isOffline || !(typeof (this.editorConfig.customization) == 'object' && this.editorConfig.customization.commentAuthorOnly); + this.appOptions.canEditComments= this.appOptions.isOffline || !this.permissions.editCommentAuthorOnly; + this.appOptions.canDeleteComments= this.appOptions.isOffline || !this.permissions.deleteCommentAuthorOnly; + if ((typeof (this.editorConfig.customization) == 'object') && this.editorConfig.customization.commentAuthorOnly===true) { + console.log("Obsolete: The 'commentAuthorOnly' parameter of the 'customization' section is deprecated. Please use 'editCommentAuthorOnly' and 'deleteCommentAuthorOnly' parameters in the permissions instead."); + if (this.permissions.editCommentAuthorOnly===undefined && this.permissions.deleteCommentAuthorOnly===undefined) + this.appOptions.canEditComments = this.appOptions.canDeleteComments = this.appOptions.isOffline; + } this.appOptions.isSignatureSupport= this.appOptions.isEdit && this.appOptions.isDesktopApp && this.appOptions.isOffline && this.api.asc_isSignaturesSupport() && !(this.appOptions.isEditDiagram || this.appOptions.isEditMailMerge); this.appOptions.isPasswordSupport = this.appOptions.isEdit && this.api.asc_isProtectionSupport() && !(this.appOptions.isEditDiagram || this.appOptions.isEditMailMerge); this.appOptions.canProtect = (this.appOptions.isSignatureSupport || this.appOptions.isPasswordSupport); diff --git a/apps/spreadsheeteditor/mobile/app/controller/Main.js b/apps/spreadsheeteditor/mobile/app/controller/Main.js index b7bfde73c..2453f91a4 100644 --- a/apps/spreadsheeteditor/mobile/app/controller/Main.js +++ b/apps/spreadsheeteditor/mobile/app/controller/Main.js @@ -757,7 +757,13 @@ define([ me.appOptions.canComments = me.appOptions.canLicense && (me.permissions.comment===undefined ? me.appOptions.isEdit : me.permissions.comment) && (me.editorConfig.mode !== 'view'); me.appOptions.canComments = me.appOptions.canComments && !((typeof (me.editorConfig.customization) == 'object') && me.editorConfig.customization.comments===false); me.appOptions.canViewComments = me.appOptions.canComments || !((typeof (me.editorConfig.customization) == 'object') && me.editorConfig.customization.comments===false); - me.appOptions.canEditComments = me.appOptions.isOffline || !(typeof (me.editorConfig.customization) == 'object' && me.editorConfig.customization.commentAuthorOnly); + me.appOptions.canEditComments= me.appOptions.isOffline || !me.permissions.editCommentAuthorOnly; + me.appOptions.canDeleteComments= me.appOptions.isOffline || !me.permissions.deleteCommentAuthorOnly; + if ((typeof (this.editorConfig.customization) == 'object') && me.editorConfig.customization.commentAuthorOnly===true) { + console.log("Obsolete: The 'commentAuthorOnly' parameter of the 'customization' section is deprecated. Please use 'editCommentAuthorOnly' and 'deleteCommentAuthorOnly' parameters in the permissions instead."); + if (me.permissions.editCommentAuthorOnly===undefined && me.permissions.deleteCommentAuthorOnly===undefined) + me.appOptions.canEditComments = me.appOptions.canDeleteComments = me.appOptions.isOffline; + } me.appOptions.canChat = me.appOptions.canLicense && !me.appOptions.isOffline && !((typeof (me.editorConfig.customization) == 'object') && me.editorConfig.customization.chat===false); me.appOptions.trialMode = params.asc_getLicenseMode();