1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-27 17:18:04 +01:00

org people subvault selection

This commit is contained in:
Kyle Spearrin 2017-03-11 23:02:43 -05:00
parent 0acab61f2e
commit 6ece16ccc9
7 changed files with 273 additions and 4 deletions

View File

@ -39,6 +39,21 @@
});
};
$scope.edit = function (id) {
var modal = $uibModal.open({
animation: true,
templateUrl: 'app/organization/views/organizationPeopleEdit.html',
controller: 'organizationPeopleEditController',
resolve: {
id: function () { return id; }
}
});
modal.result.then(function () {
loadList();
});
};
function loadList() {
apiService.organizationUsers.list({ orgId: $state.params.orgId }, function (list) {
var users = [];

View File

@ -0,0 +1,90 @@
angular
.module('bit.organization')
.controller('organizationPeopleEditController', function ($scope, $state, $uibModalInstance, apiService, cipherService, id) {
$scope.loading = true;
$scope.selectedSubvaults = [];
$scope.selectedSubvaultsReadOnly = [];
$uibModalInstance.opened.then(function () {
apiService.subvaults.listOrganization({ orgId: $state.params.orgId }, function (list) {
$scope.subvaults = cipherService.decryptSubvaults(list.Data, $state.params.orgId, true);
$scope.loading = false;
});
apiService.organizationUsers.get({ orgId: $state.params.orgId, id: id }, function (user) {
if (user && user.Subvaults) {
var subvaults = [];
var subvaultsReadOnly = [];
for (var i = 0; i < user.Subvaults.Data.length; i++) {
subvaults.push(user.Subvaults.Data[i].SubvaultId);
if (user.Subvaults.Data[i].ReadOnly) {
subvaultsReadOnly.push(user.Subvaults.Data[i].SubvaultId);
}
}
}
$scope.selectedSubvaults = subvaults;
$scope.selectedSubvaultsReadOnly = subvaultsReadOnly;
});
});
$scope.toggleSubvaultSelectionAll = function ($event) {
var subvaultIds = [];
if ($event.target.checked) {
for (var i = 0; i < $scope.subvaults.length; i++) {
subvaultIds.push($scope.subvaults[i].id);
}
}
else {
$scope.selectedSubvaultsReadOnly = [];
}
$scope.selectedSubvaults = subvaultIds;
};
$scope.toggleSubvaultSelection = function (id) {
var i = $scope.selectedSubvaults.indexOf(id);
if (i > -1) {
$scope.selectedSubvaults.splice(i, 1);
var j = $scope.selectedSubvaultsReadOnly.indexOf(id);
if (j > -1) {
$scope.selectedSubvaultsReadOnly.splice(j, 1);
}
}
else {
$scope.selectedSubvaults.push(id);
}
};
$scope.toggleSubvaultReadOnlySelection = function (id) {
var i = $scope.selectedSubvaultsReadOnly.indexOf(id);
if (i > -1) {
$scope.selectedSubvaultsReadOnly.splice(i, 1);
}
else {
$scope.selectedSubvaultsReadOnly.push(id);
}
};
$scope.submit = function (model) {
var subvaults = [];
for (var i = 0; i < $scope.selectedSubvaults.length; i++) {
subvaults.push({
id: null,
subvaultId: $scope.selectedSubvaults[i],
readOnly: $scope.selectedSubvaultsReadOnly.indexOf($scope.selectedSubvaults[i]) > -1
});
}
apiService.organizationUsers.put({ orgId: $state.params.orgId, id: 0 }, {
subvaults: subvaults
}, function () {
$uibModalInstance.close();
});
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
});

View File

@ -1,9 +1,71 @@
angular
.module('bit.organization')
.controller('organizationPeopleInviteController', function ($scope, $state, $uibModalInstance, apiService) {
.controller('organizationPeopleInviteController', function ($scope, $state, $uibModalInstance, apiService, cipherService) {
$scope.loading = true;
$scope.selectedSubvaults = [];
$scope.selectedSubvaultsReadOnly = [];
$uibModalInstance.opened.then(function () {
apiService.subvaults.listOrganization({ orgId: $state.params.orgId }, function (list) {
$scope.subvaults = cipherService.decryptSubvaults(list.Data, $state.params.orgId, true);
$scope.loading = false;
});
});
$scope.toggleSubvaultSelectionAll = function ($event) {
var subvaultIds = [];
if ($event.target.checked)
{
for (var i = 0; i < $scope.subvaults.length; i++) {
subvaultIds.push($scope.subvaults[i].id);
}
}
else {
$scope.selectedSubvaultsReadOnly = [];
}
$scope.selectedSubvaults = subvaultIds;
};
$scope.toggleSubvaultSelection = function (id) {
var i = $scope.selectedSubvaults.indexOf(id);
if (i > -1) {
$scope.selectedSubvaults.splice(i, 1);
var j = $scope.selectedSubvaultsReadOnly.indexOf(id);
if (j > -1) {
$scope.selectedSubvaultsReadOnly.splice(j, 1);
}
}
else {
$scope.selectedSubvaults.push(id);
}
};
$scope.toggleSubvaultReadOnlySelection = function (id) {
var i = $scope.selectedSubvaultsReadOnly.indexOf(id);
if (i > -1) {
$scope.selectedSubvaultsReadOnly.splice(i, 1);
}
else {
$scope.selectedSubvaultsReadOnly.push(id);
}
};
$scope.submit = function (model) {
apiService.organizationUsers.invite({ orgId: $state.params.orgId }, { email: model.email }, function () {
var subvaults = [];
for (var i = 0; i < $scope.selectedSubvaults.length; i++) {
subvaults.push({
subvaultId: $scope.selectedSubvaults[i],
readOnly: $scope.selectedSubvaultsReadOnly.indexOf($scope.selectedSubvaults[i]) > -1
});
}
apiService.organizationUsers.invite({ orgId: $state.params.orgId }, {
email: model.email,
subvaults: subvaults
}, function () {
$uibModalInstance.close();
});
};

View File

@ -41,7 +41,7 @@
class="img-circle" alt="User Image">
</td>
<td valign="middle">
{{user.email}}
<a href="javascript:void(0)" ng-click="edit(user.id)">{{user.email}}</a>
<div ng-if="user.name"><small class="text-muted">{{user.name}}</small></div>
</td>
<td style="width: 80px;" valign="middle">

View File

@ -0,0 +1,58 @@
<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-user"></i> Edit User</h4>
</div>
<form name="form" ng-submit="form.$valid && submit()" api-form="submitPromise">
<div class="modal-body">
<h4>Subvault Access</h4>
<div ng-show="loading && !subvaults.length">
Loading...
</div>
<div ng-show="!loading && !subvaults.length">
<p>No subvaults.</p>
</div>
<div class="table-responsive" ng-show="subvaults.length" style="margin: 0;">
<table class="table table-striped table-hover" style="margin: 0;">
<thead>
<tr>
<th style="width: 40px;">
<input type="checkbox"
ng-checked="selectedSubvaults.length === subvaults.length"
ng-click="toggleSubvaultSelectionAll($event)">
</th>
<th>Name</th>
<th style="width: 100px; text-align: center;">Read Only</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="subvault in subvaults | orderBy: ['name']">
<td style="width: 40px;" valign="middle">
<input type="checkbox"
name="selectedSubvaults[]"
value="{{subvault.id}}"
ng-checked="selectedSubvaults.indexOf(subvault.id) > -1"
ng-click="toggleSubvaultSelection(subvault.id)">
</td>
<td valign="middle">
{{subvault.name}}
</td>
<td style="width: 100px; text-align: center;" valign="middle">
<input type="checkbox"
name="selectedSubvaultsReadonly[]"
value="{{subvault.id}}"
ng-disabled="selectedSubvaults.indexOf(subvault.id) === -1"
ng-checked="selectedSubvaultsReadOnly.indexOf(subvault.id) > -1"
ng-click="toggleSubvaultReadOnlySelection(subvault.id)">
</td>
</tr>
</tbody>
</table>
</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

@ -18,6 +18,50 @@
<label for="email">Email</label>
<input type="email" id="email" name="Email" ng-model="model.email" class="form-control" required api-field />
</div>
<h4>Subvault Access</h4>
<div ng-show="loading && !subvaults.length">
Loading...
</div>
<div ng-show="!loading && !subvaults.length">
<p>No subvaults.</p>
</div>
<div class="table-responsive" ng-show="subvaults.length" style="margin: 0;">
<table class="table table-striped table-hover" style="margin: 0;">
<thead>
<tr>
<th style="width: 40px;">
<input type="checkbox"
ng-checked="selectedSubvaults.length === subvaults.length"
ng-click="toggleSubvaultSelectionAll($event)">
</th>
<th>Name</th>
<th style="width: 100px; text-align: center;">Read Only</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="subvault in subvaults | orderBy: ['name']">
<td style="width: 40px;" valign="middle">
<input type="checkbox"
name="selectedSubvaults[]"
value="{{subvault.id}}"
ng-checked="selectedSubvaults.indexOf(subvault.id) > -1"
ng-click="toggleSubvaultSelection(subvault.id)">
</td>
<td valign="middle">
{{subvault.name}}
</td>
<td style="width: 100px; text-align: center;" valign="middle">
<input type="checkbox"
name="selectedSubvaultsReadonly[]"
value="{{subvault.id}}"
ng-disabled="selectedSubvaults.indexOf(subvault.id) === -1"
ng-checked="selectedSubvaultsReadOnly.indexOf(subvault.id) > -1"
ng-click="toggleSubvaultReadOnlySelection(subvault.id)">
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary btn-flat" ng-disabled="inviteForm.$loading">
@ -26,4 +70,3 @@
<button type="button" class="btn btn-default btn-flat" ng-click="close()">Close</button>
</div>
</form>

View File

@ -124,6 +124,7 @@
<script src="app/organization/organizationDashboardController.js"></script>
<script src="app/organization/organizationPeopleController.js"></script>
<script src="app/organization/organizationPeopleInviteController.js"></script>
<script src="app/organization/organizationPeopleEditController.js"></script>
<script src="app/organization/organizationSubvaultsController.js"></script>
<script src="app/organization/organizationSubvaultsAddController.js"></script>