Skip to content

Commit

Permalink
[feature] Refactor "version history" to use reconnection as in refres…
Browse files Browse the repository at this point in the history
…hFile
  • Loading branch information
konovalovsergey committed Nov 29, 2024
1 parent b717ca9 commit bc9867b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 80 deletions.
21 changes: 0 additions & 21 deletions Common/sources/commondefines.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ function InputCommand(data, copyExplicit) {
this['username'] = data['username'];
this['tokenSession'] = data['tokenSession'];
this['tokenDownload'] = data['tokenDownload'];
this['tokenHistory'] = data['tokenHistory'];
this['data'] = data['data'];
this['editorid'] = data['editorid'];
this['format'] = data['format'];
Expand Down Expand Up @@ -84,7 +83,6 @@ function InputCommand(data, copyExplicit) {
this['savekey'] = data['savekey'];
this['userconnectionid'] = data['userconnectionid'];
this['responsekey'] = data['responsekey'];
this['docconnectionid'] = data['docconnectionid'];
this['jsonparams'] = data['jsonparams'];
this['lcid'] = data['lcid'];
this['useractionid'] = data['useractionid'];
Expand All @@ -101,7 +99,6 @@ function InputCommand(data, copyExplicit) {
this['savepassword'] = data['savepassword'];
this['withoutPassword'] = data['withoutPassword'];
this['outputurls'] = data['outputurls'];
this['closeonerror'] = data['closeonerror'];
this['serverVersion'] = data['serverVersion'];
this['rediskey'] = data['rediskey'];
this['nobase64'] = data['nobase64'];
Expand All @@ -127,7 +124,6 @@ function InputCommand(data, copyExplicit) {
this['username'] = undefined;
this['tokenSession'] = undefined;//string validate
this['tokenDownload'] = undefined;//string validate
this['tokenHistory'] = undefined;//string validate
this['data'] = undefined;//string
//to open
this['editorid'] = undefined;//int
Expand All @@ -152,7 +148,6 @@ function InputCommand(data, copyExplicit) {
this['savekey'] = undefined;//int document id to save
this['userconnectionid'] = undefined;//string internal
this['responsekey'] = undefined;
this['docconnectionid'] = undefined;//string internal
this['jsonparams'] = undefined;//string
this['lcid'] = undefined;
this['useractionid'] = undefined;
Expand All @@ -165,7 +160,6 @@ function InputCommand(data, copyExplicit) {
this['savepassword'] = undefined;
this['withoutPassword'] = undefined;
this['outputurls'] = undefined;
this['closeonerror'] = undefined;
this['serverVersion'] = undefined;
this['rediskey'] = undefined;
this['nobase64'] = true;
Expand Down Expand Up @@ -218,9 +212,6 @@ InputCommand.prototype = {
getTokenDownload: function() {
return this['tokenDownload'];
},
getTokenHistory: function() {
return this['tokenHistory'];
},
getData: function() {
return this['data'];
},
Expand Down Expand Up @@ -359,12 +350,6 @@ InputCommand.prototype = {
setResponseKey: function(data) {
this['responsekey'] = data;
},
getDocConnectionId: function() {
return this['docconnectionid'];
},
setDocConnectionId: function(data) {
this['docconnectionid'] = data;
},
getJsonParams: function() {
return this['jsonparams'];
},
Expand Down Expand Up @@ -447,12 +432,6 @@ InputCommand.prototype = {
getOutputUrls: function() {
return this['outputurls'];
},
getCloseOnError: function() {
return this['closeonerror'];
},
setCloseOnError: function(data) {
this['closeonerror'] = data;
},
getServerVersion: function() {
return this['serverVersion'];
},
Expand Down
75 changes: 16 additions & 59 deletions DocService/sources/DocsCoServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1734,11 +1734,6 @@ exports.install = function(server, callbackFunction) {
case 'close':
yield* closeDocument(ctx, conn);
break;
case 'versionHistory' : {
let cmd = new commonDefines.InputCommand(data.cmd);
yield* versionHistory(ctx, conn, cmd);
break;
}
case 'openDocument' : {
var cmd = new commonDefines.InputCommand(data.message);
cmd.fillFromConnection(conn);
Expand Down Expand Up @@ -1949,42 +1944,6 @@ exports.install = function(server, callbackFunction) {
}
}

function* versionHistory(ctx, conn, cmd) {
const tenTokenEnableBrowser = ctx.getCfg('services.CoAuthoring.token.enable.browser', cfgTokenEnableBrowser);

var docIdOld = conn.docId;
var docIdNew = cmd.getDocId();
//check jwt
if (tenTokenEnableBrowser) {
var checkJwtRes = yield checkJwt(ctx, cmd.getTokenHistory(), commonDefines.c_oAscSecretType.Browser);
if (checkJwtRes.decoded) {
fillVersionHistoryFromJwt(ctx, checkJwtRes.decoded, cmd);
docIdNew = cmd.getDocId();
cmd.setWithAuthorization(true);
} else {
sendData(ctx, conn, {type: "expiredToken", code: checkJwtRes.code, description: checkJwtRes.description});
return;
}
}
if (docIdOld !== docIdNew) {
//remove presence(other data was removed before in closeDocument)
yield removePresence(ctx, conn);
var hvals = yield editorData.getPresence(ctx, docIdOld, connections);
if (hvals.length <= 0) {
yield editorData.removePresenceDocument(ctx, docIdOld);
}

//apply new
conn.docId = docIdNew;
yield addPresence(ctx, conn, true);
if (tenTokenEnableBrowser) {
let sessionToken = yield fillJwtByConnection(ctx, conn);
sendDataRefreshToken(ctx, conn, sessionToken);
}
}
//open
yield canvasService.openDocument(ctx, conn, cmd, null);
}
// Getting changes for the document (either from the cache or accessing the database, but only if there were saves)
function* getDocumentChanges(ctx, docId, optStartIndex, optEndIndex) {
// If during that moment, while we were waiting for a response from the database, everyone left, then nothing needs to be sent
Expand Down Expand Up @@ -2492,22 +2451,23 @@ exports.install = function(server, callbackFunction) {
}
return res;
}
function fillVersionHistoryFromJwt(ctx, decoded, cmd) {
function fillVersionHistoryFromJwt(ctx, decoded, data) {
let openCmd = data.openCmd;
data.mode = 'view';
data.coEditingMode = 'strict';
data.docid = decoded.key;
openCmd.url = decoded.url;
if (decoded.changesUrl && decoded.previous) {
let versionMatch = cmd.getServerVersion() === commonDefines.buildVersion;
let openPreviousVersion = cmd.getDocId() === decoded.previous.key;
let versionMatch = openCmd.serverVersion === commonDefines.buildVersion;
let openPreviousVersion = openCmd.id === decoded.previous.key;
if (versionMatch && openPreviousVersion) {
cmd.setUrl(decoded.previous.url);
cmd.setDocId(decoded.previous.key);
data.docid = decoded.previous.key;
openCmd.url = decoded.previous.url;
} else {
ctx.logger.warn('fillVersionHistoryFromJwt serverVersion mismatch or mismatch between previous url and changes. serverVersion=%s docId=%s', cmd.getServerVersion(), cmd.getDocId());
cmd.setUrl(decoded.url);
cmd.setDocId(decoded.key);
ctx.logger.warn('fillVersionHistoryFromJwt serverVersion mismatch or mismatch between previous url and changes. serverVersion=%s docId=%s', openCmd.serverVersion, openCmd.id);
}
} else {
cmd.setUrl(decoded.url);
cmd.setDocId(decoded.key);
}
return true;
}

function* auth(ctx, conn, data) {
Expand Down Expand Up @@ -2536,6 +2496,9 @@ exports.install = function(server, callbackFunction) {
} else if (decoded.editorConfig && undefined !== decoded.editorConfig.ds_sessionTimeConnect) {
//reconnection
fillDataFromJwtRes = fillDataFromJwt(ctx, decoded, data);
} else if (decoded.version) {//version required, but maybe add new type like jwtSession?
//version history
fillDataFromJwtRes = fillVersionHistoryFromJwt(ctx, decoded, data);
} else {
//opening
let validationErr = validateAuthToken(data, decoded);
Expand Down Expand Up @@ -3668,13 +3631,7 @@ exports.install = function(server, callbackFunction) {
output.fromObject(data.output);
var outputData = output.getData();

var docConnectionId = cmd.getDocConnectionId();
var docId;
if(docConnectionId){
docId = docConnectionId;
} else {
docId = cmd.getDocId();
}
var docId = cmd.getDocId();
if (cmd.getUserConnectionId()) {
participants = getParticipantUser(docId, cmd.getUserConnectionId());
} else {
Expand Down

0 comments on commit bc9867b

Please sign in to comment.