mirror of
https://github.com/plankanban/planka.git
synced 2025-07-24 15:49:46 +02:00
parent
ad7fb51cfa
commit
2ee1166747
1557 changed files with 76832 additions and 47042 deletions
|
@ -1,24 +1,12 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.project)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.user)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'ref',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
|
@ -31,22 +19,41 @@ module.exports = {
|
|||
},
|
||||
|
||||
exits: {
|
||||
projectInValuesMustBePrivate: {},
|
||||
userInValuesMustBeAdminOrProjectOwner: {},
|
||||
userAlreadyProjectManager: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const projectManager = await ProjectManager.create({
|
||||
projectId: values.project.id,
|
||||
userId: values.user.id,
|
||||
})
|
||||
.intercept('E_UNIQUE', 'userAlreadyProjectManager')
|
||||
.fetch();
|
||||
if (values.project.ownerProjectManagerId) {
|
||||
throw 'projectInValuesMustBePrivate';
|
||||
}
|
||||
|
||||
const projectRelatedUserIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(
|
||||
projectManager.projectId,
|
||||
);
|
||||
if (!sails.helpers.users.isAdminOrProjectOwner(values.user)) {
|
||||
throw 'userInValuesMustBeAdminOrProjectOwner';
|
||||
}
|
||||
|
||||
let projectManager;
|
||||
try {
|
||||
projectManager = await ProjectManager.qm.createOne({
|
||||
projectId: values.project.id,
|
||||
userId: values.user.id,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code === 'E_UNIQUE') {
|
||||
throw 'userAlreadyProjectManager';
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
record: values.project,
|
||||
});
|
||||
|
||||
const projectRelatedUserIds = await scoper.getProjectRelatedUserIds();
|
||||
|
||||
projectRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
|
@ -54,6 +61,9 @@ module.exports = {
|
|||
'projectManagerCreate',
|
||||
{
|
||||
item: projectManager,
|
||||
included: {
|
||||
users: [sails.helpers.users.presentOne(values.user, {})], // FIXME: hack
|
||||
},
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
@ -61,13 +71,13 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'projectManagerCreate',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: projectManager,
|
||||
included: {
|
||||
users: [values.user],
|
||||
users: [sails.helpers.users.presentOne(values.user)],
|
||||
projects: [values.project],
|
||||
},
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
|
|
|
@ -1,9 +1,22 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
user: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
|
@ -13,14 +26,54 @@ module.exports = {
|
|||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
mustNotBeLast: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const projectRelatedUserIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(
|
||||
inputs.record.projectId,
|
||||
const projectManagersLeft = await sails.helpers.projects.getProjectManagersTotalById(
|
||||
inputs.project.id,
|
||||
inputs.record.id,
|
||||
);
|
||||
|
||||
const projectManager = await ProjectManager.destroyOne(inputs.record.id);
|
||||
if (projectManagersLeft === 0) {
|
||||
throw 'mustNotBeLast';
|
||||
}
|
||||
|
||||
const scoper = await sails.helpers.projects.makeScoper.with({
|
||||
record: inputs.project,
|
||||
});
|
||||
|
||||
await scoper.getProjectManagerUserIds();
|
||||
|
||||
const projectManager = await ProjectManager.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (projectManager) {
|
||||
if (inputs.user.role !== User.Roles.ADMIN || inputs.project.ownerProjectManagerId) {
|
||||
const boardIds = await sails.helpers.projects.getBoardIdsById(projectManager.projectId);
|
||||
const boardMemberships = await scoper.getBoardMembershipsForWholeProject();
|
||||
|
||||
const membershipBoardIds = boardMemberships.reduce((result, boardMembership) => {
|
||||
if (boardMembership.userId !== projectManager.userId) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result.push(boardMembership.boardId);
|
||||
return result;
|
||||
}, []);
|
||||
|
||||
const missingBoardIds = _.difference(boardIds, membershipBoardIds);
|
||||
|
||||
missingBoardIds.forEach((boardId) => {
|
||||
sails.sockets.removeRoomMembersFromRooms(
|
||||
`@user:${projectManager.userId}`,
|
||||
`board:${boardId}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
const projectRelatedUserIds = await scoper.getProjectRelatedUserIds();
|
||||
|
||||
projectRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
|
@ -34,9 +87,13 @@ module.exports = {
|
|||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
event: 'projectManagerDelete',
|
||||
data: {
|
||||
buildData: () => ({
|
||||
item: projectManager,
|
||||
},
|
||||
included: {
|
||||
users: [sails.helpers.users.presentOne(inputs.user)],
|
||||
projects: [inputs.project],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
criteria: {
|
||||
type: 'json',
|
||||
custom: criteriaValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return ProjectManager.find(inputs.criteria).sort('id');
|
||||
},
|
||||
};
|
|
@ -0,0 +1,40 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
pathNotFound: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const projectManager = await ProjectManager.qm.getOneById(inputs.id);
|
||||
|
||||
if (!projectManager) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const project = await Project.qm.getOneById(projectManager.projectId);
|
||||
|
||||
if (!project) {
|
||||
throw {
|
||||
pathNotFound: {
|
||||
projectManager,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
projectManager,
|
||||
project,
|
||||
};
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue