From e9d129993ac7968c43d3b8c595e65dcb5bc33fbc Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Mon, 15 Apr 2024 09:38:33 +0100 Subject: [PATCH 01/15] introduce new key setting KEY_HEALTH_CHECK_INTERVAL --- forge/db/models/Project.js | 5 +++-- forge/db/models/ProjectSettings.js | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/forge/db/models/Project.js b/forge/db/models/Project.js index 660746243e..437e0d59a2 100644 --- a/forge/db/models/Project.js +++ b/forge/db/models/Project.js @@ -17,7 +17,7 @@ const { DataTypes, Op } = require('sequelize') const Controllers = require('../controllers') -const { KEY_HOSTNAME, KEY_SETTINGS, KEY_HA, KEY_PROTECTED } = require('./ProjectSettings') +const { KEY_HOSTNAME, KEY_SETTINGS, KEY_HA, KEY_PROTECTED, KEY_HEALTH_CHECK_INTERVAL } = require('./ProjectSettings') const BANNED_NAME_LIST = [ 'www', @@ -358,7 +358,8 @@ module.exports = { { key: KEY_SETTINGS }, { key: KEY_HOSTNAME }, { key: KEY_HA }, - { key: KEY_PROTECTED } + { key: KEY_PROTECTED }, + { key: KEY_HEALTH_CHECK_INTERVAL } ] }, required: false diff --git a/forge/db/models/ProjectSettings.js b/forge/db/models/ProjectSettings.js index 5bb9de7eba..1f9c566c13 100644 --- a/forge/db/models/ProjectSettings.js +++ b/forge/db/models/ProjectSettings.js @@ -13,12 +13,14 @@ const KEY_SETTINGS = 'settings' const KEY_HOSTNAME = 'hostname' const KEY_HA = 'ha' const KEY_PROTECTED = 'protected' +const KEY_HEALTH_CHECK_INTERVAL = 'healthCheckInterval' module.exports = { KEY_SETTINGS, KEY_HOSTNAME, KEY_HA, KEY_PROTECTED, + KEY_HEALTH_CHECK_INTERVAL, name: 'ProjectSettings', schema: { ProjectId: { type: DataTypes.UUID, unique: 'pk_settings' }, From 7efe08c2077916679ae5d8222f1de817eba4b220 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Mon, 15 Apr 2024 09:49:05 +0100 Subject: [PATCH 02/15] update API for launcher settings (KEY_HEALTH_CHECK_INTERVAL) --- forge/db/views/Project.js | 16 +++++++++++++++- forge/routes/api/project.js | 21 ++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/forge/db/views/Project.js b/forge/db/views/Project.js index 527e8bc317..6163610a69 100644 --- a/forge/db/views/Project.js +++ b/forge/db/views/Project.js @@ -1,4 +1,4 @@ -const { KEY_HOSTNAME, KEY_SETTINGS, KEY_HA, KEY_PROTECTED } = require('../models/ProjectSettings') +const { KEY_HOSTNAME, KEY_SETTINGS, KEY_HA, KEY_PROTECTED, KEY_HEALTH_CHECK_INTERVAL } = require('../models/ProjectSettings') module.exports = function (app) { app.addSchema({ @@ -32,6 +32,13 @@ module.exports = function (app) { protected: { type: 'object', additionalProperties: true + }, + launcherSettings: { + type: 'object', + properties: { + healthCheckInterval: { type: 'number' } + }, + additionalProperties: false } } }) @@ -61,6 +68,13 @@ module.exports = function (app) { } else { result.settings = {} } + // Launcher Settings + const heathCheckIntervalRow = proj.ProjectSettings?.find((projectSettingsRow) => projectSettingsRow.key === KEY_HEALTH_CHECK_INTERVAL) + if (heathCheckIntervalRow) { + result.launcherSettings = {} + result.launcherSettings.healthCheckInterval = heathCheckIntervalRow?.value + } + // Environment result.settings.env = app.db.controllers.Project.insertPlatformSpecificEnvVars(proj, result.settings.env) if (!result.settings.palette?.modules) { // If there are no modules listed in settings, check the StorageSettings diff --git a/forge/routes/api/project.js b/forge/routes/api/project.js index d5585a20f5..38f3c60332 100644 --- a/forge/routes/api/project.js +++ b/forge/routes/api/project.js @@ -1,4 +1,4 @@ -const { KEY_HOSTNAME, KEY_SETTINGS } = require('../../db/models/ProjectSettings') +const { KEY_HOSTNAME, KEY_SETTINGS, KEY_HEALTH_CHECK_INTERVAL } = require('../../db/models/ProjectSettings') const { Roles } = require('../../lib/roles') const { isFQDN } = require('../../lib/validate') @@ -312,6 +312,7 @@ module.exports = async function (app) { name: { type: 'string' }, hostname: { type: 'string' }, settings: { type: 'object' }, + launcherSettings: { type: 'object' }, projectType: { type: 'string' }, stack: { type: 'string' }, sourceProject: { @@ -478,6 +479,19 @@ module.exports = async function (app) { changesToPersist.stack = { from: request.project.stack, to: stack } } + // Launcher settings + if (request.body?.launcherSettings?.healthCheckInterval) { + const oldInterval = await request.project.getSetting(KEY_HEALTH_CHECK_INTERVAL) + const newInterval = parseInt(request.body.launcherSettings.healthCheckInterval, 10) + if (isNaN(newInterval) || newInterval < 1000) { + reply.code(400).send({ code: 'invalid_heathCheckInterval', error: 'Invalid heath check interval' }) + return + } + if (oldInterval !== newInterval) { + changesToPersist.healthCheckInterval = { from: oldInterval, to: newInterval } + } + } + /// Persist the changes const updates = new app.auditLog.formatters.UpdatesCollection() const transaction = await app.db.sequelize.transaction() // start a transaction @@ -541,6 +555,11 @@ module.exports = async function (app) { } } + if (changesToPersist.healthCheckInterval) { + await request.project.updateSetting(KEY_HEALTH_CHECK_INTERVAL, changesToPersist.healthCheckInterval.to, { transaction }) + updates.pushDifferences({ healthCheckInterval: changesToPersist.healthCheckInterval.from }, { healthCheckInterval: changesToPersist.healthCheckInterval.to }) + } + await transaction.commit() // all good, commit the transaction // Log the updates From a7e25854aaa6f3ff553626d0f151085668f2faa8 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Mon, 15 Apr 2024 09:53:22 +0100 Subject: [PATCH 03/15] add launcher settings page to instance settings. --- .../instance/Settings/LauncherSettings.vue | 91 +++++++++++++++++++ .../src/pages/instance/Settings/index.vue | 1 + .../src/pages/instance/Settings/routes.js | 2 + 3 files changed, 94 insertions(+) create mode 100644 frontend/src/pages/instance/Settings/LauncherSettings.vue diff --git a/frontend/src/pages/instance/Settings/LauncherSettings.vue b/frontend/src/pages/instance/Settings/LauncherSettings.vue new file mode 100644 index 0000000000..bb36efafe5 --- /dev/null +++ b/frontend/src/pages/instance/Settings/LauncherSettings.vue @@ -0,0 +1,91 @@ + + + diff --git a/frontend/src/pages/instance/Settings/index.vue b/frontend/src/pages/instance/Settings/index.vue index 1b2dec9146..52054cb9a9 100644 --- a/frontend/src/pages/instance/Settings/index.vue +++ b/frontend/src/pages/instance/Settings/index.vue @@ -68,6 +68,7 @@ export default { this.sideNavigation.push({ name: 'Editor', path: './editor' }) this.sideNavigation.push({ name: 'Security', path: './security' }) this.sideNavigation.push({ name: 'Palette', path: './palette' }) + this.sideNavigation.push({ name: 'Launcher', path: './launcher' }) if (this.features.emailAlerts && this.team.type.properties.features?.emailAlerts) { this.sideNavigation.push({ name: 'Alerts', path: './alerts' }) } diff --git a/frontend/src/pages/instance/Settings/routes.js b/frontend/src/pages/instance/Settings/routes.js index 1331805bc7..9c5cc9705d 100644 --- a/frontend/src/pages/instance/Settings/routes.js +++ b/frontend/src/pages/instance/Settings/routes.js @@ -5,6 +5,7 @@ import InstanceSettingsEditor from './Editor.vue' import InstanceSettingsEnvVar from './Environment.vue' import InstanceSettingsGeneral from './General.vue' import InstanceSettingsHA from './HighAvailability.vue' +import InstanceSettingsLauncher from './LauncherSettings.vue' import InstanceSettingsPalette from './Palette.vue' import InstanceSettingsProtect from './ProtectInstance.vue' import InstanceSettingsSecurity from './Security.vue' @@ -26,5 +27,6 @@ export default [ title: 'Instance - Change Type' } }, + { path: 'launcher', name: 'InstanceSettingsLauncher', component: InstanceSettingsLauncher }, { path: 'alerts', component: InstanceSettingsAlerts } ] From c56437ad3cb93cd984141f30b87f09b00587c771 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Mon, 15 Apr 2024 11:06:06 +0100 Subject: [PATCH 04/15] fix existing test - remove brittle length check --- test/e2e/frontend/cypress/tests-ee/instances/alerts.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/e2e/frontend/cypress/tests-ee/instances/alerts.spec.js b/test/e2e/frontend/cypress/tests-ee/instances/alerts.spec.js index abba6c0778..405e480ac3 100644 --- a/test/e2e/frontend/cypress/tests-ee/instances/alerts.spec.js +++ b/test/e2e/frontend/cypress/tests-ee/instances/alerts.spec.js @@ -28,7 +28,6 @@ describe('FlowFuse EE - Instance - Alerts', () => { navigateToInstanceSettings('BTeam', 'instance-2-1') // check Alerts in list and click - cy.get('[data-el="section-side-menu"] li').should('have.length', 8) cy.get('[data-el="section-side-menu"] li:last a').contains('Alerts') cy.get('[data-el="section-side-menu"] li:last').click() From 7c11b328210edbb3f02a39056eece0d62983a89d Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Mon, 15 Apr 2024 11:45:20 +0100 Subject: [PATCH 05/15] add e2e test --- .../instance/Settings/LauncherSettings.vue | 4 +- .../tests/instances/settings/launcher.spec.js | 58 +++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 test/e2e/frontend/cypress/tests/instances/settings/launcher.spec.js diff --git a/frontend/src/pages/instance/Settings/LauncherSettings.vue b/frontend/src/pages/instance/Settings/LauncherSettings.vue index bb36efafe5..4a3bce45bb 100644 --- a/frontend/src/pages/instance/Settings/LauncherSettings.vue +++ b/frontend/src/pages/instance/Settings/LauncherSettings.vue @@ -1,6 +1,6 @@