From 6563e83e4f0830b892fcd2190fe3eb5a032a81b6 Mon Sep 17 00:00:00 2001 From: Sergey Konovalov Date: Mon, 2 Sep 2024 01:05:21 +0300 Subject: [PATCH] [se] save back document opened from TemplateSource; For bug 69573 --- DocService/sources/DocsCoServer.js | 19 +++++++++++++++---- DocService/sources/canvasservice.js | 22 +++++++++++++++++++++- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/DocService/sources/DocsCoServer.js b/DocService/sources/DocsCoServer.js index 9037ad84..4b841cc6 100644 --- a/DocService/sources/DocsCoServer.js +++ b/DocService/sources/DocsCoServer.js @@ -927,7 +927,7 @@ async function applyForceSaveCache(ctx, docId, forceSave, type, opt_userConnecti } async function startForceSave(ctx, docId, type, opt_userdata, opt_formdata, opt_userId, opt_userConnectionId, opt_userConnectionDocId, opt_userIndex, opt_responseKey, opt_baseUrl, - opt_queue, opt_pubsub, opt_conn, opt_initShardKey, opt_jsonParams) { + opt_queue, opt_pubsub, opt_conn, opt_initShardKey, opt_jsonParams, opt_changeInfo) { const tenForceSaveUsingButtonWithoutChanges = ctx.getCfg('services.CoAuthoring.server.forceSaveUsingButtonWithoutChanges', cfgForceSaveUsingButtonWithoutChanges); ctx.logger.debug('startForceSave start'); let res = {code: commonDefines.c_oAscServerCommandErrors.NoError, time: null, inProgress: false}; @@ -940,15 +940,20 @@ async function startForceSave(ctx, docId, type, opt_userdata, opt_formdata, opt_ }); if (!hasEncrypted) { let forceSave = await editorData.getForceSave(ctx, docId); - let startWithoutChanges = !forceSave && opt_conn && (commonDefines.c_oAscForceSaveTypes.Form === type || + let forceSaveWithConnection = opt_conn && (commonDefines.c_oAscForceSaveTypes.Form === type || (commonDefines.c_oAscForceSaveTypes.Button === type && tenForceSaveUsingButtonWithoutChanges)); + let startWithoutChanges = !forceSave && (forceSaveWithConnection || opt_changeInfo); if (startWithoutChanges) { //stub to send forms without changes let newChangesLastDate = new Date(); newChangesLastDate.setMilliseconds(0);//remove milliseconds avoid issues with MySQL datetime rounding let newChangesLastTime = newChangesLastDate.getTime(); - let baseUrl = utils.getBaseUrlByConnection(ctx, opt_conn); - let changeInfo = getExternalChangeInfo(opt_conn.user, newChangesLastTime, opt_conn.lang); + let baseUrl = opt_baseUrl || ""; + let changeInfo = opt_changeInfo; + if (opt_conn) { + baseUrl = utils.getBaseUrlByConnection(ctx, opt_conn); + changeInfo = getExternalChangeInfo(opt_conn.user, newChangesLastTime, opt_conn.lang); + } await editorData.setForceSave(ctx, docId, newChangesLastTime, 0, baseUrl, changeInfo, null); forceSave = await editorData.getForceSave(ctx, docId); } @@ -2815,6 +2820,12 @@ exports.install = function(server, callbackFunction) { let openedAt = openedAtStr ? sqlBase.DocumentAdditional.prototype.getOpenedAt(openedAtStr) : canvasService.getOpenedAt(resultRow); const endAuthRes = yield* endAuth(ctx, conn, false, documentCallback, openedAt); if (endAuthRes && cmd) { + //todo to allow forcesave TemplateSource after convertion(move to better place) + if (wopiParamsFull?.commonInfo?.fileInfo?.TemplateSource) { + let newChangesLastDate = new Date(); + newChangesLastDate.setMilliseconds(0);//remove milliseconds avoid issues with MySQL datetime rounding + cmd.setExternalChangeInfo(getExternalChangeInfo(conn.user, newChangesLastDate.getTime(), conn.lang)); + } yield canvasService.openDocument(ctx, conn, cmd, upsertRes, bIsRestore); } } diff --git a/DocService/sources/canvasservice.js b/DocService/sources/canvasservice.js index a22b9f8f..5d9d9d6a 100644 --- a/DocService/sources/canvasservice.js +++ b/DocService/sources/canvasservice.js @@ -179,6 +179,9 @@ async function getOutputData(ctx, cmd, outputData, key, optConn, optAdditionalOu password = sqlBase.DocumentPassword.prototype.getCurPassword(ctx, row.password); creationDate = row.created_at && row.created_at.getTime(); openedAt = getOpenedAt(row); + if (optAdditionalOutput) { + optAdditionalOutput.row = row; + } } switch (status) { case commonDefines.FileStatus.SaveVersion: @@ -1826,9 +1829,26 @@ exports.receiveTask = function(data, ack) { if (updateRes.affectedRows > 0) { var outputData = new OutputData(cmd.getCommand()); var command = cmd.getCommand(); - var additionalOutput = {needUrlKey: null, needUrlMethod: null, needUrlType: null, needUrlIsCorrectPassword: undefined, creationDate: undefined, openedAt: undefined}; + var additionalOutput = {needUrlKey: null, needUrlMethod: null, needUrlType: null, + needUrlIsCorrectPassword: undefined, creationDate: undefined, openedAt: undefined, row: undefined}; if ('open' === command || 'reopen' === command) { yield getOutputData(ctx, cmd, outputData, cmd.getDocId(), null, additionalOutput); + //wopi from TemplateSource + if (additionalOutput.row) { + let row = additionalOutput.row; + let userAuthStr = sqlBase.UserCallback.prototype.getCallbackByUserIndex(ctx, row.callback); + let wopiParams = wopiClient.parseWopiCallback(ctx, userAuthStr, row.callback); + if (wopiParams?.commonInfo?.fileInfo?.TemplateSource) { + ctx.logger.debug('receiveTask: save document opened from TemplateSource'); + //todo + //no need to wait to open file faster + void docsCoServer.startForceSave(ctx, cmd.getDocId(), commonDefines.c_oAscForceSaveTypes.Timeout, + undefined, undefined, undefined, undefined, + undefined, undefined, undefined, row.baseurl, + undefined,undefined,undefined,undefined, + undefined,cmd.getExternalChangeInfo()); + } + } } else if ('save' === command || 'savefromorigin' === command) { let status = yield getOutputData(ctx, cmd, outputData, cmd.getDocId() + cmd.getSaveKey(), null, additionalOutput); if (commonDefines.FileStatus.Ok === status && (cmd.getSaveAsPath() || cmd.getIsSaveAs())) {