support: add route to repair apps

This commit is contained in:
Girish Ramakrishnan
2024-07-11 18:30:29 +02:00
parent 8754a208b1
commit 0bab0ed748
3 changed files with 27 additions and 1 deletions
+12
View File
@@ -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');
+14 -1
View File
@@ -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, {}));
}
+1
View File
@@ -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);