Merge permission sources into one. Use global variable for file permission.

Signed-off-by: Gökay Şatır <gokaysatir@collabora.com>
Change-Id: I19b6c0e95ccc3249219c88224b8c183992cd3b6d
pull/5478/head
Gökay Şatır 2022-11-15 14:09:06 +03:00 committed by Gökay ŞATIR
parent fa14b9aecf
commit 192e12a864
6 changed files with 25 additions and 30 deletions

View File

@ -248,12 +248,12 @@ L.Map.include({
// Can user make changes to the document or not
// i.e: user can not make changes(even can not add comments) is document is shared as read only
canUserWrite: function() {
return window.docPermission === 'edit';
return app.file.permission === 'edit';
},
// If user has write access he can always add comments
isPermissionEditForComments: function() {
return this.canUserWrite();
return this.canUserWrite() || app.file.editComment;
},
// Is user currently in read only mode (i.e: initial mobile read only view mode, user may have write access)

View File

@ -39,9 +39,7 @@ app.definitions.Socket = L.Class.extend({
connect: function(socket) {
var map = this._map;
if (map.options.permission) {
map.options.docParams['permission'] = map.options.permission;
}
map.options.docParams['permission'] = app.file.permission;
if (this.socket) {
this.close();
}
@ -598,33 +596,30 @@ app.definitions.Socket = L.Class.extend({
var perm = textMsg.substring('perm:'.length).trim();
// Never make the permission more permissive than it originally was.
if (this._map.options.permission == 'edit')
{
this._map.options.permission = perm;
}
if (app.file.permission == 'edit')
app.file.permission = perm;
if (this._map._docLayer) {
this._map.setPermission(this._map.options.permission);
}
if (this._map._docLayer)
this._map.setPermission(app.file.permission);
app.file.disableSidebar = perm !== 'edit';
app.file.readOnly = this._map.options.permission === 'readonly';
app.file.readOnly = app.file.permission === 'readonly';
return;
}
else if (textMsg.startsWith('filemode:')) {
var json = JSON.parse(textMsg.substring('filemode:'.length).trim());
// Never make the permission more permissive than it originally was.
if (this._map.options.permission == 'edit' && json.readOnly)
if (app.file.permission == 'edit' && json.readOnly)
{
this._map.options.permission = 'readonly';
app.file.permission = 'readonly';
}
if (this._map._docLayer) {
this._map.setPermission(this._map.options.permission);
this._map.setPermission(app.file.permission);
}
app.file.readOnly = this._map.options.permission === 'readonly';
app.file.readOnly = app.file.permission === 'readonly';
app.file.editComment = json.editComment; // Allowed even in readonly mode.
}
else if (textMsg.startsWith('lockfailed:')) {
@ -1281,7 +1276,7 @@ app.definitions.Socket = L.Class.extend({
// if this is save-as, we need to load the document with edit permission
// otherwise the user has to close the doc then re-open it again
// in order to be able to edit.
this._map.options.permission = 'edit';
app.file.permission = 'edit';
this.close();
this._map.loadDocument();
this._map.sendInitUNOCommands();
@ -1373,7 +1368,6 @@ app.definitions.Socket = L.Class.extend({
var docLayer = null;
if (command.type === 'text') {
docLayer = new L.WriterTileLayer('', {
permission: this._map.options.permission,
tileWidthTwips: tileWidthTwips / app.dpiScale,
tileHeightTwips: tileHeightTwips / app.dpiScale,
docType: command.type
@ -1381,7 +1375,6 @@ app.definitions.Socket = L.Class.extend({
}
else if (command.type === 'spreadsheet') {
docLayer = new L.CalcTileLayer('', {
permission: this._map.options.permission,
tileWidthTwips: tileWidthTwips / app.dpiScale,
tileHeightTwips: tileHeightTwips / app.dpiScale,
docType: command.type
@ -1389,7 +1382,6 @@ app.definitions.Socket = L.Class.extend({
}
else if (command.type === 'presentation' || command.type === 'drawing') {
docLayer = new L.ImpressTileLayer('', {
permission: this._map.options.permission,
tileWidthTwips: tileWidthTwips / app.dpiScale,
tileHeightTwips: tileHeightTwips / app.dpiScale,
docType: command.type
@ -1409,7 +1401,7 @@ app.definitions.Socket = L.Class.extend({
this._map._isNotebookbarLoadedOnCore = false;
var uiMode = this._map.uiManager.getCurrentMode();
this._map.fire('changeuimode', {mode: uiMode, force: true});
this._map.setPermission(this._map.options.permission);
this._map.setPermission(app.file.permission);
}
this._map.fire('docloaded', {status: true});

View File

@ -9,6 +9,7 @@ window.app = { // Shouldn't have any functions defined.
file: {
editComment: false,
readOnly: true,
permission: 'readonly',
disableSidebar: false,
size: {
pixels: [0, 0], // This can change according to the zoom level and document's size.
@ -78,4 +79,6 @@ if (activateValidation) {
};
window.app = new Proxy(window.app, validator);
window.app.file = new Proxy(window.app.file, validator);
}

View File

@ -5442,7 +5442,7 @@ L.CanvasTileLayer = L.Layer.extend({
// This layergroup contains all the layers corresponding to other's view
this._viewLayerGroup = new L.LayerGroup();
if (this.options.permission !== 'readonly') {
if (app.file.permission !== 'readonly') {
map.addLayer(this._viewLayerGroup);
}
@ -5511,7 +5511,7 @@ L.CanvasTileLayer = L.Layer.extend({
// generated just for the validity-dropdown-icon.
map.on('dropdownmarkertapped', this._onDropDownButtonClick, this);
map.setPermission(this.options.permission);
map.setPermission(app.file.permission);
map.fire('statusindicator', {statusType: 'coolloaded'});

View File

@ -16,7 +16,9 @@ else if (wopiSrc !== '' && accessHeader !== '') {
}
var filePath = getParameterByName('file_path');
var permission = getParameterByName('permission') || 'edit';
app.file.permission = getParameterByName('permission') || 'edit';
var timestamp = getParameterByName('timestamp');
// Should the document go inactive or not
var alwaysActive = getParameterByName('alwaysactive');
@ -45,7 +47,6 @@ var map = L.map('map', {
server: host,
doc: docURL,
docParams: docParams,
permission: permission,
timestamp: timestamp,
documentContainer: 'document-container',
debug: debugMode,
@ -78,7 +79,6 @@ window.addEventListener('beforeunload', function () {
}
});
window.docPermission = permission;
window.bundlejsLoaded = true;

View File

@ -122,10 +122,10 @@ L.Map.WOPI = L.Handler.extend({
this.UserCanRename = !!wopiInfo['UserCanRename'];
this.EnableShare = !!wopiInfo['EnableShare'];
this.UserCanWrite = !!wopiInfo['UserCanWrite'];
if (this.UserCanWrite)
window.docPermission = 'edit';
if (this.UserCanWrite) // There are 2 places that set the file permissions, WOPI and URI. Don't change permission if URI doesn't allow.
app.file.permission = (app.file.permission === 'edit' ? 'edit': app.file.permission);
else
window.docPermission = 'readonly';
app.file.permission = 'readonly';
if (wopiInfo['HideUserList'])
this.HideUserList = wopiInfo['HideUserList'].split(',');