mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
77 lines
1.4 KiB
JavaScript
Executable file
77 lines
1.4 KiB
JavaScript
Executable file
const Errors = {
|
|
NOT_ENOUGH_RIGHTS: {
|
|
notEnoughRights: 'Not enough rights',
|
|
},
|
|
LIST_NOT_FOUND: {
|
|
listNotFound: 'List not found',
|
|
},
|
|
};
|
|
|
|
module.exports = {
|
|
inputs: {
|
|
id: {
|
|
type: 'string',
|
|
regex: /^[0-9]+$/,
|
|
required: true,
|
|
},
|
|
position: {
|
|
type: 'number',
|
|
},
|
|
name: {
|
|
type: 'string',
|
|
isNotEmptyString: true,
|
|
},
|
|
},
|
|
|
|
exits: {
|
|
notEnoughRights: {
|
|
responseType: 'forbidden',
|
|
},
|
|
listNotFound: {
|
|
responseType: 'notFound',
|
|
},
|
|
},
|
|
|
|
async fn(inputs) {
|
|
const { currentUser } = this.req;
|
|
|
|
const path = await sails.helpers.lists
|
|
.getProjectPath(inputs.id)
|
|
.intercept('pathNotFound', () => Errors.LIST_NOT_FOUND);
|
|
|
|
let { list } = path;
|
|
const { board, project } = path;
|
|
|
|
const boardMembership = await BoardMembership.findOne({
|
|
boardId: board.id,
|
|
userId: currentUser.id,
|
|
});
|
|
|
|
if (!boardMembership) {
|
|
throw Errors.LIST_NOT_FOUND; // Forbidden
|
|
}
|
|
|
|
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
|
throw Errors.NOT_ENOUGH_RIGHTS;
|
|
}
|
|
|
|
const values = _.pick(inputs, ['position', 'name']);
|
|
|
|
list = await sails.helpers.lists.updateOne.with({
|
|
values,
|
|
project,
|
|
board,
|
|
record: list,
|
|
actorUser: currentUser,
|
|
request: this.req,
|
|
});
|
|
|
|
if (!list) {
|
|
throw Errors.LIST_NOT_FOUND;
|
|
}
|
|
|
|
return {
|
|
item: list,
|
|
};
|
|
},
|
|
};
|