mirror of
https://github.com/plankanban/planka.git
synced 2025-12-24 09:15:01 +03:00
feat: Add ability to configure and test SMTP via UI
This commit is contained in:
@@ -59,6 +59,28 @@ module.exports = function defineOidcHook(sails) {
|
||||
return client;
|
||||
},
|
||||
|
||||
async getBootstrap() {
|
||||
const instance = await this.getClient();
|
||||
|
||||
if (!instance) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const authorizationUrlParams = {
|
||||
scope: sails.config.custom.oidcScopes,
|
||||
};
|
||||
|
||||
if (!sails.config.custom.oidcUseDefaultResponseMode) {
|
||||
authorizationUrlParams.response_mode = sails.config.custom.oidcResponseMode;
|
||||
}
|
||||
|
||||
return {
|
||||
authorizationUrl: instance.authorizationUrl(authorizationUrlParams),
|
||||
endSessionUrl: instance.issuer.end_session_endpoint ? instance.endSessionUrl({}) : null,
|
||||
isEnforced: sails.config.custom.oidcEnforced,
|
||||
};
|
||||
},
|
||||
|
||||
isEnabled() {
|
||||
return !!sails.config.custom.oidcIssuer;
|
||||
},
|
||||
|
||||
@@ -9,6 +9,37 @@ const defaultFind = (criteria) => Notification.find(criteria).sort('id DESC');
|
||||
|
||||
/* Query methods */
|
||||
|
||||
const create = (arrayOfValues) =>
|
||||
sails.getDatastore().transaction(async (db) => {
|
||||
const notifications = await Notification.createEach(arrayOfValues).fetch().usingConnection(db);
|
||||
const userIds = sails.helpers.utils.mapRecords(notifications, 'userId', true, true);
|
||||
|
||||
if (userIds.length > 0) {
|
||||
const queryValues = [];
|
||||
const inValues = userIds.map((userId) => {
|
||||
queryValues.push(userId);
|
||||
return `$${queryValues.length}`;
|
||||
});
|
||||
|
||||
queryValues.push(LIMIT);
|
||||
|
||||
const query = `
|
||||
WITH exceeded_notification AS (
|
||||
SELECT id, ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY id DESC) AS rank
|
||||
FROM notification
|
||||
WHERE user_id IN (${inValues.join(', ')}) AND is_read = FALSE
|
||||
)
|
||||
UPDATE notification
|
||||
SET is_read = TRUE
|
||||
WHERE id IN (SELECT id FROM exceeded_notification WHERE rank > $${queryValues.length})
|
||||
`;
|
||||
|
||||
await sails.sendNativeQuery(query, queryValues).usingConnection(db);
|
||||
}
|
||||
|
||||
return notifications;
|
||||
});
|
||||
|
||||
const createOne = (values) => {
|
||||
if (values.userId) {
|
||||
return sails.getDatastore().transaction(async (db) => {
|
||||
@@ -26,7 +57,7 @@ const createOne = (values) => {
|
||||
)
|
||||
UPDATE notification
|
||||
SET is_read = TRUE
|
||||
WHERE id in (SELECT id FROM exceeded_notification)
|
||||
WHERE id IN (SELECT id FROM exceeded_notification)
|
||||
`;
|
||||
|
||||
await sails.sendNativeQuery(query, [values.userId, LIMIT]).usingConnection(db);
|
||||
@@ -66,6 +97,7 @@ const updateOne = (criteria, values) => Notification.updateOne(criteria).set({ .
|
||||
const delete_ = (criteria) => Notification.destroy(criteria).fetch();
|
||||
|
||||
module.exports = {
|
||||
create,
|
||||
createOne,
|
||||
getByIds,
|
||||
getUnreadByUserId,
|
||||
|
||||
@@ -14,6 +14,11 @@ const getByUserId = (userId) =>
|
||||
userId,
|
||||
});
|
||||
|
||||
const getByUserIds = (userIds) =>
|
||||
defaultFind({
|
||||
userId: userIds,
|
||||
});
|
||||
|
||||
const getByBoardId = (boardId) =>
|
||||
defaultFind({
|
||||
boardId,
|
||||
@@ -36,6 +41,7 @@ const deleteOne = (criteria) => NotificationService.destroyOne(criteria);
|
||||
module.exports = {
|
||||
createOne,
|
||||
getByUserId,
|
||||
getByUserIds,
|
||||
getByBoardId,
|
||||
getByBoardIds,
|
||||
getOneById,
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
/**
|
||||
* smtp hook
|
||||
*
|
||||
* @description :: A hook definition. Extends Sails by adding shadow routes, implicit actions,
|
||||
* and/or initialization logic.
|
||||
* @docs :: https://sailsjs.com/docs/concepts/extending-sails/hooks
|
||||
*/
|
||||
|
||||
const nodemailer = require('nodemailer');
|
||||
|
||||
module.exports = function defineSmtpHook(sails) {
|
||||
let transporter = null;
|
||||
|
||||
return {
|
||||
/**
|
||||
* Runs when this Sails app loads/lifts.
|
||||
*/
|
||||
|
||||
async initialize() {
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
sails.log.info('Initializing custom hook (`smtp`)');
|
||||
|
||||
transporter = nodemailer.createTransport({
|
||||
pool: true,
|
||||
host: sails.config.custom.smtpHost,
|
||||
port: sails.config.custom.smtpPort,
|
||||
name: sails.config.custom.smtpName,
|
||||
secure: sails.config.custom.smtpSecure,
|
||||
auth: sails.config.custom.smtpUser && {
|
||||
user: sails.config.custom.smtpUser,
|
||||
pass: sails.config.custom.smtpPassword,
|
||||
},
|
||||
tls: {
|
||||
rejectUnauthorized: sails.config.custom.smtpTlsRejectUnauthorized,
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
getTransporter() {
|
||||
return transporter;
|
||||
},
|
||||
|
||||
isEnabled() {
|
||||
return !!sails.config.custom.smtpHost;
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user