feat: Add internal runtime configuration

This commit is contained in:
Maksim Eltyshev
2026-01-22 18:02:42 +01:00
parent b852481850
commit 1264fd5715
79 changed files with 561 additions and 122 deletions
@@ -0,0 +1,51 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
const Errors = {
NOT_ENOUGH_RIGHTS: {
notEnoughRights: 'Not enough rights',
},
};
module.exports = {
inputs: {
storageLimit: {
type: 'string',
isNotEmptyString: true,
maxLength: 256,
allowNull: true,
},
activeUsersLimit: {
type: 'number',
min: 0,
allowNull: true,
},
},
exits: {
notEnoughRights: {
responseType: 'forbidden',
},
},
async fn(inputs) {
// eslint-disable-next-line no-restricted-syntax
for (const fieldName of Object.keys(inputs)) {
if (!_.isNil(sails.config.custom[fieldName])) {
throw Errors.NOT_ENOUGH_RIGHTS;
}
}
const values = _.pick(inputs, ['storageLimit', 'activeUsersLimit']);
const internalConfig = await sails.helpers.internalConfig.updateMain.with({
values,
});
return {
item: internalConfig,
};
},
};
@@ -202,11 +202,11 @@ module.exports = {
({ user } = await User.qm.updateOne(user.id, values));
}
const config = await Config.qm.getOneMain();
const internalConfig = await InternalConfig.qm.getOneMain();
if (!config.isInitialized) {
if (!internalConfig.isInitialized) {
if (user.role === User.Roles.ADMIN) {
await Config.qm.updateOneMain({
await InternalConfig.qm.updateOneMain({
isInitialized: true,
});
} else {
@@ -119,7 +119,7 @@
* enum:
* - Email already in use
* - Username already in use
* - Active user limit reached
* - Active users limit reached
* description: Specific error message
* example: Email already in use
* 422:
@@ -182,8 +182,8 @@ const Errors = {
USERNAME_ALREADY_IN_USE: {
usernameAlreadyInUse: 'Username already in use',
},
ACTIVE_USER_LIMIT_REACHED: {
activeUserLimitReached: 'Active user limit reached',
ACTIVE_USERS_LIMIT_REACHED: {
activeUsersLimitReached: 'Active users limit reached',
},
MISSING_VALUES: {
missingValues: 'Unable to retrieve required values (email, name)',
@@ -229,7 +229,7 @@ module.exports = {
usernameAlreadyInUse: {
responseType: 'conflict',
},
activeUserLimitReached: {
activeUsersLimitReached: {
responseType: 'conflict',
},
missingValues: {
@@ -250,7 +250,7 @@ module.exports = {
.intercept('invalidUserinfoConfiguration', () => Errors.INVALID_USERINFO_CONFIGURATION)
.intercept('emailAlreadyInUse', () => Errors.EMAIL_ALREADY_IN_USE)
.intercept('usernameAlreadyInUse', () => Errors.USERNAME_ALREADY_IN_USE)
.intercept('activeLimitReached', () => Errors.ACTIVE_USER_LIMIT_REACHED)
.intercept('activeLimitReached', () => Errors.ACTIVE_USERS_LIMIT_REACHED)
.intercept('missingValues', () => Errors.MISSING_VALUES);
return sails.helpers.accessTokens.handleSteps
+3 -2
View File
@@ -47,7 +47,7 @@
* type: boolean
* description: Whether OIDC authentication is enforced (users must use OIDC to login)
* example: false
* activeUserLimit:
* activeUsersLimit:
* type: number
* nullable: true
* description: Maximum number of active users allowed (conditionally added for admins if configured)
@@ -68,10 +68,11 @@ module.exports = {
async fn() {
const { currentUser } = this.req;
const internalConfig = await InternalConfig.qm.getOneMain();
const oidc = await sails.hooks.oidc.getBootstrap();
return {
item: sails.helpers.bootstrap.presentOne(oidc, currentUser),
item: sails.helpers.bootstrap.presentOne(internalConfig, oidc, currentUser),
};
},
};