import Planka upstream

This commit is contained in:
xiaojibeier
2026-07-18 11:48:22 +08:00
commit c26fd3b190
1564 changed files with 214813 additions and 0 deletions
@@ -0,0 +1,82 @@
/*!
* 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,
},
project: {
type: 'ref',
required: true,
},
actorUser: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
exits: {
limitReached: {},
},
async fn(inputs) {
const { values } = inputs;
const notificationServicesTotal = await sails.helpers.boards.getNotificationServicesTotal(
values.board.id,
);
// TODO: move to config?
if (notificationServicesTotal >= 5) {
throw 'limitReached';
}
const notificationService = await NotificationService.qm.createOne({
...values,
boardId: values.board.id,
});
const scoper = sails.helpers.projects.makeScoper.with({
notificationService,
record: inputs.project,
board: values.board,
});
const notificationServiceRelatedUserIds = await scoper.getNotificationServiceRelatedUserIds();
notificationServiceRelatedUserIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'notificationServiceCreate',
{
item: notificationService,
},
inputs.request,
);
});
const webhooks = await Webhook.qm.getAll();
sails.helpers.utils.sendWebhooks.with({
webhooks,
event: Webhook.Events.NOTIFICATION_SERVICE_CREATE,
buildData: () => ({
item: notificationService,
included: {
projects: [inputs.project],
boards: [values.board],
},
}),
user: inputs.actorUser,
});
return notificationService;
},
};
@@ -0,0 +1,67 @@
/*!
* 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: {},
},
async fn(inputs) {
const { values } = inputs;
const notificationServicesTotal = await sails.helpers.users.getNotificationServicesTotal(
values.user.id,
);
// TODO: move to config?
if (notificationServicesTotal >= 5) {
throw 'limitReached';
}
const notificationService = await NotificationService.qm.createOne({
...values,
userId: values.user.id,
});
sails.sockets.broadcast(
`user:${notificationService.userId}`,
'notificationServiceCreate',
{
item: notificationService,
},
inputs.request,
);
const webhooks = await Webhook.qm.getAll();
sails.helpers.utils.sendWebhooks.with({
webhooks,
event: Webhook.Events.NOTIFICATION_SERVICE_CREATE,
buildData: () => ({
item: notificationService,
included: {
users: [values.user],
},
}),
user: inputs.actorUser,
});
return notificationService;
},
};
@@ -0,0 +1,70 @@
/*!
* 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,
},
project: {
type: 'ref',
required: true,
},
board: {
type: 'ref',
required: true,
},
actorUser: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const notificationService = await NotificationService.qm.deleteOne(inputs.record.id);
if (notificationService) {
const scoper = sails.helpers.projects.makeScoper.with({
notificationService,
record: inputs.project,
board: inputs.board,
});
const notificationServiceRelatedUserIds = await scoper.getNotificationServiceRelatedUserIds();
notificationServiceRelatedUserIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'notificationServiceDelete',
{
item: notificationService,
},
inputs.request,
);
});
const webhooks = await Webhook.qm.getAll();
sails.helpers.utils.sendWebhooks.with({
webhooks,
event: Webhook.Events.NOTIFICATION_SERVICE_DELETE,
buildData: () => ({
item: notificationService,
included: {
projects: [inputs.project],
boards: [inputs.board],
},
}),
user: inputs.actorUser,
});
}
return notificationService;
},
};
@@ -0,0 +1,55 @@
/*!
* 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,
},
user: {
type: 'ref',
required: true,
},
actorUser: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const notificationService = await NotificationService.qm.deleteOne(inputs.record.id);
if (notificationService) {
sails.sockets.broadcast(
`user:${notificationService.userId}`,
'notificationServiceDelete',
{
item: notificationService,
},
inputs.request,
);
const webhooks = await Webhook.qm.getAll();
sails.helpers.utils.sendWebhooks.with({
webhooks,
event: Webhook.Events.NOTIFICATION_SERVICE_DELETE,
buildData: () => ({
item: notificationService,
included: {
users: [inputs.user],
},
}),
user: inputs.actorUser,
});
}
return notificationService;
},
};
@@ -0,0 +1,56 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
module.exports = {
inputs: {
id: {
type: 'string',
required: true,
},
},
exits: {
pathNotFound: {},
},
async fn(inputs) {
const notificationService = await NotificationService.qm.getOneById(inputs.id);
if (!notificationService) {
throw 'pathNotFound';
}
let pathToProject;
if (notificationService.userId) {
const user = await User.qm.getOneById(notificationService.userId);
if (!user) {
throw {
pathNotFound: {
notificationService,
},
};
}
pathToProject = {
user,
};
} else if (notificationService.boardId) {
pathToProject = await sails.helpers.boards
.getPathToProjectById(notificationService.boardId)
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
notificationService,
...nodes,
},
}));
}
return {
notificationService,
...pathToProject,
};
},
};
@@ -0,0 +1,79 @@
/*!
* 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,
},
board: {
type: 'ref',
required: true,
},
project: {
type: 'ref',
required: true,
},
actorUser: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const { values } = inputs;
const notificationService = await NotificationService.qm.updateOne(inputs.record.id, values);
if (notificationService) {
const scoper = sails.helpers.projects.makeScoper.with({
notificationService,
record: inputs.project,
board: inputs.board,
});
const notificationServiceRelatedUserIds = await scoper.getNotificationServiceRelatedUserIds();
notificationServiceRelatedUserIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'notificationServiceUpdate',
{
item: notificationService,
},
inputs.request,
);
});
const webhooks = await Webhook.qm.getAll();
sails.helpers.utils.sendWebhooks.with({
webhooks,
event: Webhook.Events.NOTIFICATION_SERVICE_UPDATE,
buildData: () => ({
item: notificationService,
included: {
projects: [inputs.project],
boards: [inputs.board],
},
}),
buildPrevData: () => ({
item: inputs.record,
}),
user: inputs.actorUser,
});
}
return notificationService;
},
};
@@ -0,0 +1,64 @@
/*!
* 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,
},
user: {
type: 'ref',
required: true,
},
actorUser: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const { values } = inputs;
const notificationService = await NotificationService.qm.updateOne(inputs.record.id, values);
if (notificationService) {
sails.sockets.broadcast(
`user:${notificationService.userId}`,
'notificationServiceUpdate',
{
item: notificationService,
},
inputs.request,
);
const webhooks = await Webhook.qm.getAll();
sails.helpers.utils.sendWebhooks.with({
webhooks,
event: Webhook.Events.NOTIFICATION_SERVICE_UPDATE,
buildData: () => ({
item: notificationService,
included: {
users: [inputs.user],
},
}),
buildPrevData: () => ({
item: inputs.record,
}),
user: inputs.actorUser,
});
}
return notificationService;
},
};