Refactoring change access rights. Fix Bug 43103, Bug 43105

This commit is contained in:
Julia Radzhabova 2019-10-09 13:23:40 +03:00
parent 6589ca76c2
commit 611c12e885
11 changed files with 62 additions and 102 deletions

View file

@ -101,6 +101,8 @@ define([
Common.NotificationCenter.on('spelling:turn', this.onTurnSpelling.bind(this)); Common.NotificationCenter.on('spelling:turn', this.onTurnSpelling.bind(this));
Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this)); Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this));
Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this)); Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this));
Common.NotificationCenter.on('collaboration:sharing', this.changeAccessRights.bind(this));
Common.NotificationCenter.on('collaboration:sharingdeny', this.onLostEditRights.bind(this));
this.userCollection.on('reset', _.bind(this.onUpdateUsers, this)); this.userCollection.on('reset', _.bind(this.onUpdateUsers, this));
this.userCollection.on('add', _.bind(this.onUpdateUsers, this)); this.userCollection.on('add', _.bind(this.onUpdateUsers, this));
@ -112,6 +114,7 @@ define([
this.currentUserId = data.config.user.id; this.currentUserId = data.config.user.id;
this.sdkViewName = data['sdkviewname'] || this.sdkViewName; this.sdkViewName = data['sdkviewname'] || this.sdkViewName;
} }
return this;
}, },
setApi: function (api) { setApi: function (api) {
if (api) { if (api) {
@ -130,9 +133,16 @@ define([
this.popoverChanges = new Common.Collections.ReviewChanges(); this.popoverChanges = new Common.Collections.ReviewChanges();
this.view = this.createView('Common.Views.ReviewChanges', { mode: mode }); this.view = this.createView('Common.Views.ReviewChanges', { mode: mode });
!!this.appConfig.sharingSettingsUrl && this.appConfig.sharingSettingsUrl.length && Common.Gateway.on('showsharingsettings', _.bind(this.changeAccessRights, this));
!!this.appConfig.sharingSettingsUrl && this.appConfig.sharingSettingsUrl.length && Common.Gateway.on('setsharingsettings', _.bind(this.setSharingSettings, this));
return this; return this;
}, },
loadDocument: function(data) {
this.document = data.doc;
},
SetDisabled: function(state) { SetDisabled: function(state) {
if (this.dlgChanges) if (this.dlgChanges)
this.dlgChanges.close(); this.dlgChanges.close();
@ -724,9 +734,34 @@ define([
}, },
onLostEditRights: function() { onLostEditRights: function() {
this._readonlyRights = true;
this.view && this.view.onLostEditRights(); this.view && this.view.onLostEditRights();
}, },
changeAccessRights: function(btn,event,opts) {
if (this._docAccessDlg || this._readonlyRights) return;
var me = this;
me._docAccessDlg = new Common.Views.DocumentAccessDialog({
settingsurl: this.appConfig.sharingSettingsUrl
});
me._docAccessDlg.on('accessrights', function(obj, rights){
me.setSharingSettings({sharingSettings: rights});
}).on('close', function(obj){
me._docAccessDlg = undefined;
});
me._docAccessDlg.show();
},
setSharingSettings: function(data) {
if (data) {
this.document.info.sharingSettings = data.sharingSettings;
Common.NotificationCenter.trigger('collaboration:sharingupdate', data.sharingSettings);
Common.NotificationCenter.trigger('mentions:clearusers', this);
}
},
onCoAuthoringDisconnect: function() { onCoAuthoringDisconnect: function() {
this.SetDisabled(true); this.SetDisabled(true);
}, },

View file

@ -190,7 +190,7 @@ define([
function onUsersClick(e) { function onUsersClick(e) {
if ( !$btnUsers.menu ) { if ( !$btnUsers.menu ) {
$panelUsers.removeClass('open'); $panelUsers.removeClass('open');
this.fireEvent('click:users', this); Common.NotificationCenter.trigger('collaboration:sharing');
} else { } else {
var usertip = $btnUsers.data('bs.tooltip'); var usertip = $btnUsers.data('bs.tooltip');
if ( usertip ) { if ( usertip ) {
@ -245,7 +245,7 @@ define([
var $labelChangeRights = $panelUsers.find('#tlb-change-rights'); var $labelChangeRights = $panelUsers.find('#tlb-change-rights');
$labelChangeRights.on('click', function(e) { $labelChangeRights.on('click', function(e) {
$panelUsers.removeClass('open'); $panelUsers.removeClass('open');
me.fireEvent('click:users', me); Common.NotificationCenter.trigger('collaboration:sharing');
}); });
$labelChangeRights[(!mode.isOffline && !mode.isReviewOnly && mode.sharingSettingsUrl && mode.sharingSettingsUrl.length)?'show':'hide'](); $labelChangeRights[(!mode.isOffline && !mode.isReviewOnly && mode.sharingSettingsUrl && mode.sharingSettingsUrl.length)?'show':'hide']();

View file

@ -62,7 +62,6 @@ define([
'hide': _.bind(this.onHideChat, this) 'hide': _.bind(this.onHideChat, this)
}, },
'Common.Views.Header': { 'Common.Views.Header': {
'click:users': _.bind(this.clickStatusbarUsers, this),
'file:settings': _.bind(this.clickToolbarSettings,this), 'file:settings': _.bind(this.clickToolbarSettings,this),
'history:show': function () { 'history:show': function () {
if ( !this.leftMenu.panelHistory.isVisible() ) if ( !this.leftMenu.panelHistory.isVisible() )
@ -532,10 +531,6 @@ define([
}, },
/** coauthoring begin **/ /** coauthoring begin **/
clickStatusbarUsers: function() {
this.leftMenu.menuFile.panels['rights'].changeAccessRights();
},
onHideChat: function() { onHideChat: function() {
$(this.leftMenu.btnChat.el).blur(); $(this.leftMenu.btnChat.el).blur();
Common.NotificationCenter.trigger('layout:changed', 'leftmenu'); Common.NotificationCenter.trigger('layout:changed', 'leftmenu');

View file

@ -1260,7 +1260,7 @@ define([
var me = this, var me = this,
application = this.getApplication(), application = this.getApplication(),
reviewController = application.getController('Common.Controllers.ReviewChanges'); reviewController = application.getController('Common.Controllers.ReviewChanges');
reviewController.setMode(me.appOptions).setConfig({config: me.editorConfig}, me.api); reviewController.setMode(me.appOptions).setConfig({config: me.editorConfig}, me.api).loadDocument({doc:me.document});
if (this.appOptions.isEdit || this.appOptions.isRestrictedEdit) { // set api events for toolbar in the Restricted Editing mode if (this.appOptions.isEdit || this.appOptions.isRestrictedEdit) { // set api events for toolbar in the Restricted Editing mode
var toolbarController = application.getController('Toolbar'); var toolbarController = application.getController('Toolbar');
@ -2074,6 +2074,7 @@ define([
var filemenu = this.getApplication().getController('LeftMenu').getView('LeftMenu').getMenu('file'); var filemenu = this.getApplication().getController('LeftMenu').getView('LeftMenu').getMenu('file');
filemenu.loadDocument({doc:this.document}); filemenu.loadDocument({doc:this.document});
filemenu.panels && filemenu.panels['info'] && filemenu.panels['info'].updateInfo(this.document); filemenu.panels && filemenu.panels['info'] && filemenu.panels['info'].updateInfo(this.document);
this.getApplication().getController('Common.Controllers.ReviewChanges').loadDocument({doc:this.document});
Common.Gateway.metaChange(meta); Common.Gateway.metaChange(meta);
}, },

View file

@ -1192,7 +1192,7 @@ define([
this.updateInfo(this.doc); this.updateInfo(this.doc);
Common.NotificationCenter.on('collaboration:sharing', this.changeAccessRights.bind(this)); Common.NotificationCenter.on('collaboration:sharingupdate', this.updateSharingSettings.bind(this));
Common.NotificationCenter.on('collaboration:sharingdeny', this.onLostEditRights.bind(this)); Common.NotificationCenter.on('collaboration:sharingdeny', this.onLostEditRights.bind(this));
this.$el = $(node).html($markup); this.$el = $(node).html($markup);
@ -1245,36 +1245,16 @@ define([
setMode: function(mode) { setMode: function(mode) {
this.sharingSettingsUrl = mode.sharingSettingsUrl; this.sharingSettingsUrl = mode.sharingSettingsUrl;
!!this.sharingSettingsUrl && this.sharingSettingsUrl.length && Common.Gateway.on('showsharingsettings', _.bind(this.changeAccessRights, this));
!!this.sharingSettingsUrl && this.sharingSettingsUrl.length && Common.Gateway.on('setsharingsettings', _.bind(this.setSharingSettings, this));
return this; return this;
}, },
changeAccessRights: function(btn,event,opts) { changeAccessRights: function(btn,event,opts) {
if (this._docAccessDlg || this._readonlyRights) return; Common.NotificationCenter.trigger('collaboration:sharing');
var me = this;
me._docAccessDlg = new Common.Views.DocumentAccessDialog({
settingsurl: this.sharingSettingsUrl
});
me._docAccessDlg.on('accessrights', function(obj, rights){
me.updateSharingSettings(rights);
}).on('close', function(obj){
me._docAccessDlg = undefined;
});
me._docAccessDlg.show();
},
setSharingSettings: function(data) {
data && this.updateSharingSettings(data.sharingSettings);
}, },
updateSharingSettings: function(rights) { updateSharingSettings: function(rights) {
this.doc.info.sharingSettings = rights;
this._ShowHideInfoItem('rights', this.doc.info.sharingSettings!==undefined && this.doc.info.sharingSettings!==null && this.doc.info.sharingSettings.length>0); this._ShowHideInfoItem('rights', this.doc.info.sharingSettings!==undefined && this.doc.info.sharingSettings!==null && this.doc.info.sharingSettings.length>0);
this.cntRights.html(this.templateRights({users: this.doc.info.sharingSettings})); this.cntRights.html(this.templateRights({users: this.doc.info.sharingSettings}));
Common.NotificationCenter.trigger('mentions:clearusers', this);
}, },
onLostEditRights: function() { onLostEditRights: function() {

View file

@ -62,8 +62,7 @@ define([
'hide': _.bind(this.onHideChat, this) 'hide': _.bind(this.onHideChat, this)
}, },
'Common.Views.Header': { 'Common.Views.Header': {
'file:settings': _.bind(this.clickToolbarSettings,this), 'file:settings': _.bind(this.clickToolbarSettings,this)
'click:users': _.bind(this.clickStatusbarUsers, this)
}, },
'Common.Views.Plugins': { 'Common.Views.Plugins': {
'plugin:open': _.bind(this.onPluginOpen, this), 'plugin:open': _.bind(this.onPluginOpen, this),
@ -368,10 +367,6 @@ define([
}, },
/** coauthoring begin **/ /** coauthoring begin **/
clickStatusbarUsers: function() {
this.leftMenu.menuFile.panels['rights'].changeAccessRights();
},
onHideChat: function() { onHideChat: function() {
$(this.leftMenu.btnChat.el).blur(); $(this.leftMenu.btnChat.el).blur();
Common.NotificationCenter.trigger('layout:changed', 'leftmenu'); Common.NotificationCenter.trigger('layout:changed', 'leftmenu');

View file

@ -970,22 +970,21 @@ define([
commentsController.setConfig({config: this.editorConfig, sdkviewname: '#id_main_parent'}, this.api); commentsController.setConfig({config: this.editorConfig, sdkviewname: '#id_main_parent'}, this.api);
} }
/** coauthoring end **/ /** coauthoring end **/
var me = this,
application = this.getApplication(),
reviewController = application.getController('Common.Controllers.ReviewChanges');
reviewController.setMode(me.appOptions).setConfig({config: me.editorConfig}, me.api).loadDocument({doc:me.document});
if (this.appOptions.isEdit) { if (this.appOptions.isEdit) {
var me = this, var toolbarController = application.getController('Toolbar'),
application = this.getApplication(),
toolbarController = application.getController('Toolbar'),
rightmenuController = application.getController('RightMenu'), rightmenuController = application.getController('RightMenu'),
fontsControllers = application.getController('Common.Controllers.Fonts'), fontsControllers = application.getController('Common.Controllers.Fonts');
reviewController = application.getController('Common.Controllers.ReviewChanges');
// me.getStore('SlideLayouts'); // me.getStore('SlideLayouts');
fontsControllers && fontsControllers.setApi(me.api); fontsControllers && fontsControllers.setApi(me.api);
toolbarController && toolbarController.setApi(me.api); toolbarController && toolbarController.setApi(me.api);
rightmenuController && rightmenuController.setApi(me.api); rightmenuController && rightmenuController.setApi(me.api);
reviewController.setMode(me.appOptions).setConfig({config: me.editorConfig}, me.api);
if (me.appOptions.canProtect) if (me.appOptions.canProtect)
application.getController('Common.Controllers.Protection').setMode(me.appOptions).setConfig({config: me.editorConfig}, me.api); application.getController('Common.Controllers.Protection').setMode(me.appOptions).setConfig({config: me.editorConfig}, me.api);
@ -1766,6 +1765,7 @@ define([
var filemenu = this.getApplication().getController('LeftMenu').getView('LeftMenu').getMenu('file'); var filemenu = this.getApplication().getController('LeftMenu').getView('LeftMenu').getMenu('file');
filemenu.loadDocument({doc:this.document}); filemenu.loadDocument({doc:this.document});
filemenu.panels && filemenu.panels['info'] && filemenu.panels['info'].updateInfo(this.document); filemenu.panels && filemenu.panels['info'] && filemenu.panels['info'].updateInfo(this.document);
this.getApplication().getController('Common.Controllers.ReviewChanges').loadDocument({doc:this.document});
Common.Gateway.metaChange(meta); Common.Gateway.metaChange(meta);
}, },

View file

@ -1010,7 +1010,7 @@ define([
}); });
} }
Common.NotificationCenter.on('collaboration:sharing', this.changeAccessRights.bind(this)); Common.NotificationCenter.on('collaboration:sharingupdate', this.updateSharingSettings.bind(this));
Common.NotificationCenter.on('collaboration:sharingdeny', this.onLostEditRights.bind(this)); Common.NotificationCenter.on('collaboration:sharingdeny', this.onLostEditRights.bind(this));
return this; return this;
@ -1051,36 +1051,16 @@ define([
setMode: function(mode) { setMode: function(mode) {
this.sharingSettingsUrl = mode.sharingSettingsUrl; this.sharingSettingsUrl = mode.sharingSettingsUrl;
!!this.sharingSettingsUrl && this.sharingSettingsUrl.length && Common.Gateway.on('showsharingsettings', _.bind(this.changeAccessRights, this));
!!this.sharingSettingsUrl && this.sharingSettingsUrl.length && Common.Gateway.on('setsharingsettings', _.bind(this.setSharingSettings, this));
return this; return this;
}, },
changeAccessRights: function(btn,event,opts) { changeAccessRights: function(btn,event,opts) {
if (this._docAccessDlg || this._readonlyRights) return; Common.NotificationCenter.trigger('collaboration:sharing');
var me = this;
me._docAccessDlg = new Common.Views.DocumentAccessDialog({
settingsurl: this.sharingSettingsUrl
});
me._docAccessDlg.on('accessrights', function(obj, rights){
me.updateSharingSettings(rights);
}).on('close', function(obj){
me._docAccessDlg = undefined;
});
me._docAccessDlg.show();
},
setSharingSettings: function(data) {
data && this.updateSharingSettings(data.sharingSettings);
}, },
updateSharingSettings: function(rights) { updateSharingSettings: function(rights) {
this.doc.info.sharingSettings = rights;
this._ShowHideInfoItem('rights', this.doc.info.sharingSettings!==undefined && this.doc.info.sharingSettings!==null && this.doc.info.sharingSettings.length>0); this._ShowHideInfoItem('rights', this.doc.info.sharingSettings!==undefined && this.doc.info.sharingSettings!==null && this.doc.info.sharingSettings.length>0);
this.cntRights.html(this.templateRights({users: this.doc.info.sharingSettings})); this.cntRights.html(this.templateRights({users: this.doc.info.sharingSettings}));
Common.NotificationCenter.trigger('mentions:clearusers', this);
}, },
onLostEditRights: function() { onLostEditRights: function() {

View file

@ -56,8 +56,7 @@ define([
'hide': _.bind(this.onHidePlugins, this) 'hide': _.bind(this.onHidePlugins, this)
}, },
'Common.Views.Header': { 'Common.Views.Header': {
'file:settings': _.bind(this.clickToolbarSettings,this), 'file:settings': _.bind(this.clickToolbarSettings,this)
'click:users': _.bind(this.clickStatusbarUsers, this)
}, },
'LeftMenu': { 'LeftMenu': {
'file:show': _.bind(this.fileShowHide, this, true), 'file:show': _.bind(this.fileShowHide, this, true),
@ -432,10 +431,6 @@ define([
}, },
/** coauthoring begin **/ /** coauthoring begin **/
clickStatusbarUsers: function() {
this.leftMenu.menuFile.panels['rights'].changeAccessRights();
},
onHideChat: function() { onHideChat: function() {
$(this.leftMenu.btnChat.el).blur(); $(this.leftMenu.btnChat.el).blur();
Common.NotificationCenter.trigger('layout:changed', 'leftmenu'); Common.NotificationCenter.trigger('layout:changed', 'leftmenu');

View file

@ -1044,24 +1044,22 @@ define([
this.api); this.api);
} }
/** coauthoring end **/ /** coauthoring end **/
var me = this,
application = this.getApplication(),
reviewController = application.getController('Common.Controllers.ReviewChanges');
reviewController.setMode(me.appOptions).setConfig({config: me.editorConfig}, me.api).loadDocument({doc:me.appOptions.spreadsheet});
if (this.appOptions.isEdit) { if (this.appOptions.isEdit) {
var me = this, var toolbarController = application.getController('Toolbar'),
application = this.getApplication(),
toolbarController = application.getController('Toolbar'),
statusbarController = application.getController('Statusbar'), statusbarController = application.getController('Statusbar'),
rightmenuController = application.getController('RightMenu'), rightmenuController = application.getController('RightMenu'),
fontsControllers = application.getController('Common.Controllers.Fonts'), fontsControllers = application.getController('Common.Controllers.Fonts');
reviewController = application.getController('Common.Controllers.ReviewChanges');
fontsControllers && fontsControllers.setApi(me.api); fontsControllers && fontsControllers.setApi(me.api);
toolbarController && toolbarController.setApi(me.api); toolbarController && toolbarController.setApi(me.api);
// statusbarController && statusbarController.setApi(me.api); // statusbarController && statusbarController.setApi(me.api);
rightmenuController && rightmenuController.setApi(me.api); rightmenuController && rightmenuController.setApi(me.api);
reviewController.setMode(me.appOptions).setConfig({config: me.editorConfig}, me.api);
if (me.appOptions.canProtect) if (me.appOptions.canProtect)
application.getController('Common.Controllers.Protection').setMode(me.appOptions).setConfig({config: me.editorConfig}, me.api); application.getController('Common.Controllers.Protection').setMode(me.appOptions).setConfig({config: me.editorConfig}, me.api);
@ -2046,6 +2044,7 @@ define([
this.appOptions.spreadsheet.title = meta.title; this.appOptions.spreadsheet.title = meta.title;
filemenu.loadDocument({doc:this.appOptions.spreadsheet}); filemenu.loadDocument({doc:this.appOptions.spreadsheet});
filemenu.panels && filemenu.panels['info'] && filemenu.panels['info'].updateInfo(this.appOptions.spreadsheet); filemenu.panels && filemenu.panels['info'] && filemenu.panels['info'].updateInfo(this.appOptions.spreadsheet);
app.getController('Common.Controllers.ReviewChanges').loadDocument({doc:this.appOptions.spreadsheet});
Common.Gateway.metaChange(meta); Common.Gateway.metaChange(meta);
}, },

View file

@ -1461,7 +1461,7 @@ define([
}); });
} }
Common.NotificationCenter.on('collaboration:sharing', this.changeAccessRights.bind(this)); Common.NotificationCenter.on('collaboration:sharingupdate', this.updateSharingSettings.bind(this));
Common.NotificationCenter.on('collaboration:sharingdeny', this.onLostEditRights.bind(this)); Common.NotificationCenter.on('collaboration:sharingdeny', this.onLostEditRights.bind(this));
return this; return this;
@ -1501,36 +1501,16 @@ define([
setMode: function(mode) { setMode: function(mode) {
this.sharingSettingsUrl = mode.sharingSettingsUrl; this.sharingSettingsUrl = mode.sharingSettingsUrl;
!!this.sharingSettingsUrl && this.sharingSettingsUrl.length && Common.Gateway.on('showsharingsettings', _.bind(this.changeAccessRights, this));
!!this.sharingSettingsUrl && this.sharingSettingsUrl.length && Common.Gateway.on('setsharingsettings', _.bind(this.setSharingSettings, this));
return this; return this;
}, },
changeAccessRights: function(btn,event,opts) { changeAccessRights: function(btn,event,opts) {
if (this._docAccessDlg || this._readonlyRights) return; Common.NotificationCenter.trigger('collaboration:sharing');
var me = this;
me._docAccessDlg = new Common.Views.DocumentAccessDialog({
settingsurl: this.sharingSettingsUrl
});
me._docAccessDlg.on('accessrights', function(obj, rights){
me.updateSharingSettings(rights);
}).on('close', function(obj){
me._docAccessDlg = undefined;
});
me._docAccessDlg.show();
},
setSharingSettings: function(data) {
data && this.updateSharingSettings(data.sharingSettings);
}, },
updateSharingSettings: function(rights) { updateSharingSettings: function(rights) {
this.doc.info.sharingSettings = rights;
this._ShowHideInfoItem('rights', this.doc.info.sharingSettings!==undefined && this.doc.info.sharingSettings!==null && this.doc.info.sharingSettings.length>0); this._ShowHideInfoItem('rights', this.doc.info.sharingSettings!==undefined && this.doc.info.sharingSettings!==null && this.doc.info.sharingSettings.length>0);
this.cntRights.html(this.templateRights({users: this.doc.info.sharingSettings})); this.cntRights.html(this.templateRights({users: this.doc.info.sharingSettings}));
Common.NotificationCenter.trigger('mentions:clearusers', this);
}, },
onLostEditRights: function() { onLostEditRights: function() {