From e8dcb54c788761cb80d9a03e1c71315f8b8fec5b Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 18 Dec 2020 13:23:14 +0300 Subject: [PATCH] Fix changing user name --- apps/common/main/lib/controller/Chat.js | 1 + .../main/app/controller/Main.js | 4 +- .../mobile/app/controller/DocumentHolder.js | 1 + .../main/app/controller/Main.js | 56 +++++++++++++++++-- .../main/app/controller/Main.js | 54 +++++++++++++++++- 5 files changed, 107 insertions(+), 9 deletions(-) diff --git a/apps/common/main/lib/controller/Chat.js b/apps/common/main/lib/controller/Chat.js index 5731e4721..aa895823d 100644 --- a/apps/common/main/lib/controller/Chat.js +++ b/apps/common/main/lib/controller/Chat.js @@ -169,6 +169,7 @@ define([ })); } else { user.set({online: change.asc_getState()}); + user.set({username: change.asc_getUserName()}); } } }, diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 89daacf96..7483f8d41 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -393,7 +393,7 @@ define([ $('#editor-container').append('
' + '
'.repeat(20) + '
'); } - var value = Common.localStorage.getItem("de-macros-mode"); + value = Common.localStorage.getItem("de-macros-mode"); if (value === null) { value = this.editorConfig.customization ? this.editorConfig.customization.macrosMode : 'warn'; value = (value == 'enable') ? 1 : (value == 'disable' ? 2 : 0); @@ -2386,7 +2386,7 @@ define([ var docInfo = new Asc.asc_CDocInfo(); docInfo.put_UserInfo(_user); - me.api.asc_setDocInfo(docInfo); + me.api.asc_changeDocInfo(docInfo); Common.Utils.UserInfoParser.setCurrentName(name); appHeader.setUserName(Common.Utils.UserInfoParser.getParsedName(name)); diff --git a/apps/documenteditor/mobile/app/controller/DocumentHolder.js b/apps/documenteditor/mobile/app/controller/DocumentHolder.js index 4684d4a32..3370f19f3 100644 --- a/apps/documenteditor/mobile/app/controller/DocumentHolder.js +++ b/apps/documenteditor/mobile/app/controller/DocumentHolder.js @@ -439,6 +439,7 @@ define([ })); } else { user.set({online: change.asc_getState()}); + user.set({username: change.asc_getUserName()}); } } }, diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index af7ee014f..67621ed1d 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -49,6 +49,7 @@ define([ 'common/main/lib/controller/Fonts', 'common/main/lib/collection/TextArt', 'common/main/lib/view/OpenDialog', + 'common/main/lib/view/UserNameDialog', 'common/main/lib/util/LocalStorage', 'presentationeditor/main/app/collection/ShapeGroups', 'presentationeditor/main/app/collection/SlideLayouts', @@ -303,8 +304,10 @@ define([ loadConfig: function(data) { this.editorConfig = $.extend(this.editorConfig, data.config); + var value = Common.localStorage.getItem("guest-username"); + Common.Utils.InternalSettings.set("guest-username", value); this.editorConfig.user = - this.appOptions.user = Common.Utils.fillUserInfo(data.config.user, this.editorConfig.lang, this.textAnonymous); + this.appOptions.user = Common.Utils.fillUserInfo(data.config.user, this.editorConfig.lang, value ? (value + ' (' + this.textGuest + ')' ) : this.textAnonymous); this.appOptions.isDesktopApp = this.editorConfig.targetApp == 'desktop'; this.appOptions.canCreateNew = this.editorConfig.canRequestCreateNew || !_.isEmpty(this.editorConfig.createUrl); this.appOptions.canOpenRecent = this.editorConfig.recent !== undefined && !this.appOptions.isDesktopApp; @@ -332,6 +335,8 @@ define([ this.appOptions.canRequestSharingSettings = this.editorConfig.canRequestSharingSettings; this.appOptions.mentionShare = !((typeof (this.appOptions.customization) == 'object') && (this.appOptions.customization.mentionShare==false)); + this.appOptions.user.guest && Common.NotificationCenter.on('user:rename', _.bind(this.showRenameUserDialog, this)); + appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header'); appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : ''); @@ -346,7 +351,7 @@ define([ $('#editor-container').append('
'); } - var value = Common.localStorage.getItem("pe-macros-mode"); + value = Common.localStorage.getItem("pe-macros-mode"); if (value === null) { value = this.editorConfig.customization ? this.editorConfig.customization.macrosMode : 'warn'; value = (value == 'enable') ? 1 : (value == 'disable' ? 2 : 0); @@ -841,6 +846,7 @@ define([ Common.Gateway.documentReady(); $('.doc-placeholder').remove(); + this.appOptions.user.guest && (Common.Utils.InternalSettings.get("guest-username")===null) && this.showRenameUserDialog(); }, onLicenseChanged: function(params) { @@ -983,6 +989,8 @@ define([ 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.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)); this.appOptions.canRename && appHeader.setCanRename(true); @@ -1998,7 +2006,43 @@ define([ me.api.asc_SetAutoCorrectHyphensWithDash(value); }, - + + showRenameUserDialog: function() { + if (this._renameDialog) return; + + var me = this; + var value = Common.Utils.InternalSettings.get("guest-username"); + this._renameDialog = new Common.Views.UserNameDialog({ + label: this.textRenameLabel, + error: this.textRenameError, + value: value || '', + check: (value!==null), + validation: function(value) { + return value.length<128 ? true : me.textLongName; + }, + handler: function(result, {input: input, checkbox: checkbox}) { + if (result == 'ok') { + var name = input ? input + ' (' + me.textGuest + ')' : me.textAnonymous; + var _user = new Asc.asc_CUserInfo(); + _user.put_FullName(name); + + var docInfo = new Asc.asc_CDocInfo(); + docInfo.put_UserInfo(_user); + me.api.asc_changeDocInfo(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"); + Common.Utils.InternalSettings.set("guest-username", input); + } + } + }); + this._renameDialog.on('close', function() { + me._renameDialog = undefined; + }); + this._renameDialog.show(Common.Utils.innerWidth() - this._renameDialog.options.width - 15, 30); + }, + // Translation 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', @@ -2355,7 +2399,11 @@ define([ textRemember: 'Remember my choice', warnLicenseLimitedRenewed: 'License needs to be renewed.
You have a limited access to document editing functionality.
Please contact your administrator to get full access', warnLicenseLimitedNoAccess: 'License expired.
You have no access to document editing functionality.
Please contact your administrator.', - saveErrorTextDesktop: 'This file cannot be saved or created.
Possible reasons are:
1. The file is read-only.
2. The file is being edited by other users.
3. The disk is full or corrupted.' + saveErrorTextDesktop: 'This file cannot be saved or created.
Possible reasons are:
1. The file is read-only.
2. The file is being edited by other users.
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' } })(), PE.Controllers.Main || {})) }); diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index a8fcf876e..3b5dca8ad 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -49,6 +49,7 @@ define([ 'common/main/lib/controller/Fonts', 'common/main/lib/collection/TextArt', 'common/main/lib/view/OpenDialog', + 'common/main/lib/view/UserNameDialog', 'common/main/lib/util/LanguageInfo', 'common/main/lib/util/LocalStorage', 'spreadsheeteditor/main/app/collection/ShapeGroups', @@ -326,8 +327,10 @@ define([ this.appOptions = {}; + var value = Common.localStorage.getItem("guest-username"); + Common.Utils.InternalSettings.set("guest-username", value); 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.canCreateNew = this.editorConfig.canRequestCreateNew || !_.isEmpty(this.editorConfig.createUrl); this.appOptions.canOpenRecent = this.editorConfig.recent !== undefined && !this.appOptions.isDesktopApp; @@ -362,6 +365,8 @@ define([ this.appOptions.canFeaturePivot = true; this.appOptions.canFeatureViews = !!this.api.asc_isSupportFeature("sheet-views"); + this.appOptions.user.guest && Common.NotificationCenter.on('user:rename', _.bind(this.showRenameUserDialog, this)); + 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 : ''); @@ -386,7 +391,7 @@ define([ this.api.asc_setLocale(reg, decimal, group); } - var value = Common.localStorage.getBool("sse-settings-r1c1"); + value = Common.localStorage.getBool("sse-settings-r1c1"); Common.Utils.InternalSettings.set("sse-settings-r1c1", value); this.api.asc_setR1C1Mode(value); @@ -906,6 +911,7 @@ define([ } else checkWarns(); Common.Gateway.documentReady(); + this.appOptions.user.guest && (Common.Utils.InternalSettings.get("guest-username")===null) && this.showRenameUserDialog(); }, onLicenseChanged: function(params) { @@ -1039,6 +1045,8 @@ define([ this.appOptions.canRename && this.headerView.setCanRename(true); 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.setCurrentName(this.appOptions.user.fullname); + this.appOptions.canUseReviewPermissions && Common.Utils.UserInfoParser.setReviewPermissions(this.editorConfig.customization.reviewPermissions); this.headerView.setUserName(Common.Utils.UserInfoParser.getParsedName(this.appOptions.user.fullname)); } else this.appOptions.canModifyFilter = true; @@ -2315,6 +2323,42 @@ define([ me.api.asc_setIncludeNewRowColTable(value); }, + showRenameUserDialog: function() { + if (this._renameDialog) return; + + var me = this; + var value = Common.Utils.InternalSettings.get("guest-username"); + this._renameDialog = new Common.Views.UserNameDialog({ + label: this.textRenameLabel, + error: this.textRenameError, + value: value || '', + check: (value!==null), + validation: function(value) { + return value.length<128 ? true : me.textLongName; + }, + handler: function(result, {input: input, checkbox: checkbox}) { + if (result == 'ok') { + var name = input ? input + ' (' + me.textGuest + ')' : me.textAnonymous; + var _user = new Asc.asc_CUserInfo(); + _user.put_FullName(name); + + var docInfo = new Asc.asc_CDocInfo(); + docInfo.put_UserInfo(_user); + me.api.asc_changeDocInfo(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"); + Common.Utils.InternalSettings.set("guest-username", input); + } + } + }); + this._renameDialog.on('close', function() { + me._renameDialog = undefined; + }); + this._renameDialog.show(Common.Utils.innerWidth() - this._renameDialog.options.width - 15, 30); + }, + 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', notcriticalErrorTitle: 'Warning', @@ -2694,7 +2738,11 @@ define([ errorChangeFilteredRange: 'This will change a filtered range on your worksheet.
To complete this task, please remove AutoFilters.', warnLicenseLimitedRenewed: 'License needs to be renewed.
You have a limited access to document editing functionality.
Please contact your administrator to get full access', warnLicenseLimitedNoAccess: 'License expired.
You have no access to document editing functionality.
Please contact your administrator.', - saveErrorTextDesktop: 'This file cannot be saved or created.
Possible reasons are:
1. The file is read-only.
2. The file is being edited by other users.
3. The disk is full or corrupted.' + saveErrorTextDesktop: 'This file cannot be saved or created.
Possible reasons are:
1. The file is read-only.
2. The file is being edited by other users.
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' } })(), SSE.Controllers.Main || {})) });