diff --git a/src/views/app.html b/src/views/app.html index a18d0f219..8d08e90cb 100644 --- a/src/views/app.html +++ b/src/views/app.html @@ -202,22 +202,22 @@ -

- Add an A record manually for {{ appClone.location }} to this Cloudron's public IP +

+ Add an A record manually for {{ clone.location }} to this Cloudron's public IP

-
{{ appClone.error.port }}
-
+
{{ clone.error.port }}
+
-
-
@@ -227,7 +227,7 @@
diff --git a/src/views/app.js b/src/views/app.js index 0c254a3d7..873b1cfc0 100644 --- a/src/views/app.js +++ b/src/views/app.js @@ -6,6 +6,7 @@ /* global asyncForEach */ /* global RSTATES */ /* global ISTATES */ +/* global ERROR */ // TODO use this once we enable custom SSL certificate ui again @@ -690,7 +691,7 @@ angular.module('Application').controller('AppController', ['$scope', '$location' }; $scope.clone = { - busy: true, + busy: false, error: {}, backup: null, @@ -734,28 +735,52 @@ angular.module('Application').controller('AppController', ['$scope', '$location' backupId: $scope.clone.backup.id }; - Client.cloneApp($scope.app.id, data, function (error/*, clonedApp */) { - $scope.clone.busy = false; - + Client.checkDNSRecords(data.domain, data.location, function (error, result) { if (error) { - if (error.statusCode === 409) { - if (error.portName) { - $scope.clone.error.port = error.message; - } else if (error.domain) { - $scope.clone.error.location = 'This location is already taken.'; - $('#cloneLocationInput').focus(); - } else { - Client.error(error); - } + Client.error(error); + $scope.clone.busy = false; + return; + } + if (result.error) { + if (result.error.reason === ERROR.ACCESS_DENIED) { + $scope.clone.error.location = 'DNS credentials for ' + data.domain + ' are invalid. Update it in Domains & Certs view'; } else { - Client.error(error); + $scope.clone.error.location = result.error.message; } + $scope.clone.needsOverwrite = true; + $scope.clone.busy = false; + return; + } + if (result.needsOverwrite) { + $scope.clone.error.location = 'DNS Record already exists. Confirm that the domain is not in use for services external to Cloudron'; + $scope.clone.needsOverwrite = true; + $scope.clone.busy = false; return; } - $('#cloneModal').modal('hide'); + Client.cloneApp($scope.app.id, data, function (error/*, clonedApp */) { + $scope.clone.busy = false; - $location.path('/apps'); + if (error) { + if (error.statusCode === 409) { + if (error.portName) { + $scope.clone.error.port = error.message; + } else if (error.domain) { + $scope.clone.error.location = 'This location is already taken.'; + $('#cloneLocationInput').focus(); + } else { + Client.error(error); + } + } else { + Client.error(error); + } + return; + } + + $('#cloneModal').modal('hide'); + + $location.path('/apps'); + }); }); } }; diff --git a/src/views/appstore.js b/src/views/appstore.js index d1d5a5043..6e9707260 100644 --- a/src/views/appstore.js +++ b/src/views/appstore.js @@ -2,6 +2,7 @@ /* global angular:false */ /* global $:false */ +/* global ERROR */ angular.module('Application').controller('AppStoreController', ['$scope', '$location', '$timeout', '$routeParams', 'Client', function ($scope, $location, $timeout, $routeParams, Client) { Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); });