Skip to content

Commit 7a09adc

Browse files
authored
Re-enables copying for external attachment docs (#1603)
## Context With the addition of the attachments archive UI (#1551), it's possible to successfully copy a document that's using external attachments. This is done by manually restoring the attachments in the copied document. ## This commit This removes the checks for external attachments from the copy endpoints. ## Related issues #1021 #1551
1 parent f876f9a commit 7a09adc

File tree

2 files changed

+7
-27
lines changed

2 files changed

+7
-27
lines changed

app/server/lib/uploads.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {ApiError} from 'app/common/ApiError';
22
import {InactivityTimer} from 'app/common/InactivityTimer';
33
import {FetchUrlOptions, FileUploadResult, UPLOAD_URL_PATH, UploadResult} from 'app/common/uploads';
4-
import {DocAttachmentsLocation, getUrlFromPrefix} from 'app/common/UserAPI';
4+
import {getUrlFromPrefix} from 'app/common/UserAPI';
55
import {getAuthorizedUserId, getTransitiveHeaders, getUserId, isSingleUserMode,
66
RequestWithLogin} from 'app/server/lib/Authorizer';
77
import {expressWrap} from 'app/server/lib/expressWrap';
@@ -504,27 +504,6 @@ export async function fetchDoc(
504504
const docWorkerUrl = docWorker ? docWorker.internalUrl : getUrlFromPrefix(server.getHomeInternalUrl(), selfPrefix);
505505
const apiBaseUrl = docWorkerUrl.replace(/\/*$/, '/');
506506

507-
// Documents with external attachments can't be copied right now. Check status and alert the user.
508-
// Copying as a template is fine, as no attachments will be copied.
509-
if (!template) {
510-
const transferStatusResponse = await fetch(
511-
new URL(`api/docs/${docId}/attachments/transferStatus`, apiBaseUrl).href,
512-
{
513-
headers: {
514-
...headers,
515-
'Content-Type': 'application/json',
516-
}
517-
}
518-
);
519-
if (!transferStatusResponse.ok) {
520-
throw new ApiError(await transferStatusResponse.text(), transferStatusResponse.status);
521-
}
522-
const attachmentsLocation: DocAttachmentsLocation = (await transferStatusResponse.json()).locationSummary;
523-
if (attachmentsLocation !== 'internal' && attachmentsLocation !== 'none') {
524-
throw new ApiError("Cannot copy a document with external attachments", 400);
525-
}
526-
}
527-
528507
// Download the document, in full or as a template.
529508
const url = new URL(`api/docs/${docId}/download?template=${Number(template)}`, apiBaseUrl);
530509
return _fetchURL(url.href, accessId, {headers});

test/server/lib/DocApi.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,21 +2988,22 @@ function testDocApi(settings: {
29882988
assert.deepEqual(tarUploadResp.data, { error: "File is not a valid .tar" });
29892989
});
29902990

2991-
it("POST /docs/{did}/copy fails when the document has external attachments", async function () {
2991+
it("POST /docs/{did}/copy doesn't throw when the document has external attachments", async function () {
29922992
const worker1 = await userApi.getWorkerAPI(docId);
2993-
await assert.isRejected(worker1.copyDoc(docId, undefined, 'copy'), /status 400/);
2993+
await worker1.copyDoc(docId, undefined, 'copy');
29942994
});
29952995

2996-
it("POST /docs/{did} with sourceDocId fails to copy a document with external attachments", async function () {
2996+
it("POST /docs/{did} with sourceDocId can copy a document with external attachments", async function () {
29972997
const chimpyWs = await userApi.newWorkspace({name: "Chimpy's Workspace"}, ORG_NAME);
29982998
const resp = await axios.post(`${homeUrl}/api/docs`, {
29992999
sourceDocumentId: docId,
30003000
documentName: 'copy of TestDocExternalAttachments',
30013001
asTemplate: false,
30023002
workspaceId: chimpyWs
30033003
}, chimpy);
3004-
assert.equal(resp.status, 400);
3005-
assert.match(resp.data.error, /external attachments/);
3004+
assert.equal(resp.status, 200);
3005+
assert.isString(resp.data);
3006+
// There's no expectation that the external attachments are copied - just that the document is.
30063007
});
30073008
});
30083009
});

0 commit comments

Comments
 (0)