Merge branch 'master' of https://github.com/plankanban/planka into plankanban-master
commit
41161d13e9
@ -1 +1 @@
|
|||||||
REACT_APP_VERSION=1.16.1
|
REACT_APP_VERSION=1.16.2
|
||||||
|
|||||||
@ -0,0 +1,82 @@
|
|||||||
|
const Errors = {
|
||||||
|
NOT_ENOUGH_RIGHTS: {
|
||||||
|
notEnoughRights: 'Not enough rights',
|
||||||
|
},
|
||||||
|
CARD_NOT_FOUND: {
|
||||||
|
cardNotFound: 'Card not found',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
inputs: {
|
||||||
|
id: {
|
||||||
|
type: 'string',
|
||||||
|
regex: /^[0-9]+$/,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
position: {
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
exits: {
|
||||||
|
notEnoughRights: {
|
||||||
|
responseType: 'forbidden',
|
||||||
|
},
|
||||||
|
cardNotFound: {
|
||||||
|
responseType: 'notFound',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
async fn(inputs) {
|
||||||
|
const { currentUser } = this.req;
|
||||||
|
|
||||||
|
const { card, list, board } = await sails.helpers.cards
|
||||||
|
.getProjectPath(inputs.id)
|
||||||
|
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
|
||||||
|
|
||||||
|
const boardMembership = await BoardMembership.findOne({
|
||||||
|
boardId: card.boardId,
|
||||||
|
userId: currentUser.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!boardMembership) {
|
||||||
|
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||||
|
}
|
||||||
|
|
||||||
|
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
||||||
|
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
const values = _.pick(inputs, ['position', 'name']);
|
||||||
|
|
||||||
|
const {
|
||||||
|
card: nextCard,
|
||||||
|
cardMemberships,
|
||||||
|
cardLabels,
|
||||||
|
tasks,
|
||||||
|
} = await sails.helpers.cards.duplicateOne.with({
|
||||||
|
board,
|
||||||
|
list,
|
||||||
|
record: card,
|
||||||
|
values: {
|
||||||
|
...values,
|
||||||
|
creatorUser: currentUser,
|
||||||
|
},
|
||||||
|
request: this.req,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
item: nextCard,
|
||||||
|
included: {
|
||||||
|
cardMemberships,
|
||||||
|
cardLabels,
|
||||||
|
tasks,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -0,0 +1,144 @@
|
|||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
inputs: {
|
||||||
|
record: {
|
||||||
|
type: 'ref',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
values: {
|
||||||
|
type: 'ref',
|
||||||
|
custom: valuesValidator,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
board: {
|
||||||
|
type: 'ref',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
list: {
|
||||||
|
type: 'ref',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
request: {
|
||||||
|
type: 'ref',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
async fn(inputs) {
|
||||||
|
const { values } = inputs;
|
||||||
|
|
||||||
|
const cards = await sails.helpers.lists.getCards(inputs.record.listId);
|
||||||
|
|
||||||
|
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||||
|
values.position,
|
||||||
|
cards,
|
||||||
|
);
|
||||||
|
|
||||||
|
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||||
|
await Card.update({
|
||||||
|
id,
|
||||||
|
listId: inputs.record.listId,
|
||||||
|
}).set({
|
||||||
|
position: nextPosition,
|
||||||
|
});
|
||||||
|
|
||||||
|
sails.sockets.broadcast(`board:${inputs.record.boardId}`, 'cardUpdate', {
|
||||||
|
item: {
|
||||||
|
id,
|
||||||
|
position: nextPosition,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const card = await Card.create({
|
||||||
|
..._.pick(inputs.record, [
|
||||||
|
'boardId',
|
||||||
|
'listId',
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
'dueDate',
|
||||||
|
'stopwatch',
|
||||||
|
]),
|
||||||
|
...values,
|
||||||
|
position,
|
||||||
|
creatorUserId: values.creatorUser.id,
|
||||||
|
}).fetch();
|
||||||
|
|
||||||
|
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 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 nextTasks = await Task.createEach(tasksValues).fetch();
|
||||||
|
|
||||||
|
sails.sockets.broadcast(
|
||||||
|
`board:${card.boardId}`,
|
||||||
|
'cardCreate',
|
||||||
|
{
|
||||||
|
item: card,
|
||||||
|
},
|
||||||
|
inputs.request,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (values.creatorUser.subscribeToOwnCards) {
|
||||||
|
await CardSubscription.create({
|
||||||
|
cardId: card.id,
|
||||||
|
userId: card.creatorUserId,
|
||||||
|
}).tolerate('E_UNIQUE');
|
||||||
|
|
||||||
|
sails.sockets.broadcast(`user:${card.creatorUserId}`, 'cardUpdate', {
|
||||||
|
item: {
|
||||||
|
id: card.id,
|
||||||
|
isSubscribed: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await sails.helpers.actions.createOne.with({
|
||||||
|
values: {
|
||||||
|
card,
|
||||||
|
type: Action.Types.CREATE_CARD, // TODO: introduce separate type?
|
||||||
|
data: {
|
||||||
|
list: _.pick(inputs.list, ['id', 'name']),
|
||||||
|
},
|
||||||
|
user: values.creatorUser,
|
||||||
|
},
|
||||||
|
board: inputs.board,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
card,
|
||||||
|
cardMemberships: nextCardMemberships,
|
||||||
|
cardLabels: nextCardLabels,
|
||||||
|
tasks: nextTasks,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue