mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
(core) make document assignment endpoint available via /housekeeping api
Summary: The /assign endpoint checks if a document is on the desired worker and moves it if not. This is never done under regular operation, but is useful when quarantining a misbehaving document. The endpoint was failing to operate correctly if the requester did not have access to the document. This diff makes the endpoint accessible through a /housekeeping route, using the same pattern as the /force-reload endpoint. Test Plan: added test Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D3109
This commit is contained in:
parent
cce679d928
commit
10a4cbb6bd
@ -161,6 +161,16 @@ export class Housekeeper {
|
|||||||
headers,
|
headers,
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Move a document to its assigned worker. Can be useful during administrative
|
||||||
|
// actions.
|
||||||
|
app.post('/api/housekeeping/docs/:docId/assign', this._withSupport(async (docId, headers) => {
|
||||||
|
const url = await this._server.getHomeUrlByDocId(docId, `/api/docs/${docId}/assign`);
|
||||||
|
return fetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers,
|
||||||
|
});
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,8 +132,6 @@ export class DocWorkerApi {
|
|||||||
const isOwner = expressWrap(this._assertAccess.bind(this, 'owners', false));
|
const isOwner = expressWrap(this._assertAccess.bind(this, 'owners', false));
|
||||||
// check user can edit document, with soft-deleted documents being acceptable
|
// check user can edit document, with soft-deleted documents being acceptable
|
||||||
const canEditMaybeRemoved = expressWrap(this._assertAccess.bind(this, 'editors', true));
|
const canEditMaybeRemoved = expressWrap(this._assertAccess.bind(this, 'editors', true));
|
||||||
// check document exists, don't check user access
|
|
||||||
const docExists = expressWrap(this._assertAccess.bind(this, null, false));
|
|
||||||
// converts google code to access token and adds it to request object
|
// converts google code to access token and adds it to request object
|
||||||
const decodeGoogleToken = expressWrap(googleAuthTokenMiddleware.bind(null));
|
const decodeGoogleToken = expressWrap(googleAuthTokenMiddleware.bind(null));
|
||||||
|
|
||||||
@ -581,7 +579,7 @@ export class DocWorkerApi {
|
|||||||
// and frees it for reassignment if not. Has no effect if document is in the
|
// and frees it for reassignment if not. Has no effect if document is in the
|
||||||
// expected group. Does not require specific rights. Returns true if the document
|
// expected group. Does not require specific rights. Returns true if the document
|
||||||
// is freed up for reassignment, otherwise false.
|
// is freed up for reassignment, otherwise false.
|
||||||
this._app.post('/api/docs/:docId/assign', docExists, throttled(async (req, res) => {
|
this._app.post('/api/docs/:docId/assign', canEdit, throttled(async (req, res) => {
|
||||||
const docId = getDocId(req);
|
const docId = getDocId(req);
|
||||||
const status = await this._docWorkerMap.getDocWorker(docId);
|
const status = await this._docWorkerMap.getDocWorker(docId);
|
||||||
if (!status) { res.json(false); return; }
|
if (!status) { res.json(false); return; }
|
||||||
|
Loading…
Reference in New Issue
Block a user