Add permissions for edit/remove comments

This commit is contained in:
Julia Radzhabova 2021-03-17 12:02:06 +03:00
parent 5a373f76bb
commit f35e929713
12 changed files with 115 additions and 53 deletions

View file

@ -51,6 +51,11 @@
editCommentAuthorOnly: <can edit your own comments only> // default = false
deleteCommentAuthorOnly: <can delete your own comments only> // 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: {

View file

@ -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);
}

View file

@ -73,7 +73,9 @@
<% if (removable) { %>
<div class="btn-delete img-commonctrl"></div>
<% } %>
<% if (editable) { %>
<div class="btn-resolve <% if (resolved) print('comment-resolved') %>" data-toggle="tooltip"></div>
<% } %>
</div>
<% } %>

View file

@ -74,7 +74,9 @@
<% if (removable) { %>
<div class="btn-delete img-commonctrl"></div>
<% } %>
<% if (editable) { %>
<div class="btn-resolve <% if (resolved) print('comment-resolved') %>" data-toggle="tooltip"></div>
<% } %>
</div>
<% } %>

View file

@ -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<arr2.length; i++) {
if (arr1.indexOf(arr2[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; i<groups.length; i++)
groups[i] = groups[i].trim();
return groups;
} else
return undefined;
}
},
setCurrentName: function(name) {
username = name;
this.setReviewPermissions(reviewGroups, reviewPermissions);
_reviewPermissions && this.setReviewPermissions(null, _reviewPermissions); // old version of review permissions
},
getCurrentName: function() {
@ -1024,27 +1031,59 @@ Common.Utils.UserInfoParser = new(function() {
setReviewPermissions: function(groups, permissions) {
if (groups) {
if (typeof groups == 'object' && groups.length>0)
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);
}
}
})();

View file

@ -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;

View file

@ -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);

View file

@ -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();

View file

@ -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);

View file

@ -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();

View file

@ -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;

View file

@ -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;