diff --git a/src/app/organization/organizationDeleteController.js b/src/app/organization/organizationDeleteController.js new file mode 100644 index 0000000000..8075d21ea9 --- /dev/null +++ b/src/app/organization/organizationDeleteController.js @@ -0,0 +1,26 @@ +angular + .module('bit.organization') + + .controller('organizationDeleteController', function ($scope, $state, apiService, $uibModalInstance, cryptoService, + authService, toastr, $analytics) { + $analytics.eventTrack('organizationDeleteController', { category: 'Modal' }); + $scope.submit = function () { + var request = { + masterPasswordHash: cryptoService.hashPassword($scope.masterPassword) + }; + + $scope.submitPromise = apiService.organizations.del({ id: $state.params.orgId }, request, function () { + $uibModalInstance.dismiss('cancel'); + authService.removeProfileOrganization($state.params.orgId); + $analytics.eventTrack('Deleted Organization'); + $state.go('backend.user.vault').then(function () { + toastr.success('This organization and all associated data has been deleted.', + 'Organization Deleted'); + }); + }).$promise; + }; + + $scope.close = function () { + $uibModalInstance.dismiss('cancel'); + }; + }); diff --git a/src/app/organization/organizationSettingsController.js b/src/app/organization/organizationSettingsController.js index 6e9ad777eb..32e8604098 100644 --- a/src/app/organization/organizationSettingsController.js +++ b/src/app/organization/organizationSettingsController.js @@ -1,7 +1,7 @@ angular .module('bit.organization') - .controller('organizationSettingsController', function ($scope, $state, apiService, toastr, authService) { + .controller('organizationSettingsController', function ($scope, $state, apiService, toastr, authService, $uibModal) { $scope.model = {}; $scope.$on('$viewContentLoaded', function () { apiService.organizations.get({ id: $state.params.orgId }, function (org) { @@ -20,4 +20,12 @@ }); }).$promise; }; + + $scope.delete = function () { + $uibModal.open({ + animation: true, + templateUrl: 'app/organization/views/organizationDelete.html', + controller: 'organizationDeleteController' + }); + }; }); diff --git a/src/app/organization/views/organizationDelete.html b/src/app/organization/views/organizationDelete.html new file mode 100644 index 0000000000..4f4db0d84b --- /dev/null +++ b/src/app/organization/views/organizationDelete.html @@ -0,0 +1,34 @@ + +
+ + +
diff --git a/src/app/organization/views/organizationSettings.html b/src/app/organization/views/organizationSettings.html index f17eec60d9..aa3335d6ab 100644 --- a/src/app/organization/views/organizationSettings.html +++ b/src/app/organization/views/organizationSettings.html @@ -49,4 +49,17 @@ +
+
+

Danger Zone

+
+
+ Careful, these actions are not reversible! +
+ +
diff --git a/src/app/services/authService.js b/src/app/services/authService.js index 5c1268a5f5..53bb0477c5 100644 --- a/src/app/services/authService.js +++ b/src/app/services/authService.js @@ -140,6 +140,19 @@ angular }); }; + _service.removeProfileOrganization = function (orgId) { + return _service.getUserProfile().then(function (profile) { + if (profile) { + if (profile.organizations && profile.organizations.hasOwnProperty(orgId)) { + delete profile.organizations[orgId]; + _userProfile = profile; + } + + cryptoService.clearOrgKey(orgId); + } + }); + }; + _service.updateProfileOrganization = function (org) { return _service.getUserProfile().then(function (profile) { if (profile) { diff --git a/src/app/services/cryptoService.js b/src/app/services/cryptoService.js index b8830bd60a..482d053b04 100644 --- a/src/app/services/cryptoService.js +++ b/src/app/services/cryptoService.js @@ -193,6 +193,16 @@ angular delete $sessionStorage.orgKeys; }; + _service.clearOrgKey = function (orgId) { + if (_orgKeys.hasOwnProperty(orgId)) { + delete _orgKeys[orgId]; + } + + if ($sessionStorage.orgKeys.hasOwnProperty(orgId)) { + delete $sessionStorage.orgKeys[orgId]; + } + }; + _service.clearKeys = function () { _service.clearKey(); _service.clearKeyPair(); diff --git a/src/index.html b/src/index.html index 4b97b98e98..3bcf1b9a23 100644 --- a/src/index.html +++ b/src/index.html @@ -141,6 +141,7 @@ +