diff --git a/src/caas.js b/src/caas.js index 40e355a25..c281a7c07 100644 --- a/src/caas.js +++ b/src/caas.js @@ -2,6 +2,7 @@ exports = module.exports = { migrate: migrate, + changePlan: changePlan, upgrade: upgrade }; @@ -103,6 +104,15 @@ function doMigrate(options, callback) { callback(null); } +function changePlan(options, callback) { + assert.strictEqual(typeof options, 'object'); + assert.strictEqual(typeof callback, 'function'); + + if (config.isDemo()) return callback(new CaasError(CaasError.BAD_FIELD, 'Not allowed in demo mode')); + + doMigrate(options, callback); +} + function migrate(options, callback) { assert.strictEqual(typeof options, 'object'); assert.strictEqual(typeof callback, 'function'); diff --git a/src/routes/caas.js b/src/routes/caas.js index 1b91f444c..3850994f8 100644 --- a/src/routes/caas.js +++ b/src/routes/caas.js @@ -1,7 +1,7 @@ 'use strict'; exports = module.exports = { - migrate: migrate + changePlan: changePlan }; var caas = require('../caas.js'), @@ -12,7 +12,7 @@ var caas = require('../caas.js'), HttpSuccess = require('connect-lastmile').HttpSuccess, _ = require('underscore'); -function migrate(req, res, next) { +function changePlan(req, res, next) { if (config.provider() !== 'caas') return next(new HttpError(422, 'Cannot use migrate API with this provider')); if ('size' in req.body && typeof req.body.size !== 'string') return next(new HttpError(400, 'size must be string')); @@ -32,7 +32,7 @@ function migrate(req, res, next) { if (options.domain) options.domain = options.domain.toLowerCase(); - caas.migrate(req.body, function (error) { // pass req.body because 'domain' can have arbitrary options + caas.changePlan(req.body, function (error) { // pass req.body because 'domain' can have arbitrary options if (error && error.reason === CaasError.BAD_STATE) return next(new HttpError(409, error.message)); if (error && error.reason === CaasError.BAD_FIELD) return next(new HttpError(400, error.message)); if (error) return next(new HttpError(500, error)); diff --git a/src/server.js b/src/server.js index 65211769b..adb305f76 100644 --- a/src/server.js +++ b/src/server.js @@ -238,7 +238,7 @@ function initializeExpressSync() { router.del ('/api/v1/domains/:domain', settingsScope, routes.user.requireAdmin, routes.user.verifyPassword, routes.domains.del); // caas routes - router.post('/api/v1/caas/migrate', cloudronScope, routes.user.requireAdmin, routes.user.verifyPassword, routes.caas.migrate); + router.post('/api/v1/caas/change_plan', cloudronScope, routes.user.requireAdmin, routes.user.verifyPassword, routes.caas.changePlan); // disable server socket "idle" timeout. we use the timeout middleware to handle timeouts on a route level // we rely on nginx for timeouts on the TCP level (see client_header_timeout) diff --git a/webadmin/src/js/client.js b/webadmin/src/js/client.js index e26adf1be..8ff8ebbf6 100644 --- a/webadmin/src/js/client.js +++ b/webadmin/src/js/client.js @@ -828,11 +828,11 @@ angular.module('Application').service('Client', ['$http', 'md5', 'Notification', }).error(defaultErrorHandler(callback)); }; - Client.prototype.migrate = function (options, password, callback) { + Client.prototype.changePlan = function (options, password, callback) { var data = options; data.password = password; - post('/api/v1/caas/migrate', data).success(function(data, status) { + post('/api/v1/caas/change_plan', data).success(function(data, status) { if (status !== 202 || typeof data !== 'object') return callback(new ClientError(status, data)); callback(null, data); }).error(defaultErrorHandler(callback)); diff --git a/webadmin/src/views/settings.js b/webadmin/src/views/settings.js index 2753ed62f..806ea9d6f 100644 --- a/webadmin/src/views/settings.js +++ b/webadmin/src/views/settings.js @@ -96,7 +96,7 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca region: $scope.currentRegionSlug }; - Client.migrate(options, $scope.planChange.password, function (error) { + Client.changePlan(options, $scope.planChange.password, function (error) { $scope.planChange.busy = false; if (error) {