mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) updates from grist-core
This commit is contained in:
@@ -50,7 +50,7 @@ import {IDocWorkerMap} from "app/server/lib/DocWorkerMap";
|
||||
import {DownloadOptions, parseExportParameters} from "app/server/lib/Export";
|
||||
import {downloadCSV} from "app/server/lib/ExportCSV";
|
||||
import {collectTableSchemaInFrictionlessFormat} from "app/server/lib/ExportTableSchema";
|
||||
import {downloadXLSX} from "app/server/lib/ExportXLSX";
|
||||
import {streamXLSX} from "app/server/lib/ExportXLSX";
|
||||
import {expressWrap} from 'app/server/lib/expressWrap';
|
||||
import {filterDocumentInPlace} from "app/server/lib/filterUtils";
|
||||
import {googleAuthTokenMiddleware} from "app/server/lib/GoogleAuth";
|
||||
@@ -173,6 +173,7 @@ export class DocWorkerApi {
|
||||
const canView = expressWrap(this._assertAccess.bind(this, 'viewers', false));
|
||||
// check document exists (not soft deleted) and user can edit it
|
||||
const canEdit = expressWrap(this._assertAccess.bind(this, 'editors', false));
|
||||
const checkAnonymousCreation = expressWrap(this._checkAnonymousCreation.bind(this));
|
||||
const isOwner = expressWrap(this._assertAccess.bind(this, 'owners', false));
|
||||
// check user can edit document, with soft-deleted documents being acceptable
|
||||
const canEditMaybeRemoved = expressWrap(this._assertAccess.bind(this, 'editors', true));
|
||||
@@ -1241,7 +1242,7 @@ export class DocWorkerApi {
|
||||
*
|
||||
* TODO: unify this with the other document creation and import endpoints.
|
||||
*/
|
||||
this._app.post('/api/docs', expressWrap(async (req, res) => {
|
||||
this._app.post('/api/docs', checkAnonymousCreation, expressWrap(async (req, res) => {
|
||||
const userId = getUserId(req);
|
||||
|
||||
let uploadId: number|undefined;
|
||||
@@ -1522,6 +1523,17 @@ export class DocWorkerApi {
|
||||
return await this._dbManager.increaseUsage(getDocScope(req), limit, {delta: 1});
|
||||
}
|
||||
|
||||
/**
|
||||
* Disallow document creation for anonymous users if GRIST_ANONYMOUS_CREATION is set to false.
|
||||
*/
|
||||
private async _checkAnonymousCreation(req: Request, res: Response, next: NextFunction) {
|
||||
const isAnonPlayground = isAffirmative(process.env.GRIST_ANON_PLAYGROUND ?? true);
|
||||
if (isAnonymousUser(req) && !isAnonPlayground) {
|
||||
throw new ApiError('Anonymous document creation is disabled', 403);
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
||||
private async _assertAccess(role: 'viewers'|'editors'|'owners'|null, allowRemoved: boolean,
|
||||
req: Request, res: Response, next: NextFunction) {
|
||||
const scope = getDocScope(req);
|
||||
@@ -1969,3 +1981,14 @@ export interface WebhookSubscription {
|
||||
unsubscribeKey: string;
|
||||
webhookId: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts `activeDoc` to XLSX and sends the converted data through `res`.
|
||||
*/
|
||||
export async function downloadXLSX(activeDoc: ActiveDoc, req: Request,
|
||||
res: Response, options: DownloadOptions) {
|
||||
const {filename} = options;
|
||||
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
res.setHeader('Content-Disposition', contentDisposition(filename + '.xlsx'));
|
||||
return streamXLSX(activeDoc, req, res, options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user