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) {
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;
}
return this;
@ -183,7 +193,8 @@ define([
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),
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.popoverChanges.reset(changes);
@ -195,14 +206,15 @@ define([
this.getPopover().showReview(animate, lock, lockUser);
if (this.appConfig.canReview && !this.appConfig.isReviewOnly && this._state.lock !== lock) {
this.view.btnAccept.setDisabled(lock==true);
this.view.btnReject.setDisabled(lock==true);
var btnlock = lock || !editable;
if (this.appConfig.canReview && !this.appConfig.isReviewOnly && this._state.lock !== btnlock) {
this.view.btnAccept.setDisabled(btnlock);
this.view.btnReject.setDisabled(btnlock);
if (this.dlgChanges) {
this.dlgChanges.btnAccept.setDisabled(lock==true);
this.dlgChanges.btnReject.setDisabled(lock==true);
this.dlgChanges.btnAccept.setDisabled(btnlock);
this.dlgChanges.btnReject.setDisabled(btnlock);
}
this._state.lock = lock;
this._state.lock = btnlock;
}
this._state.posx = posX;
this._state.posy = posY;
@ -459,7 +471,7 @@ define([
scope : me.view,
hint : !me.appConfig.canReview,
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);
@ -467,10 +479,15 @@ define([
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){
if (this.userCollection && id!==null){
var rec = this.userCollection.findUser(id);
if (rec) return rec.get('username');
if (rec) return Common.Utils.UserInfoParser.getParsedName(rec.get('username'));
}
return '';
},

View file

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

View file

@ -959,4 +959,31 @@ Common.Utils.ModalWindow = new(function() {
return count>0;
}
}
})();
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) {
return Common.Utils.String.htmlEncode(username);
return Common.Utils.String.htmlEncode(Common.Utils.UserInfoParser.getParsedName(username));
},
hide: function () {

View file

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

View file

@ -128,7 +128,9 @@ define([
$userList.html(templateUserList({
users: collection.chain().filter(function(item){return item.get('online') && !item.get('view')}).groupBy(function(item) {return item.get('idOriginal');}).value(),
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({

View file

@ -90,7 +90,7 @@ define([
'<% } %>',
'<div class="user-name">',
'<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>',
'<% if (canRestore && selected) { %>',
'<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']);
});
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]);
});
@ -116,7 +116,7 @@ define([
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]);
});
@ -202,14 +202,14 @@ define([
this.btnAccept = new Common.UI.Button({
cls: 'btn-toolbar x-huge icon-top',
caption: this.txtAccept,
split: true,
split: !this.appConfig.canUseReviewPermissions,
iconCls: 'toolbar__icon btn-review-save'
});
this.btnReject = new Common.UI.Button({
cls: 'btn-toolbar x-huge icon-top',
caption: this.txtReject,
split: true,
split: !this.appConfig.canUseReviewPermissions,
iconCls: 'toolbar__icon btn-review-deny'
});
@ -358,36 +358,37 @@ define([
if ( config.canReview ) {
me.btnTurnOn.updateHint(me.tipReview);
me.btnAccept.setMenu(
new Common.UI.Menu({
items: [
{
caption: me.txtAcceptCurrent,
value: 'current'
},
{
caption: me.txtAcceptAll,
value: 'all'
}
]
})
);
if (!me.appConfig.canUseReviewPermissions) {
me.btnAccept.setMenu(
new Common.UI.Menu({
items: [
{
caption: me.txtAcceptCurrent,
value: 'current'
},
{
caption: me.txtAcceptAll,
value: 'all'
}
]
})
);
me.btnReject.setMenu(
new Common.UI.Menu({
items: [
{
caption: me.txtRejectCurrent,
value: 'current'
},
{
caption: me.txtRejectAll,
value: 'all'
}
]
})
);
}
me.btnAccept.updateHint([me.tipAcceptCurrent, me.txtAcceptChanges]);
me.btnReject.setMenu(
new Common.UI.Menu({
items: [
{
caption: me.txtRejectCurrent,
value: 'current'
},
{
caption: me.txtRejectAll,
value: 'all'
}
]
})
);
me.btnReject.updateHint([me.tipRejectCurrent, me.txtRejectChanges]);
if (config.canFeatureComparison) {
@ -583,7 +584,7 @@ define([
},
getUserName: function (username) {
return Common.Utils.String.htmlEncode(username);
return Common.Utils.String.htmlEncode(Common.Utils.UserInfoParser.getParsedName(username));
},
turnChanges: function(state) {
@ -771,7 +772,7 @@ define([
caption : this.txtAccept,
split : true,
disabled : this.mode.isReviewOnly,
menu : new Common.UI.Menu({
menu : this.mode.canUseReviewPermissions ? false : new Common.UI.Menu({
items: [
this.mnuAcceptCurrent = new Common.UI.MenuItem({
caption: this.txtAcceptCurrent,
@ -791,7 +792,7 @@ define([
caption : this.txtReject,
split : true,
disabled : this.mode.isReviewOnly,
menu : new Common.UI.Menu({
menu : this.mode.canUseReviewPermissions ? false : new Common.UI.Menu({
items: [
this.mnuRejectCurrent = new Common.UI.MenuItem({
caption: this.txtRejectCurrent,
@ -819,7 +820,7 @@ define([
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]);
});
@ -827,7 +828,7 @@ define([
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]);
});

View file

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

View file

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

View file

@ -1121,7 +1121,7 @@ define([
visible = this._ShowHideInfoItem(this.lblModifyDate, !!value) || visible;
value = props.asc_getLastModifiedBy();
if (value)
this.lblModifyBy.text(value);
this.lblModifyBy.text(Common.Utils.UserInfoParser.getParsedName(value));
visible = this._ShowHideInfoItem(this.lblModifyBy, !!value) || visible;
$('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));
appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header');
appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '')
.setUserName(this.appOptions.user.fullname);
appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '');
if (this.editorConfig.lang)
this.api.asc_setLocale(this.editorConfig.lang);
@ -976,6 +975,10 @@ define([
if (this.appOptions.canBranding)
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.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins);
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions);

View file

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

View file

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

View file

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

View file

@ -360,8 +360,7 @@ define([
this.appOptions.canFeaturePivot = !!this.api.asc_isSupportFeature("pivot-tables");
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 : '')
.setUserName(this.appOptions.user.fullname);
this.headerView.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '');
var reg = Common.localStorage.getItem("sse-settings-reg-settings"),
isUseBaseSeparator = Common.localStorage.getBool("sse-settings-use-base-separator", true),
@ -1032,6 +1031,9 @@ define([
this.headerView.setBranding(this.editorConfig.customization);
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
this.appOptions.canModifyFilter = true;

View file

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

View file

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