mirror of
https://github.com/plankanban/planka.git
synced 2025-07-24 15:49:46 +02:00
parent
ad7fb51cfa
commit
2ee1166747
1557 changed files with 76832 additions and 47042 deletions
|
@ -1,77 +1,96 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
if (!_.isPlainObject(value.card)) {
|
||||
return false;
|
||||
}
|
||||
const escapeMarkdown = require('escape-markdown');
|
||||
const escapeHtml = require('escape-html');
|
||||
|
||||
if (!_.isPlainObject(value.user)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const truncateString = (string, maxLength = 30) =>
|
||||
string.length > maxLength ? `${string.substring(0, 30)}...` : string;
|
||||
|
||||
const buildAndSendMarkdownMessage = async (card, action, actorUser, send) => {
|
||||
const cardLink = `<${sails.config.custom.baseUrl}/cards/${card.id}|${card.name}>`;
|
||||
|
||||
let markdown;
|
||||
const buildTitle = (action, t) => {
|
||||
switch (action.type) {
|
||||
case Action.Types.CREATE_CARD:
|
||||
markdown = `${cardLink} was created by ${actorUser.name} in *${action.data.list.name}*`;
|
||||
|
||||
break;
|
||||
return t('Card Created');
|
||||
case Action.Types.MOVE_CARD:
|
||||
markdown = `${cardLink} was moved by ${actorUser.name} to *${action.data.toList.name}*`;
|
||||
|
||||
break;
|
||||
case Action.Types.COMMENT_CARD:
|
||||
// TODO: truncate text?
|
||||
markdown = `*${actorUser.name}* commented on ${cardLink}:\n>${action.data.text}`;
|
||||
|
||||
break;
|
||||
return t('Card Moved');
|
||||
default:
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
await send(markdown);
|
||||
};
|
||||
|
||||
const buildAndSendHtmlMessage = async (card, action, actorUser, send) => {
|
||||
const cardLink = `<a href="${sails.config.custom.baseUrl}/cards/${card.id}">${card.name}</a>`;
|
||||
const buildBodyByFormat = (board, card, action, actorUser, t) => {
|
||||
const markdownCardLink = `[${escapeMarkdown(card.name)}](${sails.config.custom.baseUrl}/cards/${card.id})`;
|
||||
const htmlCardLink = `<a href="${sails.config.custom.baseUrl}/cards/${card.id}}">${escapeHtml(card.name)}</a>`;
|
||||
|
||||
let html;
|
||||
switch (action.type) {
|
||||
case Action.Types.CREATE_CARD:
|
||||
html = `${cardLink} was created by ${actorUser.name} in <b>${action.data.list.name}</b>`;
|
||||
case Action.Types.CREATE_CARD: {
|
||||
const listName = sails.helpers.lists.makeName(action.data.list);
|
||||
|
||||
break;
|
||||
case Action.Types.MOVE_CARD:
|
||||
html = `${cardLink} was moved by ${actorUser.name} to <b>${action.data.toList.name}</b>`;
|
||||
return {
|
||||
text: t('%s created %s in %s on %s', actorUser.name, card.name, listName, board.name),
|
||||
markdown: t(
|
||||
'%s created %s in %s on %s',
|
||||
escapeMarkdown(actorUser.name),
|
||||
markdownCardLink,
|
||||
`**${escapeMarkdown(listName)}**`,
|
||||
escapeMarkdown(board.name),
|
||||
),
|
||||
html: t(
|
||||
'%s created %s in %s on %s',
|
||||
escapeHtml(actorUser.name),
|
||||
htmlCardLink,
|
||||
`<b>${escapeHtml(listName)}</b>`,
|
||||
escapeHtml(board.name),
|
||||
),
|
||||
};
|
||||
}
|
||||
case Action.Types.MOVE_CARD: {
|
||||
const fromListName = sails.helpers.lists.makeName(action.data.fromList);
|
||||
const toListName = sails.helpers.lists.makeName(action.data.toList);
|
||||
|
||||
break;
|
||||
case Action.Types.COMMENT_CARD: {
|
||||
html = `<b>${actorUser.name}</b> commented on ${cardLink}:\n<i>${truncateString(action.data.text)}</i>`;
|
||||
|
||||
break;
|
||||
return {
|
||||
text: t(
|
||||
'%s moved %s from %s to %s on %s',
|
||||
actorUser.name,
|
||||
card.name,
|
||||
fromListName,
|
||||
toListName,
|
||||
board.name,
|
||||
),
|
||||
markdown: t(
|
||||
'%s moved %s from %s to %s on %s',
|
||||
escapeMarkdown(actorUser.name),
|
||||
markdownCardLink,
|
||||
`**${escapeMarkdown(fromListName)}**`,
|
||||
`**${escapeMarkdown(toListName)}**`,
|
||||
escapeMarkdown(board.name),
|
||||
),
|
||||
html: t(
|
||||
'%s moved %s from %s to %s on %s',
|
||||
escapeHtml(actorUser.name),
|
||||
htmlCardLink,
|
||||
`<b>${escapeHtml(fromListName)}</b>`,
|
||||
`<b>${escapeHtml(toListName)}</b>`,
|
||||
escapeHtml(board.name),
|
||||
),
|
||||
};
|
||||
}
|
||||
default:
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
await send(html);
|
||||
const buildAndSendNotifications = async (services, board, card, action, actorUser, t) => {
|
||||
await sails.helpers.utils.sendNotifications(
|
||||
services,
|
||||
buildTitle(action, t),
|
||||
buildBodyByFormat(board, card, action, actorUser, t),
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
|
@ -94,14 +113,14 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const action = await Action.create({
|
||||
const action = await Action.qm.createOne({
|
||||
...values,
|
||||
cardId: values.card.id,
|
||||
userId: values.user.id,
|
||||
}).fetch();
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${values.card.boardId}`,
|
||||
`board:${inputs.board.id}`,
|
||||
'actionCreate',
|
||||
{
|
||||
item: action,
|
||||
|
@ -111,7 +130,7 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'actionCreate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: action,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
|
@ -119,55 +138,59 @@ module.exports = {
|
|||
lists: [inputs.list],
|
||||
cards: [values.card],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: values.user,
|
||||
});
|
||||
|
||||
const subscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(
|
||||
action.cardId,
|
||||
action.userId,
|
||||
);
|
||||
if (action.type !== Action.Types.CREATE_CARD) {
|
||||
const cardSubscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(
|
||||
action.cardId,
|
||||
action.userId,
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
subscriptionUserIds.map(async (userId) =>
|
||||
sails.helpers.notifications.createOne.with({
|
||||
values: {
|
||||
userId,
|
||||
action,
|
||||
},
|
||||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
list: inputs.list,
|
||||
card: values.card,
|
||||
actorUser: values.user,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const boardSubscriptionUserIds = await sails.helpers.boards.getSubscriptionUserIds(
|
||||
inputs.board.id,
|
||||
action.userId,
|
||||
);
|
||||
|
||||
if (sails.config.custom.slackBotToken) {
|
||||
buildAndSendMarkdownMessage(
|
||||
values.card,
|
||||
action,
|
||||
values.user,
|
||||
sails.helpers.utils.sendSlackMessage,
|
||||
const notifiableUserIds = _.union(cardSubscriptionUserIds, boardSubscriptionUserIds);
|
||||
|
||||
await Promise.all(
|
||||
notifiableUserIds.map((userId) =>
|
||||
sails.helpers.notifications.createOne.with({
|
||||
values: {
|
||||
userId,
|
||||
action,
|
||||
type: action.type,
|
||||
data: {
|
||||
...action.data,
|
||||
card: _.pick(values.card, ['name']),
|
||||
},
|
||||
creatorUser: values.user,
|
||||
card: values.card,
|
||||
},
|
||||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
list: inputs.list,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (sails.config.custom.googleChatWebhookUrl) {
|
||||
buildAndSendMarkdownMessage(
|
||||
values.card,
|
||||
action,
|
||||
values.user,
|
||||
sails.helpers.utils.sendGoogleChatMessage,
|
||||
);
|
||||
}
|
||||
const notificationServices = await NotificationService.qm.getByBoardId(inputs.board.id);
|
||||
|
||||
if (sails.config.custom.telegramBotToken) {
|
||||
buildAndSendHtmlMessage(
|
||||
if (notificationServices.length > 0) {
|
||||
const services = notificationServices.map((notificationService) =>
|
||||
_.pick(notificationService, ['url', 'format']),
|
||||
);
|
||||
|
||||
buildAndSendNotifications(
|
||||
services,
|
||||
inputs.board,
|
||||
values.card,
|
||||
action,
|
||||
values.user,
|
||||
sails.helpers.utils.sendTelegramMessage,
|
||||
sails.helpers.utils.makeTranslator(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: criteriaValidator,
|
||||
},
|
||||
limit: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return Action.find(inputs.criteria).sort('id DESC').limit(inputs.limit);
|
||||
},
|
||||
};
|
|
@ -1,34 +0,0 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
pathNotFound: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const action = await Action.findOne(inputs.criteria);
|
||||
|
||||
if (!action) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const path = await sails.helpers.cards
|
||||
.getProjectPath(action.cardId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
action,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
action,
|
||||
...path,
|
||||
};
|
||||
},
|
||||
};
|
|
@ -1,24 +1,12 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.card)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.creatorUser)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
/*!
|
||||
* 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',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
|
@ -35,7 +23,6 @@ module.exports = {
|
|||
},
|
||||
requestId: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
|
@ -45,17 +32,17 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const attachment = await Attachment.create({
|
||||
const attachment = await Attachment.qm.createOne({
|
||||
...values,
|
||||
cardId: values.card.id,
|
||||
creatorUserId: values.creatorUser.id,
|
||||
}).fetch();
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${values.card.boardId}`,
|
||||
`board:${inputs.board.id}`,
|
||||
'attachmentCreate',
|
||||
{
|
||||
item: attachment,
|
||||
item: sails.helpers.attachments.presentOne(attachment),
|
||||
requestId: inputs.requestId,
|
||||
},
|
||||
inputs.request,
|
||||
|
@ -63,29 +50,31 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'attachmentCreate',
|
||||
data: {
|
||||
item: attachment,
|
||||
buildData: () => ({
|
||||
item: sails.helpers.attachments.presentOne(attachment),
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
cards: [values.card],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: values.creatorUser,
|
||||
});
|
||||
|
||||
if (!values.card.coverAttachmentId && attachment.image) {
|
||||
await sails.helpers.cards.updateOne.with({
|
||||
record: values.card,
|
||||
values: {
|
||||
coverAttachmentId: attachment.id,
|
||||
},
|
||||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
list: inputs.list,
|
||||
actorUser: values.creatorUser,
|
||||
});
|
||||
if (!values.card.coverAttachmentId) {
|
||||
if (attachment.type === Attachment.Types.FILE && attachment.data.image) {
|
||||
await sails.helpers.cards.updateOne.with({
|
||||
record: values.card,
|
||||
values: {
|
||||
coverAttachmentId: attachment.id,
|
||||
},
|
||||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
list: inputs.list,
|
||||
actorUser: values.creatorUser,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return attachment;
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/*!
|
||||
* 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: {
|
||||
|
@ -40,43 +45,38 @@ module.exports = {
|
|||
board: inputs.board,
|
||||
list: inputs.list,
|
||||
actorUser: inputs.actorUser,
|
||||
request: inputs.request,
|
||||
});
|
||||
}
|
||||
|
||||
const attachment = await Attachment.archiveOne(inputs.record.id);
|
||||
const { attachment, fileReference } = await Attachment.qm.deleteOne(inputs.record.id, {
|
||||
isFile: inputs.record.type === Attachment.Types.FILE,
|
||||
});
|
||||
|
||||
if (attachment) {
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
|
||||
try {
|
||||
await fileManager.deleteDir(
|
||||
`${sails.config.custom.attachmentsPathSegment}/${attachment.dirname}`,
|
||||
);
|
||||
} catch (error) {
|
||||
console.warn(error.stack); // eslint-disable-line no-console
|
||||
if (fileReference) {
|
||||
sails.helpers.attachments.removeUnreferencedFiles(fileReference);
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'attachmentDelete',
|
||||
{
|
||||
item: attachment,
|
||||
item: sails.helpers.attachments.presentOne(attachment),
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'attachmentDelete',
|
||||
data: {
|
||||
item: attachment,
|
||||
buildData: () => ({
|
||||
item: sails.helpers.attachments.presentOne(attachment),
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
cards: [inputs.card],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: criteriaValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return Attachment.find(inputs.criteria).sort('id');
|
||||
},
|
||||
};
|
39
server/api/helpers/attachments/get-path-to-project-by-id.js
Normal file
39
server/api/helpers/attachments/get-path-to-project-by-id.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*!
|
||||
* 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 attachment = await Attachment.qm.getOneById(inputs.id);
|
||||
|
||||
if (!attachment) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const pathToProject = await sails.helpers.cards
|
||||
.getPathToProjectById(attachment.cardId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
attachment,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
attachment,
|
||||
...pathToProject,
|
||||
};
|
||||
},
|
||||
};
|
|
@ -1,34 +0,0 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
pathNotFound: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const attachment = await Attachment.findOne(inputs.criteria);
|
||||
|
||||
if (!attachment) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const path = await sails.helpers.cards
|
||||
.getProjectPath(attachment.cardId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
attachment,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
attachment,
|
||||
...path,
|
||||
};
|
||||
},
|
||||
};
|
19
server/api/helpers/attachments/present-many.js
Normal file
19
server/api/helpers/attachments/present-many.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
records: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
return inputs.records.map((record) => sails.helpers.attachments.presentOne(record));
|
||||
},
|
||||
};
|
56
server/api/helpers/attachments/present-one.js
Normal file
56
server/api/helpers/attachments/present-one.js
Normal file
|
@ -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 = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
let data;
|
||||
if (inputs.record.type === Attachment.Types.FILE) {
|
||||
data = {
|
||||
...inputs.record,
|
||||
data: {
|
||||
..._.omit(inputs.record.data, [
|
||||
'fileReferenceId',
|
||||
'filename',
|
||||
'image.thumbnailsExtension',
|
||||
]),
|
||||
url: `${sails.config.custom.baseUrl}/attachments/${inputs.record.id}/download/${inputs.record.data.filename}`,
|
||||
thumbnailUrls: inputs.record.data.image && {
|
||||
outside360: `${sails.config.custom.baseUrl}/attachments/${inputs.record.id}/download/thumbnails/outside-360.${inputs.record.data.image.thumbnailsExtension}`,
|
||||
outside720: `${sails.config.custom.baseUrl}/attachments/${inputs.record.id}/download/thumbnails/outside-720.${inputs.record.data.image.thumbnailsExtension}`,
|
||||
},
|
||||
},
|
||||
};
|
||||
} else if (inputs.record.type === Attachment.Types.LINK) {
|
||||
const faviconFilename = `${inputs.record.data.hostname}.png`;
|
||||
|
||||
let faviconUrl = null;
|
||||
if (sails.helpers.utils.isPreloadedFaviconExists(inputs.record.data.hostname)) {
|
||||
faviconUrl = `${sails.config.custom.baseUrl}/preloaded-favicons/${faviconFilename}`;
|
||||
} else {
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
faviconUrl = `${fileManager.buildUrl(`${sails.config.custom.faviconsPathSegment}/${faviconFilename}`)}`;
|
||||
}
|
||||
|
||||
data = {
|
||||
...inputs.record,
|
||||
data: {
|
||||
..._.omit(inputs.record.data, 'hostname'),
|
||||
faviconUrl,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
};
|
28
server/api/helpers/attachments/process-link.js
Normal file
28
server/api/helpers/attachments/process-link.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const { URL } = require('url');
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
url: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { hostname } = new URL(inputs.url);
|
||||
|
||||
if (!sails.helpers.utils.isPreloadedFaviconExists(hostname)) {
|
||||
await sails.helpers.utils.downloadFavicon(inputs.url);
|
||||
}
|
||||
|
||||
return {
|
||||
hostname,
|
||||
url: inputs.url,
|
||||
};
|
||||
},
|
||||
};
|
|
@ -1,8 +1,16 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const fsPromises = require('fs').promises;
|
||||
const { rimraf } = require('rimraf');
|
||||
const { v4: uuid } = require('uuid');
|
||||
const { getEncoding } = require('istextorbinary');
|
||||
const mime = require('mime');
|
||||
const sharp = require('sharp');
|
||||
|
||||
const filenamify = require('../../../utils/filenamify');
|
||||
const { MAX_SIZE_IN_BYTES_TO_GET_ENCODING } = require('../../../constants');
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
|
@ -15,78 +23,115 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
|
||||
const dirname = uuid();
|
||||
const dirPathSegment = `${sails.config.custom.attachmentsPathSegment}/${dirname}`;
|
||||
const { id: fileReferenceId } = await FileReference.create().fetch();
|
||||
const dirPathSegment = `${sails.config.custom.attachmentsPathSegment}/${fileReferenceId}`;
|
||||
const filename = filenamify(inputs.file.filename);
|
||||
|
||||
const mimeType = mime.getType(filename);
|
||||
const sizeInBytes = inputs.file.size;
|
||||
|
||||
let buffer;
|
||||
let encoding = null;
|
||||
|
||||
if (sizeInBytes <= MAX_SIZE_IN_BYTES_TO_GET_ENCODING) {
|
||||
try {
|
||||
buffer = await fsPromises.readFile(inputs.file.fd);
|
||||
} catch (error) {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
if (buffer) {
|
||||
encoding = getEncoding(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
const filePath = await fileManager.move(
|
||||
inputs.file.fd,
|
||||
`${dirPathSegment}/${filename}`,
|
||||
inputs.file.type,
|
||||
);
|
||||
|
||||
let image = sharp(filePath || inputs.file.fd, {
|
||||
animated: true,
|
||||
});
|
||||
|
||||
let metadata;
|
||||
try {
|
||||
metadata = await image.metadata();
|
||||
} catch (error) {} // eslint-disable-line no-empty
|
||||
|
||||
const fileData = {
|
||||
dirname,
|
||||
const data = {
|
||||
fileReferenceId,
|
||||
filename,
|
||||
mimeType,
|
||||
sizeInBytes,
|
||||
encoding,
|
||||
image: null,
|
||||
name: inputs.file.filename,
|
||||
};
|
||||
|
||||
if (metadata && !['svg', 'pdf'].includes(metadata.format)) {
|
||||
let { width, pageHeight: height = metadata.height } = metadata;
|
||||
if (metadata.orientation && metadata.orientation > 4) {
|
||||
[image, width, height] = [image.rotate(), height, width];
|
||||
if (!['image/svg+xml', 'application/pdf'].includes(mimeType)) {
|
||||
let image = sharp(buffer || filePath, {
|
||||
animated: true,
|
||||
});
|
||||
|
||||
let metadata;
|
||||
try {
|
||||
metadata = await image.metadata();
|
||||
} catch (error) {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
const isPortrait = height > width;
|
||||
const thumbnailsExtension = metadata.format === 'jpeg' ? 'jpg' : metadata.format;
|
||||
if (metadata) {
|
||||
let { width, pageHeight: height = metadata.height } = metadata;
|
||||
if (metadata.orientation && metadata.orientation > 4) {
|
||||
[image, width, height] = [image.rotate(), height, width];
|
||||
}
|
||||
|
||||
try {
|
||||
const resizeBuffer = await image
|
||||
.resize(
|
||||
256,
|
||||
isPortrait ? 320 : undefined,
|
||||
width < 256 || (isPortrait && height < 320)
|
||||
? {
|
||||
kernel: sharp.kernel.nearest,
|
||||
}
|
||||
: undefined,
|
||||
)
|
||||
.toBuffer();
|
||||
const thumbnailsPathSegment = `${dirPathSegment}/thumbnails`;
|
||||
const thumbnailsExtension = metadata.format === 'jpeg' ? 'jpg' : metadata.format;
|
||||
|
||||
await fileManager.save(
|
||||
`${dirPathSegment}/thumbnails/cover-256.${thumbnailsExtension}`,
|
||||
resizeBuffer,
|
||||
inputs.file.type,
|
||||
);
|
||||
try {
|
||||
const outside360Buffer = await image
|
||||
.resize(360, 360, {
|
||||
fit: 'outside',
|
||||
withoutEnlargement: true,
|
||||
})
|
||||
.png({
|
||||
quality: 75,
|
||||
force: false,
|
||||
})
|
||||
.toBuffer();
|
||||
|
||||
fileData.image = {
|
||||
width,
|
||||
height,
|
||||
thumbnailsExtension,
|
||||
};
|
||||
} catch (error) {
|
||||
console.warn(error.stack); // eslint-disable-line no-console
|
||||
await fileManager.save(
|
||||
`${thumbnailsPathSegment}/outside-360.${thumbnailsExtension}`,
|
||||
outside360Buffer,
|
||||
inputs.file.type,
|
||||
);
|
||||
|
||||
const outside720Buffer = await image
|
||||
.resize(720, 720, {
|
||||
fit: 'outside',
|
||||
withoutEnlargement: true,
|
||||
})
|
||||
.png({
|
||||
quality: 75,
|
||||
force: false,
|
||||
})
|
||||
.toBuffer();
|
||||
|
||||
await fileManager.save(
|
||||
`${thumbnailsPathSegment}/outside-720.${thumbnailsExtension}`,
|
||||
outside720Buffer,
|
||||
inputs.file.type,
|
||||
);
|
||||
|
||||
data.image = {
|
||||
width,
|
||||
height,
|
||||
thumbnailsExtension,
|
||||
};
|
||||
} catch (error) {
|
||||
sails.log.warn(error.stack);
|
||||
await fileManager.deleteDir(thumbnailsPathSegment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!filePath) {
|
||||
try {
|
||||
await rimraf(inputs.file.fd);
|
||||
} catch (error) {
|
||||
console.warn(error.stack); // eslint-disable-line no-console
|
||||
}
|
||||
await rimraf(inputs.file.fd);
|
||||
}
|
||||
|
||||
return fileData;
|
||||
return data;
|
||||
},
|
||||
};
|
||||
|
|
35
server/api/helpers/attachments/remove-unreferenced-files.js
Normal file
35
server/api/helpers/attachments/remove-unreferenced-files.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
fileReferenceOrFileReferences: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
const fileReferences = _.isPlainObject(inputs.fileReferenceOrFileReferences)
|
||||
? [inputs.fileReferenceOrFileReferences]
|
||||
: inputs.fileReferenceOrFileReferences;
|
||||
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
|
||||
fileReferences.forEach(async (fileReference) => {
|
||||
if (fileReference.total !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
await fileManager.deleteDir(
|
||||
`${sails.config.custom.attachmentsPathSegment}/${fileReference.id}`,
|
||||
);
|
||||
|
||||
await FileReference.destroyOne(fileReference.id);
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,3 +1,8 @@
|
|||
/*!
|
||||
* 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: {
|
||||
|
@ -36,32 +41,32 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const attachment = await Attachment.updateOne(inputs.record.id).set({ ...values });
|
||||
const attachment = await Attachment.qm.updateOne(inputs.record.id, values);
|
||||
|
||||
if (attachment) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'attachmentUpdate',
|
||||
{
|
||||
item: attachment,
|
||||
item: sails.helpers.attachments.presentOne(attachment),
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'attachmentUpdate',
|
||||
data: {
|
||||
item: attachment,
|
||||
buildData: () => ({
|
||||
item: sails.helpers.attachments.presentOne(attachment),
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
cards: [inputs.card],
|
||||
},
|
||||
},
|
||||
prevData: {
|
||||
item: inputs.record,
|
||||
},
|
||||
}),
|
||||
buildPrevData: () => ({
|
||||
item: sails.helpers.attachments.presentOne(inputs.record),
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
|
73
server/api/helpers/background-images/create-one.js
Normal file
73
server/api/helpers/background-images/create-one.js
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*!
|
||||
* 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,
|
||||
},
|
||||
requestId: {
|
||||
type: 'string',
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const backgroundImage = await BackgroundImage.qm.createOne({
|
||||
...values,
|
||||
projectId: values.project.id,
|
||||
});
|
||||
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
record: values.project,
|
||||
});
|
||||
|
||||
const projectRelatedUserIds = await scoper.getProjectRelatedUserIds();
|
||||
|
||||
projectRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'backgroundImageCreate',
|
||||
{
|
||||
item: sails.helpers.backgroundImages.presentOne(backgroundImage),
|
||||
requestId: inputs.requestId,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
});
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'backgroundImageCreate',
|
||||
buildData: () => ({
|
||||
item: sails.helpers.backgroundImages.presentOne(backgroundImage),
|
||||
included: {
|
||||
projects: [values.project],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
await sails.helpers.projects.updateOne.with({
|
||||
scoper,
|
||||
record: values.project,
|
||||
values: {
|
||||
backgroundImage,
|
||||
backgroundType: Project.BackgroundTypes.IMAGE,
|
||||
},
|
||||
actorUser: inputs.actorUser,
|
||||
});
|
||||
|
||||
return backgroundImage;
|
||||
},
|
||||
};
|
75
server/api/helpers/background-images/delete-one.js
Normal file
75
server/api/helpers/background-images/delete-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,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
record: inputs.project,
|
||||
});
|
||||
|
||||
if (inputs.project.backgroundType === Project.BackgroundTypes.IMAGE) {
|
||||
if (inputs.record.id === inputs.project.backgroundImageId) {
|
||||
await sails.helpers.projects.updateOne.with({
|
||||
scoper,
|
||||
record: inputs.project,
|
||||
values: {
|
||||
backgroundType: null,
|
||||
},
|
||||
actorUser: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const backgroundImage = await BackgroundImage.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (backgroundImage) {
|
||||
sails.helpers.backgroundImages.removeRelatedFiles(backgroundImage);
|
||||
|
||||
const projectRelatedUserIds = await scoper.getProjectRelatedUserIds();
|
||||
|
||||
projectRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'backgroundImageDelete',
|
||||
{
|
||||
item: sails.helpers.backgroundImages.presentOne(backgroundImage),
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
});
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'backgroundImageDelete',
|
||||
buildData: () => ({
|
||||
item: sails.helpers.backgroundImages.presentOne(backgroundImage),
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return backgroundImage;
|
||||
},
|
||||
};
|
|
@ -0,0 +1,40 @@
|
|||
/*!
|
||||
* 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 backgroundImage = await BackgroundImage.qm.getOneById(inputs.id);
|
||||
|
||||
if (!backgroundImage) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const project = await Project.qm.getOneById(backgroundImage.projectId);
|
||||
|
||||
if (!project) {
|
||||
throw {
|
||||
pathNotFound: {
|
||||
backgroundImage,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
backgroundImage,
|
||||
project,
|
||||
};
|
||||
},
|
||||
};
|
19
server/api/helpers/background-images/present-many.js
Normal file
19
server/api/helpers/background-images/present-many.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
records: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
return inputs.records.map((record) => sails.helpers.backgroundImages.presentOne(record));
|
||||
},
|
||||
};
|
27
server/api/helpers/background-images/present-one.js
Normal file
27
server/api/helpers/background-images/present-one.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
|
||||
return {
|
||||
..._.omit(inputs.record, ['dirname', 'extension']),
|
||||
url: `${fileManager.buildUrl(`${sails.config.custom.backgroundImagesPathSegment}/${inputs.record.dirname}/original.${inputs.record.extension}`)}`,
|
||||
thumbnailUrls: {
|
||||
outside360: `${fileManager.buildUrl(`${sails.config.custom.backgroundImagesPathSegment}/${inputs.record.dirname}/outside-360.${inputs.record.extension}`)}`,
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
|
@ -1,4 +1,10 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const { rimraf } = require('rimraf');
|
||||
const mime = require('mime');
|
||||
const { v4: uuid } = require('uuid');
|
||||
const sharp = require('sharp');
|
||||
|
||||
|
@ -15,6 +21,12 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const mimeType = mime.getType(inputs.file.filename);
|
||||
if (['image/svg+xml', 'application/pdf'].includes(mimeType)) {
|
||||
await rimraf(inputs.file.fd);
|
||||
throw 'fileIsNotImage';
|
||||
}
|
||||
|
||||
let image = sharp(inputs.file.fd, {
|
||||
animated: true,
|
||||
});
|
||||
|
@ -23,27 +35,25 @@ module.exports = {
|
|||
try {
|
||||
metadata = await image.metadata();
|
||||
} catch (error) {
|
||||
throw 'fileIsNotImage';
|
||||
}
|
||||
|
||||
if (['svg', 'pdf'].includes(metadata.format)) {
|
||||
await rimraf(inputs.file.fd);
|
||||
throw 'fileIsNotImage';
|
||||
}
|
||||
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
|
||||
const dirname = uuid();
|
||||
const dirPathSegment = `${sails.config.custom.projectBackgroundImagesPathSegment}/${dirname}`;
|
||||
const dirPathSegment = `${sails.config.custom.backgroundImagesPathSegment}/${dirname}`;
|
||||
|
||||
let { width, pageHeight: height = metadata.height } = metadata;
|
||||
if (metadata.orientation && metadata.orientation > 4) {
|
||||
[image, width, height] = [image.rotate(), height, width];
|
||||
image = image.rotate();
|
||||
}
|
||||
|
||||
const extension = metadata.format === 'jpeg' ? 'jpg' : metadata.format;
|
||||
|
||||
let sizeInBytes;
|
||||
try {
|
||||
const originalBuffer = await image.toBuffer();
|
||||
sizeInBytes = originalBuffer.length;
|
||||
|
||||
await fileManager.save(
|
||||
`${dirPathSegment}/original.${extension}`,
|
||||
|
@ -51,44 +61,37 @@ module.exports = {
|
|||
inputs.file.type,
|
||||
);
|
||||
|
||||
const cover336Buffer = await image
|
||||
.resize(
|
||||
336,
|
||||
200,
|
||||
width < 336 || height < 200
|
||||
? {
|
||||
kernel: sharp.kernel.nearest,
|
||||
}
|
||||
: undefined,
|
||||
)
|
||||
const outside360Buffer = await image
|
||||
.resize(360, 360, {
|
||||
fit: 'outside',
|
||||
withoutEnlargement: true,
|
||||
})
|
||||
.png({
|
||||
quality: 75,
|
||||
force: false,
|
||||
})
|
||||
.toBuffer();
|
||||
|
||||
await fileManager.save(
|
||||
`${dirPathSegment}/cover-336.${extension}`,
|
||||
cover336Buffer,
|
||||
`${dirPathSegment}/outside-360.${extension}`,
|
||||
outside360Buffer,
|
||||
inputs.file.type,
|
||||
);
|
||||
} catch (error1) {
|
||||
console.warn(error1.stack); // eslint-disable-line no-console
|
||||
} catch (error) {
|
||||
sails.log.warn(error.stack);
|
||||
|
||||
try {
|
||||
fileManager.deleteDir(dirPathSegment);
|
||||
} catch (error2) {
|
||||
console.warn(error2.stack); // eslint-disable-line no-console
|
||||
}
|
||||
await fileManager.deleteDir(dirPathSegment);
|
||||
await rimraf(inputs.file.fd);
|
||||
|
||||
throw 'fileIsNotImage';
|
||||
}
|
||||
|
||||
try {
|
||||
await rimraf(inputs.file.fd);
|
||||
} catch (error) {
|
||||
console.warn(error.stack); // eslint-disable-line no-console
|
||||
}
|
||||
await rimraf(inputs.file.fd);
|
||||
|
||||
return {
|
||||
dirname,
|
||||
extension,
|
||||
sizeInBytes,
|
||||
};
|
||||
},
|
||||
};
|
29
server/api/helpers/background-images/remove-related-files.js
Normal file
29
server/api/helpers/background-images/remove-related-files.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
recordOrRecords: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
const backgroundImages = _.isPlainObject(inputs.recordOrRecords)
|
||||
? [inputs.recordOrRecords]
|
||||
: inputs.recordOrRecords;
|
||||
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
|
||||
backgroundImages.forEach(async (backgroundImage) => {
|
||||
await fileManager.deleteDir(
|
||||
`${sails.config.custom.backgroundImagesPathSegment}/${backgroundImage.dirname}`,
|
||||
);
|
||||
});
|
||||
},
|
||||
};
|
59
server/api/helpers/base-custom-field-groups/create-one.js
Normal file
59
server/api/helpers/base-custom-field-groups/create-one.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*!
|
||||
* 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',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const baseCustomFieldGroup = await BaseCustomFieldGroup.qm.createOne({
|
||||
...values,
|
||||
projectId: values.project.id,
|
||||
});
|
||||
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
record: values.project,
|
||||
});
|
||||
|
||||
const projectRelatedUserIds = await scoper.getProjectRelatedUserIds();
|
||||
|
||||
projectRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'baseCustomFieldGroupCreate',
|
||||
{
|
||||
item: baseCustomFieldGroup,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
});
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'baseCustomFieldGroupCreate',
|
||||
buildData: () => ({
|
||||
item: baseCustomFieldGroup,
|
||||
included: {
|
||||
projects: [values.project],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
return baseCustomFieldGroup;
|
||||
},
|
||||
};
|
62
server/api/helpers/base-custom-field-groups/delete-one.js
Normal file
62
server/api/helpers/base-custom-field-groups/delete-one.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*!
|
||||
* 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,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
await sails.helpers.baseCustomFieldGroups.deleteRelated(inputs.record);
|
||||
|
||||
const baseCustomFieldGroup = await BaseCustomFieldGroup.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (baseCustomFieldGroup) {
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
record: inputs.project,
|
||||
});
|
||||
|
||||
const projectRelatedUserIds = await scoper.getProjectRelatedUserIds();
|
||||
|
||||
projectRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'baseCustomFieldGroupDelete',
|
||||
{
|
||||
item: baseCustomFieldGroup,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
});
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'baseCustomFieldGroupDelete',
|
||||
buildData: () => ({
|
||||
item: baseCustomFieldGroup,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return baseCustomFieldGroup;
|
||||
},
|
||||
};
|
|
@ -0,0 +1,34 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
recordOrRecords: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
let baseCustomFieldGroupIdOrIds;
|
||||
if (_.isPlainObject(inputs.recordOrRecords)) {
|
||||
({
|
||||
recordOrRecords: { id: baseCustomFieldGroupIdOrIds },
|
||||
} = inputs);
|
||||
} else if (_.every(inputs.recordOrRecords, _.isPlainObject)) {
|
||||
baseCustomFieldGroupIdOrIds = sails.helpers.utils.mapRecords(inputs.recordOrRecords);
|
||||
}
|
||||
|
||||
const customFieldGroups = await CustomFieldGroup.qm.delete({
|
||||
baseCustomFieldGroupId: baseCustomFieldGroupIdOrIds,
|
||||
});
|
||||
|
||||
await sails.helpers.customFieldGroups.deleteRelated(customFieldGroups);
|
||||
|
||||
await CustomField.qm.delete({
|
||||
baseCustomFieldGroupId: baseCustomFieldGroupIdOrIds,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -0,0 +1,40 @@
|
|||
/*!
|
||||
* 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 baseCustomFieldGroup = await BaseCustomFieldGroup.qm.getOneById(inputs.id);
|
||||
|
||||
if (!baseCustomFieldGroup) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const project = await Project.qm.getOneById(baseCustomFieldGroup.projectId);
|
||||
|
||||
if (!project) {
|
||||
throw {
|
||||
pathNotFound: {
|
||||
baseCustomFieldGroup,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
baseCustomFieldGroup,
|
||||
project,
|
||||
};
|
||||
},
|
||||
};
|
69
server/api/helpers/base-custom-field-groups/update-one.js
Normal file
69
server/api/helpers/base-custom-field-groups/update-one.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*!
|
||||
* 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,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const baseCustomFieldGroup = await BaseCustomFieldGroup.qm.updateOne(inputs.record.id, values);
|
||||
|
||||
if (baseCustomFieldGroup) {
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
record: inputs.project,
|
||||
});
|
||||
|
||||
const projectRelatedUserIds = await scoper.getProjectRelatedUserIds();
|
||||
|
||||
projectRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'baseCustomFieldGroupUpdate',
|
||||
{
|
||||
item: baseCustomFieldGroup,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
});
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'baseCustomFieldGroupUpdate',
|
||||
buildData: () => ({
|
||||
item: baseCustomFieldGroup,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
},
|
||||
}),
|
||||
buildPrevData: () => ({
|
||||
item: inputs.record,
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return baseCustomFieldGroup;
|
||||
},
|
||||
};
|
|
@ -1,24 +1,16 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
if (!_.isPlainObject(value.board)) {
|
||||
return false;
|
||||
}
|
||||
const { v4: uuid } = require('uuid');
|
||||
|
||||
if (!_.isPlainObject(value.user)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
const normalizeValues = require('../../../utils/normalize-values');
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
|
@ -41,21 +33,29 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (values.role === BoardMembership.Roles.EDITOR) {
|
||||
delete values.canComment;
|
||||
} else if (values.role === BoardMembership.Roles.VIEWER) {
|
||||
if (_.isNil(values.canComment)) {
|
||||
values.canComment = false;
|
||||
}
|
||||
}
|
||||
const normalizedValues = normalizeValues(
|
||||
{
|
||||
...BoardMembership.SHARED_RULES,
|
||||
...BoardMembership.RULES_BY_ROLE[values.role],
|
||||
},
|
||||
values,
|
||||
);
|
||||
|
||||
const boardMembership = await BoardMembership.create({
|
||||
...values,
|
||||
boardId: values.board.id,
|
||||
userId: values.user.id,
|
||||
})
|
||||
.intercept('E_UNIQUE', 'userAlreadyBoardMember')
|
||||
.fetch();
|
||||
let boardMembership;
|
||||
try {
|
||||
boardMembership = await BoardMembership.qm.createOne({
|
||||
...normalizedValues,
|
||||
projectId: values.board.projectId,
|
||||
boardId: values.board.id,
|
||||
userId: values.user.id,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code === 'E_UNIQUE') {
|
||||
throw 'userAlreadyBoardMember';
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`user:${boardMembership.userId}`,
|
||||
|
@ -66,25 +66,36 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${boardMembership.boardId}`,
|
||||
'boardMembershipCreate',
|
||||
{
|
||||
item: boardMembership,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
const tempRoom = uuid();
|
||||
|
||||
sails.sockets.addRoomMembersToRooms(`board:${boardMembership.boardId}`, tempRoom, () => {
|
||||
sails.sockets.removeRoomMembersFromRooms(`user:${boardMembership.userId}`, tempRoom, () => {
|
||||
sails.sockets.broadcast(
|
||||
tempRoom,
|
||||
'boardMembershipCreate',
|
||||
{
|
||||
item: boardMembership,
|
||||
included: {
|
||||
users: [sails.helpers.users.presentOne(values.user, {})], // FIXME: hack
|
||||
},
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.sockets.removeRoomMembersFromRooms(tempRoom, tempRoom);
|
||||
});
|
||||
});
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'boardMembershipCreate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: boardMembership,
|
||||
included: {
|
||||
users: [values.user],
|
||||
users: [sails.helpers.users.presentOne(values.user)],
|
||||
projects: [inputs.project],
|
||||
boards: [values.board],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const { v4: uuid } = require('uuid');
|
||||
|
||||
module.exports = {
|
||||
|
@ -6,6 +11,10 @@ module.exports = {
|
|||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
|
@ -24,73 +33,89 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
await BoardSubscription.qm.delete({
|
||||
boardId: inputs.record.boardId,
|
||||
userId: inputs.user.id,
|
||||
});
|
||||
|
||||
const cardIds = await sails.helpers.boards.getCardIds(inputs.record.boardId);
|
||||
|
||||
await CardSubscription.destroy({
|
||||
await CardSubscription.qm.delete({
|
||||
cardId: cardIds,
|
||||
userId: inputs.record.userId,
|
||||
userId: inputs.user.id,
|
||||
});
|
||||
|
||||
await CardMembership.destroy({
|
||||
await CardMembership.qm.delete({
|
||||
cardId: cardIds,
|
||||
userId: inputs.record.userId,
|
||||
userId: inputs.user.id,
|
||||
});
|
||||
|
||||
const boardMembership = await BoardMembership.destroyOne(inputs.record.id);
|
||||
const taskLists = await TaskList.qm.getByCardIds(cardIds);
|
||||
const taskListIds = sails.helpers.utils.mapRecords(taskLists);
|
||||
|
||||
await Task.qm.update(
|
||||
{
|
||||
taskListId: taskListIds,
|
||||
assigneeUserId: inputs.user.id,
|
||||
},
|
||||
{
|
||||
assigneeUserId: null,
|
||||
},
|
||||
);
|
||||
|
||||
const boardMembership = await BoardMembership.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (boardMembership) {
|
||||
const notify = (room) => {
|
||||
sails.sockets.broadcast(
|
||||
room,
|
||||
'boardMembershipDelete',
|
||||
{
|
||||
item: boardMembership,
|
||||
},
|
||||
inputs.request,
|
||||
if (inputs.user.role !== User.Roles.ADMIN || inputs.project.ownerProjectManagerId) {
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(
|
||||
boardMembership.userId,
|
||||
inputs.project.id,
|
||||
);
|
||||
};
|
||||
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(
|
||||
inputs.record.userId,
|
||||
inputs.project.id,
|
||||
if (!isProjectManager) {
|
||||
sails.sockets.removeRoomMembersFromRooms(
|
||||
`@user:${boardMembership.userId}`,
|
||||
`board:${boardMembership.boardId}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`user:${boardMembership.userId}`,
|
||||
'boardMembershipDelete',
|
||||
{
|
||||
item: boardMembership,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
if (!isProjectManager) {
|
||||
sails.sockets.removeRoomMembersFromRooms(
|
||||
`@user:${boardMembership.userId}`,
|
||||
`board:${boardMembership.boardId}`,
|
||||
() => {
|
||||
notify(`board:${boardMembership.boardId}`);
|
||||
},
|
||||
);
|
||||
}
|
||||
const tempRoom = uuid();
|
||||
|
||||
notify(`user:${boardMembership.userId}`);
|
||||
|
||||
if (isProjectManager) {
|
||||
const tempRoom = uuid();
|
||||
|
||||
sails.sockets.addRoomMembersToRooms(`board:${boardMembership.boardId}`, tempRoom, () => {
|
||||
sails.sockets.removeRoomMembersFromRooms(
|
||||
`user:${boardMembership.userId}`,
|
||||
sails.sockets.addRoomMembersToRooms(`board:${boardMembership.boardId}`, tempRoom, () => {
|
||||
sails.sockets.removeRoomMembersFromRooms(`user:${boardMembership.userId}`, tempRoom, () => {
|
||||
sails.sockets.broadcast(
|
||||
tempRoom,
|
||||
() => {
|
||||
notify(tempRoom);
|
||||
sails.sockets.removeRoomMembersFromRooms(tempRoom, tempRoom);
|
||||
'boardMembershipDelete',
|
||||
{
|
||||
item: boardMembership,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.sockets.removeRoomMembersFromRooms(tempRoom, tempRoom);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'boardMembershipDelete',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: boardMembership,
|
||||
included: {
|
||||
users: [sails.helpers.users.presentOne(inputs.user)],
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: criteriaValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return BoardMembership.find(inputs.criteria).sort('id');
|
||||
},
|
||||
};
|
|
@ -0,0 +1,39 @@
|
|||
/*!
|
||||
* 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 boardMembership = await BoardMembership.qm.getOneById(inputs.id);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const pathToProject = await sails.helpers.boards
|
||||
.getPathToProjectById(boardMembership.boardId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
boardMembership,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
boardMembership,
|
||||
...pathToProject,
|
||||
};
|
||||
},
|
||||
};
|
|
@ -1,34 +0,0 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
pathNotFound: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const boardMembership = await BoardMembership.findOne(inputs.criteria);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const path = await sails.helpers.boards
|
||||
.getProjectPath(boardMembership.boardId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
boardMembership,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
boardMembership,
|
||||
...path,
|
||||
};
|
||||
},
|
||||
};
|
|
@ -1,3 +1,12 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const { v4: uuid } = require('uuid');
|
||||
|
||||
const normalizeValues = require('../../../utils/normalize-values');
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
|
@ -27,25 +36,21 @@ module.exports = {
|
|||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
const role = values.role || inputs.record.role;
|
||||
|
||||
if (role === BoardMembership.Roles.EDITOR) {
|
||||
values.canComment = null;
|
||||
} else if (role === BoardMembership.Roles.VIEWER) {
|
||||
const canComment = _.isUndefined(values.canComment)
|
||||
? inputs.record.canComment
|
||||
: values.canComment;
|
||||
const normalizedValues = normalizeValues(
|
||||
{
|
||||
...BoardMembership.SHARED_RULES,
|
||||
...BoardMembership.RULES_BY_ROLE[values.role || inputs.record.role],
|
||||
},
|
||||
values,
|
||||
inputs.record,
|
||||
);
|
||||
|
||||
if (_.isNull(canComment)) {
|
||||
values.canComment = false;
|
||||
}
|
||||
}
|
||||
|
||||
const boardMembership = await BoardMembership.updateOne(inputs.record.id).set({ ...values });
|
||||
const boardMembership = await BoardMembership.qm.updateOne(inputs.record.id, normalizedValues);
|
||||
|
||||
if (boardMembership) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${boardMembership.boardId}`,
|
||||
`user:${boardMembership.userId}`,
|
||||
'boardMembershipUpdate',
|
||||
{
|
||||
item: boardMembership,
|
||||
|
@ -53,18 +58,35 @@ module.exports = {
|
|||
inputs.request,
|
||||
);
|
||||
|
||||
const tempRoom = uuid();
|
||||
|
||||
sails.sockets.addRoomMembersToRooms(`board:${boardMembership.boardId}`, tempRoom, () => {
|
||||
sails.sockets.removeRoomMembersFromRooms(`user:${boardMembership.userId}`, tempRoom, () => {
|
||||
sails.sockets.broadcast(
|
||||
tempRoom,
|
||||
'boardMembershipUpdate',
|
||||
{
|
||||
item: boardMembership,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.sockets.removeRoomMembersFromRooms(tempRoom, tempRoom);
|
||||
});
|
||||
});
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'boardMembershipUpdate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: boardMembership,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
},
|
||||
},
|
||||
prevData: {
|
||||
}),
|
||||
buildPrevData: () => ({
|
||||
item: inputs.record,
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,41 +1,16 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.project)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
const importValidator = (value) => {
|
||||
if (!value.type || !Object.values(Board.ImportTypes).includes(value.type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.board)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
/*!
|
||||
* 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',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
import: {
|
||||
type: 'json',
|
||||
custom: importValidator,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
|
@ -43,7 +18,6 @@ module.exports = {
|
|||
},
|
||||
requestId: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
|
@ -53,60 +27,81 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const projectManagerUserIds = await sails.helpers.projects.getManagerUserIds(values.project.id);
|
||||
const boards = await sails.helpers.projects.getBoards(values.project.id);
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
record: values.project,
|
||||
});
|
||||
|
||||
const boards = await Board.qm.getByProjectId(values.project.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
boards,
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Board.update({
|
||||
id,
|
||||
projectId: values.project.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
values.position = position;
|
||||
|
||||
// TODO: move out of loop
|
||||
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(id);
|
||||
const boardRelatedUserIds = _.union(projectManagerUserIds, boardMemberUserIds);
|
||||
if (repositions.length > 0) {
|
||||
await scoper.getUserIdsWithFullProjectVisibility();
|
||||
const clonedScoper = scoper.clone();
|
||||
|
||||
boardRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await Board.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
projectId: reposition.record.projectId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
clonedScoper.replaceBoard(reposition.record);
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const boardRelatedUserIds = await clonedScoper.getBoardRelatedUserIds();
|
||||
|
||||
boardRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
});
|
||||
});
|
||||
|
||||
const board = await Board.create({
|
||||
...values,
|
||||
position,
|
||||
projectId: values.project.id,
|
||||
}).fetch();
|
||||
|
||||
if (inputs.import && inputs.import.type === Board.ImportTypes.TRELLO) {
|
||||
await sails.helpers.boards.importFromTrello(board, inputs.import.board, inputs.actorUser);
|
||||
}
|
||||
}
|
||||
|
||||
const boardMembership = await BoardMembership.create({
|
||||
boardId: board.id,
|
||||
userId: inputs.actorUser.id,
|
||||
role: BoardMembership.Roles.EDITOR,
|
||||
}).fetch();
|
||||
const { board, boardMembership, lists } = await Board.qm.createOne(
|
||||
{
|
||||
...values,
|
||||
projectId: values.project.id,
|
||||
},
|
||||
{
|
||||
user: inputs.actorUser,
|
||||
},
|
||||
);
|
||||
|
||||
projectManagerUserIds.forEach((userId) => {
|
||||
if (inputs.import && inputs.import.type === Board.ImportTypes.TRELLO) {
|
||||
await sails.helpers.boards.importFromTrello(board, lists, inputs.import.board);
|
||||
}
|
||||
|
||||
scoper.board = board;
|
||||
scoper.boardMemberships = [boardMembership];
|
||||
|
||||
const boardRelatedUserIds = await scoper.getBoardRelatedUserIds();
|
||||
|
||||
boardRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'boardCreate',
|
||||
{
|
||||
item: board,
|
||||
included: {
|
||||
boardMemberships: userId === boardMembership.userId ? [boardMembership] : [],
|
||||
},
|
||||
requestId: inputs.requestId,
|
||||
},
|
||||
inputs.request,
|
||||
|
@ -115,12 +110,13 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'boardCreate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: board,
|
||||
included: {
|
||||
projects: [values.project],
|
||||
boardMemberships: [boardMembership],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/*!
|
||||
* 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: {
|
||||
|
@ -18,18 +23,20 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const boardMemberships = await BoardMembership.destroy({
|
||||
boardId: inputs.record.id,
|
||||
}).fetch();
|
||||
const { boardMemberships } = await sails.helpers.boards.deleteRelated(inputs.record);
|
||||
|
||||
const board = await Board.archiveOne(inputs.record.id);
|
||||
const board = await Board.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (board) {
|
||||
sails.sockets.removeRoomMembersFromRooms(`board:${board.id}`, `board:${board.id}`);
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
board,
|
||||
record: inputs.project,
|
||||
});
|
||||
|
||||
const projectManagerUserIds = await sails.helpers.projects.getManagerUserIds(board.projectId);
|
||||
const boardMemberUserIds = sails.helpers.utils.mapRecords(boardMemberships, 'userId');
|
||||
const boardRelatedUserIds = _.union(projectManagerUserIds, boardMemberUserIds);
|
||||
scoper.boardMemberships = boardMemberships;
|
||||
const boardRelatedUserIds = await scoper.getBoardRelatedUserIds();
|
||||
|
||||
sails.sockets.removeRoomMembersFromRooms(`board:${board.id}`, `board:${board.id}`);
|
||||
|
||||
boardRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
|
@ -44,12 +51,12 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'boardDelete',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: board,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
|
44
server/api/helpers/boards/delete-related.js
Normal file
44
server/api/helpers/boards/delete-related.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
recordOrRecords: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
let boardIdOrIds;
|
||||
if (_.isPlainObject(inputs.recordOrRecords)) {
|
||||
({
|
||||
recordOrRecords: { id: boardIdOrIds },
|
||||
} = inputs);
|
||||
} else if (_.every(inputs.recordOrRecords, _.isPlainObject)) {
|
||||
boardIdOrIds = sails.helpers.utils.mapRecords(inputs.recordOrRecords);
|
||||
}
|
||||
|
||||
const boardMemberships = await BoardMembership.qm.delete({
|
||||
boardId: boardIdOrIds,
|
||||
});
|
||||
|
||||
await Label.qm.delete({
|
||||
boardId: boardIdOrIds,
|
||||
});
|
||||
|
||||
const lists = await List.qm.delete({
|
||||
boardId: boardIdOrIds,
|
||||
});
|
||||
|
||||
await sails.helpers.lists.deleteRelated(lists);
|
||||
|
||||
await NotificationService.qm.delete({
|
||||
boardId: boardIdOrIds,
|
||||
});
|
||||
|
||||
return { boardMemberships };
|
||||
},
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return sails.helpers.boardMemberships.getMany({
|
||||
boardId: inputs.idOrIds,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,16 +1,18 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const cards = await sails.helpers.boards.getCards(inputs.idOrIds);
|
||||
const cards = await Card.qm.getByBoardId(inputs.id);
|
||||
|
||||
return sails.helpers.utils.mapRecords(cards);
|
||||
},
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return sails.helpers.cards.getMany({
|
||||
boardId: inputs.idOrIds,
|
||||
});
|
||||
},
|
||||
};
|
23
server/api/helpers/boards/get-finite-lists-by-id.js
Normal file
23
server/api/helpers/boards/get-finite-lists-by-id.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*!
|
||||
* 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,
|
||||
},
|
||||
exceptListIdOrIds: {
|
||||
type: 'json',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return List.qm.getByBoardId(inputs.id, {
|
||||
exceptIdOrIds: inputs.exceptListIdOrIds,
|
||||
typeOrTypes: List.FINITE_TYPES,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,29 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
exceptLabelIdOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const criteria = {
|
||||
boardId: inputs.idOrIds,
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.exceptLabelIdOrIds)) {
|
||||
criteria.id = {
|
||||
'!=': inputs.exceptLabelIdOrIds,
|
||||
};
|
||||
}
|
||||
|
||||
return sails.helpers.labels.getMany(criteria);
|
||||
},
|
||||
};
|
|
@ -1,29 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
exceptListIdOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const criteria = {
|
||||
boardId: inputs.idOrIds,
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.exceptListIdOrIds)) {
|
||||
criteria.id = {
|
||||
'!=': inputs.exceptListIdOrIds,
|
||||
};
|
||||
}
|
||||
|
||||
return sails.helpers.lists.getMany(criteria);
|
||||
},
|
||||
};
|
|
@ -1,14 +0,0 @@
|
|||
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: criteriaValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return Board.find(inputs.criteria).sort('position');
|
||||
},
|
||||
};
|
|
@ -1,17 +1,19 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const boardMemberships = await sails.helpers.boards.getBoardMemberships(inputs.idOrIds);
|
||||
const boardMemberships = await BoardMembership.qm.getByBoardId(inputs.id);
|
||||
|
||||
return sails.helpers.utils.mapRecords(boardMemberships, 'userId', _.isArray(inputs.idOrIds));
|
||||
return sails.helpers.utils.mapRecords(boardMemberships, 'userId');
|
||||
},
|
||||
};
|
||||
|
|
19
server/api/helpers/boards/get-notification-services-total.js
Normal file
19
server/api/helpers/boards/get-notification-services-total.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*!
|
||||
* 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,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const notificationServices = await NotificationService.qm.getByBoardId(inputs.id);
|
||||
|
||||
return notificationServices.length;
|
||||
},
|
||||
};
|
|
@ -1,7 +1,12 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
@ -11,13 +16,13 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const board = await Board.findOne(inputs.criteria);
|
||||
const board = await Board.qm.getOneById(inputs.id);
|
||||
|
||||
if (!board) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const project = await Project.findOne(board.projectId);
|
||||
const project = await Project.qm.getOneById(board.projectId);
|
||||
|
||||
if (!project) {
|
||||
throw {
|
24
server/api/helpers/boards/get-subscription-user-ids.js
Normal file
24
server/api/helpers/boards/get-subscription-user-ids.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*!
|
||||
* 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,
|
||||
},
|
||||
exceptUserIdOrIds: {
|
||||
type: 'json',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const boardSubscriptions = await BoardSubscription.qm.getByBoardId(inputs.id, {
|
||||
exceptUserIdOrIds: inputs.exceptUserIdOrIds,
|
||||
});
|
||||
|
||||
return sails.helpers.utils.mapRecords(boardSubscriptions, 'userId');
|
||||
},
|
||||
};
|
|
@ -1,4 +1,9 @@
|
|||
const POSITION_GAP = 65535; // TODO: move to config
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const { POSITION_GAP } = require('../../../constants');
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
|
@ -6,151 +11,122 @@ module.exports = {
|
|||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
trelloBoard: {
|
||||
type: 'json',
|
||||
lists: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
trelloBoard: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const trelloToPlankaLabels = {};
|
||||
const convertLabelColor = (trelloLabelColor) =>
|
||||
Label.COLORS.find((color) => color.includes(trelloLabelColor)) || 'desert-sand';
|
||||
|
||||
const getTrelloLists = () => inputs.trelloBoard.lists.filter((list) => !list.closed);
|
||||
|
||||
const getUsedTrelloLabels = () => {
|
||||
const result = {};
|
||||
inputs.trelloBoard.cards
|
||||
.map((card) => card.labels)
|
||||
.flat()
|
||||
.forEach((label) => {
|
||||
result[label.id] = label;
|
||||
const labelIdByTrelloLabelId = {};
|
||||
await Promise.all(
|
||||
inputs.trelloBoard.labels.map(async (trelloLabel, index) => {
|
||||
const { id } = await Label.qm.createOne({
|
||||
boardId: inputs.board.id,
|
||||
position: POSITION_GAP * (index + 1),
|
||||
name: trelloLabel.name || null,
|
||||
color: convertLabelColor(trelloLabel.color),
|
||||
});
|
||||
|
||||
return Object.values(result);
|
||||
};
|
||||
labelIdByTrelloLabelId[trelloLabel.id] = id;
|
||||
}),
|
||||
);
|
||||
|
||||
const getTrelloCardsOfList = (listId) =>
|
||||
inputs.trelloBoard.cards.filter((card) => card.idList === listId && !card.closed);
|
||||
const openedTrelloLists = inputs.trelloBoard.lists.filter((list) => !list.closed);
|
||||
|
||||
const getAllTrelloCheckItemsOfCard = (cardId) =>
|
||||
inputs.trelloBoard.checklists
|
||||
.filter((checklist) => checklist.idCard === cardId)
|
||||
.map((checklist) => checklist.checkItems)
|
||||
.flat();
|
||||
const listIdByTrelloListId = {};
|
||||
await Promise.all(
|
||||
openedTrelloLists.map(async (trelloList) => {
|
||||
const { id } = await List.qm.createOne({
|
||||
boardId: inputs.board.id,
|
||||
type: List.Types.ACTIVE,
|
||||
position: trelloList.pos,
|
||||
name: trelloList.name,
|
||||
});
|
||||
|
||||
const getTrelloCommentsOfCard = (cardId) =>
|
||||
inputs.trelloBoard.actions.filter(
|
||||
(action) =>
|
||||
action.type === 'commentCard' &&
|
||||
action.data &&
|
||||
action.data.card &&
|
||||
action.data.card.id === cardId,
|
||||
);
|
||||
listIdByTrelloListId[trelloList.id] = id;
|
||||
}),
|
||||
);
|
||||
|
||||
const getPlankaLabelColor = (trelloLabelColor) =>
|
||||
Label.COLORS.find((color) => color.indexOf(trelloLabelColor) !== -1) || 'desert-sand';
|
||||
const { id: archiveListId } = inputs.lists.find((list) => list.type === List.Types.ARCHIVE);
|
||||
|
||||
const importCardLabels = async (plankaCard, trelloCard) => {
|
||||
return Promise.all(
|
||||
trelloCard.labels.map(async (trelloLabel) => {
|
||||
return CardLabel.create({
|
||||
cardId: plankaCard.id,
|
||||
labelId: trelloToPlankaLabels[trelloLabel.id].id,
|
||||
const cardIdByTrelloCardId = {};
|
||||
await Promise.all(
|
||||
inputs.trelloBoard.cards.map(async (trelloCard) => {
|
||||
const values = {
|
||||
boardId: inputs.board.id,
|
||||
type: Card.Types.PROJECT,
|
||||
position: trelloCard.pos,
|
||||
name: trelloCard.name,
|
||||
description: trelloCard.desc || null,
|
||||
dueDate: trelloCard.due,
|
||||
listChangedAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
const listId = listIdByTrelloListId[trelloCard.idList];
|
||||
|
||||
if (trelloCard.closed) {
|
||||
Object.assign(values, {
|
||||
listId: archiveListId,
|
||||
prevListId: listId,
|
||||
});
|
||||
} else {
|
||||
values.listId = listId || archiveListId;
|
||||
}
|
||||
|
||||
const { id } = await Card.qm.createOne(values);
|
||||
cardIdByTrelloCardId[trelloCard.id] = id;
|
||||
|
||||
return Promise.all(
|
||||
trelloCard.idLabels.map(async (trelloLabelId) =>
|
||||
CardLabel.qm.createOne({
|
||||
cardId: id,
|
||||
labelId: labelIdByTrelloLabelId[trelloLabelId],
|
||||
}),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
inputs.trelloBoard.checklists.map(async (trelloChecklist) => {
|
||||
const { id } = await TaskList.qm.createOne({
|
||||
cardId: cardIdByTrelloCardId[trelloChecklist.idCard],
|
||||
position: trelloChecklist.pos,
|
||||
name: trelloChecklist.name,
|
||||
});
|
||||
|
||||
return Promise.all(
|
||||
trelloChecklist.checkItems.map(async (trelloCheckItem) =>
|
||||
Task.qm.createOne({
|
||||
taskListId: id,
|
||||
position: trelloCheckItem.pos,
|
||||
name: trelloCheckItem.name,
|
||||
isCompleted: trelloCheckItem.state === 'complete',
|
||||
}),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
const trelloCommentActions = inputs.trelloBoard.actions
|
||||
.filter((action) => action.type === 'commentCard')
|
||||
.reverse();
|
||||
|
||||
await Promise.all(
|
||||
trelloCommentActions.map(async (trelloAction) =>
|
||||
Comment.qm.createOne({
|
||||
cardId: cardIdByTrelloCardId[trelloAction.data.card.id],
|
||||
text: `${trelloAction.data.text}\n\n---\n*Note: imported comment, originally posted by\n${trelloAction.memberCreator.fullName} (${trelloAction.memberCreator.username}) on ${trelloAction.date}*`,
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const importTasks = async (plankaCard, trelloCard) => {
|
||||
// TODO find workaround for tasks/checklist mismapping, see issue trello2planka#5
|
||||
return Promise.all(
|
||||
getAllTrelloCheckItemsOfCard(trelloCard.id).map(async (trelloCheckItem) => {
|
||||
return Task.create({
|
||||
cardId: plankaCard.id,
|
||||
position: trelloCheckItem.pos,
|
||||
name: trelloCheckItem.name,
|
||||
isCompleted: trelloCheckItem.state === 'complete',
|
||||
}).fetch();
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const importComments = async (plankaCard, trelloCard) => {
|
||||
const trelloComments = getTrelloCommentsOfCard(trelloCard.id);
|
||||
trelloComments.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime());
|
||||
|
||||
return Promise.all(
|
||||
trelloComments.map(async (trelloComment) => {
|
||||
return Action.create({
|
||||
cardId: plankaCard.id,
|
||||
userId: inputs.actorUser.id,
|
||||
type: 'commentCard',
|
||||
data: {
|
||||
text:
|
||||
`${trelloComment.data.text}\n\n---\n*Note: imported comment, originally posted by ` +
|
||||
`\n${trelloComment.memberCreator.fullName} (${trelloComment.memberCreator.username}) on ${trelloComment.date}*`,
|
||||
},
|
||||
}).fetch();
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const importCards = async (plankaList, trelloList) => {
|
||||
return Promise.all(
|
||||
getTrelloCardsOfList(trelloList.id).map(async (trelloCard) => {
|
||||
const plankaCard = await Card.create({
|
||||
boardId: inputs.board.id,
|
||||
listId: plankaList.id,
|
||||
creatorUserId: inputs.actorUser.id,
|
||||
position: trelloCard.pos,
|
||||
name: trelloCard.name,
|
||||
description: trelloCard.desc || null,
|
||||
dueDate: trelloCard.due,
|
||||
}).fetch();
|
||||
|
||||
await importCardLabels(plankaCard, trelloCard);
|
||||
await importTasks(plankaCard, trelloCard);
|
||||
await importComments(plankaCard, trelloCard);
|
||||
|
||||
return plankaCard;
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const importLabels = async () => {
|
||||
return Promise.all(
|
||||
getUsedTrelloLabels().map(async (trelloLabel, index) => {
|
||||
const plankaLabel = await Label.create({
|
||||
boardId: inputs.board.id,
|
||||
position: POSITION_GAP * (index + 1),
|
||||
name: trelloLabel.name || null,
|
||||
color: getPlankaLabelColor(trelloLabel.color),
|
||||
}).fetch();
|
||||
|
||||
trelloToPlankaLabels[trelloLabel.id] = plankaLabel;
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const importLists = async () => {
|
||||
return Promise.all(
|
||||
getTrelloLists().map(async (trelloList) => {
|
||||
const plankaList = await List.create({
|
||||
boardId: inputs.board.id,
|
||||
name: trelloList.name,
|
||||
position: trelloList.pos,
|
||||
}).fetch();
|
||||
|
||||
return importCards(plankaList, trelloList);
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
await importLabels();
|
||||
await importLists();
|
||||
),
|
||||
);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const { rimraf } = require('rimraf');
|
||||
|
||||
|
@ -13,25 +18,31 @@ module.exports = {
|
|||
invalidFile: {},
|
||||
},
|
||||
|
||||
// TODO: add better validation
|
||||
async fn(inputs) {
|
||||
const content = await fs.promises.readFile(inputs.file.fd);
|
||||
const trelloBoard = JSON.parse(content);
|
||||
|
||||
let trelloBoard;
|
||||
try {
|
||||
trelloBoard = JSON.parse(content);
|
||||
} catch (error) {
|
||||
await rimraf(inputs.file.fd);
|
||||
throw 'invalidFile';
|
||||
}
|
||||
|
||||
if (
|
||||
!trelloBoard ||
|
||||
!_.isArray(trelloBoard.labels) ||
|
||||
!_.isArray(trelloBoard.lists) ||
|
||||
!_.isArray(trelloBoard.cards) ||
|
||||
!_.isArray(trelloBoard.checklists) ||
|
||||
!_.isArray(trelloBoard.actions)
|
||||
) {
|
||||
await rimraf(inputs.file.fd);
|
||||
throw 'invalidFile';
|
||||
}
|
||||
|
||||
try {
|
||||
await rimraf(inputs.file.fd);
|
||||
} catch (error) {
|
||||
console.warn(error.stack); // eslint-disable-line no-console
|
||||
}
|
||||
await rimraf(inputs.file.fd);
|
||||
|
||||
return trelloBoard;
|
||||
},
|
||||
|
|
|
@ -1,14 +1,7 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
|
@ -18,7 +11,6 @@ module.exports = {
|
|||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
|
@ -35,52 +27,72 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
const { isSubscribed, ...values } = inputs.values;
|
||||
|
||||
const projectManagerUserIds = await sails.helpers.projects.getManagerUserIds(
|
||||
inputs.record.projectId,
|
||||
);
|
||||
|
||||
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(inputs.record.id);
|
||||
const boardRelatedUserIds = _.union(projectManagerUserIds, boardMemberUserIds);
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const boards = await sails.helpers.projects.getBoards(
|
||||
inputs.record.projectId,
|
||||
inputs.record.id,
|
||||
);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
boards,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Board.update({
|
||||
id,
|
||||
projectId: inputs.record.projectId,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
boardRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
});
|
||||
let board;
|
||||
if (_.isEmpty(values)) {
|
||||
board = inputs.record;
|
||||
} else {
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
record: inputs.project,
|
||||
});
|
||||
}
|
||||
|
||||
const board = await Board.updateOne(inputs.record.id).set({ ...values });
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const boards = await Board.qm.getByProjectId(inputs.record.projectId, {
|
||||
exceptIdOrIds: inputs.record.id,
|
||||
});
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
boards,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
if (repositions.length > 0) {
|
||||
await scoper.getUserIdsWithFullProjectVisibility();
|
||||
const clonedScoper = scoper.clone();
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await Board.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
projectId: reposition.record.projectId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
clonedScoper.replaceBoard(reposition.record);
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const boardRelatedUserIds = await clonedScoper.getBoardRelatedUserIds();
|
||||
|
||||
boardRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
board = await Board.qm.updateOne(inputs.record.id, values);
|
||||
|
||||
if (!board) {
|
||||
return board;
|
||||
}
|
||||
|
||||
scoper.board = board;
|
||||
const boardRelatedUserIds = await scoper.getBoardRelatedUserIds();
|
||||
|
||||
if (board) {
|
||||
boardRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
|
@ -94,19 +106,60 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'boardUpdate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: board,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
},
|
||||
},
|
||||
prevData: {
|
||||
}),
|
||||
buildPrevData: () => ({
|
||||
item: inputs.record,
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
if (!_.isUndefined(isSubscribed)) {
|
||||
const wasSubscribed = await sails.helpers.users.isBoardSubscriber(
|
||||
inputs.actorUser.id,
|
||||
board.id,
|
||||
);
|
||||
|
||||
if (isSubscribed !== wasSubscribed) {
|
||||
if (isSubscribed) {
|
||||
try {
|
||||
await BoardSubscription.qm.createOne({
|
||||
boardId: board.id,
|
||||
userId: inputs.actorUser.id,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code !== 'E_UNIQUE') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await BoardSubscription.qm.deleteOne({
|
||||
boardId: board.id,
|
||||
userId: inputs.actorUser.id,
|
||||
});
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`user:${inputs.actorUser.id}`,
|
||||
'boardUpdate',
|
||||
{
|
||||
item: {
|
||||
isSubscribed,
|
||||
id: board.id,
|
||||
},
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
|
||||
return board;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,24 +1,12 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.card)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.label)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
/*!
|
||||
* 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',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
|
@ -49,16 +37,23 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const cardLabel = await CardLabel.create({
|
||||
...values,
|
||||
cardId: values.card.id,
|
||||
labelId: values.label.id,
|
||||
})
|
||||
.intercept('E_UNIQUE', 'labelAlreadyInCard')
|
||||
.fetch();
|
||||
let cardLabel;
|
||||
try {
|
||||
cardLabel = await CardLabel.qm.createOne({
|
||||
...values,
|
||||
cardId: values.card.id,
|
||||
labelId: values.label.id,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code === 'E_UNIQUE') {
|
||||
throw 'labelAlreadyInCard';
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${values.card.boardId}`,
|
||||
`board:${inputs.board.id}`,
|
||||
'cardLabelCreate',
|
||||
{
|
||||
item: cardLabel,
|
||||
|
@ -68,7 +63,7 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardLabelCreate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: cardLabel,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
|
@ -77,7 +72,7 @@ module.exports = {
|
|||
lists: [inputs.list],
|
||||
cards: [values.card],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/*!
|
||||
* 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: {
|
||||
|
@ -30,7 +35,7 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const cardLabel = await CardLabel.destroyOne(inputs.record.id);
|
||||
const cardLabel = await CardLabel.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (cardLabel) {
|
||||
sails.sockets.broadcast(
|
||||
|
@ -44,7 +49,7 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardLabelDelete',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: cardLabel,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
|
@ -52,7 +57,7 @@ module.exports = {
|
|||
lists: [inputs.list],
|
||||
cards: [inputs.card],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: criteriaValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return CardLabel.find(inputs.criteria).sort('id');
|
||||
},
|
||||
};
|
|
@ -1,24 +1,12 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.card)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.user) && !_.isString(value.userId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
/*!
|
||||
* 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',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
|
@ -53,15 +41,22 @@ module.exports = {
|
|||
values.userId = values.user.id;
|
||||
}
|
||||
|
||||
const cardMembership = await CardMembership.create({
|
||||
...values,
|
||||
cardId: values.card.id,
|
||||
})
|
||||
.intercept('E_UNIQUE', 'userAlreadyCardMember')
|
||||
.fetch();
|
||||
let cardMembership;
|
||||
try {
|
||||
cardMembership = await CardMembership.qm.createOne({
|
||||
...values,
|
||||
cardId: values.card.id,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code === 'E_UNIQUE') {
|
||||
throw 'userAlreadyCardMember';
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${values.card.boardId}`,
|
||||
`board:${inputs.board.id}`,
|
||||
'cardMembershipCreate',
|
||||
{
|
||||
item: cardMembership,
|
||||
|
@ -71,7 +66,7 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardMembershipCreate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: cardMembership,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
|
@ -79,17 +74,22 @@ module.exports = {
|
|||
lists: [inputs.list],
|
||||
cards: [values.card],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
const cardSubscription = await CardSubscription.create({
|
||||
cardId: cardMembership.cardId,
|
||||
userId: cardMembership.userId,
|
||||
isPermanent: false,
|
||||
})
|
||||
.tolerate('E_UNIQUE')
|
||||
.fetch();
|
||||
let cardSubscription;
|
||||
try {
|
||||
cardSubscription = await CardSubscription.qm.createOne({
|
||||
cardId: cardMembership.cardId,
|
||||
userId: cardMembership.userId,
|
||||
isPermanent: false,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code !== 'E_UNIQUE') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
if (cardSubscription) {
|
||||
sails.sockets.broadcast(
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/*!
|
||||
* 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: {
|
||||
|
@ -30,7 +35,7 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const cardMembership = await CardMembership.destroyOne(inputs.record.id);
|
||||
const cardMembership = await CardMembership.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (cardMembership) {
|
||||
sails.sockets.broadcast(
|
||||
|
@ -44,7 +49,7 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardMembershipDelete',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: cardMembership,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
|
@ -52,11 +57,11 @@ module.exports = {
|
|||
lists: [inputs.list],
|
||||
cards: [inputs.card],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
const cardSubscription = await CardSubscription.destroyOne({
|
||||
const cardSubscription = await CardSubscription.qm.deleteOne({
|
||||
cardId: cardMembership.cardId,
|
||||
userId: cardMembership.userId,
|
||||
isPermanent: false,
|
||||
|
@ -69,8 +74,6 @@ module.exports = {
|
|||
isSubscribed: false,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhook
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: criteriaValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return CardMembership.find(inputs.criteria).sort('id');
|
||||
},
|
||||
};
|
|
@ -1,14 +0,0 @@
|
|||
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: criteriaValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return CardSubscription.find(inputs.criteria).sort('id');
|
||||
},
|
||||
};
|
|
@ -1,38 +1,18 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.list)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.creatorUser)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
/*!
|
||||
* 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',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
|
@ -45,50 +25,55 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (_.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
if (sails.helpers.lists.isFinite(values.list)) {
|
||||
if (_.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
|
||||
if (values.dueDate) {
|
||||
if (_.isNil(values.isDueDateCompleted)) {
|
||||
values.isDueDateCompleted = false;
|
||||
const cards = await Card.qm.getByListId(values.list.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
cards,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
if (repositions.length > 0) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await Card.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
listId: reposition.record.listId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${values.board.id}`, 'cardUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
} else {
|
||||
delete values.isDueDateCompleted;
|
||||
delete values.position;
|
||||
}
|
||||
|
||||
const cards = await sails.helpers.lists.getCards(values.list.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
cards,
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Card.update({
|
||||
id,
|
||||
listId: values.list.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${values.list.boardId}`, 'cardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
});
|
||||
|
||||
const card = await Card.create({
|
||||
const card = await Card.qm.createOne({
|
||||
...values,
|
||||
position,
|
||||
boardId: values.list.boardId,
|
||||
boardId: values.board.id,
|
||||
listId: values.list.id,
|
||||
creatorUserId: values.creatorUser.id,
|
||||
}).fetch();
|
||||
listChangedAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${card.boardId}`,
|
||||
|
@ -101,22 +86,28 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardCreate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
boards: [values.board],
|
||||
lists: [values.list],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: values.creatorUser,
|
||||
});
|
||||
|
||||
if (values.creatorUser.subscribeToOwnCards) {
|
||||
await CardSubscription.create({
|
||||
cardId: card.id,
|
||||
userId: card.creatorUserId,
|
||||
}).tolerate('E_UNIQUE');
|
||||
try {
|
||||
await CardSubscription.qm.createOne({
|
||||
cardId: card.id,
|
||||
userId: card.creatorUserId,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code !== 'E_UNIQUE') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(`user:${card.creatorUserId}`, 'cardUpdate', {
|
||||
item: {
|
||||
|
@ -133,14 +124,13 @@ module.exports = {
|
|||
card,
|
||||
type: Action.Types.CREATE_CARD,
|
||||
data: {
|
||||
list: _.pick(values.list, ['id', 'name']),
|
||||
list: _.pick(values.list, ['id', 'type', 'name']),
|
||||
},
|
||||
user: values.creatorUser,
|
||||
},
|
||||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
board: values.board,
|
||||
list: values.list,
|
||||
request: inputs.request,
|
||||
});
|
||||
|
||||
return card;
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
const buildAndSendMarkdownMessage = async (card, actorUser, send) => {
|
||||
await send(`*${card.name}* was deleted by ${actorUser.name}`);
|
||||
};
|
||||
|
||||
const buildAndSendHtmlMessage = async (card, actorUser, send) => {
|
||||
await send(`<b>${card.name}</b> was deleted by ${actorUser.name}`);
|
||||
};
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
|
@ -34,7 +31,9 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const card = await Card.archiveOne(inputs.record.id);
|
||||
await sails.helpers.cards.deleteRelated(inputs.record);
|
||||
|
||||
const card = await Card.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (card) {
|
||||
sails.sockets.broadcast(
|
||||
|
@ -48,32 +47,16 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardDelete',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
if (sails.config.custom.slackBotToken) {
|
||||
buildAndSendMarkdownMessage(card, inputs.actorUser, sails.helpers.utils.sendSlackMessage);
|
||||
}
|
||||
|
||||
if (sails.config.custom.googleChatWebhookUrl) {
|
||||
buildAndSendMarkdownMessage(
|
||||
card,
|
||||
inputs.actorUser,
|
||||
sails.helpers.utils.sendGoogleChatMessage,
|
||||
);
|
||||
}
|
||||
|
||||
if (sails.config.custom.telegramBotToken) {
|
||||
buildAndSendHtmlMessage(card, inputs.actorUser, sails.helpers.utils.sendTelegramMessage);
|
||||
}
|
||||
}
|
||||
|
||||
return card;
|
||||
|
|
62
server/api/helpers/cards/delete-related.js
Normal file
62
server/api/helpers/cards/delete-related.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
recordOrRecords: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
let cardIdOrIds;
|
||||
if (_.isPlainObject(inputs.recordOrRecords)) {
|
||||
({
|
||||
recordOrRecords: { id: cardIdOrIds },
|
||||
} = inputs);
|
||||
} else if (_.every(inputs.recordOrRecords, _.isPlainObject)) {
|
||||
cardIdOrIds = sails.helpers.utils.mapRecords(inputs.recordOrRecords);
|
||||
}
|
||||
|
||||
await CardSubscription.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
|
||||
await CardMembership.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
|
||||
await CardLabel.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
|
||||
const taskLists = await TaskList.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
|
||||
await sails.helpers.taskLists.deleteRelated(taskLists);
|
||||
|
||||
const { fileReferences } = await Attachment.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
|
||||
sails.helpers.attachments.removeUnreferencedFiles(fileReferences);
|
||||
|
||||
const customFieldGroups = await CustomFieldGroup.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
|
||||
await sails.helpers.customFieldGroups.deleteRelated(customFieldGroups);
|
||||
|
||||
await Comment.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
|
||||
await Action.qm.delete({
|
||||
cardId: cardIdOrIds,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,18 +1,7 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.creatorUser)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
|
@ -21,8 +10,7 @@ module.exports = {
|
|||
required: true,
|
||||
},
|
||||
values: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
|
@ -37,74 +25,199 @@ module.exports = {
|
|||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
join: {
|
||||
type: 'boolean',
|
||||
defaultsTo: false,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
positionMustBeInValues: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const cards = await sails.helpers.lists.getCards(inputs.record.listId);
|
||||
if (sails.helpers.lists.isFinite(inputs.list)) {
|
||||
if (_.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
cards,
|
||||
);
|
||||
const cards = await Card.qm.getByListId(inputs.list.id);
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Card.update({
|
||||
id,
|
||||
listId: inputs.record.listId,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
cards,
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.record.boardId}`, 'cardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
values.position = position;
|
||||
|
||||
// TODO: send webhooks
|
||||
});
|
||||
if (repositions.length > 0) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await Card.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
listId: reposition.record.listId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
const card = await Card.create({
|
||||
sails.sockets.broadcast(`board:${inputs.record.boardId}`, 'cardUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let card = await Card.qm.createOne({
|
||||
..._.pick(inputs.record, [
|
||||
'boardId',
|
||||
'listId',
|
||||
'prevListId',
|
||||
'type',
|
||||
'name',
|
||||
'description',
|
||||
'dueDate',
|
||||
'isDueDateCompleted',
|
||||
'stopwatch',
|
||||
]),
|
||||
...values,
|
||||
position,
|
||||
creatorUserId: values.creatorUser.id,
|
||||
}).fetch();
|
||||
listChangedAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const cardMemberships = await CardMembership.qm.getByCardId(inputs.record.id);
|
||||
|
||||
const cardMemberships = await sails.helpers.cards.getCardMemberships(inputs.record.id);
|
||||
const cardMembershipsValues = cardMemberships.map((cardMembership) => ({
|
||||
..._.pick(cardMembership, ['userId']),
|
||||
cardId: card.id,
|
||||
}));
|
||||
const nextCardMemberships = await CardMembership.createEach(cardMembershipsValues).fetch();
|
||||
|
||||
const cardLabels = await sails.helpers.cards.getCardLabels(inputs.record.id);
|
||||
const nextCardMemberships = await CardMembership.qm.create(cardMembershipsValues);
|
||||
|
||||
const cardLabels = await CardLabel.qm.getByCardId(inputs.record.id);
|
||||
|
||||
const cardLabelsValues = cardLabels.map((cardLabel) => ({
|
||||
..._.pick(cardLabel, ['labelId']),
|
||||
cardId: card.id,
|
||||
}));
|
||||
const nextCardLabels = await CardLabel.createEach(cardLabelsValues).fetch();
|
||||
|
||||
const tasks = await sails.helpers.cards.getTasks(inputs.record.id);
|
||||
const tasksValues = tasks.map((task) => ({
|
||||
..._.pick(task, ['position', 'name', 'isCompleted']),
|
||||
cardId: card.id,
|
||||
const nextCardLabels = await CardLabel.qm.create(cardLabelsValues);
|
||||
|
||||
const taskLists = await TaskList.qm.getByCardId(inputs.record.id);
|
||||
const taskListIds = sails.helpers.utils.mapRecords(taskLists);
|
||||
|
||||
const tasks = await Task.qm.getByTaskListIds(taskListIds);
|
||||
const attachments = await Attachment.qm.getByCardId(inputs.record.id);
|
||||
|
||||
const customFieldGroups = await CustomFieldGroup.qm.getByCardId(inputs.record.id);
|
||||
const customFieldGroupIds = sails.helpers.utils.mapRecords(customFieldGroups);
|
||||
|
||||
const customFields = await CustomField.qm.getByCustomFieldGroupIds(customFieldGroupIds);
|
||||
const customFieldValues = await CustomFieldValue.qm.getByCardId(inputs.record.id);
|
||||
|
||||
const ids = await sails.helpers.utils.generateIds(
|
||||
taskLists.length + attachments.length + customFieldGroups.length + customFields.length,
|
||||
);
|
||||
|
||||
const nextTaskListIdByTaskListId = {};
|
||||
const nextTaskListsValues = await taskLists.map((taskList) => {
|
||||
const id = ids.shift();
|
||||
nextTaskListIdByTaskListId[taskList.id] = id;
|
||||
|
||||
return {
|
||||
..._.pick(taskList, ['position', 'name', 'showOnFrontOfCard']),
|
||||
id,
|
||||
cardId: card.id,
|
||||
};
|
||||
});
|
||||
|
||||
const nextTaskLists = await TaskList.qm.create(nextTaskListsValues);
|
||||
|
||||
const nextTasksValues = tasks.map((task) => ({
|
||||
..._.pick(task, ['assigneeUserId', 'position', 'name', 'isCompleted']),
|
||||
taskListId: nextTaskListIdByTaskListId[task.taskListId],
|
||||
}));
|
||||
const nextTasks = await Task.createEach(tasksValues).fetch();
|
||||
|
||||
const nextTasks = await Task.qm.create(nextTasksValues);
|
||||
|
||||
const nextAttachmentIdByAttachmentId = {};
|
||||
const nextAttachmentsValues = attachments.map((attachment) => {
|
||||
const id = ids.shift();
|
||||
nextAttachmentIdByAttachmentId[attachment.id] = id;
|
||||
|
||||
return {
|
||||
..._.pick(attachment, ['type', 'data', 'name']),
|
||||
id,
|
||||
cardId: card.id,
|
||||
creatorUserId: card.creatorUserId,
|
||||
};
|
||||
});
|
||||
|
||||
const nextAttachments = await Attachment.qm.create(nextAttachmentsValues);
|
||||
|
||||
if (inputs.record.coverAttachmentId) {
|
||||
const nextCoverAttachmentId = nextAttachmentIdByAttachmentId[inputs.record.coverAttachmentId];
|
||||
|
||||
if (nextCoverAttachmentId) {
|
||||
card = await Card.qm.updateOne(card.id, {
|
||||
coverAttachmentId: nextCoverAttachmentId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const nextCustomFieldGroupIdByCustomFieldGroupId = {};
|
||||
const nextCustomFieldGroupsValues = customFieldGroups.map((customFieldGroup) => {
|
||||
const id = ids.shift();
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldGroup.id] = id;
|
||||
|
||||
return {
|
||||
..._.pick(customFieldGroup, ['baseCustomFieldGroupId', 'position', 'name']),
|
||||
id,
|
||||
cardId: card.id,
|
||||
};
|
||||
});
|
||||
|
||||
const nextCustomFieldGroups = await CustomFieldGroup.qm.create(nextCustomFieldGroupsValues);
|
||||
|
||||
const nextCustomFieldIdByCustomFieldId = {};
|
||||
const nextCustomFieldsValues = customFields.map((customField) => {
|
||||
const id = ids.shift();
|
||||
nextCustomFieldIdByCustomFieldId[customField.id] = id;
|
||||
|
||||
return {
|
||||
..._.pick(customField, ['position', 'name', 'showOnFrontOfCard']),
|
||||
id,
|
||||
customFieldGroupId:
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customField.customFieldGroupId],
|
||||
};
|
||||
});
|
||||
|
||||
const nextCustomFields = await CustomField.qm.create(nextCustomFieldsValues);
|
||||
|
||||
const nextCustomFieldValuesValues = customFieldValues.map((customFieldValue) => ({
|
||||
..._.pick(customFieldValue, ['content']),
|
||||
cardId: card.id,
|
||||
customFieldGroupId:
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldValue.customFieldGroupId] ||
|
||||
customFieldValue.customFieldGroupId,
|
||||
customFieldId:
|
||||
nextCustomFieldIdByCustomFieldId[customFieldValue.customFieldId] ||
|
||||
customFieldValue.customFieldId,
|
||||
}));
|
||||
|
||||
const nextCustomFieldValues = await CustomFieldValue.qm.create(nextCustomFieldValuesValues);
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${card.boardId}`,
|
||||
|
@ -117,22 +230,36 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardCreate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
cardMemberships: nextCardMemberships,
|
||||
cardLabels: nextCardLabels,
|
||||
taskLists: nextTaskLists,
|
||||
tasks: nextTasks,
|
||||
attachments: sails.helpers.attachments.presentMany(nextAttachments),
|
||||
customFieldGroups: nextCustomFieldGroups,
|
||||
customFields: nextCustomFields,
|
||||
customFieldValues: nextCustomFieldValues,
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: values.creatorUser,
|
||||
});
|
||||
|
||||
if (values.creatorUser.subscribeToOwnCards) {
|
||||
await CardSubscription.create({
|
||||
cardId: card.id,
|
||||
userId: card.creatorUserId,
|
||||
}).tolerate('E_UNIQUE');
|
||||
try {
|
||||
await CardSubscription.qm.createOne({
|
||||
cardId: card.id,
|
||||
userId: card.creatorUserId,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code !== 'E_UNIQUE') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(`user:${card.creatorUserId}`, 'cardUpdate', {
|
||||
item: {
|
||||
|
@ -149,21 +276,25 @@ module.exports = {
|
|||
card,
|
||||
type: Action.Types.CREATE_CARD, // TODO: introduce separate type?
|
||||
data: {
|
||||
list: _.pick(inputs.list, ['id', 'name']),
|
||||
list: _.pick(inputs.list, ['id', 'type', 'name']),
|
||||
},
|
||||
user: values.creatorUser,
|
||||
},
|
||||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
list: inputs.list,
|
||||
request: inputs.request,
|
||||
});
|
||||
|
||||
return {
|
||||
card,
|
||||
cardMemberships: nextCardMemberships,
|
||||
cardLabels: nextCardLabels,
|
||||
taskLists: nextTaskLists,
|
||||
tasks: nextTasks,
|
||||
attachments: nextAttachments,
|
||||
customFieldGroups: nextCustomFieldGroups,
|
||||
customFields: nextCustomFields,
|
||||
customFieldValues: nextCustomFieldValues,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
const LIMIT = 50;
|
||||
|
||||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
beforeId: {
|
||||
type: 'string',
|
||||
},
|
||||
withDetails: {
|
||||
type: 'boolean',
|
||||
defaultsTo: false,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const criteria = {
|
||||
cardId: inputs.idOrIds,
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.beforeId)) {
|
||||
criteria.id = {
|
||||
'<': inputs.beforeId,
|
||||
};
|
||||
}
|
||||
|
||||
if (!inputs.withDetails) {
|
||||
criteria.type = Action.Types.COMMENT_CARD;
|
||||
}
|
||||
|
||||
return sails.helpers.actions.getMany(criteria, LIMIT);
|
||||
},
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return sails.helpers.attachments.getMany({
|
||||
cardId: inputs.idOrIds,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return sails.helpers.cardLabels.getMany({
|
||||
cardId: inputs.idOrIds,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return sails.helpers.cardMemberships.getMany({
|
||||
cardId: inputs.idOrIds,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,29 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
exceptUserIdOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const criteria = {
|
||||
cardId: inputs.idOrIds,
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.exceptUserIdOrIds)) {
|
||||
criteria.userId = {
|
||||
'!=': inputs.exceptUserIdOrIds,
|
||||
};
|
||||
}
|
||||
|
||||
return sails.helpers.cardSubscriptions.getMany(criteria);
|
||||
},
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const cardLabels = await sails.helpers.cards.getCardLabels(inputs.idOrIds);
|
||||
|
||||
return sails.helpers.utils.mapRecords(cardLabels, 'labelId', _.isArray(inputs.idOrIds));
|
||||
},
|
||||
};
|
|
@ -1,17 +1,20 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const labelIds = await sails.helpers.cards.getLabelIds(inputs.idOrIds);
|
||||
const cardLabels = await CardLabel.qm.getByCardId(inputs.id);
|
||||
const labelIds = sails.helpers.utils.mapRecords(cardLabels, 'labelId');
|
||||
|
||||
return sails.helpers.labels.getMany(labelIds);
|
||||
return Label.qm.getByIds(labelIds);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: criteriaValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return Card.find(inputs.criteria).sort('position');
|
||||
},
|
||||
};
|
39
server/api/helpers/cards/get-path-to-project-by-id.js
Normal file
39
server/api/helpers/cards/get-path-to-project-by-id.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*!
|
||||
* 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 card = await Card.qm.getOneById(inputs.id);
|
||||
|
||||
if (!card) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const pathToProject = await sails.helpers.lists
|
||||
.getPathToProjectById(card.listId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
card,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
card,
|
||||
...pathToProject,
|
||||
};
|
||||
},
|
||||
};
|
|
@ -1,34 +0,0 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
pathNotFound: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const card = await Card.findOne(inputs.criteria);
|
||||
|
||||
if (!card) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const path = await sails.helpers.lists
|
||||
.getProjectPath(card.listId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
card,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
card,
|
||||
...path,
|
||||
};
|
||||
},
|
||||
};
|
|
@ -1,24 +1,24 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
exceptUserIdOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const cardSubscriptions = await sails.helpers.cards.getCardSubscriptions(
|
||||
inputs.idOrIds,
|
||||
inputs.exceptUserIdOrIds,
|
||||
);
|
||||
const cardSubscriptions = await CardSubscription.qm.getByCardId(inputs.id, {
|
||||
exceptUserIdOrIds: inputs.exceptUserIdOrIds,
|
||||
});
|
||||
|
||||
return sails.helpers.utils.mapRecords(cardSubscriptions, 'userId', _.isArray(inputs.idOrIds));
|
||||
return sails.helpers.utils.mapRecords(cardSubscriptions, 'userId');
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
exceptTaskIdOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const criteria = {
|
||||
cardId: inputs.idOrIds,
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.exceptTaskIdOrIds)) {
|
||||
criteria.id = {
|
||||
'!=': inputs.exceptTaskIdOrIds,
|
||||
};
|
||||
}
|
||||
|
||||
return sails.helpers.tasks.getMany(criteria);
|
||||
},
|
||||
};
|
56
server/api/helpers/cards/read-notifications-for-user.js
Normal file
56
server/api/helpers/cards/read-notifications-for-user.js
Normal file
|
@ -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: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
// TODO: add actorUser as well?
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const notifications = await Notification.qm.update(
|
||||
{
|
||||
userId: inputs.user.id,
|
||||
cardId: inputs.record.id,
|
||||
isRead: false,
|
||||
},
|
||||
{
|
||||
isRead: true,
|
||||
},
|
||||
);
|
||||
|
||||
notifications.forEach((notification) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${notification.userId}`,
|
||||
'notificationUpdate',
|
||||
{
|
||||
item: notification,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
// TODO: with prevData?
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'notificationUpdate',
|
||||
buildData: () => ({
|
||||
item: notification,
|
||||
}),
|
||||
user: inputs.user,
|
||||
});
|
||||
});
|
||||
|
||||
return notifications;
|
||||
},
|
||||
};
|
|
@ -1,28 +1,9 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.board)) {
|
||||
if (!_.isPlainObject(value.project)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.board)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.list) && !_.isPlainObject(value.list)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
const { POSITION_GAP } = require('../../../constants');
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
|
@ -31,8 +12,7 @@ module.exports = {
|
|||
required: true,
|
||||
},
|
||||
values: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
|
@ -61,8 +41,10 @@ module.exports = {
|
|||
boardInValuesMustBelongToProject: {},
|
||||
listMustBeInValues: {},
|
||||
listInValuesMustBelongToBoard: {},
|
||||
coverAttachmentInValuesMustContainImage: {},
|
||||
},
|
||||
|
||||
// TODO: use normalizeValues and refactor
|
||||
async fn(inputs) {
|
||||
const { isSubscribed, ...values } = inputs.values;
|
||||
|
||||
|
@ -102,90 +84,314 @@ module.exports = {
|
|||
|
||||
const list = values.list || inputs.list;
|
||||
|
||||
if (values.list && _.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const cards = await sails.helpers.lists.getCards(list.id, inputs.record.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
cards,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Card.update({
|
||||
id,
|
||||
listId: list.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${board.id}`, 'cardUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
});
|
||||
}
|
||||
|
||||
const dueDate = _.isUndefined(values.dueDate) ? inputs.record.dueDate : values.dueDate;
|
||||
|
||||
if (dueDate) {
|
||||
const isDueDateCompleted = _.isUndefined(values.isDueDateCompleted)
|
||||
? inputs.record.isDueDateCompleted
|
||||
: values.isDueDateCompleted;
|
||||
|
||||
if (_.isNull(isDueDateCompleted)) {
|
||||
values.isDueDateCompleted = false;
|
||||
if (sails.helpers.lists.isFinite(list)) {
|
||||
if (values.list && _.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
} else {
|
||||
values.isDueDateCompleted = null;
|
||||
values.position = null;
|
||||
}
|
||||
|
||||
if (values.coverAttachment) {
|
||||
if (!values.coverAttachment.data.image) {
|
||||
throw 'coverAttachmentInValuesMustContainImage';
|
||||
}
|
||||
|
||||
values.coverAttachmentId = values.coverAttachment.id;
|
||||
}
|
||||
|
||||
let card;
|
||||
if (_.isEmpty(values)) {
|
||||
card = inputs.record;
|
||||
} else {
|
||||
let prevLabels;
|
||||
if (values.board) {
|
||||
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(values.board.id);
|
||||
|
||||
await CardSubscription.destroy({
|
||||
cardId: inputs.record.id,
|
||||
userId: {
|
||||
'!=': boardMemberUserIds,
|
||||
},
|
||||
if (!_.isNil(values.position)) {
|
||||
const cards = await Card.qm.getByListId(list.id, {
|
||||
exceptIdOrIds: inputs.record.id,
|
||||
});
|
||||
|
||||
await CardMembership.destroy({
|
||||
cardId: inputs.record.id,
|
||||
userId: {
|
||||
'!=': boardMemberUserIds,
|
||||
},
|
||||
});
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
cards,
|
||||
);
|
||||
|
||||
prevLabels = await sails.helpers.cards.getLabels(inputs.record.id);
|
||||
values.position = position;
|
||||
|
||||
await CardLabel.destroy({
|
||||
cardId: inputs.record.id,
|
||||
});
|
||||
if (repositions.length > 0) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await Card.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
listId: reposition.record.listId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${board.id}`, 'cardUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
card = await Card.updateOne(inputs.record.id).set({ ...values });
|
||||
let prevLabels;
|
||||
if (values.board) {
|
||||
prevLabels = await sails.helpers.cards.getLabels(inputs.record.id);
|
||||
|
||||
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(values.board.id);
|
||||
|
||||
await CardSubscription.qm.delete({
|
||||
cardId: inputs.record.id,
|
||||
userId: {
|
||||
'!=': boardMemberUserIds,
|
||||
},
|
||||
});
|
||||
|
||||
await CardMembership.qm.delete({
|
||||
cardId: inputs.record.id,
|
||||
userId: {
|
||||
'!=': boardMemberUserIds,
|
||||
},
|
||||
});
|
||||
|
||||
await CardLabel.qm.delete({
|
||||
cardId: inputs.record.id,
|
||||
});
|
||||
|
||||
const taskLists = await TaskList.qm.getByCardId(inputs.record.id);
|
||||
const taskListIds = sails.helpers.utils.mapRecords(taskLists);
|
||||
|
||||
await Task.qm.update(
|
||||
{
|
||||
taskListId: taskListIds,
|
||||
assigneeUserId: {
|
||||
'!=': boardMemberUserIds,
|
||||
},
|
||||
},
|
||||
{
|
||||
assigneeUserId: null,
|
||||
},
|
||||
);
|
||||
|
||||
const boardCustomFieldGroups = await CustomFieldGroup.qm.getByBoardId(inputs.board.id);
|
||||
const boardCustomFieldGroupIds = sails.helpers.utils.mapRecords(boardCustomFieldGroups);
|
||||
|
||||
const boardCustomFields =
|
||||
await CustomField.qm.getByCustomFieldGroupIds(boardCustomFieldGroupIds);
|
||||
|
||||
const cardCustomFieldGroups = await CustomFieldGroup.qm.getByCardId(inputs.record.id);
|
||||
|
||||
let basedCardCustomFieldGroups;
|
||||
let basedCustomFieldGroups;
|
||||
let baseCustomFieldGroupById;
|
||||
let customFieldsByBaseCustomFieldGroupId;
|
||||
|
||||
if (values.project) {
|
||||
const basedBoardCustomFieldGroups = boardCustomFieldGroups.filter(
|
||||
({ baseCustomFieldGroupId }) => baseCustomFieldGroupId,
|
||||
);
|
||||
|
||||
basedCardCustomFieldGroups = cardCustomFieldGroups.filter(
|
||||
({ baseCustomFieldGroupId }) => baseCustomFieldGroupId,
|
||||
);
|
||||
|
||||
basedCustomFieldGroups = [...basedBoardCustomFieldGroups, ...basedCardCustomFieldGroups];
|
||||
|
||||
const baseCustomFieldGroupIds = sails.helpers.utils.mapRecords(
|
||||
basedCustomFieldGroups,
|
||||
'baseCustomFieldGroupId',
|
||||
true,
|
||||
);
|
||||
|
||||
const baseCustomFieldGroups =
|
||||
await BaseCustomFieldGroup.qm.getByIds(baseCustomFieldGroupIds);
|
||||
|
||||
baseCustomFieldGroupById = _.keyBy(baseCustomFieldGroups, 'id');
|
||||
|
||||
const baseCustomFields = await CustomField.qm.getByBaseCustomFieldGroupIds(
|
||||
Object.keys(baseCustomFieldGroupById),
|
||||
);
|
||||
|
||||
customFieldsByBaseCustomFieldGroupId = _.groupBy(
|
||||
baseCustomFields,
|
||||
'baseCustomFieldGroupId',
|
||||
);
|
||||
}
|
||||
|
||||
let idsTotal = boardCustomFieldGroups.length + boardCustomFields.length;
|
||||
|
||||
if (values.project) {
|
||||
idsTotal += basedCustomFieldGroups.reduce((result, customFieldGroup) => {
|
||||
const customFieldsItem =
|
||||
customFieldsByBaseCustomFieldGroupId[customFieldGroup.baseCustomFieldGroupId];
|
||||
|
||||
return result + (customFieldsItem ? customFieldsItem.length : 0);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
const ids = await sails.helpers.utils.generateIds(idsTotal);
|
||||
|
||||
const nextCustomFieldGroupIdByCustomFieldGroupId = {};
|
||||
const nextCustomFieldGroupsValues = boardCustomFieldGroups.map(
|
||||
(customFieldGroup, index) => {
|
||||
const id = ids.shift();
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldGroup.id] = id;
|
||||
|
||||
const nextValues = {
|
||||
..._.pick(customFieldGroup, ['baseCustomFieldGroupId', 'name']),
|
||||
id,
|
||||
cardId: inputs.record.id,
|
||||
position: POSITION_GAP * (index + 1),
|
||||
};
|
||||
|
||||
if (values.project && customFieldGroup.baseCustomFieldGroupId) {
|
||||
nextValues.baseCustomFieldGroupId = null;
|
||||
|
||||
if (!customFieldGroup.name) {
|
||||
nextValues.name =
|
||||
baseCustomFieldGroupById[customFieldGroup.baseCustomFieldGroupId].name;
|
||||
}
|
||||
}
|
||||
|
||||
return nextValues;
|
||||
},
|
||||
);
|
||||
|
||||
if (nextCustomFieldGroupsValues.length > 0) {
|
||||
const { position } = nextCustomFieldGroupsValues[nextCustomFieldGroupsValues.length - 1];
|
||||
|
||||
await Promise.all(
|
||||
cardCustomFieldGroups.map((customFieldGroup) =>
|
||||
CustomFieldGroup.qm.updateOne(customFieldGroup.id, {
|
||||
position: customFieldGroup.position + position,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
await CustomFieldGroup.qm.create(nextCustomFieldGroupsValues);
|
||||
|
||||
if (values.project) {
|
||||
await CustomFieldGroup.qm.update(
|
||||
{
|
||||
cardId: inputs.record.id,
|
||||
baseCustomFieldGroupId: {
|
||||
'!=': null,
|
||||
},
|
||||
},
|
||||
{
|
||||
baseCustomFieldGroupId: null,
|
||||
},
|
||||
);
|
||||
|
||||
const unnamedCustomFieldGroups = basedCardCustomFieldGroups.filter(({ name }) => !name);
|
||||
|
||||
await Promise.all(
|
||||
unnamedCustomFieldGroups.map((customFieldGroup) =>
|
||||
CustomFieldGroup.qm.updateOne(customFieldGroup.id, {
|
||||
name: baseCustomFieldGroupById[customFieldGroup.baseCustomFieldGroupId].name,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const nextCustomFieldIdByCustomFieldId = {};
|
||||
const nextCustomFieldsValues = boardCustomFields.map((customField) => {
|
||||
const id = ids.shift();
|
||||
nextCustomFieldIdByCustomFieldId[customField.id] = id;
|
||||
|
||||
return {
|
||||
..._.pick(customField, ['name', 'showOnFrontOfCard', 'position']),
|
||||
id,
|
||||
customFieldGroupId:
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customField.customFieldGroupId],
|
||||
};
|
||||
});
|
||||
|
||||
if (values.project) {
|
||||
basedCustomFieldGroups.forEach((customFieldGroup) => {
|
||||
const customFieldsItem =
|
||||
customFieldsByBaseCustomFieldGroupId[customFieldGroup.baseCustomFieldGroupId];
|
||||
|
||||
if (!customFieldsItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
customFieldsItem.forEach((customField) => {
|
||||
const id = ids.shift();
|
||||
nextCustomFieldIdByCustomFieldId[`${customFieldGroup.id}:${customField.id}`] = id;
|
||||
|
||||
nextCustomFieldsValues.push({
|
||||
..._.pick(customField, ['name', 'showOnFrontOfCard', 'position']),
|
||||
id,
|
||||
customFieldGroupId:
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldGroup.id] ||
|
||||
customFieldGroup.id,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
await CustomField.qm.create(nextCustomFieldsValues);
|
||||
|
||||
const customFieldGroupIds = boardCustomFieldGroupIds;
|
||||
if (values.project) {
|
||||
customFieldGroupIds.push(...sails.helpers.utils.mapRecords(basedCardCustomFieldGroups));
|
||||
}
|
||||
|
||||
const customFieldValues = await CustomFieldValue.qm.getByCardId(inputs.record.id, {
|
||||
customFieldGroupIdOrIds: customFieldGroupIds,
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
customFieldValues.map((customFieldValue) => {
|
||||
const updateValues = {
|
||||
customFieldGroupId:
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldValue.customFieldGroupId],
|
||||
};
|
||||
|
||||
const nextCustomFieldId =
|
||||
nextCustomFieldIdByCustomFieldId[
|
||||
`${customFieldValue.customFieldGroupId}:${customFieldValue.customFieldId}`
|
||||
] || nextCustomFieldIdByCustomFieldId[customFieldValue.customFieldId];
|
||||
|
||||
if (nextCustomFieldId) {
|
||||
updateValues.customFieldId = nextCustomFieldId;
|
||||
}
|
||||
|
||||
return CustomFieldValue.qm.updateOne(customFieldValue.id, updateValues);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (values.list) {
|
||||
values.listChangedAt = new Date().toISOString();
|
||||
|
||||
if (values.board || inputs.list.type === List.Types.TRASH) {
|
||||
values.prevListId = null;
|
||||
} else if (sails.helpers.lists.isArchiveOrTrash(values.list)) {
|
||||
values.prevListId = inputs.list.id;
|
||||
} else if (inputs.list.type === List.Types.ARCHIVE) {
|
||||
values.prevListId = null;
|
||||
}
|
||||
}
|
||||
|
||||
card = await Card.qm.updateOne(inputs.record.id, values);
|
||||
|
||||
if (!card) {
|
||||
return card;
|
||||
}
|
||||
|
||||
if (values.board) {
|
||||
const labels = await sails.helpers.boards.getLabels(card.boardId);
|
||||
const labels = await Label.qm.getByBoardId(card.boardId);
|
||||
const labelByName = _.keyBy(labels, 'name');
|
||||
|
||||
const labelIds = await Promise.all(
|
||||
|
@ -197,8 +403,8 @@ module.exports = {
|
|||
const { id } = await sails.helpers.labels.createOne.with({
|
||||
project,
|
||||
values: {
|
||||
..._.omit(label, ['id', 'boardId']),
|
||||
board: values.board,
|
||||
..._.omit(label, ['id', 'boardId', 'createdAt', 'updatedAt']),
|
||||
board,
|
||||
},
|
||||
actorUser: inputs.actorUser,
|
||||
});
|
||||
|
@ -208,21 +414,30 @@ module.exports = {
|
|||
);
|
||||
|
||||
await Promise.all(
|
||||
labelIds.map(async (labelId) =>
|
||||
CardLabel.create({
|
||||
labelId,
|
||||
cardId: card.id,
|
||||
})
|
||||
.tolerate('E_UNIQUE')
|
||||
.fetch(),
|
||||
),
|
||||
labelIds.map((labelId) => {
|
||||
try {
|
||||
return CardLabel.qm.createOne({
|
||||
labelId,
|
||||
cardId: card.id,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code !== 'E_UNIQUE') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}),
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.record.boardId}`,
|
||||
'cardDelete', // TODO: introduce separate event
|
||||
`board:${inputs.board.id}`,
|
||||
'cardUpdate',
|
||||
{
|
||||
item: inputs.record,
|
||||
item: {
|
||||
id: card.id,
|
||||
boardId: null,
|
||||
},
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
@ -231,18 +446,7 @@ module.exports = {
|
|||
item: card,
|
||||
});
|
||||
|
||||
const subscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(card.id);
|
||||
|
||||
subscriptionUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'cardUpdate', {
|
||||
item: {
|
||||
id: card.id,
|
||||
isSubscribed: true,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
});
|
||||
// TODO: add transfer action
|
||||
} else {
|
||||
sails.sockets.broadcast(
|
||||
`board:${card.boardId}`,
|
||||
|
@ -252,59 +456,67 @@ module.exports = {
|
|||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
if (values.list) {
|
||||
await sails.helpers.actions.createOne.with({
|
||||
values: {
|
||||
card,
|
||||
type: Action.Types.MOVE_CARD,
|
||||
data: {
|
||||
fromList: _.pick(inputs.list, ['id', 'type', 'name']),
|
||||
toList: _.pick(values.list, ['id', 'type', 'name']),
|
||||
},
|
||||
user: inputs.actorUser,
|
||||
},
|
||||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
list: values.list,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'cardUpdate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
projects: [project],
|
||||
boards: [board],
|
||||
lists: [list],
|
||||
},
|
||||
},
|
||||
prevData: {
|
||||
}),
|
||||
buildPrevData: () => ({
|
||||
item: inputs.record,
|
||||
},
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
if (!values.board && values.list) {
|
||||
await sails.helpers.actions.createOne.with({
|
||||
project,
|
||||
board,
|
||||
list,
|
||||
values: {
|
||||
card,
|
||||
user: inputs.actorUser,
|
||||
type: Action.Types.MOVE_CARD,
|
||||
data: {
|
||||
fromList: _.pick(inputs.list, ['id', 'name']),
|
||||
toList: _.pick(values.list, ['id', 'name']),
|
||||
},
|
||||
},
|
||||
request: inputs.request,
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: add transfer action
|
||||
}
|
||||
|
||||
if (!_.isUndefined(isSubscribed)) {
|
||||
const prevIsSubscribed = await sails.helpers.users.isCardSubscriber(
|
||||
const wasSubscribed = await sails.helpers.users.isCardSubscriber(
|
||||
inputs.actorUser.id,
|
||||
card.id,
|
||||
);
|
||||
|
||||
if (isSubscribed !== prevIsSubscribed) {
|
||||
if (isSubscribed !== wasSubscribed) {
|
||||
if (isSubscribed) {
|
||||
await CardSubscription.create({
|
||||
cardId: card.id,
|
||||
userId: inputs.actorUser.id,
|
||||
}).tolerate('E_UNIQUE');
|
||||
try {
|
||||
await CardSubscription.qm.createOne({
|
||||
cardId: card.id,
|
||||
userId: inputs.actorUser.id,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code !== 'E_UNIQUE') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await CardSubscription.destroyOne({
|
||||
await CardSubscription.qm.deleteOne({
|
||||
cardId: card.id,
|
||||
userId: inputs.actorUser.id,
|
||||
});
|
||||
|
|
171
server/api/helpers/comments/create-one.js
Normal file
171
server/api/helpers/comments/create-one.js
Normal file
|
@ -0,0 +1,171 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const escapeMarkdown = require('escape-markdown');
|
||||
const escapeHtml = require('escape-html');
|
||||
|
||||
const buildAndSendNotifications = async (services, board, card, comment, actorUser, t) => {
|
||||
const markdownCardLink = `[${escapeMarkdown(card.name)}](${sails.config.custom.baseUrl}/cards/${card.id})`;
|
||||
const htmlCardLink = `<a href="${sails.config.custom.baseUrl}/cards/${card.id}}">${escapeHtml(card.name)}</a>`;
|
||||
const commentText = _.truncate(comment.text);
|
||||
|
||||
await sails.helpers.utils.sendNotifications(services, t('New Comment'), {
|
||||
text: `${t(
|
||||
'%s left a new comment to %s on %s',
|
||||
actorUser.name,
|
||||
card.name,
|
||||
board.name,
|
||||
)}:\n${commentText}`,
|
||||
markdown: `${t(
|
||||
'%s left a new comment to %s on %s',
|
||||
escapeMarkdown(actorUser.name),
|
||||
markdownCardLink,
|
||||
escapeMarkdown(board.name),
|
||||
)}:\n\n*${escapeMarkdown(commentText)}*`,
|
||||
html: `${t(
|
||||
'%s left a new comment to %s on %s',
|
||||
escapeHtml(actorUser.name),
|
||||
htmlCardLink,
|
||||
escapeHtml(board.name),
|
||||
)}:\n\n<i>${escapeHtml(commentText)}</i>`,
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
list: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const comment = await Comment.qm.createOne({
|
||||
...values,
|
||||
cardId: values.card.id,
|
||||
userId: values.user.id,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'commentCreate',
|
||||
{
|
||||
item: comment,
|
||||
included: {
|
||||
users: [sails.helpers.users.presentOne(values.user, {})],
|
||||
},
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'commentCreate',
|
||||
buildData: () => ({
|
||||
item: comment,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
cards: [values.card],
|
||||
},
|
||||
}),
|
||||
user: values.user,
|
||||
});
|
||||
|
||||
const cardSubscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(
|
||||
comment.cardId,
|
||||
comment.userId,
|
||||
);
|
||||
|
||||
const boardSubscriptionUserIds = await sails.helpers.boards.getSubscriptionUserIds(
|
||||
inputs.board.id,
|
||||
comment.userId,
|
||||
);
|
||||
|
||||
const notifiableUserIds = _.union(cardSubscriptionUserIds, boardSubscriptionUserIds);
|
||||
|
||||
await Promise.all(
|
||||
notifiableUserIds.map((userId) =>
|
||||
sails.helpers.notifications.createOne.with({
|
||||
values: {
|
||||
userId,
|
||||
comment,
|
||||
type: Notification.Types.COMMENT_CARD,
|
||||
data: {
|
||||
card: _.pick(values.card, ['name']),
|
||||
text: comment.text,
|
||||
},
|
||||
creatorUser: values.user,
|
||||
card: values.card,
|
||||
},
|
||||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
list: inputs.list,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
if (values.user.subscribeToCardWhenCommenting) {
|
||||
let cardSubscription;
|
||||
try {
|
||||
cardSubscription = await CardSubscription.qm.createOne({
|
||||
cardId: comment.cardId,
|
||||
userId: comment.userId,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code !== 'E_UNIQUE') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
if (cardSubscription) {
|
||||
sails.sockets.broadcast(`user:${comment.userId}`, 'cardUpdate', {
|
||||
item: {
|
||||
id: comment.cardId,
|
||||
isSubscribed: true,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
|
||||
const notificationServices = await NotificationService.qm.getByBoardId(inputs.board.id);
|
||||
|
||||
if (notificationServices.length > 0) {
|
||||
const services = notificationServices.map((notificationService) =>
|
||||
_.pick(notificationService, ['url', 'format']),
|
||||
);
|
||||
|
||||
buildAndSendNotifications(
|
||||
services,
|
||||
inputs.board,
|
||||
values.card,
|
||||
comment,
|
||||
values.user,
|
||||
sails.helpers.utils.makeTranslator(),
|
||||
);
|
||||
}
|
||||
|
||||
return comment;
|
||||
},
|
||||
};
|
|
@ -1,3 +1,8 @@
|
|||
/*!
|
||||
* 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: {
|
||||
|
@ -30,33 +35,33 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const action = await Action.archiveOne(inputs.record.id);
|
||||
const comment = await Comment.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (action) {
|
||||
if (comment) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'actionDelete',
|
||||
'commentDelete',
|
||||
{
|
||||
item: action,
|
||||
item: comment,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'actionDelete',
|
||||
data: {
|
||||
item: action,
|
||||
event: 'commentDelete',
|
||||
buildData: () => ({
|
||||
item: comment,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
cards: [inputs.card],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return action;
|
||||
return comment;
|
||||
},
|
||||
};
|
39
server/api/helpers/comments/get-path-to-project-by-id.js
Normal file
39
server/api/helpers/comments/get-path-to-project-by-id.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*!
|
||||
* 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 comment = await Comment.qm.getOneById(inputs.id);
|
||||
|
||||
if (!comment) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const pathToProject = await sails.helpers.cards
|
||||
.getPathToProjectById(comment.cardId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
comment,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
|
||||
return {
|
||||
comment,
|
||||
...pathToProject,
|
||||
};
|
||||
},
|
||||
};
|
|
@ -1,3 +1,8 @@
|
|||
/*!
|
||||
* 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: {
|
||||
|
@ -36,36 +41,36 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const action = await Action.updateOne(inputs.record.id).set({ ...values });
|
||||
const comment = await Comment.qm.updateOne(inputs.record.id, values);
|
||||
|
||||
if (action) {
|
||||
if (comment) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'actionUpdate',
|
||||
'commentUpdate',
|
||||
{
|
||||
item: action,
|
||||
item: comment,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'actionUpdate',
|
||||
data: {
|
||||
item: action,
|
||||
event: 'commentUpdate',
|
||||
buildData: () => ({
|
||||
item: comment,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
cards: [inputs.card],
|
||||
},
|
||||
},
|
||||
prevData: {
|
||||
}),
|
||||
buildPrevData: () => ({
|
||||
item: inputs.record,
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return action;
|
||||
return comment;
|
||||
},
|
||||
};
|
30
server/api/helpers/config/present-one.js
Normal file
30
server/api/helpers/config/present-one.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
const data = {
|
||||
...inputs.record,
|
||||
version: sails.config.custom.version,
|
||||
};
|
||||
if (inputs.user && inputs.user.role === User.Roles.ADMIN) {
|
||||
data.activeUsersLimit = sails.config.custom.activeUsersLimit;
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
};
|
104
server/api/helpers/custom-field-groups/create-one-in-board.js
Normal file
104
server/api/helpers/custom-field-groups/create-one-in-board.js
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*!
|
||||
* 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: {
|
||||
boardMustBeInValues: {},
|
||||
baseCustomFieldGroupOrNameMustBeInValues: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (!values.board) {
|
||||
throw 'boardMustBeInValues';
|
||||
}
|
||||
|
||||
if (values.baseCustomFieldGroup) {
|
||||
values.baseCustomFieldGroupId = values.baseCustomFieldGroup.id;
|
||||
} else if (!values.name) {
|
||||
throw 'baseCustomFieldGroupOrNameMustBeInValues';
|
||||
}
|
||||
|
||||
const customFieldGroups = await CustomFieldGroup.qm.getByBoardId(values.board.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
customFieldGroups,
|
||||
);
|
||||
|
||||
if (repositions.length > 0) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await CustomFieldGroup.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
boardId: reposition.record.boardId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${values.board.id}`, 'customFieldGroupUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
|
||||
const customFieldGroup = await CustomFieldGroup.qm.createOne({
|
||||
...values,
|
||||
position,
|
||||
boardId: values.board.id,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${customFieldGroup.boardId}`,
|
||||
'customFieldGroupCreate',
|
||||
{
|
||||
item: customFieldGroup,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldGroupCreate',
|
||||
buildData: () => ({
|
||||
item: customFieldGroup,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [values.board],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
return customFieldGroup;
|
||||
},
|
||||
};
|
114
server/api/helpers/custom-field-groups/create-one-in-card.js
Normal file
114
server/api/helpers/custom-field-groups/create-one-in-card.js
Normal file
|
@ -0,0 +1,114 @@
|
|||
/*!
|
||||
* 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,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
list: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
cardMustBeInValues: {},
|
||||
baseCustomFieldGroupOrNameMustBeInValues: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (!values.card) {
|
||||
throw 'cardMustBeInValues';
|
||||
}
|
||||
|
||||
if (values.baseCustomFieldGroup) {
|
||||
values.baseCustomFieldGroupId = values.baseCustomFieldGroup.id;
|
||||
} else if (!values.name) {
|
||||
throw 'baseCustomFieldGroupOrNameMustBeInValues';
|
||||
}
|
||||
|
||||
const customFieldGroups = await CustomFieldGroup.qm.getByCardId(values.card.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
customFieldGroups,
|
||||
);
|
||||
|
||||
if (repositions.length > 0) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await CustomFieldGroup.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
cardId: reposition.record.cardId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.board.id}`, 'customFieldGroupUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
|
||||
const customFieldGroup = await CustomFieldGroup.qm.createOne({
|
||||
...values,
|
||||
position,
|
||||
cardId: values.card.id,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'customFieldGroupCreate',
|
||||
{
|
||||
item: customFieldGroup,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldGroupCreate',
|
||||
buildData: () => ({
|
||||
item: customFieldGroup,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
cards: [values.card],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
return customFieldGroup;
|
||||
},
|
||||
};
|
|
@ -0,0 +1,59 @@
|
|||
/*!
|
||||
* 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) {
|
||||
await sails.helpers.customFieldGroups.deleteRelated(inputs.record);
|
||||
|
||||
const customFieldGroup = await CustomFieldGroup.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (customFieldGroup) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${customFieldGroup.boardId}`,
|
||||
'customFieldGroupDelete',
|
||||
{
|
||||
item: customFieldGroup,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldGroupDelete',
|
||||
buildData: () => ({
|
||||
item: customFieldGroup,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return customFieldGroup;
|
||||
},
|
||||
};
|
69
server/api/helpers/custom-field-groups/delete-one-in-card.js
Normal file
69
server/api/helpers/custom-field-groups/delete-one-in-card.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*!
|
||||
* 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,
|
||||
},
|
||||
list: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
card: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
await sails.helpers.customFieldGroups.deleteRelated(inputs.record);
|
||||
|
||||
const customFieldGroup = await CustomFieldGroup.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (customFieldGroup) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'customFieldGroupDelete',
|
||||
{
|
||||
item: customFieldGroup,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldGroupDelete',
|
||||
buildData: () => ({
|
||||
item: customFieldGroup,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
cards: [inputs.card],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return customFieldGroup;
|
||||
},
|
||||
};
|
32
server/api/helpers/custom-field-groups/delete-related.js
Normal file
32
server/api/helpers/custom-field-groups/delete-related.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
recordOrRecords: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
let customFieldGroupIdOrIds;
|
||||
if (_.isPlainObject(inputs.recordOrRecords)) {
|
||||
({
|
||||
recordOrRecords: { id: customFieldGroupIdOrIds },
|
||||
} = inputs);
|
||||
} else if (_.every(inputs.recordOrRecords, _.isPlainObject)) {
|
||||
customFieldGroupIdOrIds = sails.helpers.utils.mapRecords(inputs.recordOrRecords);
|
||||
}
|
||||
|
||||
await CustomFieldValue.qm.delete({
|
||||
customFieldGroupId: customFieldGroupIdOrIds,
|
||||
});
|
||||
|
||||
await CustomField.qm.delete({
|
||||
customFieldGroupId: customFieldGroupIdOrIds,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -0,0 +1,51 @@
|
|||
/*!
|
||||
* 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 customFieldGroup = await CustomFieldGroup.qm.getOneById(inputs.id);
|
||||
|
||||
if (!customFieldGroup) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
let pathToProject;
|
||||
if (customFieldGroup.boardId) {
|
||||
pathToProject = await sails.helpers.boards
|
||||
.getPathToProjectById(customFieldGroup.boardId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
customFieldGroup,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
} else if (customFieldGroup.cardId) {
|
||||
pathToProject = await sails.helpers.cards
|
||||
.getPathToProjectById(customFieldGroup.cardId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
customFieldGroup,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
return {
|
||||
customFieldGroup,
|
||||
...pathToProject,
|
||||
};
|
||||
},
|
||||
};
|
112
server/api/helpers/custom-field-groups/update-one-in-board.js
Normal file
112
server/api/helpers/custom-field-groups/update-one-in-board.js
Normal file
|
@ -0,0 +1,112 @@
|
|||
/*!
|
||||
* 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,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
nameInValuesMustNotBeNull: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (!inputs.record.baseCustomFieldGroupId && _.isNull(values.name)) {
|
||||
throw 'nameInValuesMustNotBeNull';
|
||||
}
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const customFieldGroups = await CustomFieldGroup.qm.getByBoardId(inputs.record.boardId, {
|
||||
exceptIdOrIds: inputs.record.id,
|
||||
});
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
customFieldGroups,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
if (repositions.length > 0) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await CustomFieldGroup.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
boardId: reposition.record.boardId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.record.boardId}`, 'customFieldGroupUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const customFieldGroup = await CustomFieldGroup.qm.updateOne(inputs.record.id, values);
|
||||
|
||||
if (customFieldGroup) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${customFieldGroup.boardId}`,
|
||||
'customFieldGroupUpdate',
|
||||
{
|
||||
item: customFieldGroup,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldGroupUpdate',
|
||||
buildData: () => ({
|
||||
item: customFieldGroup,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
},
|
||||
}),
|
||||
buildPrevData: () => ({
|
||||
item: inputs.record,
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return customFieldGroup;
|
||||
},
|
||||
};
|
122
server/api/helpers/custom-field-groups/update-one-in-card.js
Normal file
122
server/api/helpers/custom-field-groups/update-one-in-card.js
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*!
|
||||
* 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,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
list: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
card: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
nameInValuesMustNotBeNull: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (!inputs.record.baseCustomFieldGroupId && _.isNull(values.name)) {
|
||||
throw 'nameInValuesMustNotBeNull';
|
||||
}
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const customFieldGroups = await CustomFieldGroup.qm.getByCardId(inputs.record.cardId, {
|
||||
exceptIdOrIds: inputs.record.id,
|
||||
});
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
customFieldGroups,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
if (repositions.length > 0) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await CustomFieldGroup.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
cardId: reposition.record.cardId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.board.id}`, 'customFieldGroupUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const customFieldGroup = await CustomFieldGroup.qm.updateOne(inputs.record.id, values);
|
||||
|
||||
if (customFieldGroup) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'customFieldGroupUpdate',
|
||||
{
|
||||
item: customFieldGroup,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldGroupUpdate',
|
||||
buildData: () => ({
|
||||
item: customFieldGroup,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
cards: [inputs.card],
|
||||
},
|
||||
}),
|
||||
buildPrevData: () => ({
|
||||
item: inputs.record,
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return customFieldGroup;
|
||||
},
|
||||
};
|
|
@ -0,0 +1,71 @@
|
|||
/*!
|
||||
* 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: 'json',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
list: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const customFieldValue = await CustomFieldValue.qm.createOrUpdateOne({
|
||||
...values,
|
||||
cardId: values.card.id,
|
||||
customFieldGroupId: values.customFieldGroup.id,
|
||||
customFieldId: values.customField.id,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'customFieldValueUpdate',
|
||||
{
|
||||
item: customFieldValue,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
// TODO: with prevData?
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldValueUpdate',
|
||||
buildData: () => ({
|
||||
item: customFieldValue,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
cards: [values.card],
|
||||
customFieldGroups: [values.customFieldGroup],
|
||||
customFields: [values.customField],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
return customFieldValue;
|
||||
},
|
||||
};
|
72
server/api/helpers/custom-field-values/delete-one.js
Normal file
72
server/api/helpers/custom-field-values/delete-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: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
list: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
card: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
customFieldGroup: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const customFieldValue = await CustomFieldValue.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (customFieldValue) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'customFieldValueDelete',
|
||||
{
|
||||
item: customFieldValue,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldValueDelete',
|
||||
buildData: () => ({
|
||||
item: customFieldValue,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
lists: [inputs.list],
|
||||
cards: [inputs.card],
|
||||
customFieldGroups: [inputs.customFieldGroup],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return customFieldValue;
|
||||
},
|
||||
};
|
|
@ -0,0 +1,110 @@
|
|||
/*!
|
||||
* 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: {
|
||||
baseCustomFieldGroupMustBeInValues: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (!values.baseCustomFieldGroup) {
|
||||
throw 'baseCustomFieldGroupMustBeInValues';
|
||||
}
|
||||
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
record: inputs.project,
|
||||
});
|
||||
|
||||
const customFieldGroupRelatedUserIds = await scoper.getProjectRelatedUserIds();
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const customFields = await CustomField.qm.getByBaseCustomFieldGroupId(
|
||||
values.baseCustomFieldGroup.id,
|
||||
);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
customFields,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await CustomField.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
baseCustomFieldGroupId: reposition.record.baseCustomFieldGroupId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
customFieldGroupRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'customFieldUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
|
||||
const customField = await CustomField.qm.createOne({
|
||||
...values,
|
||||
baseCustomFieldGroupId: values.baseCustomFieldGroup.id,
|
||||
});
|
||||
|
||||
customFieldGroupRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'customFieldCreate',
|
||||
{
|
||||
item: customField,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
});
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldCreate',
|
||||
buildData: () => ({
|
||||
item: customField,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
baseCustomFieldGroups: [values.baseCustomFieldGroup],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
return customField;
|
||||
},
|
||||
};
|
|
@ -0,0 +1,127 @@
|
|||
/*!
|
||||
* 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,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
list: {
|
||||
type: 'ref',
|
||||
},
|
||||
card: {
|
||||
type: 'ref',
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
customFieldGroupMustBeInValues: {},
|
||||
listMustBePresent: {},
|
||||
cardMustBePresent: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (!values.customFieldGroup) {
|
||||
throw 'customFieldGroupMustBeInValues';
|
||||
}
|
||||
|
||||
if (values.customFieldGroup.cardId) {
|
||||
if (!inputs.list) {
|
||||
throw 'listMustBePresent';
|
||||
}
|
||||
|
||||
if (!inputs.card) {
|
||||
throw 'cardMustBePresent';
|
||||
}
|
||||
}
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const customFields = await CustomField.qm.getByCustomFieldGroupId(values.customFieldGroup.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
customFields,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await CustomField.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
customFieldGroupId: reposition.record.customFieldGroupId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.board.id}`, 'customFieldUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
|
||||
const customField = await CustomField.qm.createOne({
|
||||
...values,
|
||||
customFieldGroupId: values.customFieldGroup.id,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'customFieldCreate',
|
||||
{
|
||||
item: customField,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldCreate',
|
||||
buildData: () => ({
|
||||
item: customField,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
customFieldGroups: [values.customFieldGroup],
|
||||
...(inputs.list && {
|
||||
lists: [inputs.list],
|
||||
}),
|
||||
...(inputs.card && {
|
||||
cards: [inputs.card],
|
||||
}),
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
return customField;
|
||||
},
|
||||
};
|
|
@ -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: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
baseCustomFieldGroup: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
await sails.helpers.customFields.deleteRelated(inputs.record);
|
||||
|
||||
const customField = await CustomField.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (customField) {
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
record: inputs.project,
|
||||
});
|
||||
|
||||
const customFieldGroupRelatedUserIds = await scoper.getProjectRelatedUserIds();
|
||||
|
||||
customFieldGroupRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'customFieldDelete',
|
||||
{
|
||||
item: customField,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
});
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldDelete',
|
||||
buildData: () => ({
|
||||
item: customField,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
baseCustomFieldGroups: [inputs.baseCustomFieldGroup],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return customField;
|
||||
},
|
||||
};
|
|
@ -0,0 +1,91 @@
|
|||
/*!
|
||||
* 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,
|
||||
},
|
||||
list: {
|
||||
type: 'ref',
|
||||
},
|
||||
card: {
|
||||
type: 'ref',
|
||||
},
|
||||
customFieldGroup: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
listMustBePresent: {},
|
||||
cardMustBePresent: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
if (inputs.customFieldGroup.cardId) {
|
||||
if (!inputs.list) {
|
||||
throw 'listMustBePresent';
|
||||
}
|
||||
|
||||
if (!inputs.card) {
|
||||
throw 'cardMustBePresent';
|
||||
}
|
||||
}
|
||||
|
||||
await sails.helpers.customFields.deleteRelated(inputs.record);
|
||||
|
||||
const customField = await CustomField.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (customField) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'customFieldDelete',
|
||||
{
|
||||
item: customField,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldDelete',
|
||||
buildData: () => ({
|
||||
item: customField,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
customFieldGroups: [inputs.customFieldGroup],
|
||||
...(inputs.list && {
|
||||
lists: [inputs.list],
|
||||
}),
|
||||
...(inputs.card && {
|
||||
cards: [inputs.card],
|
||||
}),
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return customField;
|
||||
},
|
||||
};
|
28
server/api/helpers/custom-fields/delete-related.js
Normal file
28
server/api/helpers/custom-fields/delete-related.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
recordOrRecords: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
let customFieldIdOrIds;
|
||||
if (_.isPlainObject(inputs.recordOrRecords)) {
|
||||
({
|
||||
recordOrRecords: { id: customFieldIdOrIds },
|
||||
} = inputs);
|
||||
} else if (_.every(inputs.recordOrRecords, _.isPlainObject)) {
|
||||
customFieldIdOrIds = sails.helpers.utils.mapRecords(inputs.recordOrRecords);
|
||||
}
|
||||
|
||||
await CustomFieldValue.qm.delete({
|
||||
customFieldId: customFieldIdOrIds,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -0,0 +1,51 @@
|
|||
/*!
|
||||
* 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 customField = await CustomField.qm.getOneById(inputs.id);
|
||||
|
||||
if (!customField) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
let pathToProject;
|
||||
if (customField.baseCustomFieldGroupId) {
|
||||
pathToProject = await sails.helpers.baseCustomFieldGroups
|
||||
.getPathToProjectById(customField.baseCustomFieldGroupId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
customField,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
} else if (customField.customFieldGroupId) {
|
||||
pathToProject = await sails.helpers.customFieldGroups
|
||||
.getPathToProjectById(customField.customFieldGroupId)
|
||||
.intercept('pathNotFound', (nodes) => ({
|
||||
pathNotFound: {
|
||||
customField,
|
||||
...nodes,
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
return {
|
||||
customField,
|
||||
...pathToProject,
|
||||
};
|
||||
},
|
||||
};
|
|
@ -0,0 +1,115 @@
|
|||
/*!
|
||||
* 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,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
baseCustomFieldGroup: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
record: inputs.project,
|
||||
});
|
||||
|
||||
const customFieldGroupRelatedUserIds = await scoper.getProjectRelatedUserIds();
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const customFields = await CustomField.qm.getByBaseCustomFieldGroupId(
|
||||
inputs.record.baseCustomFieldGroupId,
|
||||
{
|
||||
exceptIdOrIds: inputs.record.id,
|
||||
},
|
||||
);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
customFields,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await CustomField.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
baseCustomFieldGroupId: reposition.record.baseCustomFieldGroupId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
customFieldGroupRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(`user:${userId}`, 'customFieldUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
|
||||
const customField = await CustomField.qm.updateOne(inputs.record.id, values);
|
||||
|
||||
if (customField) {
|
||||
customFieldGroupRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'customFieldUpdate',
|
||||
{
|
||||
item: customField,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
});
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldUpdate',
|
||||
buildData: () => ({
|
||||
item: customField,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
baseCustomFieldGroups: [inputs.baseCustomFieldGroup],
|
||||
},
|
||||
}),
|
||||
buildPrevData: () => ({
|
||||
item: inputs.record,
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return customField;
|
||||
},
|
||||
};
|
|
@ -0,0 +1,137 @@
|
|||
/*!
|
||||
* 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,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
list: {
|
||||
type: 'ref',
|
||||
},
|
||||
card: {
|
||||
type: 'ref',
|
||||
},
|
||||
customFieldGroup: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
listMustBePresent: {},
|
||||
cardMustBePresent: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (inputs.customFieldGroup.cardId) {
|
||||
if (!inputs.list) {
|
||||
throw 'listMustBePresent';
|
||||
}
|
||||
|
||||
if (!inputs.card) {
|
||||
throw 'cardMustBePresent';
|
||||
}
|
||||
}
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const customFields = await CustomField.qm.getByCustomFieldGroupId(
|
||||
inputs.record.customFieldGroupId,
|
||||
{
|
||||
exceptIdOrIds: inputs.record.id,
|
||||
},
|
||||
);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
customFields,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await CustomField.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
customFieldGroupId: reposition.record.customFieldGroupId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.board.id}`, 'customFieldUpdate', {
|
||||
item: {
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
}
|
||||
}
|
||||
|
||||
const customField = await CustomField.qm.updateOne(inputs.record.id, values);
|
||||
|
||||
if (customField) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
'customFieldUpdate',
|
||||
{
|
||||
item: customField,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'customFieldUpdate',
|
||||
buildData: () => ({
|
||||
item: customField,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
customFieldGroups: [inputs.customFieldGroup],
|
||||
...(inputs.list && {
|
||||
lists: [inputs.list],
|
||||
}),
|
||||
...(inputs.card && {
|
||||
cards: [inputs.card],
|
||||
}),
|
||||
},
|
||||
}),
|
||||
buildPrevData: () => ({
|
||||
item: inputs.record,
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return customField;
|
||||
},
|
||||
};
|
|
@ -1,24 +1,12 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.board)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
/*!
|
||||
* 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',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
|
@ -37,36 +25,41 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const labels = await sails.helpers.boards.getLabels(values.board.id);
|
||||
const labels = await Label.qm.getByBoardId(values.board.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
labels,
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Label.update({
|
||||
id,
|
||||
boardId: values.board.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const reposition of repositions) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await Label.qm.updateOne(
|
||||
{
|
||||
id: reposition.record.id,
|
||||
boardId: reposition.record.boardId,
|
||||
},
|
||||
{
|
||||
position: reposition.position,
|
||||
},
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${values.board.id}`, 'labelUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
id: reposition.record.id,
|
||||
position: reposition.position,
|
||||
},
|
||||
});
|
||||
|
||||
// TODO: send webhooks
|
||||
});
|
||||
}
|
||||
|
||||
const label = await Label.create({
|
||||
const label = await Label.qm.createOne({
|
||||
...values,
|
||||
position,
|
||||
boardId: values.board.id,
|
||||
}).fetch();
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${label.boardId}`,
|
||||
|
@ -79,13 +72,13 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'labelCreate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: label,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [values.board],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/*!
|
||||
* 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: {
|
||||
|
@ -22,11 +27,9 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
await CardLabel.destroy({
|
||||
labelId: inputs.record.id,
|
||||
});
|
||||
await sails.helpers.labels.deleteRelated(inputs.record);
|
||||
|
||||
const label = await Label.archiveOne(inputs.record.id);
|
||||
const label = await Label.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (label) {
|
||||
sails.sockets.broadcast(
|
||||
|
@ -40,13 +43,13 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'labelDelete',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: label,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
|
28
server/api/helpers/labels/delete-related.js
Normal file
28
server/api/helpers/labels/delete-related.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
recordOrRecords: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
let labelIdOrIds;
|
||||
if (_.isPlainObject(inputs.recordOrRecords)) {
|
||||
({
|
||||
recordOrRecords: { id: labelIdOrIds },
|
||||
} = inputs);
|
||||
} else if (_.every(inputs.recordOrRecords, _.isPlainObject)) {
|
||||
labelIdOrIds = sails.helpers.utils.mapRecords(inputs.recordOrRecords);
|
||||
}
|
||||
|
||||
await CardLabel.qm.delete({
|
||||
labelId: labelIdOrIds,
|
||||
});
|
||||
},
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue