diff --git a/docs-core/src/main/java/com/sismics/docs/core/listener/async/WebhookAsyncListener.java b/docs-core/src/main/java/com/sismics/docs/core/listener/async/WebhookAsyncListener.java index b95f5360..5ad81ae1 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/listener/async/WebhookAsyncListener.java +++ b/docs-core/src/main/java/com/sismics/docs/core/listener/async/WebhookAsyncListener.java @@ -48,7 +48,7 @@ public class WebhookAsyncListener { @Subscribe @AllowConcurrentEvents public void on(final DocumentDeletedAsyncEvent event) { - triggerWebhook(WebhookEvent.DOCUMENT_UPDATED, event.getDocumentId()); + triggerWebhook(WebhookEvent.DOCUMENT_DELETED, event.getDocumentId()); } @Subscribe diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/WebhookResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/WebhookResource.java index 97f74251..46c96909 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/WebhookResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/WebhookResource.java @@ -29,7 +29,7 @@ public class WebhookResource extends BaseResource { * * @api {get} /webhook Get webhooks * @apiName GetWebhook - * @apiWebhook Webhook + * @apiGroup Webhook * @apiSuccess {Object[]} webhooks List of webhooks * @apiSuccess {String} webhooks.id ID * @apiSuccess {String} webhooks.event Event @@ -69,7 +69,7 @@ public class WebhookResource extends BaseResource { * @api {put} /webhook Add a webhook * @apiDescription Each time the specified event is raised, the webhook URL will be POST-ed with the following JSON payload: {"event": "Event name", "id": "ID of the document or file"} * @apiName PutWebhook - * @apiWebhook Webhook + * @apiGroup Webhook * @apiParam {String="DOCUMENT_CREATED","DOCUMENT_UPDATED","DOCUMENT_DELETED","FILE_CREATED","FILE_UPDATED","FILE_DELETED"} event Event * @apiParam {String} url URL * @apiSuccess {String} status Status OK @@ -109,7 +109,7 @@ public class WebhookResource extends BaseResource { * * @api {delete} /webhook/:id Delete a webhook * @apiName DeleteWebhook - * @apiWebhook Webhook + * @apiGroup Webhook * @apiParam {String} id Webhook ID * @apiSuccess {String} status Status OK * @apiError (client) ForbiddenError Access denied diff --git a/docs-web/src/main/webapp/src/app/docs/controller/settings/SettingsConfig.js b/docs-web/src/main/webapp/src/app/docs/controller/settings/SettingsConfig.js index 22cc0de8..d3e22dc6 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/settings/SettingsConfig.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/settings/SettingsConfig.js @@ -82,4 +82,30 @@ angular.module('docs').controller('SettingsConfig', function($scope, $rootScope, $scope.editGeneralConfig = function () { Restangular.one('app').post('config', $scope.general); }; + + // Get the webhooks + $scope.loadWebhooks = function () { + Restangular.one('webhook').get().then(function (data) { + $scope.webhooks = data.webhooks; + }); + }; + + $scope.loadWebhooks(); + + // Add a webhook + $scope.webhook = { + event: 'DOCUMENT_CREATED' + }; + $scope.addWebhook = function () { + Restangular.one('webhook').put($scope.webhook).then(function () { + $scope.loadWebhooks(); + }) + }; + + // Delete a webhook + $scope.deleteWebhook = function (webhook) { + Restangular.one('webhook', webhook.id).remove().then(function () { + $scope.loadWebhooks(); + }); + }; }); \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/locale/en.json b/docs-web/src/main/webapp/src/locale/en.json index 28b3621d..e23b5b89 100644 --- a/docs-web/src/main/webapp/src/locale/en.json +++ b/docs-web/src/main/webapp/src/locale/en.json @@ -377,7 +377,13 @@ "smtp_from": "Sender e-mail", "smtp_username": "SMTP username", "smtp_password": "SMTP password", - "smtp_updated": "SMTP configuration updated successfully" + "smtp_updated": "SMTP configuration updated successfully", + "webhooks": "Webhooks", + "webhooks_explain": "Webhooks will be called when the specified event occur. The given URL will be POST-ed with a JSON payload containing the event name and the ID of the concerned resource.", + "webhook_event": "Event", + "webhook_url": "URL", + "webhook_create_date": "Create date", + "webhook_add": "Add a webhook" }, "inbox": { "title": "Inbox scanning", diff --git a/docs-web/src/main/webapp/src/partial/docs/settings.config.html b/docs-web/src/main/webapp/src/partial/docs/settings.config.html index 9e281847..d28a26a8 100644 --- a/docs-web/src/main/webapp/src/partial/docs/settings.config.html +++ b/docs-web/src/main/webapp/src/partial/docs/settings.config.html @@ -142,4 +142,58 @@ - \ No newline at end of file + + +

+

+ +
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ +
+
+
+ +
+ + + + + + + + + + + + + + +
{{ 'settings.config.webhook_event' | translate }}{{ 'settings.config.webhook_url' | translate }}{{ 'settings.config.webhook_create_date' | translate }}
{{ webhook.event }}{{ webhook.url }}{{ webhook.create_date | date: dateFormat }} + +
+
\ No newline at end of file