import Planka upstream
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /boards/{boardId}/notification-services:
|
||||
* post:
|
||||
* summary: Create notification service for board
|
||||
* description: Creates a new notification service for a board. Requires project manager permissions.
|
||||
* tags:
|
||||
* - Notification Services
|
||||
* operationId: createBoardNotificationService
|
||||
* parameters:
|
||||
* - name: boardId
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the board to create notification service for
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - url
|
||||
* - format
|
||||
* properties:
|
||||
* url:
|
||||
* type: string
|
||||
* maxLength: 512
|
||||
* description: URL endpoint for notifications
|
||||
* example: https://service.example.com/planka
|
||||
* format:
|
||||
* type: string
|
||||
* enum: [text, markdown, html]
|
||||
* description: Format for notification messages
|
||||
* example: text
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Notification service created successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/NotificationService'
|
||||
* 400:
|
||||
* $ref: '#/components/responses/ValidationError'
|
||||
* 401:
|
||||
* $ref: '#/components/responses/Unauthorized'
|
||||
* 404:
|
||||
* $ref: '#/components/responses/NotFound'
|
||||
* 409:
|
||||
* $ref: '#/components/responses/Conflict'
|
||||
*/
|
||||
|
||||
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,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,127 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /users/{userId}/notification-services:
|
||||
* post:
|
||||
* summary: Create notification service for user
|
||||
* description: Creates a new notification service for a user. Users can only create services for themselves.
|
||||
* tags:
|
||||
* - Notification Services
|
||||
* operationId: createUserNotificationService
|
||||
* parameters:
|
||||
* - name: userId
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the user to create notification service for (must be the current user)
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - url
|
||||
* - format
|
||||
* properties:
|
||||
* url:
|
||||
* type: string
|
||||
* maxLength: 512
|
||||
* description: URL endpoint for notifications
|
||||
* example: https://service.example.com/planka
|
||||
* format:
|
||||
* type: string
|
||||
* enum: [text, markdown, html]
|
||||
* description: Format for notification messages
|
||||
* example: text
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Notification service created successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* properties:
|
||||
* item:
|
||||
* $ref: '#/components/schemas/NotificationService'
|
||||
* 400:
|
||||
* $ref: '#/components/responses/ValidationError'
|
||||
* 401:
|
||||
* $ref: '#/components/responses/Unauthorized'
|
||||
* 404:
|
||||
* $ref: '#/components/responses/NotFound'
|
||||
* 409:
|
||||
* $ref: '#/components/responses/Conflict'
|
||||
*/
|
||||
|
||||
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,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,113 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /notification-services/{id}:
|
||||
* delete:
|
||||
* summary: Delete notification service
|
||||
* description: Deletes a notification service. Users can delete their own services, project managers can delete board services.
|
||||
* tags:
|
||||
* - Notification Services
|
||||
* operationId: deleteNotificationService
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the notification service to delete
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Notification service deleted successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* properties:
|
||||
* item:
|
||||
* $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 = {
|
||||
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,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,103 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /notification-services/{id}/test:
|
||||
* post:
|
||||
* summary: Test notification service
|
||||
* description: Sends a test notification to verify the notification service is working. Users can test their own services, project managers can test board services.
|
||||
* tags:
|
||||
* - Notification Services
|
||||
* operationId: testNotificationService
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the notification service to test
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Test notification sent successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* properties:
|
||||
* item:
|
||||
* $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 = {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
await sails.helpers.utils.sendNotifications.with({
|
||||
services: [_.pick(notificationService, ['url', 'format'])],
|
||||
title: this.req.i18n.__('Test Title'),
|
||||
bodyByFormat: {
|
||||
text: this.req.i18n.__('This is a test text message!'),
|
||||
markdown: this.req.i18n.__('This is a *test* **markdown** `message`!'),
|
||||
html: this.req.i18n.__('This is a <i>test</i> <b>html</b> <code>message</code>!'),
|
||||
},
|
||||
});
|
||||
/* eslint-enable no-underscore-dangle */
|
||||
|
||||
return {
|
||||
item: notificationService,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,143 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /notification-services/{id}:
|
||||
* patch:
|
||||
* summary: Update notification service
|
||||
* description: Updates a notification service. Users can update their own services, project managers can update board services.
|
||||
* tags:
|
||||
* - Notification Services
|
||||
* operationId: updateNotificationService
|
||||
* parameters:
|
||||
* - name: id
|
||||
* in: path
|
||||
* required: true
|
||||
* description: ID of the notification service to update
|
||||
* schema:
|
||||
* type: string
|
||||
* example: "1357158568008091264"
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* url:
|
||||
* type: string
|
||||
* maxLength: 512
|
||||
* description: URL endpoint for notifications
|
||||
* example: https://service.example.com/planka
|
||||
* format:
|
||||
* type: string
|
||||
* enum: [text, markdown, html]
|
||||
* description: Format for notification messages
|
||||
* example: text
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Notification service updated successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - item
|
||||
* properties:
|
||||
* item:
|
||||
* $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 = {
|
||||
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,
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user