add subvault

This commit is contained in:
Kyle Spearrin 2017-03-09 22:08:47 -05:00
parent e7707c4826
commit 429b2b8a21
7 changed files with 139 additions and 45 deletions

View File

@ -0,0 +1,18 @@
angular
.module('bit.organization')
.controller('organizationSubvaultsAddController', function ($scope, $state, $uibModalInstance, apiService, cipherService,
$analytics) {
$scope.submit = function (model) {
var subvault = cipherService.encryptSubvault(model, $state.params.orgId);
$scope.submitPromise = apiService.subvaults.post({ orgId: $state.params.orgId }, subvault, function (response) {
$analytics.eventTrack('Created Subvault');
var decSubvault = cipherService.decryptSubvault(response, $state.params.orgId, true);
$uibModalInstance.close(decSubvault);
}).$promise;
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
});

View File

@ -1,25 +1,41 @@
angular
.module('bit.organization')
.controller('organizationSubvaultsController', function ($scope, $state, apiService) {
.controller('organizationSubvaultsController', function ($scope, $state, apiService, $uibModal, cipherService) {
$scope.subvaults = [];
$scope.loading = true;
$scope.$on('$viewContentLoaded', function () {
loadList();
});
$scope.add = function () {
var modal = $uibModal.open({
animation: true,
templateUrl: 'app/organization/views/organizationSubvaultsAdd.html',
controller: 'organizationSubvaultsAddController'
});
modal.result.then(function (subvault) {
$scope.subvaults.push(subvault);
});
};
$scope.delete = function (subvault) {
if (!confirm('Are you sure you want to delete this subvault (' + subvault.name + ')?')) {
return;
}
apiService.subvaults.del({ orgId: $state.params.orgId, id: subvault.id }, function () {
var index = $scope.subvaults.indexOf(subvault);
if (index > -1) {
$scope.subvaults.splice(index, 1);
}
});
};
function loadList() {
apiService.subvaults.listOrganization({ orgId: $state.params.orgId }, function (list) {
var subvaults = [];
for (var i = 0; i < list.Data.length; i++) {
subvaults.push({
id: list.Data[i].Id,
name: list.Data[i].Name
});
}
$scope.subvaults = subvaults;
$scope.subvaults = cipherService.decryptSubvaults(list.Data, $state.params.orgId, true);
$scope.loading = false;
});
}

View File

@ -9,20 +9,20 @@
<div class="box-header with-border">
<h3 class="box-title">Subvaults</h3>
<div class="box-tools">
<button type="button" class="btn btn-primary btn-sm btn-flat">
New subvault
<button type="button" class="btn btn-primary btn-sm btn-flat" ng-click="add()">
New Subvault
</button>
</div>
</div>
<div class="box-body" ng-class="{'no-padding': subvault.length}">
<div ng-show="loading && !subvault.length">
<div class="box-body" ng-class="{'no-padding': subvaults.length}">
<div ng-show="loading && !subvaults.length">
Loading...
</div>
<div ng-show="!loading && !subvault.length">
<div ng-show="!loading && !subvaults.length">
<p>No subvaults.</p>
<button type="button" ng-click="add()" class="btn btn-default btn-flat">Add a Subvault</button>
</div>
<div class="table-responsive" ng-show="subvault.length">
<div class="table-responsive" ng-show="subvaults.length">
<table class="table table-striped table-hover">
<tbody>
<tr ng-repeat="subvault in subvaults | orderBy: ['name']">
@ -32,13 +32,14 @@
<i class="fa fa-cog"></i> <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#" class="text-danger">Remove</a></li>
<li>
<a href="javascript:void(0)" ng-click="delete(subvault)" class="text-danger">
Delete
</a>
</li>
</ul>
</div>
</td>
<td style="width: 45px;" valign="middle">
<i class="fa fa-share-alt fa-2x"></i>
</td>
<td valign="middle">
{{subvault.name}}
</td>

View File

@ -0,0 +1,28 @@
<div class="modal-header">
<button type="button" class="close" ng-click="close()" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title"><i class="fa fa-share-alt"></i> Add Subvault</h4>
</div>
<form name="form" ng-submit="form.$valid && submit(model)" api-form="submitPromise">
<div class="modal-body">
<p>
Add a subvault.
</p>
<div class="callout callout-danger validation-errors" ng-show="form.$errors">
<h4>Errors have occured</h4>
<ul>
<li ng-repeat="e in form.$errors">{{e}}</li>
</ul>
</div>
<div class="form-group" show-errors>
<label for="email">Name</label>
<input type="text" id="name" name="Name" ng-model="model.name" class="form-control" required api-field />
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary btn-flat" ng-disabled="form.$loading">
<i class="fa fa-refresh fa-spin loading-icon" ng-show="form.$loading"></i>Submit
</button>
<button type="button" class="btn btn-default btn-flat" ng-click="close()">Close</button>
</div>
</form>

View File

@ -29,15 +29,6 @@
del: { url: _apiUri + '/ciphers/:id/delete', method: 'POST', params: { id: '@id' } }
});
_service.subvaults = $resource(_apiUri + '/subvaults/:id', {}, {
get: { method: 'GET', params: { id: '@id' } },
list: { method: 'GET', params: {} },
listOrganization: { url: _apiUri + '/subvaults/organization/:orgId', method: 'GET', params: { orgId: '@orgId' } },
post: { method: 'POST', params: {} },
put: { method: 'POST', params: { id: '@id' } },
del: { url: _apiUri + '/subvaults/:id/delete', method: 'POST', params: { id: '@id' } }
});
_service.organizations = $resource(_apiUri + '/organizations/:id', {}, {
get: { method: 'GET', params: { id: '@id' } },
getExtended: { url: _apiUri + '/organizations/:id/extended', method: 'GET', params: { id: '@id' } },
@ -56,6 +47,15 @@
del: { url: _apiUri + '/organizations/:orgId/users/:id/delete', method: 'POST', params: { id: '@id', orgId: '@orgId' } }
});
_service.subvaults = $resource(_apiUri + '/organizations/:orgId/subvaults/:id', {}, {
get: { method: 'GET', params: { id: '@id', orgId: '@orgId' } },
listMe: { url: _apiUri + '/subvaults', method: 'GET', params: {} },
listOrganization: { method: 'GET', params: { orgId: '@orgId' } },
post: { method: 'POST', params: { orgId: '@orgId' } },
put: { method: 'POST', params: { id: '@id', orgId: '@orgId' } },
del: { url: _apiUri + '/organizations/:orgId/subvaults/:id/delete', method: 'POST', params: { id: '@id', orgId: '@orgId' } }
});
_service.accounts = $resource(_apiUri + '/accounts', {}, {
register: { url: _apiUri + '/accounts/register', method: 'POST', params: {} },
emailToken: { url: _apiUri + '/accounts/email-token', method: 'POST', params: {} },

View File

@ -61,21 +61,6 @@ angular
username: decryptProperty(encryptedCipher.Data.Username, key, true)
};
try {
login.name = cryptoService.decrypt(encryptedCipher.Data.Name, key);
}
catch (err) {
login.name = '[error: cannot decrypt]';
}
try {
login.username = encryptedCipher.Data.Username && encryptedCipher.Data.Username !== '' ?
cryptoService.decrypt(encryptedCipher.Data.Username, key) : null;
}
catch (err) {
login.username = '[error: cannot decrypt]';
}
return login;
};
@ -109,6 +94,31 @@ angular
};
};
_service.decryptSubvaults = function (encryptedSubvaults, orgId, catchError) {
if (!encryptedSubvaults) throw "encryptedSubvaults is undefined or null";
var unencryptedSubvaults = [];
for (var i = 0; i < encryptedSubvaults.length; i++) {
unencryptedSubvaults.push(_service.decryptSubvault(encryptedSubvaults[i], orgId, catchError));
}
return unencryptedSubvaults;
};
_service.decryptSubvault = function (encryptedSubvault, orgId, catchError) {
if (!encryptedSubvault) throw "encryptedSubvault is undefined or null";
catchError = catchError === true ? true : false;
orgId = orgId || encryptedSubvault.OrganizationId;
var key = cryptoService.getOrgKey(orgId);
return {
id: encryptedSubvault.Id,
name: catchError ? decryptProperty(encryptedSubvault.Name, key, false) :
cryptoService.decrypt(encryptedSubvault.Name, key)
};
};
function decryptProperty(property, key, checkEmpty) {
if (checkEmpty && (!property || property === '')) {
return null;
@ -172,5 +182,25 @@ angular
};
};
_service.encryptSubvaults = function (unencryptedSubvaults, orgId) {
if (!unencryptedSubvaults) throw "unencryptedSubvaults is undefined or null";
var encryptedSubvaults = [];
for (var i = 0; i < unencryptedSubvaults.length; i++) {
encryptedSubvaults.push(_service.encryptSubvault(unencryptedSubvaults[i], orgId));
}
return encryptedSubvaults;
};
_service.encryptSubvault = function (unencryptedSubvault, orgId) {
if (!unencryptedSubvault) throw "unencryptedSubvault is undefined or null";
return {
id: unencryptedSubvault.id,
name: cryptoService.encrypt(unencryptedSubvault.name, cryptoService.getOrgKey(orgId))
};
};
return _service;
});

View File

@ -125,6 +125,7 @@
<script src="app/organization/organizationPeopleController.js"></script>
<script src="app/organization/organizationPeopleInviteController.js"></script>
<script src="app/organization/organizationSubvaultsController.js"></script>
<script src="app/organization/organizationSubvaultsAddController.js"></script>
<script src="app/settings/settingsModule.js"></script>
<script src="app/settings/settingsController.js"></script>