import Planka upstream

This commit is contained in:
xiaojibeier
2026-07-18 11:48:22 +08:00
commit c26fd3b190
1564 changed files with 214813 additions and 0 deletions
+108
View File
@@ -0,0 +1,108 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
/**
* @swagger
* /projects:
* post:
* summary: Create project
* description: Creates a project. The current user automatically becomes a project manager.
* tags:
* - Projects
* operationId: createProject
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required:
* - type
* - name
* properties:
* type:
* type: string
* enum: [private, shared]
* description: Type of the project
* example: private
* name:
* type: string
* maxLength: 128
* description: Name/title of the project
* example: Development Project
* description:
* type: string
* maxLength: 1024
* nullable: true
* description: Detailed description of the project
* example: A project for developing new features...
* responses:
* 200:
* description: Project created successfully
* content:
* application/json:
* schema:
* type: object
* required:
* - item
* - included
* properties:
* item:
* $ref: '#/components/schemas/Project'
* included:
* type: object
* required:
* - projectManagers
* properties:
* projectManagers:
* type: array
* description: Related project managers
* items:
* $ref: '#/components/schemas/ProjectManager'
* 400:
* $ref: '#/components/responses/ValidationError'
* 401:
* $ref: '#/components/responses/Unauthorized'
*/
module.exports = {
inputs: {
type: {
type: 'string',
isIn: Object.values(Project.Types),
required: true,
},
name: {
type: 'string',
maxLength: 128,
required: true,
},
description: {
type: 'string',
isNotEmptyString: true,
maxLength: 1024,
allowNull: true,
},
},
async fn(inputs) {
const { currentUser } = this.req;
const values = _.pick(inputs, ['type', 'name', 'description']);
const { project, projectManager } = await sails.helpers.projects.createOne.with({
values,
actorUser: currentUser,
request: this.req,
});
return {
item: project,
included: {
projectManagers: [projectManager],
},
};
},
};
+104
View File
@@ -0,0 +1,104 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
/**
* @swagger
* /projects/{id}:
* delete:
* summary: Delete project
* description: Deletes a project. The project must not have any boards. Requires project manager permissions.
* tags:
* - Projects
* operationId: deleteProject
* parameters:
* - name: id
* in: path
* required: true
* description: ID of the project to delete
* schema:
* type: string
* example: "1357158568008091264"
* responses:
* 200:
* description: Project deleted successfully
* content:
* application/json:
* schema:
* type: object
* required:
* - item
* properties:
* item:
* $ref: '#/components/schemas/Project'
* 400:
* $ref: '#/components/responses/ValidationError'
* 401:
* $ref: '#/components/responses/Unauthorized'
* 404:
* $ref: '#/components/responses/NotFound'
* 422:
* $ref: '#/components/responses/UnprocessableEntity'
*/
const { idInput } = require('../../../utils/inputs');
const Errors = {
PROJECT_NOT_FOUND: {
projectNotFound: 'Project not found',
},
MUST_NOT_HAVE_BOARDS: {
mustNotHaveBoards: 'Must not have boards',
},
};
module.exports = {
inputs: {
id: {
...idInput,
required: true,
},
},
exits: {
projectNotFound: {
responseType: 'notFound',
},
mustNotHaveBoards: {
responseType: 'unprocessableEntity',
},
},
async fn(inputs) {
const { currentUser } = this.req;
let project = await Project.qm.getOneById(inputs.id);
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
}
project = await sails.helpers.projects.deleteOne
.with({
record: project,
actorUser: currentUser,
request: this.req,
})
.intercept('mustNotHaveBoards', () => Errors.MUST_NOT_HAVE_BOARDS);
if (!project) {
throw Errors.PROJECT_NOT_FOUND;
}
return {
item: project,
};
},
};
+194
View File
@@ -0,0 +1,194 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
/**
* @swagger
* /projects:
* get:
* summary: Get all accessible projects
* description: Retrieves all projects the current user has access to, including managed projects, membership projects, and shared projects (for admins).
* tags:
* - Projects
* operationId: getProjects
* responses:
* 200:
* description: Projects retrieved successfully
* content:
* application/json:
* schema:
* type: object
* required:
* - items
* - included
* properties:
* items:
* type: array
* items:
* allOf:
* - $ref: '#/components/schemas/Project'
* - type: object
* properties:
* isFavorite:
* type: boolean
* description: Whether the project is marked as favorite by the current user
* example: true
* included:
* type: object
* required:
* - users
* - projectManagers
* - backgroundImages
* - baseCustomFieldGroups
* - boards
* - boardMemberships
* - customFields
* - notificationServices
* properties:
* users:
* type: array
* description: Related users
* items:
* $ref: '#/components/schemas/User'
* projectManagers:
* type: array
* description: Related project managers
* items:
* $ref: '#/components/schemas/ProjectManager'
* backgroundImages:
* type: array
* description: Related background images
* items:
* $ref: '#/components/schemas/BackgroundImage'
* baseCustomFieldGroups:
* type: array
* description: Related base custom field groups
* items:
* $ref: '#/components/schemas/BaseCustomFieldGroup'
* boards:
* type: array
* description: Related boards
* items:
* $ref: '#/components/schemas/Board'
* boardMemberships:
* type: array
* description: Related board memberships (for current user)
* items:
* $ref: '#/components/schemas/BoardMembership'
* customFields:
* type: array
* description: Related custom fields
* items:
* $ref: '#/components/schemas/CustomField'
* notificationServices:
* type: array
* description: Related notification services (for managed projects)
* items:
* $ref: '#/components/schemas/NotificationService'
* 400:
* $ref: '#/components/responses/ValidationError'
* 401:
* $ref: '#/components/responses/Unauthorized'
*/
module.exports = {
async fn() {
const { currentUser } = this.req;
let sharedProjects;
let sharedProjectIds;
const managerProjectIds = await sails.helpers.users.getManagerProjectIds(currentUser.id);
const fullyVisibleProjectIds = [...managerProjectIds];
if (currentUser.role === User.Roles.ADMIN) {
sharedProjects = await Project.qm.getShared({
exceptIdOrIds: managerProjectIds,
});
sharedProjectIds = sails.helpers.utils.mapRecords(sharedProjects);
fullyVisibleProjectIds.push(...sharedProjectIds);
}
const boardMemberships = await BoardMembership.qm.getByUserId(currentUser.id);
const membershipBoardIds = sails.helpers.utils.mapRecords(boardMemberships, 'boardId');
const membershipBoards = await Board.qm.getByIds(membershipBoardIds, {
exceptProjectIdOrIds: fullyVisibleProjectIds,
});
const membershipProjectIds = sails.helpers.utils.mapRecords(
membershipBoards,
'projectId',
true,
);
const projectIds = [...managerProjectIds, ...membershipProjectIds];
const projects = await Project.qm.getByIds(projectIds);
if (sharedProjectIds) {
projectIds.push(...sharedProjectIds);
projects.push(...sharedProjects);
}
const fullyVisibleBoards = await Board.qm.getByProjectIds(fullyVisibleProjectIds);
const boards = [...fullyVisibleBoards, ...membershipBoards];
const projectFavorites = await ProjectFavorite.qm.getByProjectIdsAndUserId(
projectIds,
currentUser.id,
);
const projectManagers = await ProjectManager.qm.getByProjectIds(projectIds);
const userIds = sails.helpers.utils.mapRecords(projectManagers, 'userId', true);
const users = await User.qm.getByIds(userIds);
const backgroundImages = await BackgroundImage.qm.getByProjectIds(projectIds);
const baseCustomFieldGroups = await BaseCustomFieldGroup.qm.getByProjectIds(projectIds);
const baseCustomFieldGroupsIds = sails.helpers.utils.mapRecords(baseCustomFieldGroups);
const customFields =
await CustomField.qm.getByBaseCustomFieldGroupIds(baseCustomFieldGroupsIds);
let notificationServices = [];
if (managerProjectIds.length > 0) {
const managerProjectIdsSet = new Set(managerProjectIds);
const managerBoardIds = boards.flatMap((board) =>
managerProjectIdsSet.has(board.projectId) ? board.id : [],
);
notificationServices = await NotificationService.qm.getByBoardIds(managerBoardIds);
}
const isFavoriteByProjectId = projectFavorites.reduce(
(result, projectFavorite) => ({
...result,
[projectFavorite.projectId]: true,
}),
{},
);
projects.forEach((project) => {
// eslint-disable-next-line no-param-reassign
project.isFavorite = isFavoriteByProjectId[project.id] || false;
});
return {
items: projects,
included: {
projectManagers,
baseCustomFieldGroups,
boards,
boardMemberships,
customFields,
notificationServices,
users: sails.helpers.users.presentMany(users, currentUser),
backgroundImages: sails.helpers.backgroundImages.presentMany(backgroundImages),
},
};
},
};
@@ -0,0 +1,192 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
/**
* @swagger
* /projects/{id}:
* get:
* summary: Get project details
* description: Retrieves comprehensive project information, including boards, board memberships, and other related data.
* tags:
* - Projects
* operationId: getProject
* parameters:
* - name: id
* in: path
* required: true
* description: ID of the project to retrieve
* schema:
* type: string
* example: "1357158568008091264"
* responses:
* 200:
* description: Project details retrieved successfully
* content:
* application/json:
* schema:
* type: object
* required:
* - item
* - included
* properties:
* item:
* allOf:
* - $ref: '#/components/schemas/Project'
* - type: object
* properties:
* isFavorite:
* type: boolean
* description: Whether the project is marked as favorite by the current user
* example: true
* included:
* type: object
* required:
* - users
* - projectManagers
* - backgroundImages
* - baseCustomFieldGroups
* - boards
* - boardMemberships
* - customFields
* - notificationServices
* properties:
* users:
* type: array
* description: Related users
* items:
* $ref: '#/components/schemas/User'
* projectManagers:
* type: array
* description: Related project managers
* items:
* $ref: '#/components/schemas/ProjectManager'
* backgroundImages:
* type: array
* description: Related background images
* items:
* $ref: '#/components/schemas/BackgroundImage'
* baseCustomFieldGroups:
* type: array
* description: Related base custom field groups
* items:
* $ref: '#/components/schemas/BaseCustomFieldGroup'
* boards:
* type: array
* description: Related boards
* items:
* $ref: '#/components/schemas/Board'
* boardMemberships:
* type: array
* description: Related board memberships (for current user)
* items:
* $ref: '#/components/schemas/BoardMembership'
* customFields:
* type: array
* description: Related custom fields
* items:
* $ref: '#/components/schemas/CustomField'
* notificationServices:
* type: array
* description: Related notification services (for managed projects)
* items:
* $ref: '#/components/schemas/NotificationService'
* 400:
* $ref: '#/components/responses/ValidationError'
* 401:
* $ref: '#/components/responses/Unauthorized'
* 404:
* $ref: '#/components/responses/NotFound'
*/
const { idInput } = require('../../../utils/inputs');
const Errors = {
PROJECT_NOT_FOUND: {
projectNotFound: 'Project not found',
},
};
module.exports = {
inputs: {
id: {
...idInput,
required: true,
},
},
exits: {
projectNotFound: {
responseType: 'notFound',
},
},
async fn(inputs) {
const { currentUser } = this.req;
const project = await Project.qm.getOneById(inputs.id);
if (!project) {
throw Errors.PROJECT_NOT_FOUND;
}
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
const boardMemberships = await BoardMembership.qm.getByProjectIdAndUserId(
project.id,
currentUser.id,
);
let boards;
if (currentUser.role !== User.Roles.ADMIN || project.ownerProjectManagerId) {
if (!isProjectManager) {
if (boardMemberships.length === 0) {
throw Errors.PROJECT_NOT_FOUND; // Forbidden
}
const boardIds = sails.helpers.utils.mapRecords(boardMemberships, 'boardId');
boards = await Board.qm.getByIds(boardIds);
}
}
if (!boards) {
boards = await Board.qm.getByProjectId(project.id);
}
project.isFavorite = await sails.helpers.users.isProjectFavorite(currentUser.id, project.id);
const projectManagers = await ProjectManager.qm.getByProjectId(project.id);
const userIds = sails.helpers.utils.mapRecords(projectManagers, 'userId');
const users = await User.qm.getByIds(userIds);
const backgroundImages = await BackgroundImage.qm.getByProjectId(project.id);
const baseCustomFieldGroups = await BaseCustomFieldGroup.qm.getByProjectId(project.id);
const baseCustomFieldGroupsIds = sails.helpers.utils.mapRecords(baseCustomFieldGroups);
const customFields =
await CustomField.qm.getByBaseCustomFieldGroupIds(baseCustomFieldGroupsIds);
let notificationServices = [];
if (isProjectManager) {
boardIds = sails.helpers.utils.mapRecords(boards);
notificationServices = await NotificationService.qm.getByBoardIds(boardIds);
}
return {
item: project,
included: {
projectManagers,
baseCustomFieldGroups,
boards,
boardMemberships,
customFields,
notificationServices,
users: sails.helpers.users.presentMany(users, currentUser),
backgroundImages: sails.helpers.backgroundImages.presentMany(backgroundImages),
},
};
},
};
+328
View File
@@ -0,0 +1,328 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
/**
* @swagger
* /projects/{id}:
* patch:
* summary: Update project
* description: Updates a project. Accessible fields depend on user permissions.
* tags:
* - Projects
* operationId: updateProject
* parameters:
* - name: id
* in: path
* required: true
* description: ID of the project to update
* schema:
* type: string
* example: "1357158568008091264"
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* ownerProjectManagerId:
* type: string
* nullable: true
* description: ID of the project manager who owns the project
* example: "1357158568008091265"
* backgroundImageId:
* type: string
* nullable: true
* description: ID of the background image used as background
* example: "1357158568008091266"
* name:
* type: string
* maxLength: 128
* description: Name/title of the project
* example: Development Project
* description:
* type: string
* maxLength: 1024
* nullable: true
* description: Detailed description of the project
* example: A project for developing new features...
* backgroundType:
* type: string
* enum: [gradient, image]
* nullable: true
* description: Type of background for the project
* example: gradient
* backgroundGradient:
* type: string
* enum: [old-lime, ocean-dive, tzepesch-style, jungle-mesh, strawberry-dust, purple-rose, sun-scream, warm-rust, sky-change, green-eyes, blue-xchange, blood-orange, sour-peel, green-ninja, algae-green, coral-reef, steel-grey, heat-waves, velvet-lounge, purple-rain, blue-steel, blueish-curve, prism-light, green-mist, red-curtain]
* nullable: true
* description: Gradient background for the project
* example: ocean-dive
* isHidden:
* type: boolean
* description: Whether the project is hidden
* example: false
* isFavorite:
* type: boolean
* description: Whether the project is marked as favorite by the current user
* example: true
* responses:
* 200:
* description: Project updated successfully
* content:
* application/json:
* schema:
* type: object
* required:
* - item
* properties:
* item:
* $ref: '#/components/schemas/Project'
* 400:
* $ref: '#/components/responses/ValidationError'
* 401:
* $ref: '#/components/responses/Unauthorized'
* 403:
* $ref: '#/components/responses/Forbidden'
* 404:
* $ref: '#/components/responses/NotFound'
* 409:
* $ref: '#/components/responses/Conflict'
* 422:
* $ref: '#/components/responses/UnprocessableEntity'
*/
const { idInput } = require('../../../utils/inputs');
const Errors = {
NOT_ENOUGH_RIGHTS: {
notEnoughRights: 'Not enough rights',
},
PROJECT_NOT_FOUND: {
projectNotFound: 'Project not found',
},
OWNER_PROJECT_MANAGER_NOT_FOUND: {
ownerProjectManagerNotFound: 'Owner project manager not found',
},
BACKGROUND_IMAGE_NOT_FOUND: {
backgroundImageNotFound: 'Background image not found',
},
PROJECT_ALREADY_HAS_OWNER_PROJECT_MANAGER: {
projectAlreadyHasOwnerProjectManager: 'Project already has owner project manager',
},
OWNER_PROJECT_MANAGER_MUST_BE_LAST_MANAGER: {
ownerProjectManagerMustBeLastManager: 'Owner project manager must be last manager',
},
BACKGROUND_IMAGE_MUST_BE_PRESENT: {
backgroundImageMustBePresent: 'Background image must be present',
},
BACKGROUND_GRADIENT_MUST_BE_PRESENT: {
backgroundGradientMustBePresent: 'Background gradient must be present',
},
};
module.exports = {
inputs: {
id: {
...idInput,
required: true,
},
ownerProjectManagerId: {
...idInput,
allowNull: true,
},
backgroundImageId: {
...idInput,
allowNull: true,
},
name: {
type: 'string',
isNotEmptyString: true,
maxLength: 128,
},
description: {
type: 'string',
isNotEmptyString: true,
maxLength: 1024,
allowNull: true,
},
backgroundType: {
type: 'string',
isIn: Object.values(Project.BackgroundTypes),
allowNull: true,
},
backgroundGradient: {
type: 'string',
isIn: Project.BACKGROUND_GRADIENTS,
allowNull: true,
},
isHidden: {
type: 'boolean',
},
isFavorite: {
type: 'boolean',
},
},
exits: {
notEnoughRights: {
responseType: 'forbidden',
},
projectNotFound: {
responseType: 'notFound',
},
ownerProjectManagerNotFound: {
responseType: 'notFound',
},
backgroundImageNotFound: {
responseType: 'notFound',
},
projectAlreadyHasOwnerProjectManager: {
responseType: 'conflict',
},
ownerProjectManagerMustBeLastManager: {
responseType: 'unprocessableEntity',
},
backgroundImageMustBePresent: {
responseType: 'unprocessableEntity',
},
backgroundGradientMustBePresent: {
responseType: 'unprocessableEntity',
},
},
async fn(inputs) {
const { currentUser } = this.req;
let project = await Project.qm.getOneById(inputs.id);
if (!project) {
throw Errors.PROJECT_NOT_FOUND;
}
const projectManager = await ProjectManager.qm.getOneByProjectIdAndUserId(
project.id,
currentUser.id,
);
const availableInputKeys = ['id', 'isFavorite'];
if (project.ownerProjectManagerId) {
if (projectManager) {
if (!_.isNil(inputs.ownerProjectManagerId)) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
availableInputKeys.push('ownerProjectManagerId', 'isHidden');
}
} else if (currentUser.role === User.Roles.ADMIN) {
availableInputKeys.push('ownerProjectManagerId', 'isHidden');
} else if (projectManager) {
availableInputKeys.push('isHidden');
}
if (projectManager) {
availableInputKeys.push(
'backgroundImageId',
'name',
'description',
'backgroundType',
'backgroundGradient',
);
}
if (_.difference(Object.keys(inputs), availableInputKeys).length > 0) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
let nextOwnerProjectManager;
if (inputs.ownerProjectManagerId) {
nextOwnerProjectManager = await ProjectManager.qm.getOneById(inputs.ownerProjectManagerId, {
projectId: project.id,
});
if (!nextOwnerProjectManager) {
throw Errors.OWNER_PROJECT_MANAGER_NOT_FOUND;
}
delete inputs.ownerProjectManagerId; // eslint-disable-line no-param-reassign
}
let nextBackgroundImage;
if (inputs.backgroundImageId) {
nextBackgroundImage = await BackgroundImage.qm.getOneById(inputs.backgroundImageId, {
projectId: project.id,
});
if (!nextBackgroundImage) {
throw Errors.BACKGROUND_IMAGE_NOT_FOUND;
}
delete inputs.backgroundImageId; // eslint-disable-line no-param-reassign
}
if (!_.isUndefined(inputs.isFavorite)) {
if (currentUser.role !== User.Roles.ADMIN || project.ownerProjectManagerId) {
if (!projectManager) {
const boardMembershipsTotal =
await sails.helpers.projects.getBoardMembershipsTotalByIdAndUserId(
project.id,
currentUser.id,
);
if (boardMembershipsTotal === 0) {
throw Errors.PROJECT_NOT_FOUND; // Forbidden
}
}
}
}
const values = _.pick(inputs, [
'ownerProjectManagerId',
'backgroundImageId',
'name',
'description',
'backgroundType',
'backgroundGradient',
'isHidden',
'isFavorite',
]);
project = await sails.helpers.projects.updateOne
.with({
record: project,
values: {
...values,
ownerProjectManager: nextOwnerProjectManager,
backgroundImage: nextBackgroundImage,
},
actorUser: currentUser,
request: this.req,
})
.intercept(
'ownerProjectManagerInValuesMustBeLastManager',
() => Errors.OWNER_PROJECT_MANAGER_MUST_BE_LAST_MANAGER,
)
.intercept(
'backgroundImageInValuesMustBePresent',
() => Errors.BACKGROUND_IMAGE_MUST_BE_PRESENT,
)
.intercept(
'backgroundGradientInValuesMustBePresent',
() => Errors.BACKGROUND_GRADIENT_MUST_BE_PRESENT,
)
.intercept(
'alreadyHasOwnerProjectManager',
() => Errors.PROJECT_ALREADY_HAS_OWNER_PROJECT_MANAGER,
);
if (!project) {
throw Errors.PROJECT_NOT_FOUND;
}
return {
item: project,
};
},
};