2017-03-21 05:05:20 +01:00
|
|
|
|
angular
|
|
|
|
|
.module('bit.vault')
|
|
|
|
|
|
2017-04-27 22:24:38 +02:00
|
|
|
|
.controller('vaultShareLoginController', function ($scope, apiService, $uibModalInstance, authService, cipherService,
|
2017-04-11 23:29:45 +02:00
|
|
|
|
loginId, $analytics, $state) {
|
2017-04-27 22:24:38 +02:00
|
|
|
|
$analytics.eventTrack('vaultShareLoginController', { category: 'Modal' });
|
2017-03-21 05:05:20 +01:00
|
|
|
|
$scope.model = {};
|
|
|
|
|
$scope.login = {};
|
2017-04-27 15:33:12 +02:00
|
|
|
|
$scope.collections = [];
|
|
|
|
|
$scope.selectedCollections = {};
|
2017-03-21 05:05:20 +01:00
|
|
|
|
$scope.organizations = [];
|
2017-04-27 15:33:12 +02:00
|
|
|
|
var organizationCollectionCounts = {};
|
|
|
|
|
$scope.loadingCollections = true;
|
2017-04-27 22:24:38 +02:00
|
|
|
|
$scope.loading = true;
|
2017-03-25 16:41:06 +01:00
|
|
|
|
$scope.readOnly = false;
|
2017-03-21 05:05:20 +01:00
|
|
|
|
|
2017-03-25 16:41:06 +01:00
|
|
|
|
apiService.logins.get({ id: loginId }).$promise.then(function (login) {
|
|
|
|
|
$scope.readOnly = !login.Edit;
|
|
|
|
|
if (login.Edit) {
|
|
|
|
|
$scope.login = cipherService.decryptLogin(login);
|
|
|
|
|
}
|
2017-03-21 05:05:20 +01:00
|
|
|
|
|
2017-03-25 16:41:06 +01:00
|
|
|
|
return login.Edit;
|
|
|
|
|
}).then(function (canEdit) {
|
2017-04-27 22:24:38 +02:00
|
|
|
|
$scope.loading = false;
|
2017-03-25 16:41:06 +01:00
|
|
|
|
if (!canEdit) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return authService.getUserProfile();
|
|
|
|
|
}).then(function (profile) {
|
2017-03-25 15:43:19 +01:00
|
|
|
|
if (profile && profile.organizations) {
|
2017-03-28 03:55:39 +02:00
|
|
|
|
var orgs = [],
|
|
|
|
|
setFirstOrg = false;
|
|
|
|
|
|
|
|
|
|
for (var i in profile.organizations) {
|
2017-04-11 23:29:45 +02:00
|
|
|
|
if (profile.organizations.hasOwnProperty(i) && profile.organizations[i].enabled) {
|
2017-03-28 03:55:39 +02:00
|
|
|
|
orgs.push({
|
|
|
|
|
id: profile.organizations[i].id,
|
|
|
|
|
name: profile.organizations[i].name
|
|
|
|
|
});
|
|
|
|
|
|
2017-04-27 15:33:12 +02:00
|
|
|
|
organizationCollectionCounts[profile.organizations[i].id] = 0;
|
2017-04-21 22:02:46 +02:00
|
|
|
|
|
2017-03-28 03:55:39 +02:00
|
|
|
|
if (!setFirstOrg) {
|
|
|
|
|
setFirstOrg = true;
|
|
|
|
|
$scope.model.organizationId = profile.organizations[i].id;
|
|
|
|
|
}
|
2017-03-25 15:43:19 +01:00
|
|
|
|
}
|
2017-03-21 05:05:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-25 15:43:19 +01:00
|
|
|
|
$scope.organizations = orgs;
|
2017-03-21 05:05:20 +01:00
|
|
|
|
|
2017-04-27 15:33:12 +02:00
|
|
|
|
apiService.collections.listMe(function (response) {
|
|
|
|
|
var collections = [];
|
2017-03-25 15:43:19 +01:00
|
|
|
|
for (var i = 0; i < response.Data.length; i++) {
|
2017-04-27 15:33:12 +02:00
|
|
|
|
var decCollection = cipherService.decryptCollection(response.Data[i]);
|
|
|
|
|
decCollection.organizationId = response.Data[i].OrganizationId;
|
|
|
|
|
collections.push(decCollection);
|
|
|
|
|
organizationCollectionCounts[decCollection.organizationId]++;
|
2017-03-25 15:43:19 +01:00
|
|
|
|
}
|
2017-03-21 05:05:20 +01:00
|
|
|
|
|
2017-04-27 15:33:12 +02:00
|
|
|
|
$scope.collections = collections;
|
|
|
|
|
$scope.loadingCollections = false;
|
2017-03-25 15:43:19 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-03-21 05:05:20 +01:00
|
|
|
|
|
2017-04-27 15:33:12 +02:00
|
|
|
|
$scope.toggleCollectionSelectionAll = function ($event) {
|
|
|
|
|
var collections = {};
|
2017-04-05 04:08:04 +02:00
|
|
|
|
if ($event.target.checked) {
|
2017-04-27 15:33:12 +02:00
|
|
|
|
for (var i = 0; i < $scope.collections.length; i++) {
|
|
|
|
|
if ($scope.model.organizationId && $scope.collections[i].organizationId === $scope.model.organizationId) {
|
|
|
|
|
collections[$scope.collections[i].id] = true;
|
2017-04-21 22:02:46 +02:00
|
|
|
|
}
|
2017-04-05 04:08:04 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 15:33:12 +02:00
|
|
|
|
$scope.selectedCollections = collections;
|
2017-04-05 04:08:04 +02:00
|
|
|
|
};
|
|
|
|
|
|
2017-04-27 15:33:12 +02:00
|
|
|
|
$scope.toggleCollectionSelection = function (id) {
|
|
|
|
|
if (id in $scope.selectedCollections) {
|
|
|
|
|
delete $scope.selectedCollections[id];
|
2017-04-05 04:08:04 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
2017-04-27 15:33:12 +02:00
|
|
|
|
$scope.selectedCollections[id] = true;
|
2017-04-05 04:08:04 +02:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-04-27 15:33:12 +02:00
|
|
|
|
$scope.collectionSelected = function (collection) {
|
|
|
|
|
return collection.id in $scope.selectedCollections;
|
2017-04-05 04:08:04 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.allSelected = function () {
|
2017-04-21 22:02:46 +02:00
|
|
|
|
if (!$scope.model.organizationId) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 15:33:12 +02:00
|
|
|
|
return Object.keys($scope.selectedCollections).length === organizationCollectionCounts[$scope.model.organizationId];
|
2017-04-21 22:02:46 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.orgChanged = function () {
|
2017-04-27 15:33:12 +02:00
|
|
|
|
$scope.selectedCollections = {};
|
2017-04-05 04:08:04 +02:00
|
|
|
|
};
|
|
|
|
|
|
2017-03-21 05:05:20 +01:00
|
|
|
|
$scope.submitPromise = null;
|
|
|
|
|
$scope.submit = function (model) {
|
|
|
|
|
$scope.login.organizationId = model.organizationId;
|
|
|
|
|
|
|
|
|
|
var request = {
|
2017-04-27 15:33:12 +02:00
|
|
|
|
collectionIds: [],
|
2017-03-21 05:05:20 +01:00
|
|
|
|
cipher: cipherService.encryptLogin($scope.login)
|
|
|
|
|
};
|
|
|
|
|
|
2017-04-27 15:33:12 +02:00
|
|
|
|
for (var id in $scope.selectedCollections) {
|
|
|
|
|
if ($scope.selectedCollections.hasOwnProperty(id)) {
|
|
|
|
|
request.collectionIds.push(id);
|
2017-04-05 04:08:04 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-12 18:41:43 +02:00
|
|
|
|
$scope.submitPromise = apiService.ciphers.putShare({ id: loginId }, request, function (response) {
|
2017-03-21 05:05:20 +01:00
|
|
|
|
$analytics.eventTrack('Shared Login');
|
2017-04-15 05:36:11 +02:00
|
|
|
|
$uibModalInstance.close(model.organizationId);
|
2017-03-21 05:05:20 +01:00
|
|
|
|
}).$promise;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.close = function () {
|
|
|
|
|
$uibModalInstance.dismiss('cancel');
|
|
|
|
|
};
|
2017-04-11 23:29:45 +02:00
|
|
|
|
|
|
|
|
|
$scope.createOrg = function () {
|
|
|
|
|
$state.go('backend.user.settingsCreateOrg').then(function () {
|
|
|
|
|
$uibModalInstance.dismiss('cancel');
|
|
|
|
|
});
|
|
|
|
|
};
|
2017-03-21 05:05:20 +01:00
|
|
|
|
});
|