[DE] Change name for guest user

This commit is contained in:
Julia Radzhabova 2020-12-10 14:48:03 +03:00
parent 3adb8f9629
commit 583065a6af
6 changed files with 224 additions and 24 deletions

View file

@ -169,7 +169,6 @@ define([
if (data) { if (data) {
this.currentUserId = data.config.user.id; this.currentUserId = data.config.user.id;
this.currentUserName = data.config.user.fullname;
this.sdkViewName = data['sdkviewname'] || this.sdkViewName; this.sdkViewName = data['sdkviewname'] || this.sdkViewName;
this.hintmode = data['hintmode'] || false; this.hintmode = data['hintmode'] || false;
this.viewmode = data['viewmode'] || false; this.viewmode = data['viewmode'] || false;
@ -217,7 +216,7 @@ define([
comment.asc_putTime(this.utcDateToString(new Date())); comment.asc_putTime(this.utcDateToString(new Date()));
comment.asc_putOnlyOfficeTime(this.ooDateToString(new Date())); comment.asc_putOnlyOfficeTime(this.ooDateToString(new Date()));
comment.asc_putUserId(this.currentUserId); comment.asc_putUserId(this.currentUserId);
comment.asc_putUserName(this.currentUserName); comment.asc_putUserName(Common.Utils.UserInfoParser.getCurrentName());
comment.asc_putSolved(false); comment.asc_putSolved(false);
if (!_.isUndefined(comment.asc_putDocumentFlag)) { if (!_.isUndefined(comment.asc_putDocumentFlag)) {
@ -355,7 +354,7 @@ define([
ascComment.asc_putTime(t.utcDateToString(new Date(comment.get('time')))); ascComment.asc_putTime(t.utcDateToString(new Date(comment.get('time'))));
ascComment.asc_putOnlyOfficeTime(t.ooDateToString(new Date(comment.get('time')))); ascComment.asc_putOnlyOfficeTime(t.ooDateToString(new Date(comment.get('time'))));
ascComment.asc_putUserId(t.currentUserId); ascComment.asc_putUserId(t.currentUserId);
ascComment.asc_putUserName(t.currentUserName); ascComment.asc_putUserName(Common.Utils.UserInfoParser.getCurrentName());
ascComment.asc_putSolved(comment.get('resolved')); ascComment.asc_putSolved(comment.get('resolved'));
ascComment.asc_putGuid(comment.get('guid')); ascComment.asc_putGuid(comment.get('guid'));
ascComment.asc_putUserData(comment.get('userdata')); ascComment.asc_putUserData(comment.get('userdata'));
@ -432,7 +431,7 @@ define([
if (reply.get('id') === replyId && !_.isUndefined(replyVal)) { if (reply.get('id') === replyId && !_.isUndefined(replyVal)) {
addReply.asc_putText(replyVal); addReply.asc_putText(replyVal);
addReply.asc_putUserId(me.currentUserId); addReply.asc_putUserId(me.currentUserId);
addReply.asc_putUserName(me.currentUserName); addReply.asc_putUserName(Common.Utils.UserInfoParser.getCurrentName());
} else { } else {
addReply.asc_putText(reply.get('reply')); addReply.asc_putText(reply.get('reply'));
addReply.asc_putUserId(reply.get('userid')); addReply.asc_putUserId(reply.get('userid'));
@ -512,7 +511,7 @@ define([
addReply.asc_putTime(me.utcDateToString(new Date())); addReply.asc_putTime(me.utcDateToString(new Date()));
addReply.asc_putOnlyOfficeTime(me.ooDateToString(new Date())); addReply.asc_putOnlyOfficeTime(me.ooDateToString(new Date()));
addReply.asc_putUserId(me.currentUserId); addReply.asc_putUserId(me.currentUserId);
addReply.asc_putUserName(me.currentUserName); addReply.asc_putUserName(Common.Utils.UserInfoParser.getCurrentName());
ascComment.asc_addReply(addReply); ascComment.asc_addReply(addReply);
@ -1308,7 +1307,7 @@ define([
time: date.getTime(), time: date.getTime(),
date: this.dateToLocaleTimeString(date), date: this.dateToLocaleTimeString(date),
userid: this.currentUserId, userid: this.currentUserId,
username: this.currentUserName, username: Common.Utils.UserInfoParser.getCurrentName(),
usercolor: (user) ? user.get('color') : null, usercolor: (user) ? user.get('color') : null,
editTextInPopover: true, editTextInPopover: true,
showReplyInPopover: false, showReplyInPopover: false,
@ -1372,7 +1371,7 @@ define([
comment.asc_putTime(this.utcDateToString(new Date())); comment.asc_putTime(this.utcDateToString(new Date()));
comment.asc_putOnlyOfficeTime(this.ooDateToString(new Date())); comment.asc_putOnlyOfficeTime(this.ooDateToString(new Date()));
comment.asc_putUserId(this.currentUserId); comment.asc_putUserId(this.currentUserId);
comment.asc_putUserName(this.currentUserName); comment.asc_putUserName(Common.Utils.UserInfoParser.getCurrentName());
comment.asc_putSolved(false); comment.asc_putSolved(false);
if (!_.isUndefined(comment.asc_putDocumentFlag)) if (!_.isUndefined(comment.asc_putDocumentFlag))

View file

@ -118,16 +118,6 @@ 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;
@ -482,7 +472,7 @@ define([
checkUserGroups: function(username) { checkUserGroups: function(username) {
var groups = Common.Utils.UserInfoParser.getParsedGroups(username); var groups = Common.Utils.UserInfoParser.getParsedGroups(username);
return this.currentUserGroups && groups && (_.intersection(this.currentUserGroups, (groups.length>0) ? groups : [""]).length>0); return Common.Utils.UserInfoParser.getCurrentGroups() && groups && (_.intersection(Common.Utils.UserInfoParser.getCurrentGroups(), (groups.length>0) ? groups : [""]).length>0);
}, },
getUserName: function(id){ getUserName: function(id){

View file

@ -98,12 +98,19 @@ define(['gateway'], function () {
var value = _getItem(name); var value = _getItem(name);
defValue = defValue || false; defValue = defValue || false;
return (value!==null) ? (parseInt(value) != 0) : defValue; return (value!==null) ? (parseInt(value) != 0) : defValue;
} };
var _getItemExists = function (name) { var _getItemExists = function (name) {
var value = _getItem(name); var value = _getItem(name);
return value !== null; return value !== null;
} };
var _removeItem = function(name) {
if (_lsAllowed)
localStorage.removeItem(name);
else
delete _store[name];
};
try { try {
var _lsAllowed = !!window.localStorage; var _lsAllowed = !!window.localStorage;
@ -122,6 +129,7 @@ define(['gateway'], function () {
getBool: _getItemAsBool, getBool: _getItemAsBool,
setBool: _setItemAsBool, setBool: _setItemAsBool,
setItem: _setItem, setItem: _setItem,
removeItem: _removeItem,
setKeysFilter: function(value) { setKeysFilter: function(value) {
_filter = value; _filter = value;
}, },

View file

@ -967,8 +967,11 @@ Common.Utils.ModalWindow = new(function() {
})(); })();
Common.Utils.UserInfoParser = new(function() { Common.Utils.UserInfoParser = new(function() {
var parse = false; var parse = false,
var separator = String.fromCharCode(160); separator = String.fromCharCode(160),
username = '',
usergroups,
permissions;
return { return {
setParser: function(value) { setParser: function(value) {
parse = !!value; parse = !!value;
@ -994,6 +997,32 @@ Common.Utils.UserInfoParser = new(function() {
return groups; return groups;
} else } else
return undefined; return undefined;
},
setCurrentName: function(name) {
username = name;
this.setReviewPermissions(permissions);
},
getCurrentName: function() {
return username;
},
setReviewPermissions: function(reviewPermissions) {
if (reviewPermissions) {
var arr = [],
groups = this.getParsedGroups(username);
groups && groups.forEach(function(group) {
var item = reviewPermissions[group.trim()];
item && (arr = arr.concat(item));
});
usergroups = arr;
permissions = reviewPermissions;
}
},
getCurrentGroups: function() {
return usergroups;
} }
} }
})(); })();

View file

@ -0,0 +1,136 @@
/*
*
* (c) Copyright Ascensio System SIA 2010-2020
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
/**
* UserNameDialog.js
*
* Created by Julia Radzhabova on 09.12.2020
* Copyright (c) 2020 Ascensio System SIA. All rights reserved.
*
*/
define([
'common/main/lib/component/Window',
'common/main/lib/component/InputField'
], function () { 'use strict';
Common.Views.UserNameDialog = Common.UI.Window.extend(_.extend({
options: {
width: 330,
header: false,
modal : false,
cls: 'modal-dlg',
buttons: ['ok', 'cancel']
},
initialize : function(options) {
_.extend(this.options, options || {});
this.template = [
'<div class="box">',
'<div class="input-row">',
'<label>' + (this.options.label ? this.options.label : this.textLabel) + '</label>',
'</div>',
'<div id="id-dlg-username-caption" class="input-row"></div>',
'<div id="id-dlg-username-chk-use" class="input-row" style="margin-top: 15px;"></div>',
'</div>'
].join('');
this.options.tpl = _.template(this.template)(this.options);
Common.UI.Window.prototype.initialize.call(this, this.options);
},
render: function() {
Common.UI.Window.prototype.render.call(this);
var me = this;
me.inputLabel = new Common.UI.InputField({
el : $('#id-dlg-username-caption'),
allowBlank : false,
blankError : me.options.error ? me.options.error : me.textLabelError,
style : 'width: 100%;',
maxLength : 128,
validateOnBlur: false,
validation : me.options.validation || function(value) {
return value ? true : '';
}
});
me.inputLabel.setValue(this.options.value || '' );
me.chAlwaysUse = new Common.UI.CheckBox({
el: $('#id-dlg-username-chk-use'),
labelText: this.textUse
});
var $window = this.getChild();
$window.find('.btn').on('click', _.bind(this.onBtnClick, this));
},
show: function() {
Common.UI.Window.prototype.show.apply(this, arguments);
var me = this;
_.delay(function(){
me.getChild('input').focus();
},50);
},
onPrimary: function(event) {
this._handleInput('ok');
return false;
},
onBtnClick: function(event) {
this._handleInput(event.currentTarget.attributes['result'].value);
},
_handleInput: function(state) {
if (this.options.handler) {
if (state == 'ok') {
if (this.inputLabel.checkValidate() !== true) {
this.inputLabel.cmpEl.find('input').focus();
return;
}
}
this.options.handler.call(this, state, {input: this.inputLabel.getValue(), checkbox: this.chAlwaysUse.getValue()=='checked'});
}
this.close();
},
textLabel: 'Label:',
textLabelError: 'Label must not be empty.',
textUse: 'Always use this name'
}, Common.Views.UserNameDialog || {}));
});

View file

@ -49,6 +49,7 @@ define([
'common/main/lib/controller/Fonts', 'common/main/lib/controller/Fonts',
'common/main/lib/collection/TextArt', 'common/main/lib/collection/TextArt',
'common/main/lib/view/OpenDialog', 'common/main/lib/view/OpenDialog',
'common/main/lib/view/UserNameDialog',
'common/main/lib/util/LocalStorage', 'common/main/lib/util/LocalStorage',
'documenteditor/main/app/collection/ShapeGroups', 'documenteditor/main/app/collection/ShapeGroups',
'documenteditor/main/app/collection/EquationGroups' 'documenteditor/main/app/collection/EquationGroups'
@ -338,8 +339,9 @@ define([
loadConfig: function(data) { loadConfig: function(data) {
this.editorConfig = $.extend(this.editorConfig, data.config); this.editorConfig = $.extend(this.editorConfig, data.config);
var value = Common.localStorage.getItem("guest-username");
this.editorConfig.user = this.editorConfig.user =
this.appOptions.user = Common.Utils.fillUserInfo(this.editorConfig.user, this.editorConfig.lang, this.textAnonymous); this.appOptions.user = Common.Utils.fillUserInfo(this.editorConfig.user, this.editorConfig.lang, value ? (value + ' (' + this.textGuest + ')' ) : this.textAnonymous);
this.appOptions.isDesktopApp = this.editorConfig.targetApp == 'desktop'; this.appOptions.isDesktopApp = this.editorConfig.targetApp == 'desktop';
this.appOptions.canCreateNew = this.editorConfig.canRequestCreateNew || !_.isEmpty(this.editorConfig.createUrl); this.appOptions.canCreateNew = this.editorConfig.canRequestCreateNew || !_.isEmpty(this.editorConfig.createUrl);
this.appOptions.canOpenRecent = this.editorConfig.recent !== undefined && !this.appOptions.isDesktopApp; this.appOptions.canOpenRecent = this.editorConfig.recent !== undefined && !this.appOptions.isDesktopApp;
@ -1117,6 +1119,8 @@ define([
$('#editor-container').css('overflow', ''); $('#editor-container').css('overflow', '');
$('.doc-placeholder').remove(); $('.doc-placeholder').remove();
!Common.localStorage.getItem("guest-username") && this.showRenameUserDialog();
}, },
onLicenseChanged: function(params) { onLicenseChanged: function(params) {
@ -1281,6 +1285,8 @@ define([
this.appOptions.canUseReviewPermissions = this.appOptions.canLicense && this.editorConfig.customization && this.editorConfig.customization.reviewPermissions && (typeof (this.editorConfig.customization.reviewPermissions) == 'object'); this.appOptions.canUseReviewPermissions = this.appOptions.canLicense && this.editorConfig.customization && this.editorConfig.customization.reviewPermissions && (typeof (this.editorConfig.customization.reviewPermissions) == 'object');
Common.Utils.UserInfoParser.setParser(this.appOptions.canUseReviewPermissions); Common.Utils.UserInfoParser.setParser(this.appOptions.canUseReviewPermissions);
Common.Utils.UserInfoParser.setCurrentName(this.appOptions.user.fullname);
this.appOptions.canUseReviewPermissions && Common.Utils.UserInfoParser.setReviewPermissions(this.editorConfig.customization.reviewPermissions);
appHeader.setUserName(Common.Utils.UserInfoParser.getParsedName(this.appOptions.user.fullname)); appHeader.setUserName(Common.Utils.UserInfoParser.getParsedName(this.appOptions.user.fullname));
this.appOptions.canRename && appHeader.setCanRename(true); this.appOptions.canRename && appHeader.setCanRename(true);
@ -2356,6 +2362,34 @@ define([
me.api.asc_SetAutoCorrectHyphensWithDash(value); me.api.asc_SetAutoCorrectHyphensWithDash(value);
}, },
showRenameUserDialog: function() {
var me = this;
var value = Common.localStorage.getItem("guest-username");
(new Common.Views.UserNameDialog({
label: this.textRenameLabel,
error: this.textRenameError,
value: value || '',
validation: function(value) {
return value.length<128 ? true : me.textLongName;
},
handler: function(result, {input: input, checkbox: checkbox}) {
if (result == 'ok') {
var name = input + ' (' + me.textGuest + ')';
var _user = new Asc.asc_CUserInfo();
_user.put_FullName(name);
var docInfo = new Asc.asc_CDocInfo();
docInfo.put_UserInfo(_user);
me.api.asc_setDocInfo(docInfo);
Common.Utils.UserInfoParser.setCurrentName(name);
appHeader.setUserName(Common.Utils.UserInfoParser.getParsedName(name));
checkbox ? Common.localStorage.setItem("guest-username", input) : Common.localStorage.removeItem("guest-username");
}
}
})).show();
},
leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.', leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.',
criticalErrorTitle: 'Error', criticalErrorTitle: 'Error',
notcriticalErrorTitle: 'Warning', notcriticalErrorTitle: 'Warning',
@ -2712,7 +2746,11 @@ define([
textRemember: 'Remember my choice', textRemember: 'Remember my choice',
warnLicenseLimitedRenewed: 'License needs to be renewed.<br>You have a limited access to document editing functionality.<br>Please contact your administrator to get full access', warnLicenseLimitedRenewed: 'License needs to be renewed.<br>You have a limited access to document editing functionality.<br>Please contact your administrator to get full access',
warnLicenseLimitedNoAccess: 'License expired.<br>You have no access to document editing functionality.<br>Please contact your administrator.', warnLicenseLimitedNoAccess: 'License expired.<br>You have no access to document editing functionality.<br>Please contact your administrator.',
saveErrorTextDesktop: 'This file cannot be saved or created.<br>Possible reasons are: <br>1. The file is read-only. <br>2. The file is being edited by other users. <br>3. The disk is full or corrupted.' saveErrorTextDesktop: 'This file cannot be saved or created.<br>Possible reasons are: <br>1. The file is read-only. <br>2. The file is being edited by other users. <br>3. The disk is full or corrupted.',
textRenameLabel: 'Enter a name to be used for collaboration',
textRenameError: 'User name must not be empty.',
textLongName: 'Enter a name that is less than 128 characters.',
textGuest: 'Guest'
} }
})(), DE.Controllers.Main || {})) })(), DE.Controllers.Main || {}))
}); });