mirror of
https://github.com/plankanban/planka.git
synced 2025-07-21 22:29:42 +02:00
parent
ad7fb51cfa
commit
2ee1166747
1557 changed files with 76832 additions and 47042 deletions
|
@ -1,48 +1,78 @@
|
|||
/*!
|
||||
* 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');
|
||||
|
||||
const Errors = {
|
||||
NOT_ENOUGH_RIGHTS: {
|
||||
notEnoughRights: 'Not enough rights',
|
||||
},
|
||||
PROJECT_MANAGER_NOT_FOUND: {
|
||||
projectManagerNotFound: 'Project manager not found',
|
||||
},
|
||||
MUST_NOT_BE_LAST: {
|
||||
mustNotBeLast: 'Must not be last',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'string',
|
||||
regex: /^[0-9]+$/,
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
notEnoughRights: {
|
||||
responseType: 'forbidden',
|
||||
},
|
||||
projectManagerNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
mustNotBeLast: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { currentUser } = this.req;
|
||||
|
||||
let projectManager = await ProjectManager.findOne(inputs.id);
|
||||
const pathToProject = await sails.helpers.projectManagers
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.PROJECT_MANAGER_NOT_FOUND);
|
||||
|
||||
if (!projectManager) {
|
||||
throw Errors.PROJECT_MANAGER_NOT_FOUND;
|
||||
let { projectManager } = pathToProject;
|
||||
const { project } = pathToProject;
|
||||
|
||||
if (currentUser.role !== User.Roles.ADMIN) {
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(
|
||||
currentUser.id,
|
||||
project.id,
|
||||
);
|
||||
|
||||
if (!isProjectManager) {
|
||||
throw Errors.PROJECT_MANAGER_NOT_FOUND; // Forbidden
|
||||
}
|
||||
}
|
||||
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(
|
||||
currentUser.id,
|
||||
projectManager.projectId,
|
||||
);
|
||||
|
||||
if (!isProjectManager) {
|
||||
throw Errors.PROJECT_MANAGER_NOT_FOUND; // Forbidden
|
||||
if (project.ownerProjectManagerId) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
// TODO: check if the last one
|
||||
projectManager = await sails.helpers.projectManagers.deleteOne.with({
|
||||
record: projectManager,
|
||||
actorUser: currentUser,
|
||||
request: this.req,
|
||||
});
|
||||
const user = await User.qm.getOneById(projectManager.userId);
|
||||
|
||||
projectManager = await sails.helpers.projectManagers.deleteOne
|
||||
.with({
|
||||
user,
|
||||
project,
|
||||
record: projectManager,
|
||||
actorUser: currentUser,
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('mustNotBeLast', () => Errors.MUST_NOT_BE_LAST);
|
||||
|
||||
if (!projectManager) {
|
||||
throw Errors.PROJECT_MANAGER_NOT_FOUND;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue