1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00
planka/server/api/controllers/boards/update.js

119 lines
2.5 KiB
JavaScript
Raw Normal View History

/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
const { idInput } = require('../../../utils/inputs');
2019-08-31 04:07:25 +05:00
const Errors = {
BOARD_NOT_FOUND: {
2020-04-03 00:35:25 +05:00
boardNotFound: 'Board not found',
},
2019-08-31 04:07:25 +05:00
};
module.exports = {
inputs: {
id: {
...idInput,
required: true,
2019-08-31 04:07:25 +05:00
},
position: {
type: 'number',
min: 0,
2019-08-31 04:07:25 +05:00
},
name: {
type: 'string',
isNotEmptyString: true,
maxLength: 128,
},
defaultView: {
type: 'string',
isIn: Object.values(Board.Views),
},
defaultCardType: {
type: 'string',
isIn: Object.values(Card.Types),
allowNull: true,
},
limitCardTypesToDefaultOne: {
type: 'boolean',
allowNull: true,
},
alwaysDisplayCardCreator: {
type: 'boolean',
},
isSubscribed: {
type: 'boolean',
},
2019-08-31 04:07:25 +05:00
},
exits: {
2020-04-03 00:35:25 +05:00
boardNotFound: {
responseType: 'notFound',
},
2019-08-31 04:07:25 +05:00
},
async fn(inputs) {
const { currentUser } = this.req;
const pathToProject = await sails.helpers.boards
.getPathToProjectById(inputs.id)
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
2019-08-31 04:07:25 +05:00
let { board } = pathToProject;
const { project } = pathToProject;
2019-08-31 04:07:25 +05:00
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
const isBoardMember = await sails.helpers.users.isBoardMember(currentUser.id, board.id);
if (!isProjectManager && !isBoardMember) {
throw Errors.BOARD_NOT_FOUND; // Forbidden
}
const availableInputKeys = ['id'];
if (isProjectManager) {
availableInputKeys.push(
'position',
'name',
'defaultView',
'defaultCardType',
'limitCardTypesToDefaultOne',
'alwaysDisplayCardCreator',
);
}
if (isBoardMember) {
availableInputKeys.push('isSubscribed');
}
if (_.difference(Object.keys(inputs), availableInputKeys).length > 0) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
const values = _.pick(inputs, [
'position',
'name',
'defaultView',
'defaultCardType',
'limitCardTypesToDefaultOne',
'alwaysDisplayCardCreator',
'isSubscribed',
]);
2022-12-26 21:10:50 +01:00
board = await sails.helpers.boards.updateOne.with({
values,
project,
2022-12-26 21:10:50 +01:00
record: board,
actorUser: currentUser,
2022-12-26 21:10:50 +01:00
request: this.req,
});
2019-08-31 04:07:25 +05:00
if (!board) {
throw Errors.BOARD_NOT_FOUND;
}
return {
item: board,
};
},
2019-08-31 04:07:25 +05:00
};