mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Adds a UI panel for managing webhooks
Summary: This adds a UI panel for managing webhooks. Work started by Cyprien Pindat. You can find the UI on a document's settings page. Main changes relative to Cyprien's demo: * Changed behavior of virtual table to be more consistent with the rest of Grist, by factoring out part of the implementation of on-demand tables. * Cell values that would create an error can now be denied and reverted (as for the rest of Grist). * Changes made by other users are integrated in a sane way. * Basic undo/redo support is added using the regular undo/redo stack. * The table list in the drop-down is now updated if schema changes. * Added a notification from back-end when webhook status is updated so constant polling isn't needed to support multi-user operation. * Factored out webhook specific logic from general virtual table support. * Made a bunch of fixes to various broken behavior. * Added tests. The code remains somewhat unpolished, and behavior in the presence of errors is imperfect in general but may be adequate for this case. I assume that we'll soon be lifting the restriction on the set of domains that are supported for webhooks - otherwise we'd want to provide some friendly way to discover that list of supported domains rather than just throwing an error. I don't actually know a lot about how the front-end works - it looks like tables/columns/fields/sections can be safely added if they have string ids that won't collide with bone fide numeric ids from the back end. Sneaky. Contains a migration, so needs an extra reviewer for that. Test Plan: added tests Reviewers: jarek, dsagal Reviewed By: jarek, dsagal Differential Revision: https://phab.getgrist.com/D3856
This commit is contained in:
@@ -14,7 +14,9 @@ import {OrgPrefs, UserOrgPrefs, UserPrefs} from 'app/common/Prefs';
|
||||
import * as roles from 'app/common/roles';
|
||||
import {addCurrentOrgToPath} from 'app/common/urlUtils';
|
||||
import {encodeQueryParams} from 'app/common/gutil';
|
||||
import {WebhookUpdate} from 'app/common/Triggers';
|
||||
import {WebhookFields, WebhookSubscribe, WebhookSummary, WebhookUpdate} from 'app/common/Triggers';
|
||||
import omitBy from 'lodash/omitBy';
|
||||
|
||||
|
||||
export type {FullUser, UserProfile};
|
||||
|
||||
@@ -454,8 +456,12 @@ export interface DocAPI {
|
||||
// Get users that are worth proposing to "View As" for access control purposes.
|
||||
getUsersForViewAs(): Promise<PermissionDataWithExtraUsers>;
|
||||
|
||||
getWebhooks(): Promise<WebhookSummary[]>;
|
||||
addWebhook(webhook: WebhookFields): Promise<{webhookId: string}>;
|
||||
removeWebhook(webhookId: string, tableId: string): Promise<void>;
|
||||
// Update webhook
|
||||
updateWebhook(webhook: WebhookUpdate): Promise<void>;
|
||||
flushWebhooks(): Promise<void>;
|
||||
}
|
||||
|
||||
// Operations that are supported by a doc worker.
|
||||
@@ -905,6 +911,19 @@ export class DocAPIImpl extends BaseAPI implements DocAPI {
|
||||
return this.requestJson(`${this._url}/usersForViewAs`);
|
||||
}
|
||||
|
||||
public async getWebhooks(): Promise<WebhookSummary[]> {
|
||||
return this.requestJson(`${this._url}/webhooks`);
|
||||
}
|
||||
|
||||
public async addWebhook(webhook: WebhookSubscribe & {tableId: string}): Promise<{webhookId: string}> {
|
||||
const {tableId} = webhook;
|
||||
return this.requestJson(`${this._url}/tables/${tableId}/_subscribe`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(
|
||||
omitBy(webhook, (val, key) => key === 'tableId' || val === null)),
|
||||
});
|
||||
}
|
||||
|
||||
public async updateWebhook(webhook: WebhookUpdate): Promise<void> {
|
||||
return this.requestJson(`${this._url}/webhooks/${webhook.id}`, {
|
||||
method: 'PATCH',
|
||||
@@ -912,6 +931,21 @@ export class DocAPIImpl extends BaseAPI implements DocAPI {
|
||||
});
|
||||
}
|
||||
|
||||
public removeWebhook(webhookId: string, tableId: string) {
|
||||
// unsubscribeKey is not required for owners
|
||||
const unsubscribeKey = '';
|
||||
return this.requestJson(`${this._url}/tables/${tableId}/_unsubscribe`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({webhookId, unsubscribeKey}),
|
||||
});
|
||||
}
|
||||
|
||||
public async flushWebhooks(): Promise<void> {
|
||||
await this.request(`${this._url}/webhooks/queue`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
}
|
||||
|
||||
public async forceReload(): Promise<void> {
|
||||
await this.request(`${this._url}/force-reload`, {
|
||||
method: 'POST'
|
||||
|
||||
Reference in New Issue
Block a user