From 0bab0ed748638bbcbee69aa6d6dd99ae4e9a3ca9 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Thu, 11 Jul 2024 18:30:29 +0200 Subject: [PATCH] support: add route to repair apps --- src/apps.js | 12 ++++++++++++ src/routes/support.js | 15 ++++++++++++++- src/server.js | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/apps.js b/src/apps.js index f0d2f37c9..cff2adb46 100644 --- a/src/apps.js +++ b/src/apps.js @@ -83,6 +83,7 @@ exports = module.exports = { restoreApps, configureApps, + repairApps, schedulePendingTasks, restartAppsUsingAddons, @@ -2197,6 +2198,17 @@ async function repair(app, data, auditSource) { return { taskId }; } +async function repairApps(auditSource) { + assert.strictEqual(typeof auditSource, 'object'); + + const apps = await list(); + + for (const app of apps) { + if (app.installationState !== exports.ISTATE_ERROR) continue; + await repair(app, { /* data */}, auditSource); + } +} + async function restore(app, backupId, auditSource) { assert.strictEqual(typeof app, 'object'); assert.strictEqual(typeof backupId, 'string'); diff --git a/src/routes/support.js b/src/routes/support.js index 93ce86003..e94119229 100644 --- a/src/routes/support.js +++ b/src/routes/support.js @@ -5,11 +5,15 @@ exports = module.exports = { getRemoteSupport, enableRemoteSupport, + + repairApps }; -const appstore = require('../appstore.js'), +const apps = require('../apps.js'), + appstore = require('../appstore.js'), assert = require('assert'), AuditSource = require('../auditsource.js'), + BoxError = require('../boxerror.js'), constants = require('../constants.js'), HttpError = require('connect-lastmile').HttpError, HttpSuccess = require('connect-lastmile').HttpSuccess, @@ -52,3 +56,12 @@ async function getRemoteSupport(req, res, next) { next(new HttpSuccess(200, { enabled })); } + +async function repairApps(req, res, next) { + assert.strictEqual(typeof req.user, 'object'); + + const [error] = await safe(apps.repairApps(AuditSource.fromRequest(req))); + if (error) return next(BoxError.toHttpError(error)); + + next(new HttpSuccess(202, {})); +} diff --git a/src/server.js b/src/server.js index be0998f1a..e0047670b 100644 --- a/src/server.js +++ b/src/server.js @@ -383,6 +383,7 @@ async function initializeExpressSync() { router.post('/api/v1/support/ticket', json, token, authorizeOwner, routes.support.createTicket); router.get ('/api/v1/support/remote_support', token, authorizeOwner, routes.support.getRemoteSupport); router.post('/api/v1/support/remote_support', json, token, authorizeOwner, routes.support.enableRemoteSupport); + router.post('/api/v1/support/repair_apps', json, token, authorizeOwner, routes.support.repairApps); // domain routes router.post('/api/v1/domains', json, token, authorizeAdmin, routes.domains.add);