appstore: add unlink account route

This commit is contained in:
Girish Ramakrishnan
2025-09-24 21:25:31 +02:00
parent a38ef2b6f5
commit 98d4d99c1b
11 changed files with 37 additions and 54 deletions

View File

@@ -17,6 +17,7 @@ exports = module.exports = {
registerCloudron3,
updateCloudron,
unlinkAccount,
getSubscription,
isFreePlan,
@@ -32,6 +33,7 @@ exports = module.exports = {
const assert = require('node:assert'),
BoxError = require('./boxerror.js'),
constants = require('./constants.js'),
dashboard = require('./dashboard.js'),
debug = require('debug')('box:appstore'),
manifestFormat = require('@cloudron/manifest-format'),
paths = require('./paths.js'),
@@ -223,9 +225,9 @@ async function getAppUpdate(app, options) {
return updateInfo;
}
async function registerCloudron3(domain, version) {
assert.strictEqual(typeof domain, 'string');
assert.strictEqual(typeof version, 'string');
async function registerCloudron3() {
const { domain } = await dashboard.getLocation();
const version = constants.VERSION;
const token = await settings.get(settings.APPSTORE_API_TOKEN_KEY);
if (token) { // when installed using setupToken, this updates the domain record when called during provisioning
@@ -250,6 +252,13 @@ async function registerCloudron3(domain, version) {
debug(`registerCloudron3: Cloudron registered with id ${response.body.cloudronId}`);
}
async function unlinkAccount() {
debug('unlinkAccount: Unlinking existing account.');
await unregister();
return await registerCloudron3();
}
async function updateCloudron(data) {
assert.strictEqual(typeof data, 'object');

View File

@@ -151,8 +151,7 @@ async function activate(username, password, email, displayName, ip, auditSource)
debug(`activate: user: ${username} email:${email}`);
const dashboardLocation = await dashboard.getLocation();
await appstore.registerCloudron3(dashboardLocation.domain, constants.VERSION);
await appstore.registerCloudron3();
const [error, ownerId] = await safe(users.createOwner(email, username, password, displayName, auditSource));
if (error && error.reason === BoxError.ALREADY_EXISTS) throw new BoxError(BoxError.CONFLICT, 'Already activated');

View File

@@ -5,15 +5,13 @@ exports = module.exports = {
getApp,
getAppVersion,
resetCloudronId,
unlinkAccount,
getSubscription
};
const appstore = require('../appstore.js'),
assert = require('node:assert'),
BoxError = require('../boxerror.js'),
constants = require('../constants.js'),
dashboard = require('../dashboard.js'),
HttpSuccess = require('@cloudron/connect-lastmile').HttpSuccess,
safe = require('safetydance'),
users = require('../users.js'),
@@ -45,13 +43,10 @@ async function getAppVersion(req, res, next) {
next(new HttpSuccess(200, manifest));
}
async function resetCloudronId(req, res, next) {
async function unlinkAccount(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
const [getLocationError, dashboardLocation] = await safe(dashboard.getLocation()); // authenticated route implies already activated
if (getLocationError) return next(BoxError.toHttpError(getLocationError));
const [registerError] = await safe(appstore.registerCloudron3(dashboardLocation.domain, constants.VERSION));
const [registerError] = await safe(appstore.unlinkAccount());
if (registerError) return next(BoxError.toHttpError(registerError));
next(new HttpSuccess(202, {}));

View File

@@ -256,7 +256,7 @@ async function initializeExpressSync() {
router.post('/api/v1/directory_server/config', json, token, authorizeAdmin, routes.directoryServer.setConfig);
// appstore and subscription routes
router.post('/api/v1/appstore/reset_cloudron_id', json, token, authorizeOwner, routes.appstore.resetCloudronId);
router.post('/api/v1/appstore/unlink_account', json, token, authorizeOwner, routes.appstore.unlinkAccount);
router.get ('/api/v1/appstore/subscription', token, authorizeUser, routes.appstore.getSubscription); // for all users
router.get ('/api/v1/appstore/apps', token, authorizeAdmin, routes.appstore.getApps);
router.get ('/api/v1/appstore/apps/:appstoreId', token, authorizeAdmin, routes.appstore.getApp);