mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 13:19:44 +02:00
feat: Move webhooks configuration from environment variable to UI
This commit is contained in:
parent
f0680831c2
commit
b22dba0d11
128 changed files with 2077 additions and 206 deletions
|
@ -105,6 +105,10 @@ module.exports = {
|
|||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
webhooks: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
|
@ -130,7 +134,8 @@ module.exports = {
|
|||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'actionCreate',
|
||||
webhooks: inputs.webhooks,
|
||||
event: Webhook.Events.ACTION_CREATE,
|
||||
buildData: () => ({
|
||||
item: action,
|
||||
included: {
|
||||
|
@ -158,6 +163,7 @@ module.exports = {
|
|||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
list: inputs.list,
|
||||
webhooks: inputs.webhooks,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
@ -187,6 +193,7 @@ module.exports = {
|
|||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
list: inputs.list,
|
||||
webhooks: inputs.webhooks,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -48,8 +48,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'attachmentCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.ATTACHMENT_CREATE,
|
||||
buildData: () => ({
|
||||
item: sails.helpers.attachments.presentOne(attachment),
|
||||
included: {
|
||||
|
@ -65,6 +68,7 @@ module.exports = {
|
|||
if (!values.card.coverAttachmentId) {
|
||||
if (attachment.type === Attachment.Types.FILE && attachment.data.image) {
|
||||
await sails.helpers.cards.updateOne.with({
|
||||
webhooks,
|
||||
record: values.card,
|
||||
values: {
|
||||
coverAttachmentId: attachment.id,
|
||||
|
|
|
@ -37,6 +37,7 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
if (inputs.record.id === inputs.card.coverAttachmentId) {
|
||||
await sails.helpers.cards.updateOne.with({
|
||||
webhooks,
|
||||
record: inputs.card,
|
||||
values: {
|
||||
coverAttachmentId: null,
|
||||
|
@ -66,8 +67,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'attachmentDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.ATTACHMENT_DELETE,
|
||||
buildData: () => ({
|
||||
item: sails.helpers.attachments.presentOne(attachment),
|
||||
included: {
|
||||
|
|
|
@ -53,8 +53,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'attachmentUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.ATTACHMENT_UPDATE,
|
||||
buildData: () => ({
|
||||
item: sails.helpers.attachments.presentOne(attachment),
|
||||
included: {
|
||||
|
|
|
@ -47,8 +47,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'backgroundImageCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.BACKGROUND_IMAGE_CREATE,
|
||||
buildData: () => ({
|
||||
item: sails.helpers.backgroundImages.presentOne(backgroundImage),
|
||||
included: {
|
||||
|
@ -60,6 +63,7 @@ module.exports = {
|
|||
|
||||
await sails.helpers.projects.updateOne.with({
|
||||
scoper,
|
||||
webhooks,
|
||||
record: values.project,
|
||||
values: {
|
||||
backgroundImage,
|
||||
|
|
|
@ -31,6 +31,7 @@ module.exports = {
|
|||
if (inputs.record.id === inputs.project.backgroundImageId) {
|
||||
await sails.helpers.projects.updateOne.with({
|
||||
scoper,
|
||||
webhooks,
|
||||
record: inputs.project,
|
||||
values: {
|
||||
backgroundType: null,
|
||||
|
@ -58,8 +59,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'backgroundImageDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.BACKGROUND_IMAGE_DELETE,
|
||||
buildData: () => ({
|
||||
item: sails.helpers.backgroundImages.presentOne(backgroundImage),
|
||||
included: {
|
||||
|
|
|
@ -43,8 +43,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'baseCustomFieldGroupCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.BASE_CUSTOM_FIELD_GROUP_CREATE,
|
||||
buildData: () => ({
|
||||
item: baseCustomFieldGroup,
|
||||
included: {
|
||||
|
|
|
@ -45,8 +45,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'baseCustomFieldGroupDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.BASE_CUSTOM_FIELD_GROUP_DELETE,
|
||||
buildData: () => ({
|
||||
item: baseCustomFieldGroup,
|
||||
included: {
|
||||
|
|
|
@ -49,8 +49,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'baseCustomFieldGroupUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.BASE_CUSTOM_FIELD_GROUP_UPDATE,
|
||||
buildData: () => ({
|
||||
item: baseCustomFieldGroup,
|
||||
included: {
|
||||
|
|
|
@ -86,8 +86,11 @@ module.exports = {
|
|||
});
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'boardMembershipCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.BOARD_MEMBERSHIP_CREATE,
|
||||
buildData: () => ({
|
||||
item: boardMembership,
|
||||
included: {
|
||||
|
|
|
@ -106,8 +106,11 @@ module.exports = {
|
|||
});
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'boardMembershipDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.BOARD_MEMBERSHIP_DELETE,
|
||||
buildData: () => ({
|
||||
item: boardMembership,
|
||||
included: {
|
||||
|
|
|
@ -75,8 +75,11 @@ module.exports = {
|
|||
});
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'boardMembershipUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.BOARD_MEMBERSHIP_UPDATE,
|
||||
buildData: () => ({
|
||||
item: boardMembership,
|
||||
included: {
|
||||
|
|
|
@ -108,8 +108,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'boardCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.BOARD_CREATE,
|
||||
buildData: () => ({
|
||||
item: board,
|
||||
included: {
|
||||
|
|
|
@ -49,8 +49,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'boardDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.BOARD_DELETE,
|
||||
buildData: () => ({
|
||||
item: board,
|
||||
included: {
|
||||
|
|
|
@ -104,8 +104,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'boardUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.BOARD_UPDATE,
|
||||
buildData: () => ({
|
||||
item: board,
|
||||
included: {
|
||||
|
|
|
@ -61,8 +61,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardLabelCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CARD_LABEL_CREATE,
|
||||
buildData: () => ({
|
||||
item: cardLabel,
|
||||
included: {
|
||||
|
|
|
@ -47,8 +47,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardLabelDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.CARD_LABEL_DELETE,
|
||||
buildData: () => ({
|
||||
item: cardLabel,
|
||||
included: {
|
||||
|
|
|
@ -61,8 +61,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardMembershipCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CARD_MEMBERSHIP_CREATE,
|
||||
buildData: () => ({
|
||||
item: cardMembership,
|
||||
included: {
|
||||
|
@ -106,6 +109,7 @@ module.exports = {
|
|||
}
|
||||
|
||||
await sails.helpers.actions.createOne.with({
|
||||
webhooks,
|
||||
values: {
|
||||
type: Action.Types.ADD_MEMBER_TO_CARD,
|
||||
data: {
|
||||
|
|
|
@ -51,8 +51,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardMembershipDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.CARD_MEMBERSHIP_DELETE,
|
||||
buildData: () => ({
|
||||
item: cardMembership,
|
||||
included: {
|
||||
|
@ -82,6 +85,7 @@ module.exports = {
|
|||
}
|
||||
|
||||
await sails.helpers.actions.createOne.with({
|
||||
webhooks,
|
||||
values: {
|
||||
type: Action.Types.REMOVE_MEMBER_FROM_CARD,
|
||||
data: {
|
||||
|
|
|
@ -84,8 +84,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CARD_CREATE,
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
|
@ -120,6 +123,7 @@ module.exports = {
|
|||
}
|
||||
|
||||
await sails.helpers.actions.createOne.with({
|
||||
webhooks,
|
||||
values: {
|
||||
card,
|
||||
type: Action.Types.CREATE_CARD,
|
||||
|
|
|
@ -45,8 +45,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.CARD_DELETE,
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
|
|
|
@ -228,8 +228,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CARD_CREATE,
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
|
@ -272,6 +275,7 @@ module.exports = {
|
|||
}
|
||||
|
||||
await sails.helpers.actions.createOne.with({
|
||||
webhooks,
|
||||
values: {
|
||||
card,
|
||||
type: Action.Types.CREATE_CARD, // TODO: introduce separate type?
|
||||
|
|
|
@ -31,6 +31,8 @@ module.exports = {
|
|||
},
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
notifications.forEach((notification) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${notification.userId}`,
|
||||
|
@ -43,7 +45,8 @@ module.exports = {
|
|||
|
||||
// TODO: with prevData?
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'notificationUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.NOTIFICATION_UPDATE,
|
||||
buildData: () => ({
|
||||
item: notification,
|
||||
}),
|
||||
|
|
|
@ -31,6 +31,9 @@ module.exports = {
|
|||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
webhooks: {
|
||||
type: 'ref',
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
|
@ -104,6 +107,8 @@ module.exports = {
|
|||
if (_.isEmpty(values)) {
|
||||
card = inputs.record;
|
||||
} else {
|
||||
const { webhooks = await Webhook.qm.getAll() } = inputs;
|
||||
|
||||
if (!_.isNil(values.position)) {
|
||||
const cards = await Card.qm.getByListId(list.id, {
|
||||
exceptIdOrIds: inputs.record.id,
|
||||
|
@ -402,6 +407,7 @@ module.exports = {
|
|||
|
||||
const { id } = await sails.helpers.labels.createOne.with({
|
||||
project,
|
||||
webhooks,
|
||||
values: {
|
||||
..._.omit(label, ['id', 'boardId', 'createdAt', 'updatedAt']),
|
||||
board,
|
||||
|
@ -459,6 +465,7 @@ module.exports = {
|
|||
|
||||
if (values.list) {
|
||||
await sails.helpers.actions.createOne.with({
|
||||
webhooks,
|
||||
values: {
|
||||
card,
|
||||
type: Action.Types.MOVE_CARD,
|
||||
|
@ -477,7 +484,8 @@ module.exports = {
|
|||
}
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CARD_UPDATE,
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
|
|
|
@ -79,8 +79,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'commentCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.COMMENT_CREATE,
|
||||
buildData: () => ({
|
||||
item: comment,
|
||||
included: {
|
||||
|
@ -125,6 +128,7 @@ module.exports = {
|
|||
await Promise.all(
|
||||
notifiableUserIds.map((userId) =>
|
||||
sails.helpers.notifications.createOne.with({
|
||||
webhooks,
|
||||
values: {
|
||||
userId,
|
||||
comment,
|
||||
|
|
|
@ -47,8 +47,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'commentDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.COMMENT_DELETE,
|
||||
buildData: () => ({
|
||||
item: comment,
|
||||
included: {
|
||||
|
|
|
@ -53,8 +53,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'commentUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.COMMENT_UPDATE,
|
||||
buildData: () => ({
|
||||
item: comment,
|
||||
included: {
|
||||
|
|
|
@ -87,8 +87,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldGroupCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CUSTOM_FIELD_GROUP_CREATE,
|
||||
buildData: () => ({
|
||||
item: customFieldGroup,
|
||||
included: {
|
||||
|
|
|
@ -95,8 +95,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldGroupCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CUSTOM_FIELD_GROUP_CREATE,
|
||||
buildData: () => ({
|
||||
item: customFieldGroup,
|
||||
included: {
|
||||
|
|
|
@ -41,8 +41,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldGroupDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.CUSTOM_FIELD_GROUP_DELETE,
|
||||
buildData: () => ({
|
||||
item: customFieldGroup,
|
||||
included: {
|
||||
|
|
|
@ -49,8 +49,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldGroupDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.CUSTOM_FIELD_GROUP_DELETE,
|
||||
buildData: () => ({
|
||||
item: customFieldGroup,
|
||||
included: {
|
||||
|
|
|
@ -91,8 +91,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldGroupUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CUSTOM_FIELD_GROUP_UPDATE,
|
||||
buildData: () => ({
|
||||
item: customFieldGroup,
|
||||
included: {
|
||||
|
|
|
@ -99,8 +99,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldGroupUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CUSTOM_FIELD_GROUP_UPDATE,
|
||||
buildData: () => ({
|
||||
item: customFieldGroup,
|
||||
included: {
|
||||
|
|
|
@ -49,9 +49,12 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
// TODO: with prevData?
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldValueUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CUSTOM_FIELD_VALUE_UPDATE,
|
||||
buildData: () => ({
|
||||
item: customFieldValue,
|
||||
included: {
|
||||
|
|
|
@ -51,8 +51,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldValueDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.CUSTOM_FIELD_VALUE_DELETE,
|
||||
buildData: () => ({
|
||||
item: customFieldValue,
|
||||
included: {
|
||||
|
|
|
@ -93,8 +93,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CUSTOM_FIELD_CREATE,
|
||||
buildData: () => ({
|
||||
item: customField,
|
||||
included: {
|
||||
|
|
|
@ -103,8 +103,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CUSTOM_FIELD_CREATE,
|
||||
buildData: () => ({
|
||||
item: customField,
|
||||
included: {
|
||||
|
|
|
@ -49,8 +49,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.CUSTOM_FIELD_DELETE,
|
||||
buildData: () => ({
|
||||
item: customField,
|
||||
included: {
|
||||
|
|
|
@ -66,8 +66,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.CUSTOM_FIELD_DELETE,
|
||||
buildData: () => ({
|
||||
item: customField,
|
||||
included: {
|
||||
|
|
|
@ -94,8 +94,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CUSTOM_FIELD_UPDATE,
|
||||
buildData: () => ({
|
||||
item: customField,
|
||||
included: {
|
||||
|
|
|
@ -109,8 +109,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CUSTOM_FIELD_UPDATE,
|
||||
buildData: () => ({
|
||||
item: customField,
|
||||
included: {
|
||||
|
|
|
@ -17,6 +17,9 @@ module.exports = {
|
|||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
webhooks: {
|
||||
type: 'ref',
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
|
@ -70,8 +73,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const { webhooks = await Webhook.qm.getAll() } = inputs;
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'labelCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.LABEL_CREATE,
|
||||
buildData: () => ({
|
||||
item: label,
|
||||
included: {
|
||||
|
|
|
@ -41,8 +41,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'labelDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.LABEL_DELETE,
|
||||
buildData: () => ({
|
||||
item: label,
|
||||
included: {
|
||||
|
|
|
@ -81,8 +81,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'labelUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.LABEL_UPDATE,
|
||||
buildData: () => ({
|
||||
item: label,
|
||||
included: {
|
||||
|
|
|
@ -38,8 +38,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'listClear',
|
||||
webhooks,
|
||||
event: Webhook.Events.LIST_CLEAR,
|
||||
buildData: () => ({
|
||||
item: inputs.record,
|
||||
included: {
|
||||
|
|
|
@ -72,8 +72,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'listCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.LIST_CREATE,
|
||||
buildData: () => ({
|
||||
item: list,
|
||||
included: {
|
||||
|
|
|
@ -57,8 +57,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'listDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.LIST_DELETE,
|
||||
buildData: () => ({
|
||||
item: list,
|
||||
included: {
|
||||
|
|
|
@ -91,10 +91,13 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
cards.forEach((card) => {
|
||||
// TODO: with prevData?
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CARD_UPDATE,
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
|
|
|
@ -100,10 +100,13 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
cards.forEach((card) => {
|
||||
// TODO: with prevData?
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.CARD_UPDATE,
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
|
|
|
@ -84,8 +84,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'listUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.LIST_UPDATE,
|
||||
buildData: () => ({
|
||||
item: list,
|
||||
included: {
|
||||
|
|
|
@ -62,8 +62,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'notificationServiceCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.NOTIFICATION_SERVICE_CREATE,
|
||||
buildData: () => ({
|
||||
item: notificationService,
|
||||
included: {
|
||||
|
|
|
@ -48,8 +48,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'notificationServiceCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.NOTIFICATION_SERVICE_CREATE,
|
||||
buildData: () => ({
|
||||
item: notificationService,
|
||||
included: {
|
||||
|
|
|
@ -49,8 +49,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'notificationServiceDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.NOTIFICATION_SERVICE_DELETE,
|
||||
buildData: () => ({
|
||||
item: notificationService,
|
||||
included: {
|
||||
|
|
|
@ -35,8 +35,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'notificationServiceDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.NOTIFICATION_SERVICE_DELETE,
|
||||
buildData: () => ({
|
||||
item: notificationService,
|
||||
included: {
|
||||
|
|
|
@ -55,8 +55,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'notificationServiceUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.NOTIFICATION_SERVICE_UPDATE,
|
||||
buildData: () => ({
|
||||
item: notificationService,
|
||||
included: {
|
||||
|
|
|
@ -41,8 +41,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'notificationServiceUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.NOTIFICATION_SERVICE_UPDATE,
|
||||
buildData: () => ({
|
||||
item: notificationService,
|
||||
included: {
|
||||
|
|
|
@ -214,6 +214,10 @@ module.exports = {
|
|||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
webhooks: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
|
@ -248,7 +252,8 @@ module.exports = {
|
|||
});
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'notificationCreate',
|
||||
webhooks: inputs.webhooks,
|
||||
event: Webhook.Events.NOTIFICATION_CREATE,
|
||||
buildData: () => ({
|
||||
item: notification,
|
||||
included: {
|
||||
|
|
|
@ -26,6 +26,8 @@ module.exports = {
|
|||
},
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
notifications.forEach((notification) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${notification.userId}`,
|
||||
|
@ -38,7 +40,8 @@ module.exports = {
|
|||
|
||||
// TODO: with prevData?
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'notificationUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.NOTIFICATION_UPDATE,
|
||||
buildData: () => ({
|
||||
item: notification,
|
||||
}),
|
||||
|
|
|
@ -37,8 +37,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'notificationUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.NOTIFICATION_UPDATE,
|
||||
buildData: () => ({
|
||||
item: notification,
|
||||
}),
|
||||
|
|
|
@ -13,6 +13,9 @@ module.exports = {
|
|||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
webhooks: {
|
||||
type: 'ref',
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
|
@ -69,8 +72,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const { webhooks = await Webhook.qm.getAll() } = inputs;
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'projectManagerCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.PROJECT_MANAGER_CREATE,
|
||||
buildData: () => ({
|
||||
item: projectManager,
|
||||
included: {
|
||||
|
|
|
@ -85,8 +85,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'projectManagerDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.PROJECT_MANAGER_DELETE,
|
||||
buildData: () => ({
|
||||
item: projectManager,
|
||||
included: {
|
||||
|
|
|
@ -44,8 +44,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'projectCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.PROJECT_CREATE,
|
||||
buildData: () => ({
|
||||
item: project,
|
||||
}),
|
||||
|
|
|
@ -51,8 +51,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'projectDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.PROJECT_DELETE,
|
||||
buildData: () => ({
|
||||
item: project,
|
||||
}),
|
||||
|
|
|
@ -20,6 +20,9 @@ module.exports = {
|
|||
scoper: {
|
||||
type: 'ref',
|
||||
},
|
||||
webhooks: {
|
||||
type: 'ref',
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
|
@ -172,8 +175,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const { webhooks = await Webhook.qm.getAll() } = inputs;
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'projectUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.PROJECT_UPDATE,
|
||||
buildData: () => ({
|
||||
item: project,
|
||||
}),
|
||||
|
|
|
@ -80,8 +80,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'taskListCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.TASK_LIST_CREATE,
|
||||
buildData: () => ({
|
||||
item: taskList,
|
||||
included: {
|
||||
|
|
|
@ -49,8 +49,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'taskListDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.TASK_LIST_DELETE,
|
||||
buildData: () => ({
|
||||
item: taskList,
|
||||
included: {
|
||||
|
|
|
@ -91,8 +91,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'taskListUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.TASK_LIST_UPDATE,
|
||||
buildData: () => ({
|
||||
item: taskList,
|
||||
included: {
|
||||
|
|
|
@ -82,8 +82,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'taskCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.TASK_CREATE,
|
||||
buildData: () => ({
|
||||
item: task,
|
||||
included: {
|
||||
|
|
|
@ -51,8 +51,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'taskDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.TASK_DELETE,
|
||||
buildData: () => ({
|
||||
item: task,
|
||||
included: {
|
||||
|
|
|
@ -112,8 +112,11 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'taskUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.TASK_UPDATE,
|
||||
buildData: () => ({
|
||||
item: task,
|
||||
included: {
|
||||
|
@ -135,6 +138,7 @@ module.exports = {
|
|||
|
||||
if (inputs.record.isCompleted !== task.isCompleted) {
|
||||
await sails.helpers.actions.createOne.with({
|
||||
webhooks,
|
||||
values: {
|
||||
type: task.isCompleted ? Action.Types.COMPLETE_TASK : Action.Types.UNCOMPLETE_TASK,
|
||||
data: {
|
||||
|
|
|
@ -96,8 +96,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'userCreate',
|
||||
webhooks,
|
||||
event: Webhook.Events.USER_CREATE,
|
||||
buildData: () => ({
|
||||
item: sails.helpers.users.presentOne(user),
|
||||
}),
|
||||
|
|
|
@ -64,8 +64,11 @@ module.exports = {
|
|||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'userDelete',
|
||||
webhooks,
|
||||
event: Webhook.Events.USER_DELETE,
|
||||
buildData: () => ({
|
||||
item: sails.helpers.users.presentOne(user),
|
||||
}),
|
||||
|
@ -81,6 +84,7 @@ module.exports = {
|
|||
lonelyProjects.map((project) =>
|
||||
// TODO: optimize with scoper
|
||||
sails.helpers.projectManagers.createOne.with({
|
||||
webhooks,
|
||||
values: {
|
||||
project,
|
||||
user: inputs.actorUser,
|
||||
|
|
|
@ -200,8 +200,11 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'userUpdate',
|
||||
webhooks,
|
||||
event: Webhook.Events.USER_UPDATE,
|
||||
buildData: () => ({
|
||||
item: sails.helpers.users.presentOne(user),
|
||||
}),
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
72
server/api/helpers/webhooks/create-one.js
Normal file
72
server/api/helpers/webhooks/create-one.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
limitReached: {},
|
||||
},
|
||||
|
||||
// TODO: use normalizeValues
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
// TODO: move to config?
|
||||
if (webhooks.length >= 10) {
|
||||
throw 'limitReached';
|
||||
}
|
||||
|
||||
if (values.events) {
|
||||
values.events = _.intersection(values.events, Object.values(Webhook.Events));
|
||||
delete values.excludedEvents;
|
||||
} else if (values.excludedEvents) {
|
||||
values.excludedEvents = _.intersection(values.excludedEvents, Object.values(Webhook.Events));
|
||||
delete values.events;
|
||||
}
|
||||
|
||||
const webhook = await Webhook.qm.createOne(values);
|
||||
webhooks.push(webhook);
|
||||
|
||||
const scoper = sails.helpers.users.makeScoper(inputs.actorUser);
|
||||
const privateUserRelatedUserIds = await scoper.getPrivateUserRelatedUserIds();
|
||||
|
||||
privateUserRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'webhookCreate',
|
||||
{
|
||||
item: webhook,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
});
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
webhooks,
|
||||
event: Webhook.Events.WEBHOOK_CREATE,
|
||||
buildData: () => ({
|
||||
item: webhook,
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
return webhook;
|
||||
},
|
||||
};
|
53
server/api/helpers/webhooks/delete-one.js
Normal file
53
server/api/helpers/webhooks/delete-one.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
const webhook = await Webhook.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (webhook) {
|
||||
const scoper = sails.helpers.users.makeScoper(inputs.actorUser);
|
||||
const privateUserRelatedUserIds = await scoper.getPrivateUserRelatedUserIds();
|
||||
|
||||
privateUserRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'webhookDelete',
|
||||
{
|
||||
item: webhook,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
});
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
webhooks,
|
||||
event: Webhook.Events.WEBHOOK_DELETE,
|
||||
buildData: () => ({
|
||||
item: webhook,
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return webhook;
|
||||
},
|
||||
};
|
75
server/api/helpers/webhooks/update-one.js
Normal file
75
server/api/helpers/webhooks/update-one.js
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
// TODO: use normalizeValues
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (values.events) {
|
||||
Object.assign(values, {
|
||||
events: _.intersection(values.events, Object.values(Webhook.Events)),
|
||||
excludedEvents: null,
|
||||
});
|
||||
} else if (values.excludedEvents) {
|
||||
Object.assign(values, {
|
||||
events: null,
|
||||
excludedEvents: _.intersection(values.excludedEvents, Object.values(Webhook.Events)),
|
||||
});
|
||||
}
|
||||
|
||||
const webhook = await Webhook.qm.updateOne(inputs.record.id, values);
|
||||
|
||||
if (webhook) {
|
||||
const scoper = sails.helpers.users.makeScoper(inputs.actorUser);
|
||||
const privateUserRelatedUserIds = await scoper.getPrivateUserRelatedUserIds();
|
||||
|
||||
privateUserRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'webhookUpdate',
|
||||
{
|
||||
item: webhook,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
webhooks,
|
||||
event: Webhook.Events.WEBHOOK_UPDATE,
|
||||
buildData: () => ({
|
||||
item: webhook,
|
||||
}),
|
||||
buildPrevData: () => ({
|
||||
item: inputs.record,
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return webhook;
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue