1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-23 23:29:43 +02:00

feat: Move webhooks configuration from environment variable to UI

This commit is contained in:
Maksim Eltyshev 2025-07-04 22:04:11 +02:00
parent f0680831c2
commit b22dba0d11
128 changed files with 2077 additions and 206 deletions

View file

@ -3,88 +3,7 @@
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
const EVENT_TYPES = {
ACTION_CREATE: 'actionCreate',
ATTACHMENT_CREATE: 'attachmentCreate',
ATTACHMENT_UPDATE: 'attachmentUpdate',
ATTACHMENT_DELETE: 'attachmentDelete',
BACKGROUND_IMAGE_CREATE: 'backgroundImageCreate',
BACKGROUND_IMAGE_DELETE: 'backgroundImageDelete',
BASE_CUSTOM_FIELD_GROUP_CREATE: 'baseCustomFieldGroupCreate',
BASE_CUSTOM_FIELD_GROUP_UPDATE: 'baseCustomFieldGroupUpdate',
BASE_CUSTOM_FIELD_GROUP_DELETE: 'baseCustomFieldGroupDelete',
BOARD_CREATE: 'boardCreate',
BOARD_UPDATE: 'boardUpdate',
BOARD_DELETE: 'boardDelete',
BOARD_MEMBERSHIP_CREATE: 'boardMembershipCreate',
BOARD_MEMBERSHIP_UPDATE: 'boardMembershipUpdate',
BOARD_MEMBERSHIP_DELETE: 'boardMembershipDelete',
CARD_CREATE: 'cardCreate',
CARD_UPDATE: 'cardUpdate',
CARD_DELETE: 'cardDelete',
CARD_LABEL_CREATE: 'cardLabelCreate',
CARD_LABEL_DELETE: 'cardLabelDelete',
CARD_MEMBERSHIP_CREATE: 'cardMembershipCreate',
CARD_MEMBERSHIP_DELETE: 'cardMembershipDelete',
COMMENT_CREATE: 'commentCreate',
COMMENT_UPDATE: 'commentUpdate',
COMMENT_DELETE: 'commentDelete',
CUSTOM_FIELD_CREATE: 'customFieldCreate',
CUSTOM_FIELD_UPDATE: 'customFieldUpdate',
CUSTOM_FIELD_DELETE: 'customFieldDelete',
CUSTOM_FIELD_GROUP_CREATE: 'customFieldGroupCreate',
CUSTOM_FIELD_GROUP_UPDATE: 'customFieldGroupUpdate',
CUSTOM_FIELD_GROUP_DELETE: 'customFieldGroupDelete',
CUSTOM_FIELD_VALUE_UPDATE: 'customFieldValueUpdate',
CUSTOM_FIELD_VALUE_DELETE: 'customFieldValueDelete',
LABEL_CREATE: 'labelCreate',
LABEL_UPDATE: 'labelUpdate',
LABEL_DELETE: 'labelDelete',
LIST_CREATE: 'listCreate',
LIST_UPDATE: 'listUpdate',
LIST_CLEAR: 'listClear',
LIST_DELETE: 'listDelete',
NOTIFICATION_CREATE: 'notificationCreate',
NOTIFICATION_UPDATE: 'notificationUpdate',
NOTIFICATION_SERVICE_CREATE: 'notificationServiceCreate',
NOTIFICATION_SERVICE_UPDATE: 'notificationServiceUpdate',
NOTIFICATION_SERVICE_DELETE: 'notificationServiceDelete',
PROJECT_CREATE: 'projectCreate',
PROJECT_UPDATE: 'projectUpdate',
PROJECT_DELETE: 'projectDelete',
PROJECT_MANAGER_CREATE: 'projectManagerCreate',
PROJECT_MANAGER_DELETE: 'projectManagerDelete',
TASK_CREATE: 'taskCreate',
TASK_UPDATE: 'taskUpdate',
TASK_DELETE: 'taskDelete',
TASK_LIST_CREATE: 'taskListCreate',
TASK_LIST_UPDATE: 'taskListUpdate',
TASK_LIST_DELETE: 'taskListDelete',
USER_CREATE: 'userCreate',
USER_UPDATE: 'userUpdate',
USER_DELETE: 'userDelete',
};
const Webhook = require('../../models/Webhook');
/**
* @typedef {Object} Included
@ -114,7 +33,7 @@ const EVENT_TYPES = {
* Sends a webhook notification to a configured URL.
*
* @param {*} webhook - Webhook configuration.
* @param {string} event - The event (see {@link EVENT_TYPES}).
* @param {string} event - The event.
* @param {Data} data - The data object containing event data and optionally included data.
* @param {Data} [prevData] - The data object containing previous state of data (optional).
* @param {ref} user - User object associated with the event.
@ -148,11 +67,11 @@ async function sendWebhook(webhook, event, data, prevData, user) {
const message = await response.text();
sails.log.error(
`Webhook ${webhook.url} failed with status ${response.status} and message: ${message}`,
`Webhook ${webhook.name} failed with status ${response.status} and message: ${message}`,
);
}
} catch (error) {
sails.log.error(`Webhook ${webhook.url} failed with error: ${error}`);
sails.log.error(`Webhook ${webhook.name} failed with error: ${error}`);
}
}
@ -160,10 +79,14 @@ module.exports = {
sync: true,
inputs: {
webhooks: {
type: 'ref',
required: true,
},
event: {
type: 'string',
required: true,
isIn: Object.values(EVENT_TYPES),
isIn: Object.values(Webhook.Events),
},
buildData: {
type: 'ref',
@ -179,11 +102,7 @@ module.exports = {
},
fn(inputs) {
if (!sails.config.custom.webhooks) {
return;
}
const webhooks = sails.config.custom.webhooks.filter((webhook) => {
const webhooks = inputs.webhooks.filter((webhook) => {
if (!webhook.url) {
return false;
}