1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-30 08:10:34 +01:00

add/edit logins from org admin vault

This commit is contained in:
Kyle Spearrin 2017-04-27 14:47:44 -04:00
parent df42c6176d
commit b5f8b1014e
12 changed files with 204 additions and 8 deletions

View File

@ -44,6 +44,10 @@ angular
$state.go('backend.user.vault');
};
$scope.searchOrganizationVault = function () {
$state.go('backend.org.vault', { orgId: $state.params.orgId });
};
$scope.addLogin = function () {
$scope.$broadcast('vaultAddLogin');
};
@ -52,6 +56,10 @@ angular
$scope.$broadcast('vaultAddFolder');
};
$scope.addOrganizationLogin = function () {
$scope.$broadcast('organizationVaultAddLogin');
};
// Append dropdown menu somewhere else
var bodyScrollbarWidth,
appendedDropdownMenu,

View File

@ -0,0 +1,50 @@
angular
.module('bit.vault')
.controller('organizationVaultAddLoginController', function ($scope, apiService, $uibModalInstance, cryptoService,
cipherService, passwordService, $analytics, orgId) {
$analytics.eventTrack('organizationVaultAddLoginController', { category: 'Modal' });
$scope.login = {};
$scope.hideFolders = $scope.hideFavorite = true;
$scope.savePromise = null;
$scope.save = function (model) {
model.organizationId = orgId;
var login = cipherService.encryptLogin(model);
$scope.savePromise = apiService.logins.postAdmin(login, function (loginResponse) {
$analytics.eventTrack('Created Organization Login');
var decLogin = cipherService.decryptLogin(loginResponse);
$uibModalInstance.close(decLogin);
}).$promise;
};
$scope.generatePassword = function () {
if (!$scope.login.password || confirm('Are you sure you want to overwrite the current password?')) {
$analytics.eventTrack('Generated Password From Add');
$scope.login.password = passwordService.generatePassword({ length: 12, special: true });
}
};
$scope.clipboardSuccess = function (e) {
e.clearSelection();
selectPassword(e);
};
$scope.clipboardError = function (e, password) {
if (password) {
selectPassword(e);
}
alert('Your web browser does not support easy clipboard copying. Copy it manually instead.');
};
function selectPassword(e) {
var target = $(e.trigger).parent().prev();
if (target.attr('type') === 'text') {
target.select();
}
}
$scope.close = function () {
$uibModalInstance.dismiss('close');
};
});

View File

@ -77,6 +77,49 @@
}
};
$scope.editLogin = function (login) {
var editModel = $uibModal.open({
animation: true,
templateUrl: 'app/vault/views/vaultEditLogin.html',
controller: 'organizationVaultEditLoginController',
resolve: {
loginId: function () { return login.id; }
}
});
editModel.result.then(function (returnVal) {
if (returnVal.action === 'edit') {
login.name = returnVal.data.name;
login.username = returnVal.data.username;
}
else if (returnVal.action === 'delete') {
var index = $scope.logins.indexOf(login);
if (index > -1) {
$scope.logins.splice(index, 1);
}
}
});
};
$scope.$on('organizationVaultAddLogin', function (event, args) {
$scope.addLogin();
});
$scope.addLogin = function () {
var addModel = $uibModal.open({
animation: true,
templateUrl: 'app/vault/views/vaultAddLogin.html',
controller: 'organizationVaultAddLoginController',
resolve: {
orgId: function () { return $state.params.orgId; }
}
});
addModel.result.then(function (addedLogin) {
$scope.logins.push(addedLogin);
});
};
$scope.editCollections = function (cipher) {
var modal = $uibModal.open({
animation: true,

View File

@ -0,0 +1,69 @@
angular
.module('bit.vault')
.controller('organizationVaultEditLoginController', function ($scope, apiService, $uibModalInstance, cryptoService,
cipherService, passwordService, loginId, $analytics) {
$analytics.eventTrack('organizationVaultEditLoginController', { category: 'Modal' });
$scope.login = {};
$scope.hideFolders = $scope.hideFavorite = true;
apiService.logins.getAdmin({ id: loginId }, function (login) {
$scope.login = cipherService.decryptLogin(login);
});
$scope.save = function (model) {
var login = cipherService.encryptLogin(model);
$scope.savePromise = apiService.logins.putAdmin({ id: loginId }, login, function (loginResponse) {
$analytics.eventTrack('Edited Organization Login');
var decLogin = cipherService.decryptLogin(loginResponse);
$uibModalInstance.close({
action: 'edit',
data: decLogin
});
}).$promise;
};
$scope.generatePassword = function () {
if (!$scope.login.password || confirm('Are you sure you want to overwrite the current password?')) {
$analytics.eventTrack('Generated Password From Edit');
$scope.login.password = passwordService.generatePassword({ length: 12, special: true });
}
};
$scope.clipboardSuccess = function (e) {
e.clearSelection();
selectPassword(e);
};
$scope.clipboardError = function (e, password) {
if (password) {
selectPassword(e);
}
alert('Your web browser does not support easy clipboard copying. Copy it manually instead.');
};
function selectPassword(e) {
var target = $(e.trigger).parent().prev();
if (target.attr('type') === 'text') {
target.select();
}
}
$scope.delete = function () {
if (!confirm('Are you sure you want to delete this login (' + $scope.login.name + ')?')) {
return;
}
apiService.ciphers.delAdmin({ id: $scope.login.id }, function () {
$analytics.eventTrack('Deleted Organization Login From Edit');
$uibModalInstance.close({
action: 'delete',
data: $scope.login.id
});
});
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
});

View File

@ -13,7 +13,7 @@
<p ng-show="loading && !collections.length">Loading...</p>
<div class="box" ng-class="{'collapsed-box': collection.collapsed}" ng-repeat="collection in collections |
orderBy: collectionSort track by collection.id"
ng-show="collections.length">
ng-show="collections.length && (!main.searchVaultText || collectionLogins.length)">
<div class="box-header with-border">
<h3 class="box-title">
<i class="fa" ng-class="{'fa-share-alt-square': collection.id, 'fa-sitemap': !collection.id}"></i>
@ -34,13 +34,18 @@
<table class="table table-striped table-hover table-vmiddle">
<tbody>
<tr ng-repeat="login in collectionLogins = (logins | filter: filterByCollection(collection) |
orderBy: ['name', 'username']) track by login.id">
filter: (main.searchVaultText || '') | orderBy: ['name', 'username']) track by login.id">
<td style="width: 70px;">
<div class="btn-group" data-append-to="body">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-cog"></i> <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>
<a href="javascript:void(0)" ng-click="editLogin(login)">
<i class="fa fa-fw fa-pencil"></i> Edit
</a>
</li>
<li>
<a href="javascript:void(0)" ng-click="editCollections(login)">
<i class="fa fa-fw fa-share-alt"></i> Collections
@ -61,7 +66,7 @@
</div>
</td>
<td>
<a href="javascript:void(0)" ng-click="editCollections(login)">{{login.name}}</a>
<a href="javascript:void(0)" ng-click="editLogin(login)">{{login.name}}</a>
<div class="text-sm text-muted">{{login.username}}</div>
</td>
</tr>

View File

@ -7,9 +7,12 @@
_service.logins = $resource(_apiUri + '/logins/:id', {}, {
get: { method: 'GET', params: { id: '@id' } },
getAdmin: { url: _apiUri + '/logins/:id/admin', method: 'GET', params: { id: '@id' } },
list: { method: 'GET', params: {} },
post: { method: 'POST', params: {} },
postAdmin: { url: _apiUri + '/logins/admin', method: 'POST', params: {} },
put: { method: 'POST', params: { id: '@id' } },
putAdmin: { url: _apiUri + '/logins/:id/admin', method: 'POST', params: { id: '@id' } },
del: { url: _apiUri + '/logins/:id/delete', method: 'POST', params: { id: '@id' } }
});

View File

@ -79,6 +79,7 @@
}
apiService.logins.del({ id: $scope.login.id }, function () {
$analytics.eventTrack('Deleted Login From Edit');
$uibModalInstance.close({
action: 'delete',
data: $scope.login.id

View File

@ -17,7 +17,7 @@
<input type="text" id="name" name="Name" ng-model="login.name" class="form-control" required api-field />
</div>
</div>
<div class="col-md-6">
<div class="col-md-6" ng-if="!hideFolders">
<div class="form-group" show-errors>
<label for="folder">Folder</label>
<select id="folder" name="FolderId" ng-model="login.folderId" class="form-control" api-field>
@ -82,7 +82,7 @@
<label for="notes">Notes</label>
<textarea id="notes" name="Notes" class="form-control" ng-model="login.notes" api-field></textarea>
</div>
<div class="checkbox">
<div class="checkbox" ng-if="!hideFavorite">
<label>
<input type="checkbox" ng-model="login.favorite" name="Favorite" />
Favorite

View File

@ -20,7 +20,7 @@
ng-readonly="readOnly" required api-field />
</div>
</div>
<div class="col-md-6">
<div class="col-md-6" ng-if="!hideFolders">
<div class="form-group" show-errors>
<label for="folder">Folder</label>
<select id="folder" name="FolderId" ng-model="login.folderId" class="form-control" api-field>
@ -96,7 +96,7 @@
<textarea id="notes" name="Notes" class="form-control" ng-model="login.notes"
ng-readonly="readOnly" api-field></textarea>
</div>
<div class="checkbox">
<div class="checkbox" ng-if="!hideFavorite">
<label>
<input type="checkbox" ng-model="login.favorite" name="Favorite" />
Favorite

View File

@ -29,6 +29,14 @@
<a ui-sref="backend.user.vault"><i class="fa fa-arrow-left"></i> Return to my vault</a>
</div>
</div>
<form class="sidebar-form">
<label for="search" class="sr-only">Search</label>
<div class="form-group has-feedback">
<input type="text" id="search" class="form-control" placeholder="Search org. vault..."
ng-focus="searchOrganizationVault()" ng-model="main.searchVaultText" />
<span class="fa fa-search form-control-feedback" aria-hidden="true"></span>
</div>
</form>
<ul class="sidebar-menu">
<li class="header">MY ORGANIZATION</li>
<li ng-class="{active: $state.is('backend.org.dashboard')}">
@ -40,6 +48,13 @@
<a ui-sref="backend.org.vault({orgId: params.orgId})">
<i class="fa fa-lock fa-fw"></i> <span>Vault</span>
</a>
<ul class="treeview-menu" ng-class="{'menu-open': $state.includes('backend.org.vault')}">
<li>
<a href="javascript:void(0)" ng-click="addOrganizationLogin()">
<i class="fa fa-plus-circle fa-fw"></i> New Login
</a>
</li>
</ul>
</li>
<li ng-class="{active: $state.is('backend.org.collections')}">
<a ui-sref="backend.org.collections({orgId: params.orgId})">

View File

@ -32,7 +32,7 @@
<form class="sidebar-form">
<label for="search" class="sr-only">Search</label>
<div class="form-group has-feedback">
<input type="text" id="search" class="form-control" placeholder="Search vault..."
<input type="text" id="search" class="form-control" placeholder="Search my vault..."
ng-focus="searchVault()" ng-model="main.searchVaultText" />
<span class="fa fa-search form-control-feedback" aria-hidden="true"></span>
</div>

View File

@ -145,6 +145,8 @@
<script src="app/organization/organizationDeleteController.js"></script>
<script src="app/organization/organizationBillingChangePlanController.js"></script>
<script src="app/organization/organizationVaultController.js"></script>
<script src="app/organization/organizationVaultAddLoginController.js"></script>
<script src="app/organization/organizationVaultEditLoginController.js"></script>
<script src="app/organization/organizationVaultLoginCollectionsController.js"></script>
<script src="app/organization/organizationGroupsController.js"></script>
<script src="app/organization/organizationCollectionsGroupsController.js"></script>