From 3e0aaa04496912f7313613cd6b39309da70f228c Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 5 Aug 2020 16:36:35 +0300 Subject: [PATCH] [Mobile] Add parameter to api config: customization.reviewPermissions (user name must be prefixed) --- .../mobile/lib/controller/Collaboration.js | 40 +++++++++++++++---- apps/common/mobile/lib/view/Collaboration.js | 29 ++++++++------ apps/common/mobile/utils/utils.js | 29 +++++++++++++- .../mobile/app/controller/DocumentHolder.js | 2 +- .../mobile/app/controller/Main.js | 3 ++ .../mobile/app/controller/Settings.js | 2 +- .../mobile/app/view/add/AddOther.js | 9 ++++- .../mobile/app/controller/Main.js | 3 ++ .../mobile/app/controller/Settings.js | 2 +- .../mobile/app/view/add/AddOther.js | 9 ++++- .../mobile/app/controller/Main.js | 3 ++ .../mobile/app/controller/Settings.js | 2 +- .../mobile/app/view/add/AddOther.js | 9 ++++- 13 files changed, 112 insertions(+), 30 deletions(-) diff --git a/apps/common/mobile/lib/controller/Collaboration.js b/apps/common/mobile/lib/controller/Collaboration.js index 1b7f6d391..c0df47d38 100644 --- a/apps/common/mobile/lib/controller/Collaboration.js +++ b/apps/common/mobile/lib/controller/Collaboration.js @@ -63,7 +63,8 @@ define([ canViewReview, arrChangeReview = [], dateChange = [], - _fileKey; + _fileKey, + _currentUserGroups; return { @@ -113,6 +114,18 @@ define([ if (editor === 'DE') { _fileKey = mode.fileKey; } + + if (mode && mode.canUseReviewPermissions) { + var permissions = mode.customization.reviewPermissions, + arr = [], + groups = Common.Utils.UserInfoParser.getParsedGroups(mode.user.fullname); + groups && groups.forEach(function(group) { + var item = permissions[group.trim()]; + item && (arr = arr.concat(item)); + }); + _currentUserGroups = arr; + } + return this; }, @@ -231,7 +244,8 @@ define([ getUsersInfo: function() { var usersArray = []; _.each(editUsers, function(item){ - var fio = item.asc_getUserName().split(' '); + var name = Common.Utils.UserInfoParser.getParsedName(item.asc_getUserName()); + var fio = name.split(' '); var initials = fio[0].substring(0, 1).toUpperCase(); if (fio.length > 1) { initials += fio[fio.length - 1].substring(0, 1).toUpperCase(); @@ -241,7 +255,7 @@ define([ color: item.asc_getColor(), id: item.asc_getId(), idOriginal: item.asc_getIdOriginal(), - name: item.asc_getUserName(), + name: name, view: item.asc_getView(), initial: initials }; @@ -300,6 +314,10 @@ define([ $('#settings-accept-all').hide(); $('#settings-reject-all').hide(); } + if (this.appConfig.canUseReviewPermissions) { + $('#settings-accept-all').hide(); + $('#settings-reject-all').hide(); + } }, onTrackChanges: function(e) { @@ -407,6 +425,11 @@ define([ $('.accept-reject').html('' + this.textDelete + ''); $('#btn-delete-change').single('click', _.bind(this.onDeleteChange, this)); } + } else { + if(arrChangeReview.length != 0 && !arrChangeReview[0].editable) { + $('#btn-accept-change').addClass('disabled'); + $('#btn-reject-change').addClass('disabled'); + } } if(displayMode == "final" || displayMode == "original") { $('#btn-accept-change').addClass('disabled'); @@ -663,9 +686,7 @@ define([ userColor = item.get_UserColor(), goto = (item.get_MoveType() == Asc.c_oAscRevisionsMove.MoveTo || item.get_MoveType() == Asc.c_oAscRevisionsMove.MoveFrom); date = me.dateToLocaleTimeString(date); - var editable = (item.get_UserId() == _userId); - - + var editable = me.appConfig.isReviewOnly && (item.get_UserId() == _userId) || !me.appConfig.isReviewOnly && (!me.appConfig.canUseReviewPermissions || me.checkUserGroups(item.get_UserName())); arr.push({date: date, user: user, usercolor: userColor, changetext: changetext, goto: goto, editable: editable}); }); arrChangeReview = arr; @@ -677,6 +698,11 @@ define([ this.updateInfoChange(); }, + checkUserGroups: function(username) { + var groups = Common.Utils.UserInfoParser.getParsedGroups(username); + return _currentUserGroups && groups && (_.intersection(_currentUserGroups, groups).length>0); + }, + dateToLocaleTimeString: function (date) { function format(date) { var strTime, @@ -736,7 +762,7 @@ define([ }, getInitials: function(name) { - var fio = name.split(' '); + var fio = Common.Utils.UserInfoParser.getParsedName(name).split(' '); var initials = fio[0].substring(0, 1).toUpperCase(); if (fio.length > 1) { initials += fio[fio.length - 1].substring(0, 1).toUpperCase(); diff --git a/apps/common/mobile/lib/view/Collaboration.js b/apps/common/mobile/lib/view/Collaboration.js index 9a90b9cc4..37701504b 100644 --- a/apps/common/mobile/lib/view/Collaboration.js +++ b/apps/common/mobile/lib/view/Collaboration.js @@ -177,7 +177,7 @@ define([ if (isAndroid) { template += '
' + comment.userInitials + '
'; } - template += '
' + comment.username + '
' + + template += '
' + me.getUserName(comment.username) + '
' + '
' + comment.date + '
'; if (isAndroid) { template += '
'; @@ -202,7 +202,7 @@ define([ if (isAndroid) { template += '
' + reply.userInitials + '
' } - template += '
' + reply.username + '
' + + template += '
' + me.getUserName(reply.username) + '
' + '
' + reply.date + '
' + '
'; if (isAndroid) { @@ -249,7 +249,7 @@ define([ '
', '
', '<% if (android) { %>
<%= item.userInitials %>
<% } %>', - '
<%= item.username %>
', + '
<%= scope.getUserName(item.username) %>
', '
<%= item.date %>
', '<% if (android) { %>
<% } %>', '
', @@ -271,7 +271,7 @@ define([ '
', '
', '<% if (android) { %>
<%= reply.userInitials %>
<% } %>', - '
<%= reply.username %>
', + '
<%= scope.getUserName(reply.username) %>
', '
<%= reply.date %>
', '
', '<% if (android) { %>
<% } %>', @@ -292,7 +292,8 @@ define([ item: comment, replys: comment.replys.length, viewmode: me.viewmode, - quote: me.sliceQuote(comment.quote) + quote: me.sliceQuote(comment.quote), + scope: me })); }); $listComments.html(items.join('')); @@ -304,7 +305,7 @@ define([ var isAndroid = Framework7.prototype.device.android === true; var template = '
' + (isAndroid ? '
' + comment.userInitials + '
' : '') + - '
' + comment.username + '
' + + '
' + this.getUserName(comment.username) + '
' + '
' + comment.date + '
' + (isAndroid ? '
' : '') + '
' + @@ -317,7 +318,7 @@ define([ var isAndroid = Framework7.prototype.device.android === true; var template = '
' + (isAndroid ? '
' + initials + '
' : '') + - '
' + name + '
' + + '
' + this.getUserName(name) + '
' + '
' + date + '
' + (isAndroid ? '
' : '') + '
' + @@ -330,7 +331,7 @@ define([ var isAndroid = Framework7.prototype.device.android === true; var template = '
' + (isAndroid ? '
' + reply.userInitials + '
' : '') + - '
' + reply.username + '
' + + '
' + this.getUserName(reply.username) + '
' + '
' + reply.date + '
' + (isAndroid ? '
' : '') + '
' + @@ -354,7 +355,7 @@ define([ '
' + '
' + (isAndroid ? '
' + initial + '
' : '') + - '
' + name + '
' + + '
' + this.getUserName(name) + '
' + '
' + date + '
' + (isAndroid ? '
' : '') + '
' + @@ -401,7 +402,7 @@ define([ '
' + '
' + (isAndroid ? '
' + comment.userInitials + '
' : '') + - '
' + comment.username + '
' + + '
' + this.getUserName(comment.username) + '
' + '
' + comment.date + '
' + (isAndroid ? '
' : '') + '
' + @@ -427,7 +428,7 @@ define([ '
' + '
' + (isAndroid ? '
' + reply.userInitials + '
' : '') + - '
' + reply.username + '
' + + '
' + this.getUserName(reply.username) + '
' + '
' + reply.date + '
' + (isAndroid ? '
' : '') + '
' + @@ -442,13 +443,17 @@ define([ renderChangeReview: function(change) { var isAndroid = Framework7.prototype.device.android === true; var template = (isAndroid ? '
' + change.initials + '
' : '') + - '
' + change.user + '
' + + '
' + this.getUserName(change.user) + '
' + '
' + change.date + '
' + (isAndroid ? '
' : '') + '
' + change.text + '
'; $('#current-change').html(_.template(template)); }, + getUserName: function (username) { + return Common.Utils.String.htmlEncode(Common.Utils.UserInfoParser.getParsedName(username)); + }, + textCollaboration: 'Collaboration', textReviewing: 'Review', textСomments: 'Сomments', diff --git a/apps/common/mobile/utils/utils.js b/apps/common/mobile/utils/utils.js index d0ea75a52..83afde1fd 100644 --- a/apps/common/mobile/utils/utils.js +++ b/apps/common/mobile/utils/utils.js @@ -126,5 +126,32 @@ define([ new IScroll(targetSelector); }, 500); } - } + }; + + Common.Utils.UserInfoParser = new(function() { + var parse = false; + return { + setParser: function(value) { + parse = !!value; + }, + + getParsedName: function(username) { + if (parse && username) { + return username.substring(username.indexOf(':')+1); + } else + return username; + }, + + getParsedGroups: function(username) { + if (parse && username) { + var idx = username.indexOf(':'), + groups = (idx>-1) ? username.substring(0, idx).split(',') : []; + for (var i=0; i
<%= comment.userInitials %>
<% } %>', - '
<%= comment.username %>
', + '
<%= scope.getUserName(comment.username) %>
', '
<%= comment.date %>
', '<% if (android) { %>
<% } %>', '
' @@ -185,7 +185,8 @@ define([ var insert = _.template(template)({ android: Framework7.prototype.device.android, comment: comment, - textAddComment: me.textAddComment + textAddComment: me.textAddComment, + scope: me }); $commentInfo.html(insert); _.defer(function () { @@ -207,6 +208,10 @@ define([ }, 100); }, + getUserName: function (username) { + return Common.Utils.String.htmlEncode(Common.Utils.UserInfoParser.getParsedName(username)); + }, + renderNumFormat: function (dataFormat, selectFormat) { var $listFormat = $('#list-format-footnote ul'), items = []; diff --git a/apps/presentationeditor/mobile/app/controller/Main.js b/apps/presentationeditor/mobile/app/controller/Main.js index 06f12f856..46862cfec 100644 --- a/apps/presentationeditor/mobile/app/controller/Main.js +++ b/apps/presentationeditor/mobile/app/controller/Main.js @@ -730,6 +730,9 @@ define([ me.appOptions.canBranding = params.asc_getCustomization(); me.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof me.editorConfig.customization == 'object'); + me.appOptions.canUseReviewPermissions = me.appOptions.canLicense && me.editorConfig.customization && me.editorConfig.customization.reviewPermissions && (typeof (me.editorConfig.customization.reviewPermissions) == 'object'); + Common.Utils.UserInfoParser.setParser(me.appOptions.canUseReviewPermissions); + me.applyModeCommonElements(); me.applyModeEditorElements(); diff --git a/apps/presentationeditor/mobile/app/controller/Settings.js b/apps/presentationeditor/mobile/app/controller/Settings.js index c939fd041..4d3f3d1b3 100644 --- a/apps/presentationeditor/mobile/app/controller/Settings.js +++ b/apps/presentationeditor/mobile/app/controller/Settings.js @@ -241,7 +241,7 @@ define([ value = props.asc_getModified(); value ? $('#settings-pe-last-mod').html(value.toLocaleString(_lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(_lang, {timeStyle: 'short'})) : $('.display-last-mode').remove(); value = props.asc_getLastModifiedBy(); - value ? $('#settings-pe-mod-by').html(value) : $('.display-mode-by').remove(); + value ? $('#settings-pe-mod-by').html(Common.Utils.UserInfoParser.getParsedName(value)) : $('.display-mode-by').remove(); value = props.asc_getCreated(); value ? $('#settings-pe-date').html(value.toLocaleString(_lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(_lang, {timeStyle: 'short'})) : $('.display-created-date').remove(); value = props.asc_getCreator(); diff --git a/apps/presentationeditor/mobile/app/view/add/AddOther.js b/apps/presentationeditor/mobile/app/view/add/AddOther.js index 5748aeb36..a1935724a 100644 --- a/apps/presentationeditor/mobile/app/view/add/AddOther.js +++ b/apps/presentationeditor/mobile/app/view/add/AddOther.js @@ -143,7 +143,7 @@ define([ var $commentInfo = $('#comment-info'); var template = [ '<% if (android) { %>
<%= comment.userInitials %>
<% } %>', - '
<%= comment.username %>
', + '
<%= scope.getUserName(comment.username) %>
', '
<%= comment.date %>
', '<% if (android) { %>
<% } %>', '
' @@ -151,7 +151,8 @@ define([ var insert = _.template(template)({ android: Framework7.prototype.device.android, comment: comment, - textAddComment: me.textAddComment + textAddComment: me.textAddComment, + scope: me }); $commentInfo.html(insert); _.defer(function () { @@ -173,6 +174,10 @@ define([ }, 100); }, + getUserName: function (username) { + return Common.Utils.String.htmlEncode(Common.Utils.UserInfoParser.getParsedName(username)); + }, + showPageTable: function() { this.showPage('#addother-insert-table'); this.renderTableStyles(); diff --git a/apps/spreadsheeteditor/mobile/app/controller/Main.js b/apps/spreadsheeteditor/mobile/app/controller/Main.js index 2a5310332..9a00d514f 100644 --- a/apps/spreadsheeteditor/mobile/app/controller/Main.js +++ b/apps/spreadsheeteditor/mobile/app/controller/Main.js @@ -743,6 +743,9 @@ define([ me.appOptions.canBranding = params.asc_getCustomization(); me.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof me.editorConfig.customization == 'object'); + + me.appOptions.canUseReviewPermissions = me.appOptions.canLicense && me.editorConfig.customization && me.editorConfig.customization.reviewPermissions && (typeof (me.editorConfig.customization.reviewPermissions) == 'object'); + Common.Utils.UserInfoParser.setParser(me.appOptions.canUseReviewPermissions); } me.appOptions.canRequestEditRights = me.editorConfig.canRequestEditRights; diff --git a/apps/spreadsheeteditor/mobile/app/controller/Settings.js b/apps/spreadsheeteditor/mobile/app/controller/Settings.js index dcea13ddf..4a0005217 100644 --- a/apps/spreadsheeteditor/mobile/app/controller/Settings.js +++ b/apps/spreadsheeteditor/mobile/app/controller/Settings.js @@ -310,7 +310,7 @@ define([ value = props.asc_getModified(); value ? $('#settings-sse-last-mod').html(value.toLocaleString(_lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(_lang, {timeStyle: 'short'})) : $('.display-last-mode').remove(); value = props.asc_getLastModifiedBy(); - value ? $('#settings-sse-mod-by').html(value) : $('.display-mode-by').remove(); + value ? $('#settings-sse-mod-by').html(Common.Utils.UserInfoParser.getParsedName(value)) : $('.display-mode-by').remove(); value = props.asc_getCreated(); value ? $('#settings-sse-date').html(value.toLocaleString(_lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(_lang, {timeStyle: 'short'})) : $('.display-created-date').remove(); value = props.asc_getCreator(); diff --git a/apps/spreadsheeteditor/mobile/app/view/add/AddOther.js b/apps/spreadsheeteditor/mobile/app/view/add/AddOther.js index 96d7d37bc..aef617c64 100644 --- a/apps/spreadsheeteditor/mobile/app/view/add/AddOther.js +++ b/apps/spreadsheeteditor/mobile/app/view/add/AddOther.js @@ -217,7 +217,7 @@ define([ var $commentInfo = $('#comment-info'); var template = [ '<% if (android) { %>
<%= comment.userInitials %>
<% } %>', - '
<%= comment.username %>
', + '
<%= scope.getUserName(comment.username) %>
', '
<%= comment.date %>
', '<% if (android) { %>
<% } %>', '
' @@ -225,7 +225,8 @@ define([ var insert = _.template(template)({ android: Framework7.prototype.device.android, comment: comment, - textAddComment: me.textAddComment + textAddComment: me.textAddComment, + scope: me }); $commentInfo.html(insert); _.defer(function () { @@ -247,6 +248,10 @@ define([ }, 100); }, + getUserName: function (username) { + return Common.Utils.String.htmlEncode(Common.Utils.UserInfoParser.getParsedName(username)); + }, + showInsertImage: function () { this.showPage('#addother-insimage');