1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-10 06:08:34 +02:00
bitwarden-browser/src/app/vault/vaultShareController.js

63 lines
2.2 KiB
JavaScript
Raw Normal View History

angular
.module('bit.vault')
.controller('vaultShareController', function ($scope, apiService, $uibModalInstance, authService, cipherService, loginId, $analytics) {
$analytics.eventTrack('vaultShareController', { category: 'Modal' });
$scope.model = {};
$scope.login = {};
$scope.subvaults = [];
$scope.organizations = [];
apiService.logins.get({ id: loginId }, function (login) {
$scope.login = cipherService.decryptLogin(login);
});
authService.getUserProfile().then(function (profile) {
if (profile && profile.organizations) {
var orgs = [];
for (var i = 0; i < profile.organizations.length; i++) {
orgs.push({
id: profile.organizations[i].id,
name: profile.organizations[i].name
});
if (i === 0) {
$scope.model.organizationId = profile.organizations[i].id;
}
}
$scope.organizations = orgs;
apiService.subvaults.listMe(function (response) {
var subvaults = [];
for (var i = 0; i < response.Data.length; i++) {
var decSubvault = cipherService.decryptSubvault(response.Data[i]);
decSubvault.organizationId = response.Data[i].OrganizationId;
subvaults.push(decSubvault);
}
$scope.subvaults = subvaults;
});
}
});
$scope.submitPromise = null;
$scope.submit = function (model) {
$scope.login.organizationId = model.organizationId;
var request = {
subvaultIds: model.subvaultIds,
cipher: cipherService.encryptLogin($scope.login)
};
$scope.savePromise = apiService.ciphers.move({ id: loginId }, request, function (response) {
$analytics.eventTrack('Shared Login');
$uibModalInstance.close();
}).$promise;
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
});