Add parameter to api config: customization.reviewPermissions (user name must be prefixed)

This commit is contained in:
Julia Radzhabova 2020-08-04 22:20:20 +03:00
parent 4ec5d92ebd
commit e222fdf4a7
18 changed files with 120 additions and 65 deletions

View file

@ -117,6 +117,16 @@ define([
if (data) { if (data) {
this.currentUserId = data.config.user.id; this.currentUserId = data.config.user.id;
if (this.appConfig && this.appConfig.canUseReviewPermissions) {
var permissions = this.appConfig.customization.reviewPermissions,
arr = [],
groups = Common.Utils.UserInfoParser.getParsedGroups(data.config.user.fullname);
groups && groups.forEach(function(group) {
var item = permissions[group.trim()];
item && (arr = arr.concat(item));
});
this.currentUserGroups = arr;
}
this.sdkViewName = data['sdkviewname'] || this.sdkViewName; this.sdkViewName = data['sdkviewname'] || this.sdkViewName;
} }
return this; return this;
@ -183,7 +193,8 @@ define([
posY = sdkchange[0].get_Y(), posY = sdkchange[0].get_Y(),
animate = ( Math.abs(this._state.posx-posX)>0.001 || Math.abs(this._state.posy-posY)>0.001) || (sdkchange.length !== this._state.changes_length), animate = ( Math.abs(this._state.posx-posX)>0.001 || Math.abs(this._state.posy-posY)>0.001) || (sdkchange.length !== this._state.changes_length),
lock = (sdkchange[0].get_LockUserId()!==null), lock = (sdkchange[0].get_LockUserId()!==null),
lockUser = this.getUserName(sdkchange[0].get_LockUserId()); lockUser = this.getUserName(sdkchange[0].get_LockUserId()),
editable = changes[0].get('editable');
this.getPopover().hideTips(); this.getPopover().hideTips();
this.popoverChanges.reset(changes); this.popoverChanges.reset(changes);
@ -195,14 +206,15 @@ define([
this.getPopover().showReview(animate, lock, lockUser); this.getPopover().showReview(animate, lock, lockUser);
if (this.appConfig.canReview && !this.appConfig.isReviewOnly && this._state.lock !== lock) { var btnlock = lock || !editable;
this.view.btnAccept.setDisabled(lock==true); if (this.appConfig.canReview && !this.appConfig.isReviewOnly && this._state.lock !== btnlock) {
this.view.btnReject.setDisabled(lock==true); this.view.btnAccept.setDisabled(btnlock);
this.view.btnReject.setDisabled(btnlock);
if (this.dlgChanges) { if (this.dlgChanges) {
this.dlgChanges.btnAccept.setDisabled(lock==true); this.dlgChanges.btnAccept.setDisabled(btnlock);
this.dlgChanges.btnReject.setDisabled(lock==true); this.dlgChanges.btnReject.setDisabled(btnlock);
} }
this._state.lock = lock; this._state.lock = btnlock;
} }
this._state.posx = posX; this._state.posx = posX;
this._state.posy = posY; this._state.posy = posY;
@ -459,7 +471,7 @@ define([
scope : me.view, scope : me.view,
hint : !me.appConfig.canReview, hint : !me.appConfig.canReview,
goto : (item.get_MoveType() == Asc.c_oAscRevisionsMove.MoveTo || item.get_MoveType() == Asc.c_oAscRevisionsMove.MoveFrom), goto : (item.get_MoveType() == Asc.c_oAscRevisionsMove.MoveTo || item.get_MoveType() == Asc.c_oAscRevisionsMove.MoveFrom),
editable : (item.get_UserId() == me.currentUserId) editable : me.appConfig.isReviewOnly && (item.get_UserId() == me.currentUserId) || !me.appConfig.isReviewOnly && (!me.appConfig.canUseReviewPermissions || me.checkUserGroups(item.get_UserName()))
}); });
arr.push(change); arr.push(change);
@ -467,10 +479,15 @@ define([
return arr; return arr;
}, },
checkUserGroups: function(username) {
var groups = Common.Utils.UserInfoParser.getParsedGroups(username);
return this.currentUserGroups && groups && (_.intersection(this.currentUserGroups, groups).length>0);
},
getUserName: function(id){ getUserName: function(id){
if (this.userCollection && id!==null){ if (this.userCollection && id!==null){
var rec = this.userCollection.findUser(id); var rec = this.userCollection.findUser(id);
if (rec) return rec.get('username'); if (rec) return Common.Utils.UserInfoParser.getParsedName(rec.get('username'));
} }
return ''; return '';
}, },

View file

@ -13,7 +13,7 @@
<% if (editable) { %> <% if (editable) { %>
<div class="btn-delete img-commonctrl"></div> <div class="btn-delete img-commonctrl"></div>
<% } %> <% } %>
<% } else { %> <% } else if (editable) { %>
<div class="btn-accept img-commonctrl"></div> <div class="btn-accept img-commonctrl"></div>
<div class="btn-reject img-commonctrl"></div> <div class="btn-reject img-commonctrl"></div>
<% } %> <% } %>

View file

@ -960,3 +960,30 @@ Common.Utils.ModalWindow = new(function() {
} }
} }
})(); })();
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<groups.length; i++)
groups[i] = groups[i].trim();
return groups;
} else
return undefined;
}
}
})();

View file

@ -267,7 +267,7 @@ define([
}, },
getUserName: function (username) { getUserName: function (username) {
return Common.Utils.String.htmlEncode(username); return Common.Utils.String.htmlEncode(Common.Utils.UserInfoParser.getParsedName(username));
}, },
hide: function () { hide: function () {

View file

@ -655,7 +655,7 @@ define([
return Common.Utils.String.ellipsis(Common.Utils.String.htmlEncode(quote), 120, true); return Common.Utils.String.ellipsis(Common.Utils.String.htmlEncode(quote), 120, true);
}, },
getUserName: function (username) { getUserName: function (username) {
return Common.Utils.String.htmlEncode(username); return Common.Utils.String.htmlEncode(Common.Utils.UserInfoParser.getParsedName(username));
}, },
pickLink: function (message) { pickLink: function (message) {

View file

@ -128,7 +128,9 @@ define([
$userList.html(templateUserList({ $userList.html(templateUserList({
users: collection.chain().filter(function(item){return item.get('online') && !item.get('view')}).groupBy(function(item) {return item.get('idOriginal');}).value(), users: collection.chain().filter(function(item){return item.get('online') && !item.get('view')}).groupBy(function(item) {return item.get('idOriginal');}).value(),
usertpl: _.template(templateUserItem), usertpl: _.template(templateUserItem),
fnEncode: Common.Utils.String.htmlEncode fnEncode: function(username) {
return Common.Utils.String.htmlEncode(Common.Utils.UserInfoParser.getParsedName(username));
}
})); }));
$userList.scroller = new Common.UI.Scroller({ $userList.scroller = new Common.UI.Scroller({

View file

@ -90,7 +90,7 @@ define([
'<% } %>', '<% } %>',
'<div class="user-name">', '<div class="user-name">',
'<div class="color" style="display: inline-block; background-color:' + '<%=usercolor%>;' + '" >', '<div class="color" style="display: inline-block; background-color:' + '<%=usercolor%>;' + '" >',
'</div><%= Common.Utils.String.htmlEncode(username) %>', '</div><%= Common.Utils.String.htmlEncode(Common.Utils.UserInfoParser.getParsedName(username)) %>',
'</div>', '</div>',
'<% if (canRestore && selected) { %>', '<% if (canRestore && selected) { %>',
'<label class="revision-restore" role="presentation" tabindex="-1">' + this.textRestore + '</label>', '<label class="revision-restore" role="presentation" tabindex="-1">' + this.textRestore + '</label>',

View file

@ -108,7 +108,7 @@ define([
me.fireEvent('reviewchange:accept', [me.btnAccept, 'current']); me.fireEvent('reviewchange:accept', [me.btnAccept, 'current']);
}); });
this.btnAccept.menu.on('item:click', function (menu, item, e) { this.btnAccept.menu && this.btnAccept.menu.on('item:click', function (menu, item, e) {
me.fireEvent('reviewchange:accept', [menu, item]); me.fireEvent('reviewchange:accept', [menu, item]);
}); });
@ -116,7 +116,7 @@ define([
me.fireEvent('reviewchange:reject', [me.btnReject, 'current']); me.fireEvent('reviewchange:reject', [me.btnReject, 'current']);
}); });
this.btnReject.menu.on('item:click', function (menu, item, e) { this.btnReject.menu && this.btnReject.menu.on('item:click', function (menu, item, e) {
me.fireEvent('reviewchange:reject', [menu, item]); me.fireEvent('reviewchange:reject', [menu, item]);
}); });
@ -202,14 +202,14 @@ define([
this.btnAccept = new Common.UI.Button({ this.btnAccept = new Common.UI.Button({
cls: 'btn-toolbar x-huge icon-top', cls: 'btn-toolbar x-huge icon-top',
caption: this.txtAccept, caption: this.txtAccept,
split: true, split: !this.appConfig.canUseReviewPermissions,
iconCls: 'toolbar__icon btn-review-save' iconCls: 'toolbar__icon btn-review-save'
}); });
this.btnReject = new Common.UI.Button({ this.btnReject = new Common.UI.Button({
cls: 'btn-toolbar x-huge icon-top', cls: 'btn-toolbar x-huge icon-top',
caption: this.txtReject, caption: this.txtReject,
split: true, split: !this.appConfig.canUseReviewPermissions,
iconCls: 'toolbar__icon btn-review-deny' iconCls: 'toolbar__icon btn-review-deny'
}); });
@ -358,6 +358,7 @@ define([
if ( config.canReview ) { if ( config.canReview ) {
me.btnTurnOn.updateHint(me.tipReview); me.btnTurnOn.updateHint(me.tipReview);
if (!me.appConfig.canUseReviewPermissions) {
me.btnAccept.setMenu( me.btnAccept.setMenu(
new Common.UI.Menu({ new Common.UI.Menu({
items: [ items: [
@ -372,8 +373,6 @@ define([
] ]
}) })
); );
me.btnAccept.updateHint([me.tipAcceptCurrent, me.txtAcceptChanges]);
me.btnReject.setMenu( me.btnReject.setMenu(
new Common.UI.Menu({ new Common.UI.Menu({
items: [ items: [
@ -388,6 +387,8 @@ define([
] ]
}) })
); );
}
me.btnAccept.updateHint([me.tipAcceptCurrent, me.txtAcceptChanges]);
me.btnReject.updateHint([me.tipRejectCurrent, me.txtRejectChanges]); me.btnReject.updateHint([me.tipRejectCurrent, me.txtRejectChanges]);
if (config.canFeatureComparison) { if (config.canFeatureComparison) {
@ -583,7 +584,7 @@ define([
}, },
getUserName: function (username) { getUserName: function (username) {
return Common.Utils.String.htmlEncode(username); return Common.Utils.String.htmlEncode(Common.Utils.UserInfoParser.getParsedName(username));
}, },
turnChanges: function(state) { turnChanges: function(state) {
@ -771,7 +772,7 @@ define([
caption : this.txtAccept, caption : this.txtAccept,
split : true, split : true,
disabled : this.mode.isReviewOnly, disabled : this.mode.isReviewOnly,
menu : new Common.UI.Menu({ menu : this.mode.canUseReviewPermissions ? false : new Common.UI.Menu({
items: [ items: [
this.mnuAcceptCurrent = new Common.UI.MenuItem({ this.mnuAcceptCurrent = new Common.UI.MenuItem({
caption: this.txtAcceptCurrent, caption: this.txtAcceptCurrent,
@ -791,7 +792,7 @@ define([
caption : this.txtReject, caption : this.txtReject,
split : true, split : true,
disabled : this.mode.isReviewOnly, disabled : this.mode.isReviewOnly,
menu : new Common.UI.Menu({ menu : this.mode.canUseReviewPermissions ? false : new Common.UI.Menu({
items: [ items: [
this.mnuRejectCurrent = new Common.UI.MenuItem({ this.mnuRejectCurrent = new Common.UI.MenuItem({
caption: this.txtRejectCurrent, caption: this.txtRejectCurrent,
@ -819,7 +820,7 @@ define([
me.fireEvent('reviewchange:accept', [me.btnAccept, 'current']); me.fireEvent('reviewchange:accept', [me.btnAccept, 'current']);
}); });
this.btnAccept.menu.on('item:click', function (menu, item, e) { this.btnAccept.menu && this.btnAccept.menu.on('item:click', function (menu, item, e) {
me.fireEvent('reviewchange:accept', [menu, item]); me.fireEvent('reviewchange:accept', [menu, item]);
}); });
@ -827,7 +828,7 @@ define([
me.fireEvent('reviewchange:reject', [me.btnReject, 'current']); me.fireEvent('reviewchange:reject', [me.btnReject, 'current']);
}); });
this.btnReject.menu.on('item:click', function (menu, item, e) { this.btnReject.menu && this.btnReject.menu.on('item:click', function (menu, item, e) {
me.fireEvent('reviewchange:reject', [menu, item]); me.fireEvent('reviewchange:reject', [menu, item]);
}); });

View file

@ -372,8 +372,7 @@ define([
this.appOptions.mentionShare = !((typeof (this.appOptions.customization) == 'object') && (this.appOptions.customization.mentionShare==false)); this.appOptions.mentionShare = !((typeof (this.appOptions.customization) == 'object') && (this.appOptions.customization.mentionShare==false));
appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header'); appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header');
appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '') appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '');
.setUserName(this.appOptions.user.fullname);
if (this.editorConfig.lang) if (this.editorConfig.lang)
this.api.asc_setLocale(this.editorConfig.lang); this.api.asc_setLocale(this.editorConfig.lang);
@ -1273,6 +1272,10 @@ define([
if (this.appOptions.canBranding) if (this.appOptions.canBranding)
appHeader.setBranding(this.editorConfig.customization); appHeader.setBranding(this.editorConfig.customization);
this.appOptions.canUseReviewPermissions = this.appOptions.canBranding && this.appOptions.canLicense && this.editorConfig.customization && this.editorConfig.customization.reviewPermissions && (typeof (this.editorConfig.customization.reviewPermissions) == 'object');
Common.Utils.UserInfoParser.setParser(this.appOptions.canUseReviewPermissions);
appHeader.setUserName(Common.Utils.UserInfoParser.getParsedName(this.appOptions.user.fullname));
this.appOptions.canRename && appHeader.setCanRename(true); this.appOptions.canRename && appHeader.setCanRename(true);
this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins); this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins);
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions); this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions);

View file

@ -359,7 +359,7 @@ define([
if (usersStore){ if (usersStore){
var rec = usersStore.findUser(id); var rec = usersStore.findUser(id);
if (rec) if (rec)
return rec.get('username'); return Common.Utils.UserInfoParser.getParsedName(rec.get('username'));
} }
return me.guestText; return me.guestText;
}; };

View file

@ -1121,7 +1121,7 @@ define([
visible = this._ShowHideInfoItem(this.lblModifyDate, !!value) || visible; visible = this._ShowHideInfoItem(this.lblModifyDate, !!value) || visible;
value = props.asc_getLastModifiedBy(); value = props.asc_getLastModifiedBy();
if (value) if (value)
this.lblModifyBy.text(value); this.lblModifyBy.text(Common.Utils.UserInfoParser.getParsedName(value));
visible = this._ShowHideInfoItem(this.lblModifyBy, !!value) || visible; visible = this._ShowHideInfoItem(this.lblModifyBy, !!value) || visible;
$('tr.divider.modify', this.el)[visible?'show':'hide'](); $('tr.divider.modify', this.el)[visible?'show':'hide']();

View file

@ -331,8 +331,7 @@ define([
this.appOptions.mentionShare = !((typeof (this.appOptions.customization) == 'object') && (this.appOptions.customization.mentionShare==false)); this.appOptions.mentionShare = !((typeof (this.appOptions.customization) == 'object') && (this.appOptions.customization.mentionShare==false));
appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header'); appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header');
appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '') appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '');
.setUserName(this.appOptions.user.fullname);
if (this.editorConfig.lang) if (this.editorConfig.lang)
this.api.asc_setLocale(this.editorConfig.lang); this.api.asc_setLocale(this.editorConfig.lang);
@ -976,6 +975,10 @@ define([
if (this.appOptions.canBranding) if (this.appOptions.canBranding)
appHeader.setBranding(this.editorConfig.customization); appHeader.setBranding(this.editorConfig.customization);
this.appOptions.canUseReviewPermissions = this.appOptions.canBranding && this.appOptions.canLicense && this.editorConfig.customization && this.editorConfig.customization.reviewPermissions && (typeof (this.editorConfig.customization.reviewPermissions) == 'object');
Common.Utils.UserInfoParser.setParser(this.appOptions.canUseReviewPermissions);
appHeader.setUserName(Common.Utils.UserInfoParser.getParsedName(this.appOptions.user.fullname));
this.appOptions.canRename && appHeader.setCanRename(true); this.appOptions.canRename && appHeader.setCanRename(true);
this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins); this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins);
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions); this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions);

View file

@ -363,7 +363,7 @@ define([
if (usersStore){ if (usersStore){
var rec = usersStore.findUser(id); var rec = usersStore.findUser(id);
if (rec) if (rec)
return rec.get('username'); return Common.Utils.UserInfoParser.getParsedName(rec.get('username'));
} }
return me.guestText; return me.guestText;
}; };

View file

@ -994,7 +994,7 @@ define([
visible = this._ShowHideInfoItem(this.lblModifyDate, !!value) || visible; visible = this._ShowHideInfoItem(this.lblModifyDate, !!value) || visible;
value = props.asc_getLastModifiedBy(); value = props.asc_getLastModifiedBy();
if (value) if (value)
this.lblModifyBy.text(value); this.lblModifyBy.text(Common.Utils.UserInfoParser.getParsedName(value));
visible = this._ShowHideInfoItem(this.lblModifyBy, !!value) || visible; visible = this._ShowHideInfoItem(this.lblModifyBy, !!value) || visible;
$('tr.divider.modify', this.el)[visible?'show':'hide'](); $('tr.divider.modify', this.el)[visible?'show':'hide']();

View file

@ -1065,7 +1065,7 @@ define([
if (usersStore){ if (usersStore){
var rec = usersStore.findUser(id); var rec = usersStore.findUser(id);
if (rec) if (rec)
return rec.get('username'); return Common.Utils.UserInfoParser.getParsedName(rec.get('username'));
} }
return me.guestText; return me.guestText;
}; };

View file

@ -360,8 +360,7 @@ define([
this.appOptions.canFeaturePivot = !!this.api.asc_isSupportFeature("pivot-tables"); this.appOptions.canFeaturePivot = !!this.api.asc_isSupportFeature("pivot-tables");
this.headerView = this.getApplication().getController('Viewport').getView('Common.Views.Header'); this.headerView = this.getApplication().getController('Viewport').getView('Common.Views.Header');
this.headerView.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '') this.headerView.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '');
.setUserName(this.appOptions.user.fullname);
var reg = Common.localStorage.getItem("sse-settings-reg-settings"), var reg = Common.localStorage.getItem("sse-settings-reg-settings"),
isUseBaseSeparator = Common.localStorage.getBool("sse-settings-use-base-separator", true), isUseBaseSeparator = Common.localStorage.getBool("sse-settings-use-base-separator", true),
@ -1032,6 +1031,9 @@ define([
this.headerView.setBranding(this.editorConfig.customization); this.headerView.setBranding(this.editorConfig.customization);
this.appOptions.canRename && this.headerView.setCanRename(true); this.appOptions.canRename && this.headerView.setCanRename(true);
this.appOptions.canUseReviewPermissions = this.appOptions.canBranding && this.appOptions.canLicense && this.editorConfig.customization && this.editorConfig.customization.reviewPermissions && (typeof (this.editorConfig.customization.reviewPermissions) == 'object');
Common.Utils.UserInfoParser.setParser(this.appOptions.canUseReviewPermissions);
this.headerView.setUserName(Common.Utils.UserInfoParser.getParsedName(this.appOptions.user.fullname));
} else } else
this.appOptions.canModifyFilter = true; this.appOptions.canModifyFilter = true;

View file

@ -1801,7 +1801,7 @@ define([
visible = this._ShowHideInfoItem(this.lblModifyDate, !!value) || visible; visible = this._ShowHideInfoItem(this.lblModifyDate, !!value) || visible;
value = props.asc_getLastModifiedBy(); value = props.asc_getLastModifiedBy();
if (value) if (value)
this.lblModifyBy.text(value); this.lblModifyBy.text(Common.Utils.UserInfoParser.getParsedName(value));
visible = this._ShowHideInfoItem(this.lblModifyBy, !!value) || visible; visible = this._ShowHideInfoItem(this.lblModifyBy, !!value) || visible;
$('tr.divider.modify', this.el)[visible?'show':'hide'](); $('tr.divider.modify', this.el)[visible?'show':'hide']();

View file

@ -361,7 +361,7 @@ define([ 'text!spreadsheeteditor/main/app/template/NameManagerDlg.template',
if (usersStore){ if (usersStore){
var rec = usersStore.findUser(id); var rec = usersStore.findUser(id);
if (rec) if (rec)
return rec.get('username'); return Common.Utils.UserInfoParser.getParsedName(rec.get('username'));
} }
return this.guestText; return this.guestText;
}, },