(core) add endpoints for clearing snapshots and actions

Summary:
This adds a snapshots/remove and states/remove endpoint, primarily
for maintenance work rather than for the end user.  If some secret
gets into document history, it is useful to be able to purge it
in an orderly way.

Test Plan: added tests

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D2694
This commit is contained in:
Paul Fitzpatrick
2020-12-18 12:37:16 -05:00
parent b1c4af4ee9
commit 24e76b4abc
10 changed files with 128 additions and 27 deletions

View File

@@ -213,9 +213,10 @@ export function optStringParam(p: any): string|undefined {
return undefined;
}
export function stringParam(p: any): string {
if (typeof p === 'string') { return p; }
throw new Error(`parameter should be a string: ${p}`);
export function stringParam(p: any, allowed?: string[]): string {
if (typeof p !== 'string') { throw new Error(`parameter should be a string: ${p}`); }
if (allowed && !allowed.includes(p)) { throw new Error(`parameter ${p} should be one of ${allowed}`); }
return p;
}
export function integerParam(p: any): number {
@@ -224,6 +225,13 @@ export function integerParam(p: any): number {
throw new Error(`parameter should be an integer: ${p}`);
}
export function optIntegerParam(p: any): number|undefined {
if (typeof p === 'number') { return Math.floor(p); }
if (typeof p === 'string') { return parseInt(p, 10); }
return undefined;
}
export interface RequestWithGristInfo extends Request {
gristInfo?: string;
}