mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) start reconciling forking with granular access
Summary: This allows a fork to be made by a user if: * That user is an owner of the document being forked, or * That user has full read access to the document being forked. The bulk of the diff is reorganization of how forking is done. ActiveDoc.fork is now responsible for creating a fork, not just a docId/urlId for the fork. Since fork creation should not be limited to the doc worker hosting the trunk, a helper endpoint is added for placing the fork. The change required sanitizing worker allocation a bit, and allowed session knowledge to be removed from HostedStorageManager. Test Plan: Added test; existing tests pass. Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2700
This commit is contained in:
@@ -42,6 +42,8 @@ export class DocApiForwarder {
|
||||
app.use('/api/docs/:docId/remove', withDoc);
|
||||
app.delete('/api/docs/:docId', withDoc);
|
||||
app.use('/api/docs/:docId/download', withDoc);
|
||||
app.use('/api/docs/:docId/fork', withDoc);
|
||||
app.use('/api/docs/:docId/create-fork', withDoc);
|
||||
app.use('/api/docs/:docId/apply', withDoc);
|
||||
app.use('/api/docs/:docId/attachments', withDoc);
|
||||
app.use('/api/docs/:docId/snapshots', withDoc);
|
||||
|
||||
@@ -328,8 +328,29 @@ export class DocWorkerMap implements IDocWorkerMap {
|
||||
* A preferred doc worker can be specified, which will be assigned
|
||||
* if no assignment is already made.
|
||||
*
|
||||
* For the special docId "import", return a potential assignment.
|
||||
* It will be up to the doc worker to assign the eventually
|
||||
* created document, if desired.
|
||||
*
|
||||
*/
|
||||
public async assignDocWorker(docId: string, workerId?: string): Promise<DocStatus> {
|
||||
if (docId === 'import') {
|
||||
const lock = await this._redlock.lock(`workers-lock`, LOCK_TIMEOUT);
|
||||
try {
|
||||
const workerId = await this._client.srandmemberAsync(`workers-available-default`);
|
||||
if (!workerId) { throw new Error('no doc worker available'); }
|
||||
const docWorker = await this._client.hgetallAsync(`worker-${workerId}`) as DocWorkerInfo|null;
|
||||
if (!docWorker) { throw new Error('no doc worker contact info available'); }
|
||||
return {
|
||||
docMD5: null,
|
||||
docWorker,
|
||||
isActive: false
|
||||
};
|
||||
} finally {
|
||||
await lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
// Check if a DocWorker is already assigned; if so return result immediately
|
||||
// without locking.
|
||||
let docStatus = await this.getDocWorker(docId);
|
||||
|
||||
Reference in New Issue
Block a user