(core) clean up snapshot list when access rules are in effect

Summary:
When access rules are in effect on a document, non-owners currently
don't have access to snapshots. Previously when the document history
tab is opened in this situation, an error toast would appear, along
with a small message that was hard to see in dark mode. This change
removes the toast and improves the message somewhat.

Test Plan: updated test

Reviewers: jarek

Reviewed By: jarek

Differential Revision: https://phab.getgrist.com/D4218
This commit is contained in:
Paul Fitzpatrick 2024-03-21 13:02:25 -04:00
parent e380fcfa90
commit 67afd74817
2 changed files with 17 additions and 3 deletions

View File

@ -74,12 +74,24 @@ export class DocHistory extends Disposable implements IDomComponent {
docApi.getSnapshots().then(result => docApi.getSnapshots().then(result =>
snapshots.isDisposed() || snapshots.set(result.snapshots)).catch(err => { snapshots.isDisposed() || snapshots.set(result.snapshots)).catch(err => {
snapshotsDenied.set(true); snapshotsDenied.set(true);
// "cannot confirm access" is what we expect if snapshots
// are denied because of access rules.
if (!String(err).match(/cannot confirm access/)) {
reportError(err); reportError(err);
}
}); });
return dom( return dom(
'div', 'div',
{tabIndex: '-1'}, // Voodoo needed to allow copying text.
dom.maybe(snapshotsDenied, () => cssSnapshotDenied( dom.maybe(snapshotsDenied, () => cssSnapshotDenied(
dom(
'p',
t("Snapshots are unavailable."), t("Snapshots are unavailable."),
),
dom(
'p',
t("Only owners have access to snapshots for documents with access rules."),
),
testId('doc-history-error'))), testId('doc-history-error'))),
// Note that most recent snapshots are first. // Note that most recent snapshots are first.
dom.domComputed(snapshots, (snapshotList) => snapshotList.map((snapshot, index) => { dom.domComputed(snapshots, (snapshotList) => snapshotList.map((snapshot, index) => {
@ -128,6 +140,8 @@ const cssSnapshot = styled('div', `
const cssSnapshotDenied = styled('div', ` const cssSnapshotDenied = styled('div', `
margin: 8px 16px; margin: 8px 16px;
text-align: center;
color: ${theme.text};
`); `);
const cssSnapshotTime = styled('div', ` const cssSnapshotTime = styled('div', `

View File

@ -1715,7 +1715,7 @@ export class ActiveDoc extends EventEmitter {
public async getSnapshots(docSession: OptDocSession, skipMetadataCache?: boolean): Promise<DocSnapshots> { public async getSnapshots(docSession: OptDocSession, skipMetadataCache?: boolean): Promise<DocSnapshots> {
if (await this._granularAccess.hasNuancedAccess(docSession)) { if (await this._granularAccess.hasNuancedAccess(docSession)) {
throw new Error('cannot confirm access to snapshots'); throw new Error('cannot confirm access to snapshots because of access rules');
} }
return this._docManager.storageManager.getSnapshots(this.docName, skipMetadataCache); return this._docManager.storageManager.getSnapshots(this.docName, skipMetadataCache);
} }