1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-24 15:49:46 +02:00

feat: Version 2

Closes #627, closes #1047
This commit is contained in:
Maksim Eltyshev 2025-05-10 02:09:06 +02:00
parent ad7fb51cfa
commit 2ee1166747
1557 changed files with 76832 additions and 47042 deletions

View file

@ -0,0 +1,75 @@
/*!
* 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 = {
BOARD_NOT_FOUND: {
boardNotFound: 'Board not found',
},
LIMIT_REACHED: {
limitReached: 'Limit reached',
},
};
module.exports = {
inputs: {
boardId: {
...idInput,
required: true,
},
url: {
type: 'string',
maxLength: 512,
required: true,
},
format: {
type: 'string',
isIn: Object.values(NotificationService.Formats),
required: true,
},
},
exits: {
boardNotFound: {
responseType: 'notFound',
},
limitReached: {
responseType: 'conflict',
},
},
async fn(inputs) {
const { currentUser } = this.req;
const { board, project } = await sails.helpers.boards
.getPathToProjectById(inputs.boardId)
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND);
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
if (!isProjectManager) {
throw Errors.BOARD_NOT_FOUND; // Forbidden
}
const values = _.pick(inputs, ['url', 'format']);
const notificationService = await sails.helpers.notificationServices.createOneInBoard
.with({
project,
values: {
...values,
board,
},
actorUser: currentUser,
request: this.req,
})
.intercept('limitReached', () => Errors.LIMIT_REACHED);
return {
item: notificationService,
};
},
};

View file

@ -0,0 +1,68 @@
/*!
* 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 = {
USER_NOT_FOUND: {
userNotFound: 'User not found',
},
LIMIT_REACHED: {
limitReached: 'Limit reached',
},
};
module.exports = {
inputs: {
userId: {
...idInput,
required: true,
},
url: {
type: 'string',
maxLength: 512,
required: true,
},
format: {
type: 'string',
isIn: Object.values(NotificationService.Formats),
required: true,
},
},
exits: {
userNotFound: {
responseType: 'notFound',
},
limitReached: {
responseType: 'conflict',
},
},
async fn(inputs) {
const { currentUser } = this.req;
if (inputs.userId !== currentUser.id) {
throw Errors.USER_NOT_FOUND; // Forbidden
}
const values = _.pick(inputs, ['url', 'format']);
const notificationService = await sails.helpers.notificationServices.createOneInUser
.with({
values: {
...values,
user: currentUser,
},
actorUser: currentUser,
request: this.req,
})
.intercept('limitReached', () => Errors.LIMIT_REACHED);
return {
item: notificationService,
};
},
};

View file

@ -0,0 +1,76 @@
/*!
* 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 = {
NOTIFICATION_SERVICE_NOT_FOUND: {
notificationServiceNotFound: 'Notification service not found',
},
};
module.exports = {
inputs: {
id: {
...idInput,
required: true,
},
},
exits: {
notificationServiceNotFound: {
responseType: 'notFound',
},
},
async fn(inputs) {
const { currentUser } = this.req;
const pathToProject = await sails.helpers.notificationServices
.getPathToUserById(inputs.id)
.intercept('pathNotFound', () => Errors.NOTIFICATION_SERVICE_NOT_FOUND);
let { notificationService } = pathToProject;
const { user, board, project } = pathToProject;
if (notificationService.userId) {
if (user.id !== currentUser.id) {
throw Errors.NOTIFICATION_SERVICE_NOT_FOUND; // Forbidden
}
notificationService = await sails.helpers.notificationServices.deleteOneInUser.with({
user,
record: notificationService,
actorUser: currentUser,
request: this.req,
});
} else if (notificationService.boardId) {
const isProjectManager = await sails.helpers.users.isProjectManager(
currentUser.id,
project.id,
);
if (!isProjectManager) {
throw Errors.NOTIFICATION_SERVICE_NOT_FOUND; // Forbidden
}
notificationService = await sails.helpers.notificationServices.deleteOneInBoard.with({
project,
board,
record: notificationService,
actorUser: currentUser,
request: this.req,
});
}
if (!notificationService) {
throw Errors.NOTIFICATION_SERVICE_NOT_FOUND;
}
return {
item: notificationService,
};
},
};

View file

@ -0,0 +1,59 @@
/*!
* 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 = {
NOTIFICATION_SERVICE_NOT_FOUND: {
notificationServiceNotFound: 'Notification service not found',
},
};
module.exports = {
inputs: {
id: {
...idInput,
required: true,
},
},
exits: {
notificationServiceNotFound: {
responseType: 'notFound',
},
},
async fn(inputs) {
const { currentUser } = this.req;
const { notificationService, user, project } = await sails.helpers.notificationServices
.getPathToUserById(inputs.id)
.intercept('pathNotFound', () => Errors.NOTIFICATION_SERVICE_NOT_FOUND);
if (notificationService.userId) {
if (user.id !== currentUser.id) {
throw Errors.NOTIFICATION_SERVICE_NOT_FOUND; // Forbidden
}
} else if (notificationService.boardId) {
const isProjectManager = await sails.helpers.users.isProjectManager(
currentUser.id,
project.id,
);
if (!isProjectManager) {
throw Errors.NOTIFICATION_SERVICE_NOT_FOUND; // Forbidden
}
}
await sails.helpers.notificationServices.testOne.with({
record: notificationService,
i18n: this.req.i18n,
});
return {
item: notificationService,
};
},
};

View file

@ -0,0 +1,89 @@
/*!
* 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 = {
NOTIFICATION_SERVICE_NOT_FOUND: {
notificationServiceNotFound: 'Notification service not found',
},
};
module.exports = {
inputs: {
id: {
...idInput,
required: true,
},
url: {
type: 'string',
isNotEmptyString: true,
maxLength: 512,
},
format: {
type: 'string',
isIn: Object.values(NotificationService.Formats),
},
},
exits: {
notificationServiceNotFound: {
responseType: 'notFound',
},
},
async fn(inputs) {
const { currentUser } = this.req;
const pathToProject = await sails.helpers.notificationServices
.getPathToUserById(inputs.id)
.intercept('pathNotFound', () => Errors.NOTIFICATION_SERVICE_NOT_FOUND);
let { notificationService } = pathToProject;
const { user, board, project } = pathToProject;
const values = _.pick(inputs, ['url', 'format']);
if (notificationService.userId) {
if (user.id !== currentUser.id) {
throw Errors.NOTIFICATION_SERVICE_NOT_FOUND; // Forbidden
}
notificationService = await sails.helpers.notificationServices.updateOneInUser.with({
values,
user,
record: notificationService,
actorUser: currentUser,
request: this.req,
});
} else if (notificationService.boardId) {
const isProjectManager = await sails.helpers.users.isProjectManager(
currentUser.id,
project.id,
);
if (!isProjectManager) {
throw Errors.NOTIFICATION_SERVICE_NOT_FOUND; // Forbidden
}
notificationService = await sails.helpers.notificationServices.updateOneInBoard.with({
values,
project,
board,
record: notificationService,
actorUser: currentUser,
request: this.req,
});
}
if (!notificationService) {
throw Errors.NOTIFICATION_SERVICE_NOT_FOUND;
}
return {
item: notificationService,
};
},
};