1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-09 05:57:40 +02:00
bitwarden-browser/src/app/organization/organizationGroupsUsersController.js
2017-05-09 19:23:49 -04:00

58 lines
2.2 KiB
JavaScript

angular
.module('bit.organization')
.controller('organizationGroupsUsersController', function ($scope, $state, $uibModalInstance, apiService,
$analytics, group, toastr) {
$analytics.eventTrack('organizationGroupUsersController', { category: 'Modal' });
$scope.loading = true;
$scope.group = group;
$scope.users = [];
$uibModalInstance.opened.then(function () {
return apiService.groups.listUsers({
orgId: $state.params.orgId,
id: group.id
}).$promise;
}).then(function (userList) {
var users = [];
if (userList && userList.Data.length) {
for (var i = 0; i < userList.Data.length; i++) {
users.push({
organizationUserId: userList.Data[i].OrganizationUserId,
name: userList.Data[i].Name,
email: userList.Data[i].Email,
type: userList.Data[i].Type,
status: userList.Data[i].Status,
accessAll: userList.Data[i].AccessAll
});
}
}
$scope.users = users;
$scope.loading = false;
});
$scope.remove = function (user) {
if (!confirm('Are you sure you want to remove this user (' + user.email + ') from this ' +
'group (' + group.name + ')?')) {
return;
}
apiService.groups.delUser({ orgId: $state.params.orgId, id: group.id, orgUserId: user.organizationUserId }, null,
function () {
toastr.success(user.email + ' has been removed.', 'User Removed');
$analytics.eventTrack('Removed User From Group');
var index = $scope.users.indexOf(user);
if (index > -1) {
$scope.users.splice(index, 1);
}
}, function () {
toastr.error('Unable to remove user.', 'Error');
});
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
});