diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js index 20ec5730d..7f7ccc3a6 100644 --- a/apps/api/documents/api.js +++ b/apps/api/documents/api.js @@ -51,6 +51,11 @@ editCommentAuthorOnly: // default = false deleteCommentAuthorOnly: // default = false, reviewGroups: ["Group1", ""] // current user can accept/reject review changes made by users from Group1 and users without a group. [] - use groups, but can't change any group's changes + commentGroups: { // {} - use groups, but can't view/edit/delete any group's comments + view: ["Group1", ""] // current user can view comments made by users from Group1 and users without a group. + edit: ["Group1", ""] // current user can edit comments made by users from Group1 and users without a group. + remove: ["Group1", ""] // current user can remove comments made by users from Group1 and users without a group. + } } }, editorConfig: { diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index f07c5b31c..1f32e1139 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -776,8 +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)); + comment.set('editable', (t.mode.canEditComments || (data.asc_getUserId() == t.currentUserId)) && Common.Utils.UserInfoParser.canEditComment(data.asc_getUserName())); + comment.set('removable', (t.mode.canDeleteComments || (data.asc_getUserId() == t.currentUserId)) && Common.Utils.UserInfoParser.canDeleteComment(data.asc_getUserName())); replies = _.clone(comment.get('replys')); @@ -803,8 +803,8 @@ define([ editTextInPopover : false, showReplyInPopover : false, scope : t.view, - editable : t.mode.canEditComments || (data.asc_getReply(i).asc_getUserId() == t.currentUserId), - removable : t.mode.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == t.currentUserId) + editable : (t.mode.canEditComments || (data.asc_getReply(i).asc_getUserId() == t.currentUserId)) && Common.Utils.UserInfoParser.canEditComment(data.asc_getReply(i).asc_getUserName()), + removable : (t.mode.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == t.currentUserId)) && Common.Utils.UserInfoParser.canDeleteComment(data.asc_getReply(i).asc_getUserName()) })); } @@ -1243,8 +1243,8 @@ define([ showReplyInPopover : false, 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), + editable : (this.mode.canEditComments || (data.asc_getUserId() == this.currentUserId)) && Common.Utils.UserInfoParser.canEditComment(data.asc_getUserName()), + removable : (this.mode.canDeleteComments || (data.asc_getUserId() == this.currentUserId)) && Common.Utils.UserInfoParser.canDeleteComment(data.asc_getUserName()), hint : !this.mode.canComments, groupName : (groupname && groupname.length>1) ? groupname[1] : null }); @@ -1281,8 +1281,8 @@ define([ editTextInPopover : false, showReplyInPopover : false, scope : this.view, - editable : this.mode.canEditComments || (data.asc_getReply(i).asc_getUserId() == this.currentUserId), - removable : this.mode.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == this.currentUserId) + editable : (this.mode.canEditComments || (data.asc_getReply(i).asc_getUserId() == this.currentUserId)) && Common.Utils.UserInfoParser.canEditComment(data.asc_getReply(i).asc_getUserName()), + removable : (this.mode.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == this.currentUserId)) && Common.Utils.UserInfoParser.canDeleteComment(data.asc_getReply(i).asc_getUserName()) })); } } @@ -1443,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 or when permissions.editCommentAuthorOnly is true + comment.set('editTextInPopover', t.mode.canEditComments && Common.Utils.UserInfoParser.canEditComment(comment.username));// 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/template/Comments.template b/apps/common/main/lib/template/Comments.template index 2ff20c34e..82a1e531b 100644 --- a/apps/common/main/lib/template/Comments.template +++ b/apps/common/main/lib/template/Comments.template @@ -73,7 +73,9 @@ <% if (removable) { %>
<% } %> + <% if (editable) { %>
+ <% } %> <% } %> diff --git a/apps/common/main/lib/template/CommentsPopover.template b/apps/common/main/lib/template/CommentsPopover.template index d74214b34..9bd905834 100644 --- a/apps/common/main/lib/template/CommentsPopover.template +++ b/apps/common/main/lib/template/CommentsPopover.template @@ -74,7 +74,9 @@ <% if (removable) { %>
<% } %> + <% if (editable) { %>
+ <% } %> <% } %> diff --git a/apps/common/main/lib/util/utils.js b/apps/common/main/lib/util/utils.js index 7f4020951..51fe76578 100644 --- a/apps/common/main/lib/util/utils.js +++ b/apps/common/main/lib/util/utils.js @@ -982,9 +982,20 @@ Common.Utils.UserInfoParser = new(function() { var parse = false, separator = String.fromCharCode(160), username = '', - usergroups, - reviewPermissions, - reviewGroups; + _reviewPermissions, + reviewGroups, + commentGroups; + + var _intersection = function (arr1, arr2) { + if (arr1 && arr2) { + for (var i=0; i-1) + return true; + } + } + return false; + }; + return { setParser: function(value) { parse = !!value; @@ -995,10 +1006,7 @@ Common.Utils.UserInfoParser = new(function() { }, getParsedName: function(username) { - if (parse && username) { - return username.substring(username.indexOf(separator)+1); - } else - return username; + return (parse && username) ? username.substring(username.indexOf(separator)+1) : username; }, getParsedGroups: function(username) { @@ -1008,13 +1016,12 @@ Common.Utils.UserInfoParser = new(function() { for (var i=0; i0) - usergroups = groups; - reviewGroups = groups; - } else if (permissions) { + reviewGroups = groups; + } else if (permissions) { // old version of review permissions var arr = [], arrgroups = this.getParsedGroups(username); arrgroups && arrgroups.forEach(function(group) { var item = permissions[group.trim()]; item && (arr = arr.concat(item)); }); - usergroups = arr; - reviewPermissions = permissions; + reviewGroups = arr; + _reviewPermissions = permissions; } }, - getCurrentGroups: function() { - return usergroups; + setCommentPermissions: function(groups) { + if (groups && typeof groups == 'object') { + commentGroups = { + view: (typeof groups.view == 'object' && groups.view.length>0) ? groups.view : null, + edit: (typeof groups.edit == 'object' && groups.edit.length>0) ? groups.edit : null, + remove: (typeof groups.remove == 'object' && groups.remove.length>0) ? groups.remove : null + }; + } }, canEditReview: function(username) { + if (!parse || !reviewGroups) return true; + var groups = this.getParsedGroups(username); - return usergroups && groups && (_.intersection(usergroups, (groups.length>0) ? groups : [""]).length>0); + groups && (groups.length==0) && (groups = [""]); + return _intersection(reviewGroups, groups); + }, + + canViewComment: function(username) { + if (!parse || !commentGroups) return true; + + var groups = this.getParsedGroups(username); + groups && (groups.length==0) && (groups = [""]); + return _intersection(commentGroups.view, groups); + }, + + canEditComment: function(username) { + if (!parse || !commentGroups) return true; + + var groups = this.getParsedGroups(username); + groups && (groups.length==0) && (groups = [""]); + return _intersection(commentGroups.edit, groups); + }, + + canDeleteComment: function(username) { + if (!parse || !commentGroups) return true; + + var groups = this.getParsedGroups(username); + groups && (groups.length==0) && (groups = [""]); + return _intersection(commentGroups.remove, groups); } } })(); \ No newline at end of file diff --git a/apps/common/mobile/lib/controller/Collaboration.js b/apps/common/mobile/lib/controller/Collaboration.js index 52a6aa3d8..07ff35429 100644 --- a/apps/common/mobile/lib/controller/Collaboration.js +++ b/apps/common/mobile/lib/controller/Collaboration.js @@ -1131,16 +1131,18 @@ define([ caption: me.textEdit, event: 'edit' }); - if (!comment.resolved) { - _menuItems.push({ - caption: me.textResolve, - event: 'resolve' - }); - } else { - _menuItems.push({ - caption: me.textReopen, - event: 'resolve' - }); + if (comment.editable) { + if (!comment.resolved) { + _menuItems.push({ + caption: me.textResolve, + event: 'resolve' + }); + } else { + _menuItems.push({ + caption: me.textReopen, + event: 'resolve' + }); + } } if ($('.container-collaboration').length > 0) { _menuItems.push({ @@ -1540,8 +1542,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), - removable : this.appConfig.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == _userId) + editable : (this.appConfig.canEditComments || (data.asc_getReply(i).asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canEditComment(username), + removable : (this.appConfig.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canDeleteComment(username) }); } } @@ -1570,8 +1572,8 @@ define([ replys : [], groupName : (groupname && groupname.length>1) ? groupname[1] : null, userInitials : this.getInitials(username), - editable : this.appConfig.canEditComments || (data.asc_getUserId() == _userId), - removable : this.appConfig.canDeleteComments || (data.asc_getUserId() == _userId) + editable : (this.appConfig.canEditComments || (data.asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canEditComment(username), + removable : (this.appConfig.canDeleteComments || (data.asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canDeleteComment(username) }; if (comment) { var replies = this.readSDKReplies(data); @@ -1607,8 +1609,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); + comment.editable = (me.appConfig.canEditComments || (data.asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canEditComment(data.asc_getUserName()); + comment.removable = (me.appConfig.canDeleteComments || (data.asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canDeleteComment(data.asc_getUserName()); replies = _.clone(comment.replys); @@ -1633,8 +1635,8 @@ define([ reply : data.asc_getReply(i).asc_getText(), time : dateReply.getTime(), userInitials : me.getInitials(username), - editable : me.appConfig.canEditComments || (data.asc_getReply(i).asc_getUserId() == _userId), - removable : me.appConfig.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == _userId) + editable : (me.appConfig.canEditComments || (data.asc_getReply(i).asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canEditComment(username), + removable : (me.appConfig.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canDeleteComment(username) }); } comment.replys = replies; diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index f4e20e493..8737b4c79 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -1333,9 +1333,11 @@ define([ this.appOptions.canUseReviewPermissions = this.appOptions.canLicense && (!!this.permissions.reviewGroups || this.editorConfig.customization && this.editorConfig.customization.reviewPermissions && (typeof (this.editorConfig.customization.reviewPermissions) == 'object')); - Common.Utils.UserInfoParser.setParser(this.appOptions.canUseReviewPermissions); + this.appOptions.canUseCommentPermissions = this.appOptions.canLicense && !!this.permissions.commentGroups; + Common.Utils.UserInfoParser.setParser(this.appOptions.canUseReviewPermissions || this.appOptions.canUseCommentPermissions); Common.Utils.UserInfoParser.setCurrentName(this.appOptions.user.fullname); this.appOptions.canUseReviewPermissions && Common.Utils.UserInfoParser.setReviewPermissions(this.permissions.reviewGroups, this.editorConfig.customization.reviewPermissions); + this.appOptions.canUseCommentPermissions && Common.Utils.UserInfoParser.setCommentPermissions(this.permissions.commentGroups); appHeader.setUserName(Common.Utils.UserInfoParser.getParsedName(Common.Utils.UserInfoParser.getCurrentName())); this.appOptions.canRename && appHeader.setCanRename(true); diff --git a/apps/documenteditor/mobile/app/controller/Main.js b/apps/documenteditor/mobile/app/controller/Main.js index 30e047d66..b056ea509 100644 --- a/apps/documenteditor/mobile/app/controller/Main.js +++ b/apps/documenteditor/mobile/app/controller/Main.js @@ -839,10 +839,12 @@ define([ me.appOptions.canUseReviewPermissions = me.appOptions.canLicense && (!!me.permissions.reviewGroups || me.editorConfig.customization && me.editorConfig.customization.reviewPermissions && (typeof (me.editorConfig.customization.reviewPermissions) == 'object')); - Common.Utils.UserInfoParser.setParser(me.appOptions.canUseReviewPermissions); + me.appOptions.canUseCommentPermissions = me.appOptions.canLicense && !!me.permissions.commentGroups; + Common.Utils.UserInfoParser.setParser(me.appOptions.canUseReviewPermissions || me.appOptions.canUseCommentPermissions); Common.Utils.UserInfoParser.setCurrentName(me.appOptions.user.fullname); me.appOptions.canUseReviewPermissions && Common.Utils.UserInfoParser.setReviewPermissions(me.permissions.reviewGroups, me.editorConfig.customization.reviewPermissions); - + me.appOptions.canUseCommentPermissions && Common.Utils.UserInfoParser.setCommentPermissions(me.permissions.commentGroups); + me.applyModeCommonElements(); me.applyModeEditorElements(); diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index ef200e2b0..3be23c570 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -1034,9 +1034,11 @@ define([ this.appOptions.canUseReviewPermissions = this.appOptions.canLicense && (!!this.permissions.reviewGroups || this.appOptions.canLicense && this.editorConfig.customization && this.editorConfig.customization.reviewPermissions && (typeof (this.editorConfig.customization.reviewPermissions) == 'object')); - Common.Utils.UserInfoParser.setParser(this.appOptions.canUseReviewPermissions); + this.appOptions.canUseCommentPermissions = this.appOptions.canLicense && !!this.permissions.commentGroups; + Common.Utils.UserInfoParser.setParser(this.appOptions.canUseReviewPermissions || this.appOptions.canUseCommentPermissions); Common.Utils.UserInfoParser.setCurrentName(this.appOptions.user.fullname); this.appOptions.canUseReviewPermissions && Common.Utils.UserInfoParser.setReviewPermissions(this.permissions.reviewGroups, this.editorConfig.customization.reviewPermissions); + this.appOptions.canUseCommentPermissions && Common.Utils.UserInfoParser.setCommentPermissions(this.permissions.commentGroups); appHeader.setUserName(Common.Utils.UserInfoParser.getParsedName(Common.Utils.UserInfoParser.getCurrentName())); this.appOptions.canRename && appHeader.setCanRename(true); diff --git a/apps/presentationeditor/mobile/app/controller/Main.js b/apps/presentationeditor/mobile/app/controller/Main.js index 2ea83421d..a0d15686f 100644 --- a/apps/presentationeditor/mobile/app/controller/Main.js +++ b/apps/presentationeditor/mobile/app/controller/Main.js @@ -762,10 +762,12 @@ define([ me.appOptions.canUseReviewPermissions = me.appOptions.canLicense && (!!me.permissions.reviewGroups || me.editorConfig.customization && me.editorConfig.customization.reviewPermissions && (typeof (me.editorConfig.customization.reviewPermissions) == 'object')); - Common.Utils.UserInfoParser.setParser(me.appOptions.canUseReviewPermissions); + me.appOptions.canUseCommentPermissions = me.appOptions.canLicense && !!me.permissions.commentGroups; + Common.Utils.UserInfoParser.setParser(me.appOptions.canUseReviewPermissions || me.appOptions.canUseCommentPermissions); Common.Utils.UserInfoParser.setCurrentName(me.appOptions.user.fullname); me.appOptions.canUseReviewPermissions && Common.Utils.UserInfoParser.setReviewPermissions(me.permissions.reviewGroups, me.editorConfig.customization.reviewPermissions); - + me.appOptions.canUseCommentPermissions && Common.Utils.UserInfoParser.setCommentPermissions(me.permissions.commentGroups); + me.applyModeCommonElements(); me.applyModeEditorElements(); diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 70ab7427e..f38c0003a 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -1081,9 +1081,11 @@ define([ this.appOptions.canRename && this.headerView.setCanRename(true); this.appOptions.canUseReviewPermissions = this.appOptions.canLicense && (!!this.permissions.reviewGroups || this.appOptions.canLicense && this.editorConfig.customization && this.editorConfig.customization.reviewPermissions && (typeof (this.editorConfig.customization.reviewPermissions) == 'object')); - Common.Utils.UserInfoParser.setParser(this.appOptions.canUseReviewPermissions); + this.appOptions.canUseCommentPermissions = this.appOptions.canLicense && !!this.permissions.commentGroups; + Common.Utils.UserInfoParser.setParser(this.appOptions.canUseReviewPermissions || this.appOptions.canUseCommentPermissions); Common.Utils.UserInfoParser.setCurrentName(this.appOptions.user.fullname); this.appOptions.canUseReviewPermissions && Common.Utils.UserInfoParser.setReviewPermissions(this.permissions.reviewGroups, this.editorConfig.customization.reviewPermissions); + this.appOptions.canUseCommentPermissions && Common.Utils.UserInfoParser.setCommentPermissions(this.permissions.commentGroups); this.headerView.setUserName(Common.Utils.UserInfoParser.getParsedName(Common.Utils.UserInfoParser.getCurrentName())); } else this.appOptions.canModifyFilter = true; diff --git a/apps/spreadsheeteditor/mobile/app/controller/Main.js b/apps/spreadsheeteditor/mobile/app/controller/Main.js index 2092e1f43..50fbab3e1 100644 --- a/apps/spreadsheeteditor/mobile/app/controller/Main.js +++ b/apps/spreadsheeteditor/mobile/app/controller/Main.js @@ -774,9 +774,11 @@ define([ me.appOptions.canUseReviewPermissions = me.appOptions.canLicense && (!!me.permissions.reviewGroups || me.editorConfig.customization && me.editorConfig.customization.reviewPermissions && (typeof (me.editorConfig.customization.reviewPermissions) == 'object')); - Common.Utils.UserInfoParser.setParser(me.appOptions.canUseReviewPermissions); + me.appOptions.canUseCommentPermissions = me.appOptions.canLicense && !!me.permissions.commentGroups; + Common.Utils.UserInfoParser.setParser(me.appOptions.canUseReviewPermissions || me.appOptions.canUseCommentPermissions); Common.Utils.UserInfoParser.setCurrentName(me.appOptions.user.fullname); me.appOptions.canUseReviewPermissions && Common.Utils.UserInfoParser.setReviewPermissions(me.permissions.reviewGroups, me.editorConfig.customization.reviewPermissions); + me.appOptions.canUseCommentPermissions && Common.Utils.UserInfoParser.setCommentPermissions(me.permissions.commentGroups); } me.appOptions.canRequestEditRights = me.editorConfig.canRequestEditRights;