From 0262ad7a472dce1155c50cc5e4d60a2004390281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Sadzi=C5=84ski?= Date: Fri, 24 May 2024 08:55:15 +0200 Subject: [PATCH] (core) Fix for ACL page for temporary documents. Summary: When the ACL page was visited by an anonymous user (for a temporary doc), it tried to load the "View as" list, which failed. Apart from example users, it was also trying to load all users the document is shared with by checking the home db. However, since the document is not persisted, it failed. Test Plan: Added new test Reviewers: Spoffy Reviewed By: Spoffy Subscribers: Spoffy Differential Revision: https://phab.getgrist.com/D4257 --- app/server/lib/ActiveDoc.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/app/server/lib/ActiveDoc.ts b/app/server/lib/ActiveDoc.ts index d86280bb..a322077b 100644 --- a/app/server/lib/ActiveDoc.ts +++ b/app/server/lib/ActiveDoc.ts @@ -79,7 +79,8 @@ import {schema, SCHEMA_VERSION} from 'app/common/schema'; import {MetaRowRecord, SingleCell} from 'app/common/TableData'; import {TelemetryEvent, TelemetryMetadataByLevel} from 'app/common/Telemetry'; import {FetchUrlOptions, UploadResult} from 'app/common/uploads'; -import {Document as APIDocument, DocReplacementOptions, DocState, DocStateComparison} from 'app/common/UserAPI'; +import {Document as APIDocument, DocReplacementOptions, + DocState, DocStateComparison, NEW_DOCUMENT_CODE} from 'app/common/UserAPI'; import {convertFromColumn} from 'app/common/ValueConverter'; import {guessColInfo} from 'app/common/ValueGuesser'; import {parseUserAction} from 'app/common/ValueParser'; @@ -1574,17 +1575,22 @@ export class ActiveDoc extends EventEmitter { }; const isShared = new Set(); - // Collect users the document is shared with. const userId = getDocSessionUserId(docSession); if (!userId) { throw new Error('Cannot determine user'); } - const db = this.getHomeDbManager(); - if (db) { - const access = db.unwrapQueryResult( - await db.getDocAccess({userId, urlId: this.docName}, { - flatten: true, excludeUsersWithoutAccess: true, - })); - result.users = access.users; - result.users.forEach(user => isShared.add(normalizeEmail(user.email))); + + const parsed = parseUrlId(this.docName); + // If this is not a temporary document (i.e. created by anonymous user). + if (parsed.trunkId !== NEW_DOCUMENT_CODE) { + // Collect users the document is shared with. + const db = this.getHomeDbManager(); + if (db) { + const access = db.unwrapQueryResult( + await db.getDocAccess({userId, urlId: this.docName}, { + flatten: true, excludeUsersWithoutAccess: true, + })); + result.users = access.users; + result.users.forEach(user => isShared.add(normalizeEmail(user.email))); + } } // Collect users from user attribute tables. Omit duplicates with users the document is