gristlabs_grist-core/app/common/DocListAPI.ts
Paul Fitzpatrick 3b3ae87ade (core) implement a safe mode for opening documents with rule problems
Summary:
Adds an "enter safe mode" option and explanation in modal that appears when a document fails to load, if user is owner. If "enter safe mode" is selected, document is reloaded on server in a special mode. Currently, the only difference is that if the acl rules fail to load, they are replaced with a fallback that grants full access to owners and no access to anyone else. An extra tag is shown to mark the document as safe mode, with an "x" for cancelling safe mode.

There are other ways a document could fail to load than just acl rules, so this is just a start.

Test Plan: added test

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D2686
2020-12-14 13:04:13 -05:00

87 lines
2.7 KiB
TypeScript

import {ActionGroup} from 'app/common/ActionGroup';
import {TableDataAction} from 'app/common/DocActions';
import {LocalPlugin} from 'app/common/plugin';
import {StringUnion} from 'app/common/StringUnion';
// Possible flavors of items in a list of documents.
export type DocEntryTag = ''|'sample'|'invite'|'shared';
export const OpenDocMode = StringUnion(
'default', // open doc with user's maximal access level
'view', // open doc limited to view access (if user has at least that level of access)
'fork', // as for 'view', but suggest a fork on any attempt to edit - the client will
// enable the editing UI experience and trigger a fork on any edit.
);
export type OpenDocMode = typeof OpenDocMode.type;
/**
* Represents an entry in the DocList.
*/
export interface DocEntry {
docId?: string; // Set for shared docs and invites
name: string;
mtime?: Date;
size?: number;
tag: DocEntryTag;
senderName?: string;
senderEmail?: string;
}
export interface DocCreationInfo {
id: string;
title: string;
}
/**
* This documents the members of the structure returned when a local
* grist document is opened.
*/
export interface OpenLocalDocResult {
docFD: number;
clientId: string; // the docFD is meaningful only in the context of this session
doc: {[tableId: string]: TableDataAction};
log: ActionGroup[];
plugins: LocalPlugin[];
recoveryMode?: boolean;
}
export interface DocListAPI {
/**
* Returns a all known Grist documents and document invites to show in the doc list.
*/
getDocList(): Promise<{docs: DocEntry[], docInvites: DocEntry[]}>;
/**
* Creates a new document, fetches it, and adds a table to it. Returns its name.
*/
createNewDoc(): Promise<string>;
/**
* Makes a copy of the given sample doc. Returns the name of the new document.
*/
importSampleDoc(sampleDocName: string): Promise<string>;
/**
* Processes an upload, containing possibly multiple files, to create a single new document, and
* returns the new document's name.
*/
importDoc(uploadId: number): Promise<string>;
/**
* Deletes a Grist document. Returns the name of the deleted document. If `deletePermanently` is
* true, the doc is deleted permanently rather than just moved to the trash.
*/
deleteDoc(docName: string, deletePermanently: boolean): Promise<string>;
/**
* Renames a document.
*/
renameDoc(oldName: string, newName: string): Promise<void>;
/**
* Opens a document, loads it, subscribes to its userAction events, and returns its metadata.
*/
openDoc(userDocName: string, openMode?: OpenDocMode,
linkParameters?: Record<string, string>): Promise<OpenLocalDocResult>;
}