mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
feat: Add ability to link tasks to cards
This commit is contained in:
parent
49203e9d56
commit
230f50e3d9
35 changed files with 761 additions and 243 deletions
|
@ -12,6 +12,9 @@ const Errors = {
|
|||
TASK_LIST_NOT_FOUND: {
|
||||
taskListNotFound: 'Task list not found',
|
||||
},
|
||||
LINKED_CARD_NOT_FOUND: {
|
||||
linkedCardNotFound: 'Linked card not found',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
@ -20,6 +23,7 @@ module.exports = {
|
|||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
linkedCardId: idInput,
|
||||
position: {
|
||||
type: 'number',
|
||||
min: 0,
|
||||
|
@ -28,7 +32,7 @@ module.exports = {
|
|||
name: {
|
||||
type: 'string',
|
||||
maxLength: 1024,
|
||||
required: true,
|
||||
// required: true,
|
||||
},
|
||||
isCompleted: {
|
||||
type: 'boolean',
|
||||
|
@ -42,6 +46,9 @@ module.exports = {
|
|||
taskListNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
linkedCardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
|
@ -51,7 +58,7 @@ module.exports = {
|
|||
.getPathToProjectById(inputs.taskListId)
|
||||
.intercept('pathNotFound', () => Errors.TASK_LIST_NOT_FOUND);
|
||||
|
||||
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
let boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
board.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
@ -64,6 +71,33 @@ module.exports = {
|
|||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
let linkedCard;
|
||||
if (!_.isUndefined(inputs.linkedCardId)) {
|
||||
const path = await sails.helpers.cards
|
||||
.getPathToProjectById(inputs.linkedCardId)
|
||||
.intercept('pathNotFound', () => Errors.LINKED_CARD_NOT_FOUND);
|
||||
|
||||
({ card: linkedCard } = path);
|
||||
|
||||
if (currentUser.role !== User.Roles.ADMIN || path.project.ownerProjectManagerId) {
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(
|
||||
currentUser.id,
|
||||
path.project.id,
|
||||
);
|
||||
|
||||
if (!isProjectManager) {
|
||||
boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
linkedCard.boardId,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.LINKED_CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name', 'isCompleted']);
|
||||
|
||||
const task = await sails.helpers.tasks.createOne.with({
|
||||
|
@ -74,6 +108,7 @@ module.exports = {
|
|||
values: {
|
||||
...values,
|
||||
taskList,
|
||||
linkedCard,
|
||||
},
|
||||
actorUser: currentUser,
|
||||
request: this.req,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue