import Planka upstream
This commit is contained in:
+226
@@ -0,0 +1,226 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /projects/{projectId}/boards:
|
||||
* post:
|
||||
* summary: Create board
|
||||
* description: Creates a board within a project. Supports importing from Trello. Requires project manager permissions.
|
||||
* tags:
|
||||
* - Boards
|
||||
* operationId: createBoard
|
||||
* parameters:
|
||||
* - name: projectId
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the project to create the board in
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* multipart/form-data:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - position
|
||||
* - name
|
||||
* properties:
|
||||
* position:
|
||||
* type: number
|
||||
* minimum: 0
|
||||
* description: Position of the board within the project
|
||||
* example: 65536
|
||||
* name:
|
||||
* type: string
|
||||
* maxLength: 128
|
||||
* description: Name/title of the board
|
||||
* example: Development Board
|
||||
* importType:
|
||||
* type: string
|
||||
* enum: [trello]
|
||||
* description: Type of import
|
||||
* example: trello
|
||||
* importFile:
|
||||
* type: string
|
||||
* format: binary
|
||||
* description: Import file
|
||||
* requestId:
|
||||
* type: string
|
||||
* maxLength: 128
|
||||
* description: Request ID for tracking
|
||||
* example: req_123456
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Board created successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* - included
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/Board'
|
||||
* included:
|
||||
* type: object
|
||||
* required:
|
||||
* - boardMemberships
|
||||
* properties:
|
||||
* boardMemberships:
|
||||
* type: array
|
||||
* items:
|
||||
* $ref: '#/components/schemas/BoardMembership'
|
||||
* 400:
|
||||
* $ref: '#/components/responses/ValidationError'
|
||||
* 401:
|
||||
* $ref: '#/components/responses/Unauthorized'
|
||||
* 404:
|
||||
* $ref: '#/components/responses/NotFound'
|
||||
* 422:
|
||||
* description: Import file upload error
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - code
|
||||
* - message
|
||||
* properties:
|
||||
* code:
|
||||
* type: string
|
||||
* description: Error code
|
||||
* example: E_UNPROCESSABLE_ENTITY
|
||||
* message:
|
||||
* type: string
|
||||
* enum:
|
||||
* - No import file was uploaded
|
||||
* - Invalid import file
|
||||
* description: Specific error message
|
||||
* example: No import file was uploaded
|
||||
*/
|
||||
|
||||
const { idInput } = require('../../../utils/inputs');
|
||||
|
||||
const Errors = {
|
||||
PROJECT_NOT_FOUND: {
|
||||
projectNotFound: 'Project not found',
|
||||
},
|
||||
NO_IMPORT_FILE_WAS_UPLOADED: {
|
||||
noImportFileWasUploaded: 'No import file was uploaded',
|
||||
},
|
||||
INVALID_IMPORT_FILE: {
|
||||
invalidImportFile: 'Invalid import file',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
projectId: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
min: 0,
|
||||
required: true,
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
maxLength: 128,
|
||||
required: true,
|
||||
},
|
||||
importType: {
|
||||
type: 'string',
|
||||
isIn: Object.values(Board.ImportTypes),
|
||||
},
|
||||
requestId: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
maxLength: 128,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
projectNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
noImportFileWasUploaded: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
invalidImportFile: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
uploadError: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs, exits) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const project = await Project.qm.getOneById(inputs.projectId);
|
||||
|
||||
if (!project) {
|
||||
throw Errors.PROJECT_NOT_FOUND;
|
||||
}
|
||||
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
|
||||
|
||||
if (!isProjectManager) {
|
||||
throw Errors.PROJECT_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
let boardImport;
|
||||
if (inputs.importType) {
|
||||
let files;
|
||||
try {
|
||||
files = await sails.helpers.utils.receiveFile(this.req.file('importFile'), false);
|
||||
} catch (error) {
|
||||
return exits.uploadError(error.message); // TODO: add error
|
||||
}
|
||||
|
||||
if (files.length === 0) {
|
||||
throw Errors.NO_IMPORT_FILE_WAS_UPLOADED;
|
||||
}
|
||||
|
||||
const file = _.last(files);
|
||||
|
||||
if (inputs.importType === Board.ImportTypes.TRELLO) {
|
||||
const trelloBoard = await sails.helpers.boards
|
||||
.processUploadedTrelloImportFile(file)
|
||||
.intercept('invalidFile', () => Errors.INVALID_IMPORT_FILE);
|
||||
|
||||
boardImport = {
|
||||
type: inputs.importType,
|
||||
board: trelloBoard,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name']);
|
||||
|
||||
const { board, boardMembership } = await sails.helpers.boards.createOne.with({
|
||||
values: {
|
||||
...values,
|
||||
project,
|
||||
},
|
||||
import: boardImport,
|
||||
actorUser: currentUser,
|
||||
requestId: inputs.requestId,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
return exits.success({
|
||||
item: board,
|
||||
included: {
|
||||
boardMemberships: [boardMembership],
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /boards/{id}:
|
||||
* delete:
|
||||
* summary: Delete board
|
||||
* description: Deletes a board and all its contents (lists, cards, etc.). Requires project manager permissions.
|
||||
* tags:
|
||||
* - Boards
|
||||
* operationId: deleteBoard
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the board to delete
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Board deleted successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/Board'
|
||||
* 400:
|
||||
* $ref: '#/components/responses/ValidationError'
|
||||
* 401:
|
||||
* $ref: '#/components/responses/Unauthorized'
|
||||
* 404:
|
||||
* $ref: '#/components/responses/NotFound'
|
||||
*/
|
||||
|
||||
const { idInput } = require('../../../utils/inputs');
|
||||
|
||||
const Errors = {
|
||||
BOARD_NOT_FOUND: {
|
||||
boardNotFound: 'Board not found',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
boardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const pathToProject = await sails.helpers.boards
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
|
||||
|
||||
let { board } = pathToProject;
|
||||
const { project } = pathToProject;
|
||||
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
|
||||
|
||||
if (!isProjectManager) {
|
||||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
board = await sails.helpers.boards.deleteOne.with({
|
||||
project,
|
||||
record: board,
|
||||
actorUser: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!board) {
|
||||
throw Errors.BOARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
return {
|
||||
item: board,
|
||||
};
|
||||
},
|
||||
};
|
||||
Executable
+281
@@ -0,0 +1,281 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /boards/{id}:
|
||||
* get:
|
||||
* summary: Get board details
|
||||
* description: Retrieves comprehensive board information, including lists, cards, and other related data.
|
||||
* tags:
|
||||
* - Boards
|
||||
* operationId: getBoard
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the board to retrieve
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* - name: subscribe
|
||||
* in: query
|
||||
* required: false
|
||||
* description: Whether to subscribe to real-time updates for this board (only for socket connections)
|
||||
* schema:
|
||||
* type: boolean
|
||||
* example: true
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Board details retrieved successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* - included
|
||||
* properties:
|
||||
* item:
|
||||
* allOf:
|
||||
* - $ref: '#/components/schemas/Board'
|
||||
* - type: object
|
||||
* properties:
|
||||
* isSubscribed:
|
||||
* type: boolean
|
||||
* description: Whether the current user is subscribed to the board
|
||||
* example: true
|
||||
* included:
|
||||
* type: object
|
||||
* required:
|
||||
* - users
|
||||
* - projects
|
||||
* - boardMemberships
|
||||
* - labels
|
||||
* - lists
|
||||
* - cards
|
||||
* - cardMemberships
|
||||
* - cardLabels
|
||||
* - taskLists
|
||||
* - tasks
|
||||
* - attachments
|
||||
* - customFieldGroups
|
||||
* - customFields
|
||||
* - customFieldValues
|
||||
* properties:
|
||||
* users:
|
||||
* type: array
|
||||
* description: Related users
|
||||
* items:
|
||||
* $ref: '#/components/schemas/User'
|
||||
* projects:
|
||||
* type: array
|
||||
* description: Parent project
|
||||
* items:
|
||||
* $ref: '#/components/schemas/Project'
|
||||
* boardMemberships:
|
||||
* type: array
|
||||
* description: Related board memberships
|
||||
* items:
|
||||
* $ref: '#/components/schemas/BoardMembership'
|
||||
* labels:
|
||||
* type: array
|
||||
* description: Related labels
|
||||
* items:
|
||||
* $ref: '#/components/schemas/Label'
|
||||
* lists:
|
||||
* type: array
|
||||
* description: Related lists
|
||||
* items:
|
||||
* $ref: '#/components/schemas/List'
|
||||
* cards:
|
||||
* type: array
|
||||
* description: Related cards
|
||||
* items:
|
||||
* allOf:
|
||||
* - $ref: '#/components/schemas/Card'
|
||||
* - type: object
|
||||
* properties:
|
||||
* isSubscribed:
|
||||
* type: boolean
|
||||
* description: Whether the current user is subscribed to the card
|
||||
* example: true
|
||||
* cardMemberships:
|
||||
* type: array
|
||||
* description: Related card-membership associations
|
||||
* items:
|
||||
* $ref: '#/components/schemas/CardMembership'
|
||||
* cardLabels:
|
||||
* type: array
|
||||
* description: Related card-label associations
|
||||
* items:
|
||||
* $ref: '#/components/schemas/CardLabel'
|
||||
* taskLists:
|
||||
* type: array
|
||||
* description: Related task lists
|
||||
* items:
|
||||
* $ref: '#/components/schemas/TaskList'
|
||||
* tasks:
|
||||
* type: array
|
||||
* description: Related tasks
|
||||
* items:
|
||||
* $ref: '#/components/schemas/Task'
|
||||
* attachments:
|
||||
* type: array
|
||||
* description: Related attachments
|
||||
* items:
|
||||
* $ref: '#/components/schemas/Attachment'
|
||||
* customFieldGroups:
|
||||
* type: array
|
||||
* description: Related custom field groups
|
||||
* items:
|
||||
* $ref: '#/components/schemas/CustomFieldGroup'
|
||||
* customFields:
|
||||
* type: array
|
||||
* description: Related custom fields
|
||||
* items:
|
||||
* $ref: '#/components/schemas/CustomField'
|
||||
* customFieldValues:
|
||||
* type: array
|
||||
* description: Related custom field values
|
||||
* items:
|
||||
* $ref: '#/components/schemas/CustomFieldValue'
|
||||
* 400:
|
||||
* $ref: '#/components/responses/ValidationError'
|
||||
* 401:
|
||||
* $ref: '#/components/responses/Unauthorized'
|
||||
* 404:
|
||||
* $ref: '#/components/responses/NotFound'
|
||||
*/
|
||||
|
||||
const { idInput } = require('../../../utils/inputs');
|
||||
|
||||
const Errors = {
|
||||
BOARD_NOT_FOUND: {
|
||||
boardNotFound: 'Board not found',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
subscribe: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
boardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const { board, project } = await sails.helpers.boards
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
|
||||
|
||||
if (currentUser.role !== User.Roles.ADMIN || project.ownerProjectManagerId) {
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(
|
||||
currentUser.id,
|
||||
project.id,
|
||||
);
|
||||
|
||||
if (!isProjectManager) {
|
||||
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
board.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
board.isSubscribed = await sails.helpers.users.isBoardSubscriber(currentUser.id, board.id);
|
||||
|
||||
const boardMemberships = await BoardMembership.qm.getByBoardId(board.id);
|
||||
const labels = await Label.qm.getByBoardId(board.id);
|
||||
const lists = await List.qm.getByBoardId(board.id);
|
||||
|
||||
const finiteLists = lists.filter((list) => sails.helpers.lists.isFinite(list));
|
||||
const finiteListIds = sails.helpers.utils.mapRecords(finiteLists);
|
||||
|
||||
const cards = await Card.qm.getByListIds(finiteListIds);
|
||||
const cardIds = sails.helpers.utils.mapRecords(cards);
|
||||
|
||||
const userIds = _.union(
|
||||
sails.helpers.utils.mapRecords(boardMemberships, 'userId'),
|
||||
sails.helpers.utils.mapRecords(cards, 'creatorUserId', true, true),
|
||||
);
|
||||
|
||||
const users = await User.qm.getByIds(userIds);
|
||||
const cardMemberships = await CardMembership.qm.getByCardIds(cardIds);
|
||||
const cardLabels = await CardLabel.qm.getByCardIds(cardIds);
|
||||
|
||||
const taskLists = await TaskList.qm.getByCardIds(cardIds);
|
||||
const taskListIds = sails.helpers.utils.mapRecords(taskLists);
|
||||
|
||||
const tasks = await Task.qm.getByTaskListIds(taskListIds);
|
||||
const attachments = await Attachment.qm.getByCardIds(cardIds);
|
||||
|
||||
const boardCustomFieldGroups = await CustomFieldGroup.qm.getByBoardId(board.id);
|
||||
const cardCustomFieldGroups = await CustomFieldGroup.qm.getByCardIds(cardIds);
|
||||
|
||||
const customFieldGroups = [...boardCustomFieldGroups, ...cardCustomFieldGroups];
|
||||
const customFieldGroupIds = sails.helpers.utils.mapRecords(customFieldGroups);
|
||||
|
||||
const customFields = await CustomField.qm.getByCustomFieldGroupIds(customFieldGroupIds);
|
||||
const customFieldValues = await CustomFieldValue.qm.getByCardIds(cardIds);
|
||||
|
||||
const cardSubscriptions = await CardSubscription.qm.getByCardIdsAndUserId(
|
||||
cardIds,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
const isSubscribedByCardId = cardSubscriptions.reduce(
|
||||
(result, cardSubscription) => ({
|
||||
...result,
|
||||
[cardSubscription.cardId]: true,
|
||||
}),
|
||||
{},
|
||||
);
|
||||
|
||||
cards.forEach((card) => {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
card.isSubscribed = isSubscribedByCardId[card.id] || false;
|
||||
});
|
||||
|
||||
if (inputs.subscribe && this.req.isSocket) {
|
||||
sails.sockets.join(this.req, `board:${board.id}`);
|
||||
}
|
||||
|
||||
return {
|
||||
item: board,
|
||||
included: {
|
||||
boardMemberships,
|
||||
labels,
|
||||
lists,
|
||||
cards,
|
||||
cardMemberships,
|
||||
cardLabels,
|
||||
taskLists,
|
||||
tasks,
|
||||
customFieldGroups,
|
||||
customFields,
|
||||
customFieldValues,
|
||||
users: sails.helpers.users.presentMany(users, currentUser),
|
||||
projects: [project],
|
||||
attachments: sails.helpers.attachments.presentMany(attachments),
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /boards/{id}:
|
||||
* patch:
|
||||
* summary: Update board
|
||||
* description: Updates a board. Project managers can update all fields, board members can only subscribe/unsubscribe.
|
||||
* tags:
|
||||
* - Boards
|
||||
* operationId: updateBoard
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the board to update
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* position:
|
||||
* type: number
|
||||
* minimum: 0
|
||||
* description: Position of the board within the project
|
||||
* example: 65536
|
||||
* name:
|
||||
* type: string
|
||||
* maxLength: 128
|
||||
* description: Name/title of the board
|
||||
* example: Development Board
|
||||
* defaultView:
|
||||
* type: string
|
||||
* enum: [kanban, grid, list]
|
||||
* description: Default view for the board
|
||||
* example: kanban
|
||||
* defaultCardType:
|
||||
* type: string
|
||||
* enum: [project, story]
|
||||
* description: Default card type for new cards
|
||||
* example: project
|
||||
* limitCardTypesToDefaultOne:
|
||||
* type: boolean
|
||||
* description: Whether to limit card types to default one
|
||||
* example: false
|
||||
* alwaysDisplayCardCreator:
|
||||
* type: boolean
|
||||
* description: Whether to always display card creators
|
||||
* example: false
|
||||
* displayCardAges:
|
||||
* type: boolean
|
||||
* description: Whether to display card ages
|
||||
* example: false
|
||||
* expandTaskListsByDefault:
|
||||
* type: boolean
|
||||
* description: Whether to expand task lists by default
|
||||
* example: false
|
||||
* isSubscribed:
|
||||
* type: boolean
|
||||
* description: Whether the current user is subscribed to the board
|
||||
* example: true
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Board updated successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/Board'
|
||||
* 400:
|
||||
* $ref: '#/components/responses/ValidationError'
|
||||
* 401:
|
||||
* $ref: '#/components/responses/Unauthorized'
|
||||
* 404:
|
||||
* $ref: '#/components/responses/NotFound'
|
||||
*/
|
||||
|
||||
const { idInput } = require('../../../utils/inputs');
|
||||
|
||||
const Errors = {
|
||||
BOARD_NOT_FOUND: {
|
||||
boardNotFound: 'Board not found',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
min: 0,
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
maxLength: 128,
|
||||
},
|
||||
defaultView: {
|
||||
type: 'string',
|
||||
isIn: Object.values(Board.Views),
|
||||
},
|
||||
defaultCardType: {
|
||||
type: 'string',
|
||||
isIn: Object.values(Card.Types),
|
||||
},
|
||||
limitCardTypesToDefaultOne: {
|
||||
type: 'boolean',
|
||||
},
|
||||
alwaysDisplayCardCreator: {
|
||||
type: 'boolean',
|
||||
},
|
||||
displayCardAges: {
|
||||
type: 'boolean',
|
||||
},
|
||||
expandTaskListsByDefault: {
|
||||
type: 'boolean',
|
||||
},
|
||||
isSubscribed: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
boardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
const pathToProject = await sails.helpers.boards
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
|
||||
|
||||
let { board } = pathToProject;
|
||||
const { project } = pathToProject;
|
||||
|
||||
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',
|
||||
'displayCardAges',
|
||||
'expandTaskListsByDefault',
|
||||
);
|
||||
}
|
||||
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',
|
||||
'displayCardAges',
|
||||
'expandTaskListsByDefault',
|
||||
'isSubscribed',
|
||||
]);
|
||||
|
||||
board = await sails.helpers.boards.updateOne.with({
|
||||
values,
|
||||
project,
|
||||
record: board,
|
||||
actorUser: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
|
||||
if (!board) {
|
||||
throw Errors.BOARD_NOT_FOUND;
|
||||
}
|
||||
|
||||
return {
|
||||
item: board,
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user