(core) Error message on Duplicate Document

Summary: Fixing error message when user can't copy document.

Test Plan: Updated tests

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3130
This commit is contained in:
Jarosław Sadziński
2021-11-09 11:34:26 +01:00
parent 267640c277
commit 96fa7ad562
4 changed files with 27 additions and 9 deletions

View File

@@ -342,7 +342,7 @@ export class DocWorkerApi {
// check if the user has download permissions.
const activeDoc = await this._getActiveDoc(req);
if (!await activeDoc.canDownload(docSessionFromRequest(req))) {
throw new Error('not authorized to download this document');
throw new ApiError('not authorized to download this document', 403);
}
return this._docWorker.downloadDoc(req, res, this._docManager.storageManager);
}

View File

@@ -67,12 +67,20 @@ export function addUploadRoute(server: GristServer, expressApp: Application, ...
const name = optStringParam(req.query.name);
if (!docId) { throw new Error('doc must be specified'); }
const accessId = makeAccessId(req, getAuthorizedUserId(req));
const uploadResult: UploadResult = await fetchDoc(server.getHomeUrl(req), docId, req, accessId,
req.query.template === '1');
if (name) {
globalUploadSet.changeUploadName(uploadResult.uploadId, accessId, name);
try {
const uploadResult: UploadResult = await fetchDoc(server.getHomeUrl(req), docId, req, accessId,
req.query.template === '1');
if (name) {
globalUploadSet.changeUploadName(uploadResult.uploadId, accessId, name);
}
res.status(200).send(JSON.stringify(uploadResult));
} catch(err) {
if ((err as ApiError).status === 403) {
res.status(403).json({error:'Insufficient access to document to copy it entirely'});
return;
}
throw err;
}
res.status(200).send(JSON.stringify(uploadResult));
}));
}