mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-23 11:56:00 +01:00
manage groups from collection add/edit
This commit is contained in:
parent
f7d1b8821c
commit
1f73269480
@ -2,11 +2,85 @@
|
||||
.module('bit.organization')
|
||||
|
||||
.controller('organizationCollectionsAddController', function ($scope, $state, $uibModalInstance, apiService, cipherService,
|
||||
$analytics) {
|
||||
$analytics, authService) {
|
||||
$analytics.eventTrack('organizationCollectionsAddController', { category: 'Modal' });
|
||||
$scope.groups = [];
|
||||
$scope.selectedGroups = {};
|
||||
$scope.loading = true;
|
||||
$scope.useGroups = false;
|
||||
|
||||
$uibModalInstance.opened.then(function () {
|
||||
return authService.getUserProfile();
|
||||
}).then(function (profile) {
|
||||
if (profile.organizations) {
|
||||
var org = profile.organizations[$state.params.orgId];
|
||||
$scope.useGroups = !!org.useGroups;
|
||||
}
|
||||
|
||||
if ($scope.useGroups) {
|
||||
return apiService.groups.listOrganization({ orgId: $state.params.orgId }).$promise;
|
||||
}
|
||||
|
||||
return null;
|
||||
}).then(function (groups) {
|
||||
if (!groups) {
|
||||
$scope.loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var groupsArr = [];
|
||||
for (var i = 0; i < groups.Data.length; i++) {
|
||||
groupsArr.push({
|
||||
id: groups.Data[i].Id,
|
||||
name: groups.Data[i].Name
|
||||
});
|
||||
}
|
||||
|
||||
$scope.groups = groupsArr;
|
||||
$scope.loading = false;
|
||||
});
|
||||
|
||||
$scope.toggleGroupSelectionAll = function ($event) {
|
||||
var groups = {};
|
||||
if ($event.target.checked) {
|
||||
for (var i = 0; i < $scope.groups.length; i++) {
|
||||
groups[$scope.groups[i].id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$scope.selectedGroups = groups;
|
||||
};
|
||||
|
||||
$scope.toggleGroupSelection = function (id) {
|
||||
if (id in $scope.selectedGroups) {
|
||||
delete $scope.selectedGroups[id];
|
||||
}
|
||||
else {
|
||||
$scope.selectedGroups[id] = true;
|
||||
}
|
||||
};
|
||||
|
||||
$scope.groupSelected = function (group) {
|
||||
return group.id in $scope.selectedGroups;
|
||||
};
|
||||
|
||||
$scope.allSelected = function () {
|
||||
return Object.keys($scope.selectedGroups).length === $scope.groups.length;
|
||||
};
|
||||
|
||||
$scope.submit = function (model) {
|
||||
var collection = cipherService.encryptCollection(model, $state.params.orgId);
|
||||
|
||||
if ($scope.useGroups) {
|
||||
collection.groupIds = [];
|
||||
|
||||
for (var id in $scope.selectedGroups) {
|
||||
if ($scope.selectedGroups.hasOwnProperty(id)) {
|
||||
collection.groupIds.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$scope.submitPromise = apiService.collections.post({ orgId: $state.params.orgId }, collection, function (response) {
|
||||
$analytics.eventTrack('Created Collection');
|
||||
var decCollection = cipherService.decryptCollection(response, $state.params.orgId, true);
|
||||
|
@ -2,18 +2,98 @@
|
||||
.module('bit.organization')
|
||||
|
||||
.controller('organizationCollectionsEditController', function ($scope, $state, $uibModalInstance, apiService, cipherService,
|
||||
$analytics, id) {
|
||||
$analytics, id, authService) {
|
||||
$analytics.eventTrack('organizationCollectionsEditController', { category: 'Modal' });
|
||||
$scope.collection = {};
|
||||
$scope.groups = [];
|
||||
$scope.selectedGroups = {};
|
||||
$scope.loading = true;
|
||||
$scope.useGroups = false;
|
||||
|
||||
$uibModalInstance.opened.then(function () {
|
||||
apiService.collections.get({ orgId: $state.params.orgId, id: id }, function (collection) {
|
||||
$scope.collection = cipherService.decryptCollection(collection);
|
||||
});
|
||||
return apiService.collections.getDetails({ orgId: $state.params.orgId, id: id }).$promise;
|
||||
}).then(function (collection) {
|
||||
$scope.collection = cipherService.decryptCollection(collection);
|
||||
|
||||
var groups = {};
|
||||
if (collection.GroupIds) {
|
||||
for (var i = 0; i < collection.GroupIds.length; i++) {
|
||||
groups[collection.GroupIds[i]] = true;
|
||||
}
|
||||
}
|
||||
$scope.selectedGroups = groups;
|
||||
|
||||
return authService.getUserProfile();
|
||||
}).then(function (profile) {
|
||||
if (profile.organizations) {
|
||||
var org = profile.organizations[$state.params.orgId];
|
||||
$scope.useGroups = !!org.useGroups;
|
||||
}
|
||||
|
||||
if ($scope.useGroups) {
|
||||
return apiService.groups.listOrganization({ orgId: $state.params.orgId }).$promise;
|
||||
}
|
||||
|
||||
return null;
|
||||
}).then(function (groups) {
|
||||
if (!groups) {
|
||||
$scope.loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var groupsArr = [];
|
||||
for (var i = 0; i < groups.Data.length; i++) {
|
||||
groupsArr.push({
|
||||
id: groups.Data[i].Id,
|
||||
name: groups.Data[i].Name
|
||||
});
|
||||
}
|
||||
|
||||
$scope.groups = groupsArr;
|
||||
$scope.loading = false;
|
||||
});
|
||||
|
||||
$scope.toggleGroupSelectionAll = function ($event) {
|
||||
var groups = {};
|
||||
if ($event.target.checked) {
|
||||
for (var i = 0; i < $scope.groups.length; i++) {
|
||||
groups[$scope.groups[i].id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$scope.selectedGroups = groups;
|
||||
};
|
||||
|
||||
$scope.toggleGroupSelection = function (id) {
|
||||
if (id in $scope.selectedGroups) {
|
||||
delete $scope.selectedGroups[id];
|
||||
}
|
||||
else {
|
||||
$scope.selectedGroups[id] = true;
|
||||
}
|
||||
};
|
||||
|
||||
$scope.groupSelected = function (group) {
|
||||
return group.id in $scope.selectedGroups;
|
||||
};
|
||||
|
||||
$scope.allSelected = function () {
|
||||
return Object.keys($scope.selectedGroups).length === $scope.groups.length;
|
||||
};
|
||||
|
||||
$scope.submit = function (model) {
|
||||
var collection = cipherService.encryptCollection(model, $state.params.orgId);
|
||||
|
||||
if ($scope.useGroups) {
|
||||
collection.groupIds = [];
|
||||
|
||||
for (var id in $scope.selectedGroups) {
|
||||
if ($scope.selectedGroups.hasOwnProperty(id)) {
|
||||
collection.groupIds.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$scope.submitPromise = apiService.collections.put({ orgId: $state.params.orgId }, collection, function (response) {
|
||||
$analytics.eventTrack('Edited Collection');
|
||||
var decCollection = cipherService.decryptCollection(response, $state.params.orgId, true);
|
||||
|
@ -24,6 +24,43 @@
|
||||
<label for="email">Name</label>
|
||||
<input type="text" id="name" name="Name" ng-model="model.name" class="form-control" required api-field />
|
||||
</div>
|
||||
<div ng-if="useGroups">
|
||||
<h4>Group Access</h4>
|
||||
<div ng-show="loading && !groups.length">
|
||||
Loading groups...
|
||||
</div>
|
||||
<div ng-show="!loading && !groups.length">
|
||||
<p>No groups for your organization.</p>
|
||||
</div>
|
||||
<div class="table-responsive" ng-show="groups.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="allSelected()"
|
||||
ng-click="toggleGroupSelectionAll($event)">
|
||||
</th>
|
||||
<th>Name</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="group in groups | orderBy: ['name']">
|
||||
<td valign="middle">
|
||||
<input type="checkbox"
|
||||
name="selectedGroups[]"
|
||||
value="{{group.id}}"
|
||||
ng-checked="groupSelected(group)"
|
||||
ng-click="toggleGroupSelection(group.id)">
|
||||
</td>
|
||||
<td valign="middle">
|
||||
{{group.name}}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary btn-flat" ng-disabled="form.$loading">
|
||||
|
@ -25,6 +25,43 @@
|
||||
<label for="email">Name</label>
|
||||
<input type="text" id="name" name="Name" ng-model="collection.name" class="form-control" required api-field />
|
||||
</div>
|
||||
<div ng-if="useGroups">
|
||||
<h4>Group Access</h4>
|
||||
<div ng-show="loading && !groups.length">
|
||||
Loading groups...
|
||||
</div>
|
||||
<div ng-show="!loading && !groups.length">
|
||||
<p>No groups for your organization.</p>
|
||||
</div>
|
||||
<div class="table-responsive" ng-show="groups.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="allSelected()"
|
||||
ng-click="toggleGroupSelectionAll($event)">
|
||||
</th>
|
||||
<th>Name</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="group in groups | orderBy: ['name']">
|
||||
<td valign="middle">
|
||||
<input type="checkbox"
|
||||
name="selectedGroups[]"
|
||||
value="{{group.id}}"
|
||||
ng-checked="groupSelected(group)"
|
||||
ng-click="toggleGroupSelection(group.id)">
|
||||
</td>
|
||||
<td valign="middle">
|
||||
{{group.name}}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary btn-flat" ng-disabled="form.$loading">
|
||||
|
@ -69,6 +69,7 @@
|
||||
|
||||
_service.collections = $resource(_apiUri + '/organizations/:orgId/collections/:id', {}, {
|
||||
get: { method: 'GET', params: { id: '@id', orgId: '@orgId' } },
|
||||
getDetails: { url: _apiUri + '/organizations/:orgId/collections/:id/details', method: 'GET', params: { id: '@id', orgId: '@orgId' } },
|
||||
listMe: { url: _apiUri + '/collections', method: 'GET', params: {} },
|
||||
listOrganization: { method: 'GET', params: { orgId: '@orgId' } },
|
||||
post: { method: 'POST', params: { orgId: '@orgId' } },
|
||||
|
Loading…
Reference in New Issue
Block a user