2018-01-22 13:01:38 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
2020-06-03 23:08:05 +02:00
|
|
|
/* global angular */
|
|
|
|
|
/* global Clipboard */
|
|
|
|
|
/* global async */
|
|
|
|
|
/* global $ */
|
2018-01-24 16:20:56 +01:00
|
|
|
|
2020-11-13 16:44:39 +01:00
|
|
|
angular.module('Application').controller('UsersController', ['$scope', '$location', '$translate', '$timeout', 'Client', function ($scope, $location, $translate, $timeout, Client) {
|
2020-02-24 12:56:13 +01:00
|
|
|
Client.onReady(function () { if (!Client.getUserInfo().isAtLeastUserManager) $location.path('/'); });
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2019-10-25 15:38:04 -07:00
|
|
|
$scope.ldapProvider = [
|
|
|
|
|
{ name: 'Active Directory', value: 'ad' },
|
|
|
|
|
{ name: 'Jumpcloud', value: 'jumpcloud' },
|
|
|
|
|
{ name: 'Okta', value: 'okta' },
|
2020-10-27 19:43:12 +01:00
|
|
|
{ name: 'Univention Corporate Server (UCS)', value: 'univention' },
|
2019-10-25 15:38:04 -07:00
|
|
|
{ name: 'Other', value: 'other' },
|
|
|
|
|
{ name: 'Disabled', value: 'noop' }
|
|
|
|
|
];
|
|
|
|
|
|
2021-03-31 14:20:16 +02:00
|
|
|
$translate(['users.externalLdap.providerOther', 'users.externalLdap.providerDisabled']).then(function (tr) {
|
|
|
|
|
if (tr['users.externalLdap.providerOther']) $scope.ldapProvider.find(function (p) { return p.value === 'other'; }).name = tr['users.externalLdap.providerOther'];
|
|
|
|
|
if (tr['users.externalLdap.providerDisabled']) $scope.ldapProvider.find(function (p) { return p.value === 'noop'; }).name = tr['users.externalLdap.providerDisabled'];
|
|
|
|
|
});
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.ready = false;
|
2020-08-10 13:59:44 -07:00
|
|
|
$scope.users = []; // users of current page
|
2020-01-09 16:21:20 +01:00
|
|
|
$scope.allUsersById = [];
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.groups = [];
|
|
|
|
|
$scope.groupsById = { };
|
|
|
|
|
$scope.config = Client.getConfig();
|
|
|
|
|
$scope.userInfo = Client.getUserInfo();
|
2018-01-23 17:09:47 +01:00
|
|
|
|
2020-06-18 12:29:25 +02:00
|
|
|
$scope.openSubscriptionSetup = function () {
|
|
|
|
|
Client.openSubscriptionSetup($scope.$parent.subscription);
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-23 17:25:47 +01:00
|
|
|
$scope.roles = [];
|
2020-08-10 13:59:44 -07:00
|
|
|
$scope.allUsers = []; // all the users and not just current page, have to load this for group assignment
|
2019-11-05 22:08:48 +01:00
|
|
|
|
2019-01-16 14:02:08 +01:00
|
|
|
$scope.userSearchString = '';
|
2019-01-15 13:30:37 +01:00
|
|
|
$scope.currentPage = 1;
|
|
|
|
|
$scope.pageItemCount = [
|
2020-11-13 16:44:39 +01:00
|
|
|
{ name: $translate.instant('main.pagination.perPageSelector', { n: 20 }), value: 20 },
|
|
|
|
|
{ name: $translate.instant('main.pagination.perPageSelector', { n: 50 }), value: 50 },
|
|
|
|
|
{ name: $translate.instant('main.pagination.perPageSelector', { n: 100 }), value: 100 }
|
2019-01-15 13:30:37 +01:00
|
|
|
];
|
|
|
|
|
$scope.pageItems = $scope.pageItemCount[0];
|
2019-01-16 14:02:08 +01:00
|
|
|
$scope.userRefreshBusy = true;
|
2019-01-15 13:30:37 +01:00
|
|
|
|
2018-07-26 23:58:25 -07:00
|
|
|
$scope.groupMembers = function (group) {
|
2020-01-09 16:21:20 +01:00
|
|
|
return group.userIds.filter(function (uid) { return !!$scope.allUsersById[uid]; }).map(function (uid) { return $scope.allUsersById[uid].username || $scope.allUsersById[uid].email; }).join(' ');
|
2018-07-26 23:58:25 -07:00
|
|
|
};
|
|
|
|
|
|
2020-03-07 14:05:58 -08:00
|
|
|
$scope.canEdit = function (user) {
|
|
|
|
|
let roleInt1 = $scope.roles.findIndex(function (role) { return role.id === $scope.userInfo.role; });
|
|
|
|
|
let roleInt2 = $scope.roles.findIndex(function (role) { return role.id === user.role; });
|
|
|
|
|
|
|
|
|
|
return (roleInt1 - roleInt2) >= 0;
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-14 17:14:32 +01:00
|
|
|
$scope.transferOwnership = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: null,
|
2021-01-19 22:26:43 +01:00
|
|
|
selectedUser: null,
|
2021-01-14 17:14:32 +01:00
|
|
|
|
2021-01-19 22:26:43 +01:00
|
|
|
show: function () {
|
2021-01-14 17:14:32 +01:00
|
|
|
$scope.transferOwnership.error = null;
|
2021-01-19 22:26:43 +01:00
|
|
|
$scope.transferOwnership.selectedUser = null;
|
2021-01-14 17:14:32 +01:00
|
|
|
|
|
|
|
|
$('#transferOwnershipModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.transferOwnership.busy = true;
|
2021-01-14 20:47:30 +01:00
|
|
|
|
2021-01-19 22:26:43 +01:00
|
|
|
Client.changeOwnership($scope.transferOwnership.selectedUser.id, function (error) {
|
2021-01-15 14:28:52 +01:00
|
|
|
$scope.transferOwnership.busy = false;
|
2021-01-14 20:47:30 +01:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
$scope.transferOwnership.error = error.message;
|
|
|
|
|
console.error('Unable to change user role:', error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-15 14:28:52 +01:00
|
|
|
$('#transferOwnershipModal').modal('hide');
|
2021-01-14 20:47:30 +01:00
|
|
|
|
2021-01-15 14:28:52 +01:00
|
|
|
// current user was demoted, reload to refresh UI state
|
|
|
|
|
window.location.reload();
|
2021-01-14 20:47:30 +01:00
|
|
|
});
|
2021-01-14 17:14:32 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.userremove = {
|
|
|
|
|
busy: false,
|
2020-03-06 12:23:50 -08:00
|
|
|
error: null,
|
2018-01-22 13:01:38 -08:00
|
|
|
userInfo: {},
|
|
|
|
|
|
|
|
|
|
show: function (userInfo) {
|
2020-03-06 12:23:50 -08:00
|
|
|
$scope.userremove.error = null;
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.userremove.userInfo = userInfo;
|
|
|
|
|
|
|
|
|
|
$('#userRemoveModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.userremove.busy = true;
|
|
|
|
|
|
2019-07-02 20:22:06 -07:00
|
|
|
Client.removeUser($scope.userremove.userInfo.id, function (error) {
|
|
|
|
|
$scope.userremove.busy = false;
|
2018-07-05 13:32:45 -07:00
|
|
|
|
2020-03-06 13:15:57 -08:00
|
|
|
if (error && error.statusCode === 403) return $scope.userremove.error = error.message;
|
2020-03-06 12:23:50 -08:00
|
|
|
else if (error) return console.error('Unable to delete user.', error);
|
2018-07-05 13:32:45 -07:00
|
|
|
|
2019-07-02 20:22:06 -07:00
|
|
|
$scope.userremove.userInfo = {};
|
2018-07-05 13:32:45 -07:00
|
|
|
|
2019-07-02 20:22:06 -07:00
|
|
|
refresh();
|
2020-02-27 15:10:56 +01:00
|
|
|
refreshAllUsers();
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2019-07-02 20:22:06 -07:00
|
|
|
$('#userRemoveModal').modal('hide');
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.useradd = {
|
|
|
|
|
busy: false,
|
|
|
|
|
alreadyTaken: false,
|
|
|
|
|
error: {},
|
|
|
|
|
email: '',
|
2021-10-26 23:39:15 +02:00
|
|
|
fallbackEmail: '',
|
2018-01-22 13:01:38 -08:00
|
|
|
username: '',
|
|
|
|
|
displayName: '',
|
2018-07-24 22:38:53 -07:00
|
|
|
selectedGroups: [],
|
2020-02-24 12:22:07 +01:00
|
|
|
role: 'user',
|
2021-09-16 20:17:37 +02:00
|
|
|
sendInvite: false,
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
show: function () {
|
2020-06-18 12:57:12 +02:00
|
|
|
if ($scope.config.features.userMaxCount && $scope.config.features.userMaxCount <= $scope.allUsers.length) {
|
|
|
|
|
$('#subscriptionRequiredModal').modal('show');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.useradd.error = {};
|
|
|
|
|
$scope.useradd.email = '';
|
2021-10-26 23:39:15 +02:00
|
|
|
$scope.useradd.fallbackEmail = '';
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.useradd.username = '';
|
|
|
|
|
$scope.useradd.displayName = '';
|
2018-07-24 22:38:53 -07:00
|
|
|
$scope.useradd.selectedGroups = [];
|
2020-02-24 12:22:07 +01:00
|
|
|
$scope.useradd.role = 'user';
|
2021-09-16 20:17:37 +02:00
|
|
|
$scope.useradd.sendInvite = false;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
$scope.useradd_form.$setUntouched();
|
|
|
|
|
$scope.useradd_form.$setPristine();
|
|
|
|
|
|
|
|
|
|
$('#userAddModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.useradd.busy = true;
|
|
|
|
|
|
|
|
|
|
$scope.useradd.alreadyTaken = false;
|
|
|
|
|
$scope.useradd.error.email = null;
|
2021-10-26 23:39:15 +02:00
|
|
|
$scope.useradd.error.fallbackEmail = null;
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.useradd.error.username = null;
|
|
|
|
|
$scope.useradd.error.displayName = null;
|
|
|
|
|
|
2018-07-26 15:52:06 -07:00
|
|
|
var user = {
|
|
|
|
|
username: $scope.useradd.username || null,
|
|
|
|
|
email: $scope.useradd.email,
|
2021-10-26 23:39:15 +02:00
|
|
|
fallbackEmail: $scope.useradd.fallbackEmail,
|
2018-07-26 15:52:06 -07:00
|
|
|
displayName: $scope.useradd.displayName,
|
2020-02-21 21:12:25 +01:00
|
|
|
role: $scope.useradd.role
|
2018-07-26 15:52:06 -07:00
|
|
|
};
|
|
|
|
|
|
2021-08-10 13:53:28 -07:00
|
|
|
Client.addUser(user, function (error, userId) {
|
2018-07-24 22:38:53 -07:00
|
|
|
if (error) {
|
|
|
|
|
$scope.useradd.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error.statusCode === 409) {
|
|
|
|
|
if (error.message.toLowerCase().indexOf('email') !== -1) {
|
|
|
|
|
$scope.useradd.error.email = 'Email already taken';
|
|
|
|
|
$scope.useradd_form.email.$setPristine();
|
|
|
|
|
$('#inputUserAddEmail').focus();
|
|
|
|
|
} else if (error.message.toLowerCase().indexOf('username') !== -1 || error.message.toLowerCase().indexOf('mailbox') !== -1) {
|
|
|
|
|
$scope.useradd.error.username = 'Username already taken';
|
|
|
|
|
$scope.useradd_form.username.$setPristine();
|
|
|
|
|
$('#inputUserAddUsername').focus();
|
|
|
|
|
} else {
|
|
|
|
|
// should not happen!!
|
|
|
|
|
console.error(error.message);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
} else if (error.statusCode === 400) {
|
|
|
|
|
if (error.message.toLowerCase().indexOf('email') !== -1) {
|
|
|
|
|
$scope.useradd.error.email = 'Invalid Email';
|
|
|
|
|
$scope.useradd.error.emailAttempted = $scope.useradd.email;
|
|
|
|
|
$scope.useradd_form.email.$setPristine();
|
|
|
|
|
$('#inputUserAddEmail').focus();
|
|
|
|
|
} else if (error.message.toLowerCase().indexOf('username') !== -1) {
|
|
|
|
|
$scope.useradd.error.username = error.message;
|
|
|
|
|
$scope.useradd_form.username.$setPristine();
|
|
|
|
|
$('#inputUserAddUsername').focus();
|
|
|
|
|
} else {
|
|
|
|
|
console.error('Unable to create user.', error.statusCode, error.message);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2018-01-22 13:01:38 -08:00
|
|
|
} else {
|
2018-07-24 22:38:53 -07:00
|
|
|
return console.error('Unable to create user.', error.statusCode, error.message);
|
2018-01-22 13:01:38 -08:00
|
|
|
}
|
|
|
|
|
}
|
2018-07-24 22:38:53 -07:00
|
|
|
|
|
|
|
|
var groupIds = $scope.useradd.selectedGroups.map(function (g) { return g.id; });
|
|
|
|
|
|
2021-09-16 08:40:25 +02:00
|
|
|
Client.setGroups(userId, groupIds, function (error) {
|
2018-07-24 22:38:53 -07:00
|
|
|
$scope.useradd.busy = false;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-08-17 16:01:40 -07:00
|
|
|
if (error) return console.error(error);
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2021-10-27 19:57:57 +02:00
|
|
|
if ($scope.useradd.sendInvite) Client.sendInviteEmail(userId, user.email, function (error) { if (error) console.error('Failed to send invite.', error); });
|
2021-09-16 20:17:37 +02:00
|
|
|
|
2018-07-24 22:38:53 -07:00
|
|
|
refresh();
|
2020-02-27 15:10:56 +01:00
|
|
|
refreshAllUsers();
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-07-24 22:38:53 -07:00
|
|
|
$('#userAddModal').modal('hide');
|
|
|
|
|
});
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.useredit = {
|
|
|
|
|
busy: false,
|
2021-09-16 13:21:55 +02:00
|
|
|
reset2FABusy: false,
|
2018-01-22 13:01:38 -08:00
|
|
|
error: {},
|
|
|
|
|
userInfo: {},
|
2019-08-30 13:32:20 +02:00
|
|
|
|
|
|
|
|
// form fields
|
2018-01-22 13:01:38 -08:00
|
|
|
email: '',
|
|
|
|
|
fallbackEmail: '',
|
2018-01-25 18:17:40 +01:00
|
|
|
aliases: {},
|
2018-07-24 15:17:51 -07:00
|
|
|
displayName: '',
|
2019-08-08 07:39:43 -07:00
|
|
|
active: false,
|
2019-08-30 13:32:20 +02:00
|
|
|
source: '',
|
2018-07-24 21:36:50 -07:00
|
|
|
selectedGroups: [],
|
2020-02-17 14:05:26 +01:00
|
|
|
role: '',
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
show: function (userInfo) {
|
|
|
|
|
$scope.useredit.error = {};
|
|
|
|
|
$scope.useredit.email = userInfo.email;
|
2018-07-24 15:17:51 -07:00
|
|
|
$scope.useredit.displayName = userInfo.displayName;
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.useredit.fallbackEmail = userInfo.fallbackEmail;
|
|
|
|
|
$scope.useredit.userInfo = userInfo;
|
2018-07-24 21:36:50 -07:00
|
|
|
$scope.useredit.selectedGroups = userInfo.groupIds.map(function (gid) { return $scope.groupsById[gid]; });
|
2019-08-08 07:39:43 -07:00
|
|
|
$scope.useredit.active = userInfo.active;
|
2019-08-30 13:32:20 +02:00
|
|
|
$scope.useredit.source = userInfo.source;
|
2020-02-24 12:22:07 +01:00
|
|
|
$scope.useredit.role = userInfo.role;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
$scope.useredit_form.$setPristine();
|
|
|
|
|
$scope.useredit_form.$setUntouched();
|
|
|
|
|
|
|
|
|
|
$('#userEditModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.useredit.error = {};
|
|
|
|
|
$scope.useredit.busy = true;
|
|
|
|
|
|
2018-01-26 15:39:35 +01:00
|
|
|
var userId = $scope.useredit.userInfo.id;
|
2018-01-22 13:01:38 -08:00
|
|
|
var data = {
|
2020-03-05 16:23:27 -08:00
|
|
|
id: userId
|
2018-01-22 13:01:38 -08:00
|
|
|
};
|
|
|
|
|
|
2020-03-05 16:23:27 -08:00
|
|
|
// only send if not the current active user
|
|
|
|
|
if (userId !== $scope.userInfo.id) {
|
|
|
|
|
data.active = $scope.useredit.active;
|
|
|
|
|
data.role = $scope.useredit.role;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 13:32:20 +02:00
|
|
|
// only change those if it is a local user
|
|
|
|
|
if (!$scope.useredit.source) {
|
|
|
|
|
data.email = $scope.useredit.email;
|
|
|
|
|
data.displayName = $scope.useredit.displayName;
|
|
|
|
|
data.fallbackEmail = $scope.useredit.fallbackEmail;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
Client.updateUser(data, function (error) {
|
|
|
|
|
if (error) {
|
|
|
|
|
$scope.useredit.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error.statusCode === 409) {
|
|
|
|
|
$scope.useredit.error.email = 'Email already taken';
|
|
|
|
|
$scope.useredit_form.email.$setPristine();
|
|
|
|
|
$('#inputUserEditEmail').focus();
|
|
|
|
|
} else {
|
2020-10-23 11:47:37 -07:00
|
|
|
$scope.useredit.error.generic = error.message;
|
2018-01-22 13:01:38 -08:00
|
|
|
console.error('Unable to update user:', error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-24 21:36:50 -07:00
|
|
|
var groupIds = $scope.useredit.selectedGroups.map(function (g) { return g.id; });
|
|
|
|
|
|
|
|
|
|
Client.setGroups(data.id, groupIds, function (error) {
|
2018-04-01 20:53:49 +02:00
|
|
|
$scope.useredit.busy = false;
|
2018-07-24 22:38:53 -07:00
|
|
|
|
|
|
|
|
if (error) return console.error('Unable to update groups for user:', error);
|
2018-04-01 20:53:49 +02:00
|
|
|
|
2020-03-05 16:14:03 -08:00
|
|
|
refreshUsers(false);
|
2018-04-01 20:53:49 +02:00
|
|
|
|
|
|
|
|
$('#userEditModal').modal('hide');
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
});
|
2021-09-16 13:21:55 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
reset2FA: function () {
|
|
|
|
|
$scope.useredit.reset2FABusy = true;
|
|
|
|
|
|
|
|
|
|
Client.disableTwoFactorAuthenticationByUserId($scope.useredit.userInfo.id, function (error) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
2021-10-19 19:08:53 -07:00
|
|
|
$timeout(function () {
|
|
|
|
|
$scope.useredit.userInfo.twoFactorAuthenticationEnabled = false;
|
|
|
|
|
$scope.useredit.reset2FABusy = false;
|
|
|
|
|
}, 3000);
|
2021-09-16 13:21:55 +02:00
|
|
|
});
|
2018-01-22 13:01:38 -08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.groupAdd = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
name: '',
|
2018-08-05 22:19:54 -07:00
|
|
|
selectedUsers: [],
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
show: function () {
|
2021-01-13 14:49:23 +01:00
|
|
|
if (!$scope.config.features.userGroups && $scope.groups.length > 0) {
|
2021-01-13 15:03:26 +01:00
|
|
|
$('#subscriptionRequiredGroupModal').modal('show');
|
2021-01-13 14:49:23 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.groupAdd.busy = false;
|
|
|
|
|
|
|
|
|
|
$scope.groupAdd.error = {};
|
|
|
|
|
$scope.groupAdd.name = '';
|
|
|
|
|
|
|
|
|
|
$scope.groupAddForm.$setUntouched();
|
|
|
|
|
$scope.groupAddForm.$setPristine();
|
|
|
|
|
|
|
|
|
|
$('#groupAddModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.groupAdd.busy = true;
|
|
|
|
|
$scope.groupAdd.error = {};
|
|
|
|
|
|
2018-08-05 22:19:54 -07:00
|
|
|
Client.createGroup($scope.groupAdd.name, function (error, result) {
|
|
|
|
|
if (error) {
|
|
|
|
|
$scope.groupAdd.busy = false;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-08-05 22:19:54 -07:00
|
|
|
if (error.statusCode === 409) {
|
|
|
|
|
$scope.groupAdd.error.name = 'Name already taken';
|
|
|
|
|
$scope.groupAddForm.name.$setPristine();
|
|
|
|
|
$('#groupAddName').focus();
|
|
|
|
|
return;
|
|
|
|
|
} else if (error.statusCode === 400) {
|
|
|
|
|
$scope.groupAdd.error.name = error.message;
|
|
|
|
|
$scope.groupAddForm.name.$setPristine();
|
|
|
|
|
$('#groupAddName').focus();
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
return console.error('Unable to create group.', error.statusCode, error.message);
|
|
|
|
|
}
|
2018-01-22 13:01:38 -08:00
|
|
|
}
|
|
|
|
|
|
2018-08-05 22:19:54 -07:00
|
|
|
var userIds = $scope.groupAdd.selectedUsers.map(function (u) { return u.id; });
|
|
|
|
|
|
|
|
|
|
Client.setGroupMembers(result.id, userIds, function (error) {
|
|
|
|
|
$scope.groupAdd.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error) return console.error('Unable to add memebers.', error.statusCode, error.message);
|
|
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
|
|
|
|
|
|
$('#groupAddModal').modal('hide');
|
|
|
|
|
});
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-18 17:45:09 -07:00
|
|
|
$scope.groupEdit = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
groupInfo: {},
|
|
|
|
|
name: '',
|
2020-06-05 08:18:40 +02:00
|
|
|
source: '',
|
2018-07-24 22:20:00 -07:00
|
|
|
selectedUsers: [],
|
2021-02-18 17:01:49 +01:00
|
|
|
selectedApps: [],
|
|
|
|
|
selectedAppsOriginal: [],
|
|
|
|
|
apps: [],
|
2018-07-24 22:20:00 -07:00
|
|
|
|
2018-06-18 17:45:09 -07:00
|
|
|
show: function (groupInfo) {
|
|
|
|
|
$scope.groupEdit.error = {};
|
|
|
|
|
$scope.groupEdit.groupInfo = groupInfo;
|
|
|
|
|
$scope.groupEdit.name = groupInfo.name;
|
2020-06-05 08:18:40 +02:00
|
|
|
$scope.groupEdit.source = groupInfo.source;
|
2020-01-09 16:21:20 +01:00
|
|
|
$scope.groupEdit.selectedUsers = groupInfo.userIds.map(function (uid) { return $scope.allUsersById[uid]; });
|
2021-02-18 17:01:49 +01:00
|
|
|
$scope.groupEdit.apps = Client.getInstalledApps();
|
|
|
|
|
|
|
|
|
|
$scope.groupEdit.selectedApps = Client.getInstalledApps().filter(function (app) {
|
|
|
|
|
if (app.accessRestriction === null || !Array.isArray(app.accessRestriction.groups)) return false;
|
|
|
|
|
return app.accessRestriction.groups.indexOf(groupInfo.id) !== -1;
|
|
|
|
|
});
|
|
|
|
|
angular.copy($scope.groupEdit.selectedApps, $scope.groupEdit.selectedAppsOriginal);
|
2018-06-18 17:45:09 -07:00
|
|
|
|
|
|
|
|
$scope.groupEdit_form.$setPristine();
|
|
|
|
|
$scope.groupEdit_form.$setUntouched();
|
|
|
|
|
|
|
|
|
|
$('#groupEditModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.groupEdit.busy = true;
|
|
|
|
|
$scope.groupEdit.error = {};
|
|
|
|
|
|
2018-07-26 11:38:20 -07:00
|
|
|
Client.updateGroup($scope.groupEdit.groupInfo.id, $scope.groupEdit.name, function (error) {
|
2018-07-24 22:31:22 -07:00
|
|
|
if (error) {
|
|
|
|
|
$scope.groupEdit.busy = false;
|
2018-06-18 17:45:09 -07:00
|
|
|
|
2018-07-24 22:31:22 -07:00
|
|
|
if (error.statusCode === 409) {
|
|
|
|
|
$scope.groupEdit.error.name = 'Name already taken';
|
|
|
|
|
$scope.groupEditForm.name.$setPristine();
|
|
|
|
|
$('#groupEditName').focus();
|
|
|
|
|
return;
|
|
|
|
|
} else if (error.statusCode === 400) {
|
|
|
|
|
$scope.groupEdit.error.name = error.message;
|
|
|
|
|
$scope.groupEditForm.name.$setPristine();
|
|
|
|
|
$('#groupEditName').focus();
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
return console.error('Unable to edit group.', error.statusCode, error.message);
|
|
|
|
|
}
|
2018-06-18 17:45:09 -07:00
|
|
|
}
|
|
|
|
|
|
2018-07-24 22:20:00 -07:00
|
|
|
var userIds = $scope.groupEdit.selectedUsers.map(function (u) { return u.id; });
|
|
|
|
|
|
|
|
|
|
Client.setGroupMembers($scope.groupEdit.groupInfo.id, userIds, function (error) {
|
2021-02-18 17:01:49 +01:00
|
|
|
if (error) {
|
|
|
|
|
$scope.groupEdit.busy = false;
|
|
|
|
|
return console.error('Unable to set group members.', error.statusCode, error.message);
|
|
|
|
|
}
|
2018-07-24 22:20:00 -07:00
|
|
|
|
2021-02-18 17:01:49 +01:00
|
|
|
// find apps where ACL has changed
|
|
|
|
|
var addedApps = $scope.groupEdit.selectedApps.filter(function (a) {
|
|
|
|
|
return !$scope.groupEdit.selectedAppsOriginal.find(function (b) { return b.id === a.id; });
|
|
|
|
|
});
|
|
|
|
|
var removedApps = $scope.groupEdit.selectedAppsOriginal.filter(function (a) {
|
|
|
|
|
return !$scope.groupEdit.selectedApps.find(function (b) { return b.id === a.id; });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async.eachSeries(addedApps, function (app, callback) {
|
|
|
|
|
var accessRestriction = app.accessRestriction;
|
|
|
|
|
if (!accessRestriction) accessRestriction = { users: [], groups: [] };
|
|
|
|
|
if (!Array.isArray(accessRestriction.groups)) accessRestriction.groups = [];
|
|
|
|
|
|
|
|
|
|
accessRestriction.groups.push($scope.groupEdit.groupInfo.id);
|
|
|
|
|
|
|
|
|
|
Client.configureApp(app.id, 'access_restriction', { accessRestriction: accessRestriction }, callback);
|
|
|
|
|
}, function (error) {
|
|
|
|
|
if (error) {
|
|
|
|
|
$scope.groupEdit.busy = false;
|
|
|
|
|
return console.error('Unable to set added app access.', error.statusCode, error.message);
|
|
|
|
|
}
|
2018-06-18 17:45:09 -07:00
|
|
|
|
2021-02-18 17:01:49 +01:00
|
|
|
async.eachSeries(removedApps, function (app, callback) {
|
|
|
|
|
var accessRestriction = app.accessRestriction;
|
|
|
|
|
if (!accessRestriction) accessRestriction = { users: [], groups: [] };
|
|
|
|
|
if (!Array.isArray(accessRestriction.groups)) accessRestriction.groups = [];
|
|
|
|
|
|
|
|
|
|
var deleted = accessRestriction.groups.splice(accessRestriction.groups.indexOf($scope.groupEdit.groupInfo.id), 1);
|
|
|
|
|
|
|
|
|
|
// if not found return early
|
|
|
|
|
if (deleted.length === 0) return callback();
|
|
|
|
|
|
|
|
|
|
Client.configureApp(app.id, 'access_restriction', { accessRestriction: accessRestriction }, callback);
|
|
|
|
|
}, function (error) {
|
|
|
|
|
$scope.groupEdit.busy = false;
|
|
|
|
|
if (error) return console.error('Unable to set removed app access.', error.statusCode, error.message);
|
|
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
|
|
|
|
|
|
// refresh apps to reflect change
|
|
|
|
|
Client.refreshInstalledApps();
|
2018-07-24 22:20:00 -07:00
|
|
|
|
2021-02-18 17:01:49 +01:00
|
|
|
$('#groupEditModal').modal('hide');
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-07-24 22:20:00 -07:00
|
|
|
});
|
2018-06-18 17:45:09 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.groupRemove = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
group: null,
|
|
|
|
|
memberCount: 0,
|
|
|
|
|
|
|
|
|
|
show: function (group) {
|
|
|
|
|
$scope.groupRemove.busy = false;
|
|
|
|
|
|
|
|
|
|
$scope.groupRemove.error = {};
|
|
|
|
|
|
|
|
|
|
$scope.groupRemove.group = angular.copy(group);
|
|
|
|
|
|
|
|
|
|
Client.getGroup(group.id, function (error, result) {
|
|
|
|
|
if (error) return console.error('Unable to fetch group information.', error.statusCode, error.message);
|
|
|
|
|
|
|
|
|
|
$scope.groupRemove.memberCount = result.userIds.length;
|
|
|
|
|
|
|
|
|
|
$('#groupRemoveModal').modal('show');
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.groupRemove.busy = true;
|
|
|
|
|
$scope.groupRemove.error = {};
|
|
|
|
|
|
2019-05-13 23:55:54 +02:00
|
|
|
Client.removeGroup($scope.groupRemove.group.id, function (error) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.groupRemove.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error) return console.error('Unable to remove group.', error.statusCode, error.message);
|
|
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
|
$('#groupRemoveModal').modal('hide');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.isMe = function (user) {
|
|
|
|
|
return user.username === Client.getUserInfo().username;
|
|
|
|
|
};
|
|
|
|
|
|
2021-09-16 14:35:17 +02:00
|
|
|
$scope.passwordReset = {
|
2018-08-17 16:01:40 -07:00
|
|
|
busy: false,
|
2021-09-16 14:35:17 +02:00
|
|
|
resetLink: '',
|
2018-08-17 16:01:40 -07:00
|
|
|
user: null,
|
2021-10-27 18:36:41 +02:00
|
|
|
email: '',
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-08-17 16:01:40 -07:00
|
|
|
show: function (user) {
|
2021-10-27 21:59:30 +02:00
|
|
|
$scope.passwordReset.busy = false;
|
|
|
|
|
$scope.passwordReset.resetLink = '';
|
2021-09-16 14:35:17 +02:00
|
|
|
$scope.passwordReset.user = user;
|
2021-10-27 18:36:41 +02:00
|
|
|
$scope.passwordReset.email = user.fallbackEmail || user.email;
|
|
|
|
|
|
|
|
|
|
Client.getPasswordResetLink(user.id, function (error, result) {
|
|
|
|
|
if (error) return console.error('Failed to get password reset link.', error);
|
2018-08-17 16:01:40 -07:00
|
|
|
|
2021-10-27 18:36:41 +02:00
|
|
|
$scope.passwordReset.resetLink = result.passwordResetLink;
|
|
|
|
|
|
|
|
|
|
$('#passwordResetModal').modal('show');
|
|
|
|
|
});
|
2018-08-17 16:01:40 -07:00
|
|
|
},
|
|
|
|
|
|
2021-10-27 18:36:41 +02:00
|
|
|
sendEmail: function () {
|
2021-09-16 14:35:17 +02:00
|
|
|
$scope.passwordReset.busy = true;
|
2021-04-15 10:54:55 +02:00
|
|
|
|
2021-10-27 18:36:41 +02:00
|
|
|
Client.sendPasswordResetEmail($scope.passwordReset.user.id, $scope.passwordReset.email, function (error) {
|
|
|
|
|
if (error) return console.error('Failed to send password reset email.', error);
|
2021-04-15 10:54:55 +02:00
|
|
|
|
2021-10-27 18:36:41 +02:00
|
|
|
$scope.passwordReset.busy = false;
|
2021-04-15 10:54:55 +02:00
|
|
|
|
2021-10-27 18:36:41 +02:00
|
|
|
$('#passwordResetModal').modal('hide');
|
2018-08-17 16:01:40 -07:00
|
|
|
});
|
|
|
|
|
}
|
2018-01-22 13:01:38 -08:00
|
|
|
};
|
|
|
|
|
|
2021-09-16 15:46:26 +02:00
|
|
|
$scope.invitation = {
|
|
|
|
|
busy: false,
|
|
|
|
|
inviteLink: '',
|
|
|
|
|
user: null,
|
2021-10-27 19:57:57 +02:00
|
|
|
email: '',
|
2021-09-16 15:46:26 +02:00
|
|
|
|
|
|
|
|
show: function (user) {
|
2021-10-27 21:59:30 +02:00
|
|
|
$scope.invitation.busy = false;
|
|
|
|
|
$scope.invitation.inviteLink = '';
|
2021-09-16 15:46:26 +02:00
|
|
|
$scope.invitation.user = user;
|
2021-10-27 21:59:30 +02:00
|
|
|
$scope.invitation.email = user.email;
|
2021-10-27 19:57:57 +02:00
|
|
|
|
|
|
|
|
Client.getInviteLink(user.id, function (error, result) {
|
|
|
|
|
if (error) return console.error('Failed to get invite link.', error);
|
|
|
|
|
|
2021-10-27 21:59:30 +02:00
|
|
|
$scope.invitation.inviteLink = result.inviteLink;
|
2021-09-16 15:46:26 +02:00
|
|
|
|
2021-10-27 19:57:57 +02:00
|
|
|
$('#invitationModal').modal('show');
|
|
|
|
|
});
|
2021-09-16 15:46:26 +02:00
|
|
|
},
|
|
|
|
|
|
2021-10-27 19:57:57 +02:00
|
|
|
sendEmail: function () {
|
2021-09-16 15:46:26 +02:00
|
|
|
$scope.invitation.busy = true;
|
|
|
|
|
|
2021-10-27 19:57:57 +02:00
|
|
|
Client.sendInviteEmail($scope.invitation.user.id, $scope.invitation.email, function (error) {
|
|
|
|
|
if (error) return console.error('Failed to send invite email.', error);
|
2021-09-16 15:46:26 +02:00
|
|
|
|
2021-10-27 19:57:57 +02:00
|
|
|
$scope.invitation.busy = false;
|
2021-09-16 15:46:26 +02:00
|
|
|
|
2021-10-27 19:57:57 +02:00
|
|
|
$('#invitationModal').modal('hide');
|
2021-09-16 15:46:26 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-09-17 15:53:11 +02:00
|
|
|
// https://stackoverflow.com/questions/1497481/javascript-password-generator
|
|
|
|
|
function generatePassword() {
|
|
|
|
|
var length = 12,
|
|
|
|
|
charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
|
|
|
|
retVal = "";
|
|
|
|
|
for (var i = 0, n = charset.length; i < length; ++i) {
|
|
|
|
|
retVal += charset.charAt(Math.floor(Math.random() * n));
|
|
|
|
|
}
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.setGhost = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: null,
|
2021-09-17 16:08:13 +02:00
|
|
|
success: false,
|
2021-09-17 15:53:11 +02:00
|
|
|
user: null,
|
|
|
|
|
password: '',
|
|
|
|
|
|
|
|
|
|
show: function (user) {
|
|
|
|
|
$scope.setGhost.busy = false;
|
2021-09-17 16:08:13 +02:00
|
|
|
$scope.setGhost.success = false;
|
2021-09-17 15:53:11 +02:00
|
|
|
$scope.setGhost.error = null;
|
|
|
|
|
$scope.setGhost.user = user;
|
|
|
|
|
$scope.setGhost.password = generatePassword();
|
|
|
|
|
|
|
|
|
|
$('#setGhostModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.setGhost.busy = true;
|
|
|
|
|
|
|
|
|
|
Client.setGhost($scope.setGhost.user.id, $scope.setGhost.password, null, function (error) {
|
|
|
|
|
$scope.setGhost.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
$scope.setGhost.error = error.message;
|
|
|
|
|
return console.error(error);
|
|
|
|
|
}
|
2021-09-17 16:08:13 +02:00
|
|
|
|
|
|
|
|
$scope.setGhost.success = true;
|
2021-09-17 15:53:11 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-09 21:51:51 -07:00
|
|
|
$scope.directoryConfig = {
|
|
|
|
|
editableUserProfiles: true,
|
2020-07-10 10:43:08 -07:00
|
|
|
mandatory2FA: false,
|
2020-07-22 18:09:30 -07:00
|
|
|
errorMessage: '',
|
2020-07-09 21:51:51 -07:00
|
|
|
|
|
|
|
|
loadDirectoryConfig: function () {
|
|
|
|
|
Client.getDirectoryConfig(function (error, result) {
|
|
|
|
|
if (error) return console.error('Unable to get directory config.', error);
|
|
|
|
|
|
|
|
|
|
$scope.directoryConfig.editableUserProfiles = !result.lockUserProfiles;
|
2020-07-10 10:43:08 -07:00
|
|
|
$scope.directoryConfig.mandatory2FA = !!result.mandatory2FA;
|
2020-07-09 21:51:51 -07:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.directoryConfig.error = '';
|
|
|
|
|
$scope.directoryConfig.busy = true;
|
|
|
|
|
$scope.directoryConfig.success = false;
|
|
|
|
|
|
|
|
|
|
var data = {
|
2020-07-10 10:43:08 -07:00
|
|
|
lockUserProfiles: !$scope.directoryConfig.editableUserProfiles,
|
|
|
|
|
mandatory2FA: $scope.directoryConfig.mandatory2FA
|
2020-07-09 21:51:51 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Client.setDirectoryConfig(data, function (error) {
|
2020-07-22 18:09:30 -07:00
|
|
|
if (error) $scope.directoryConfig.errorMessage = error.message;
|
2020-07-09 21:51:51 -07:00
|
|
|
|
|
|
|
|
$scope.directoryConfig.success = true;
|
|
|
|
|
|
|
|
|
|
$scope.directoryConfigForm.$setUntouched();
|
|
|
|
|
$scope.directoryConfigForm.$setPristine();
|
|
|
|
|
|
|
|
|
|
$timeout(function () {
|
|
|
|
|
$scope.directoryConfig.busy = false;
|
|
|
|
|
}, 3000);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-29 09:59:57 +02:00
|
|
|
$scope.externalLdap = {
|
|
|
|
|
busy: false,
|
2019-11-07 11:35:04 -08:00
|
|
|
percent: 0,
|
|
|
|
|
message: '',
|
|
|
|
|
errorMessage: '',
|
2019-08-29 09:59:57 +02:00
|
|
|
error: {},
|
2019-08-30 12:40:23 +02:00
|
|
|
taskId: 0,
|
2019-08-29 09:59:57 +02:00
|
|
|
|
2019-11-14 17:15:35 -08:00
|
|
|
syncBusy: false,
|
|
|
|
|
|
2019-08-29 09:59:57 +02:00
|
|
|
// fields
|
2019-10-25 15:38:04 -07:00
|
|
|
provider: 'noop',
|
2019-11-20 10:46:26 +01:00
|
|
|
autoCreate: false,
|
2019-08-29 09:59:57 +02:00
|
|
|
url: '',
|
2020-06-25 17:53:57 +02:00
|
|
|
acceptSelfSignedCerts: false,
|
2019-08-29 09:59:57 +02:00
|
|
|
baseDn: '',
|
|
|
|
|
filter: '',
|
2020-06-03 21:24:04 +02:00
|
|
|
groupBaseDn: '',
|
2019-08-29 09:59:57 +02:00
|
|
|
bindDn: '',
|
|
|
|
|
bindPassword: '',
|
2019-10-25 16:38:59 -07:00
|
|
|
usernameField: '',
|
2019-08-29 09:59:57 +02:00
|
|
|
|
2019-11-14 17:15:35 -08:00
|
|
|
currentConfig: {},
|
|
|
|
|
|
2019-11-07 11:35:04 -08:00
|
|
|
checkStatus: function () {
|
|
|
|
|
Client.getLatestTaskByType('syncExternalLdap', function (error, task) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
if (!task) return;
|
|
|
|
|
|
|
|
|
|
$scope.externalLdap.taskId = task.id;
|
|
|
|
|
$scope.externalLdap.updateStatus();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2019-08-29 17:22:39 +02:00
|
|
|
sync: function () {
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.syncBusy = true;
|
2019-08-29 23:19:34 +02:00
|
|
|
|
|
|
|
|
Client.startExternalLdapSync(function (error, taskId) {
|
2019-08-29 17:22:39 +02:00
|
|
|
if (error) {
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.syncBusy = false;
|
2019-08-29 17:22:39 +02:00
|
|
|
console.error('Unable to start ldap syncer task.', error);
|
2019-08-29 23:19:34 +02:00
|
|
|
return;
|
2019-08-29 17:22:39 +02:00
|
|
|
}
|
2019-08-29 23:19:34 +02:00
|
|
|
|
2019-08-30 12:40:23 +02:00
|
|
|
$scope.externalLdap.taskId = taskId;
|
2019-11-07 11:35:04 -08:00
|
|
|
$scope.externalLdap.updateStatus();
|
|
|
|
|
});
|
|
|
|
|
},
|
2019-08-30 12:40:23 +02:00
|
|
|
|
2019-11-07 11:35:04 -08:00
|
|
|
updateStatus: function () {
|
|
|
|
|
Client.getTask($scope.externalLdap.taskId, function (error, data) {
|
|
|
|
|
if (error) return window.setTimeout($scope.externalLdap.updateStatus, 5000);
|
2019-08-29 23:19:34 +02:00
|
|
|
|
2019-11-07 11:35:04 -08:00
|
|
|
if (!data.active) {
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.syncBusy = false;
|
2019-11-07 11:35:04 -08:00
|
|
|
$scope.externalLdap.message = '';
|
|
|
|
|
$scope.externalLdap.percent = 100; // indicates that 'result' is valid
|
|
|
|
|
$scope.externalLdap.errorMessage = data.success ? '' : data.error.message;
|
2019-08-30 16:56:01 +02:00
|
|
|
|
2019-11-07 11:35:04 -08:00
|
|
|
return refreshUsers();
|
2019-08-29 23:19:34 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.syncBusy = true;
|
2019-11-07 11:35:04 -08:00
|
|
|
$scope.externalLdap.percent = data.percent;
|
|
|
|
|
$scope.externalLdap.message = data.message;
|
|
|
|
|
window.setTimeout($scope.externalLdap.updateStatus, 3000);
|
2019-08-29 23:19:34 +02:00
|
|
|
});
|
2019-08-29 17:22:39 +02:00
|
|
|
},
|
|
|
|
|
|
2019-08-30 12:40:23 +02:00
|
|
|
show: function () {
|
|
|
|
|
$scope.externalLdap.busy = false;
|
|
|
|
|
$scope.externalLdap.error = {};
|
|
|
|
|
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.provider = $scope.externalLdap.currentConfig.provider;
|
|
|
|
|
$scope.externalLdap.url = $scope.externalLdap.currentConfig.url;
|
2020-06-25 17:53:57 +02:00
|
|
|
$scope.externalLdap.acceptSelfSignedCerts = $scope.externalLdap.currentConfig.acceptSelfSignedCerts;
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.baseDn = $scope.externalLdap.currentConfig.baseDn;
|
|
|
|
|
$scope.externalLdap.filter = $scope.externalLdap.currentConfig.filter;
|
2020-06-04 12:30:31 +02:00
|
|
|
$scope.externalLdap.syncGroups = $scope.externalLdap.currentConfig.syncGroups;
|
2020-06-08 14:50:32 +02:00
|
|
|
$scope.externalLdap.groupBaseDn = $scope.externalLdap.currentConfig.groupBaseDn;
|
|
|
|
|
$scope.externalLdap.groupFilter = $scope.externalLdap.currentConfig.groupFilter;
|
|
|
|
|
$scope.externalLdap.groupnameField = $scope.externalLdap.currentConfig.groupnameField;
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.bindDn = $scope.externalLdap.currentConfig.bindDn;
|
|
|
|
|
$scope.externalLdap.bindPassword = $scope.externalLdap.currentConfig.bindPassword;
|
|
|
|
|
$scope.externalLdap.usernameField = $scope.externalLdap.currentConfig.usernameField;
|
2019-11-20 10:46:26 +01:00
|
|
|
$scope.externalLdap.autoCreate = $scope.externalLdap.currentConfig.autoCreate;
|
2019-11-14 17:15:35 -08:00
|
|
|
|
2019-08-30 12:40:23 +02:00
|
|
|
$('#externalLdapModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
2019-08-29 09:59:57 +02:00
|
|
|
submit: function () {
|
|
|
|
|
$scope.externalLdap.busy = true;
|
|
|
|
|
$scope.externalLdap.error = {};
|
|
|
|
|
|
|
|
|
|
var config = {
|
2019-10-25 15:38:04 -07:00
|
|
|
provider: $scope.externalLdap.provider
|
2019-08-29 09:59:57 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-25 15:38:04 -07:00
|
|
|
if ($scope.externalLdap.provider !== 'noop') {
|
|
|
|
|
config.url = $scope.externalLdap.url;
|
2020-06-25 17:53:57 +02:00
|
|
|
config.acceptSelfSignedCerts = $scope.externalLdap.acceptSelfSignedCerts;
|
2019-10-25 15:38:04 -07:00
|
|
|
config.baseDn = $scope.externalLdap.baseDn;
|
|
|
|
|
config.filter = $scope.externalLdap.filter;
|
2019-10-25 16:38:59 -07:00
|
|
|
config.usernameField = $scope.externalLdap.usernameField;
|
2020-06-04 12:30:31 +02:00
|
|
|
config.syncGroups = $scope.externalLdap.syncGroups;
|
2020-06-03 21:24:04 +02:00
|
|
|
config.groupBaseDn = $scope.externalLdap.groupBaseDn;
|
|
|
|
|
config.groupFilter = $scope.externalLdap.groupFilter;
|
|
|
|
|
config.groupnameField = $scope.externalLdap.groupnameField;
|
2019-11-20 10:46:26 +01:00
|
|
|
config.autoCreate = $scope.externalLdap.autoCreate;
|
2019-10-25 15:38:04 -07:00
|
|
|
|
|
|
|
|
if ($scope.externalLdap.bindDn) {
|
|
|
|
|
config.bindDn = $scope.externalLdap.bindDn;
|
|
|
|
|
config.bindPassword = $scope.externalLdap.bindPassword;
|
|
|
|
|
}
|
2019-08-29 09:59:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Client.setExternalLdapConfig(config, function (error) {
|
|
|
|
|
$scope.externalLdap.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
if (error.statusCode === 424) {
|
2020-06-26 15:18:25 +02:00
|
|
|
if (error.code === 'SELF_SIGNED_CERT_IN_CHAIN') $scope.externalLdap.error.acceptSelfSignedCerts = true;
|
|
|
|
|
else $scope.externalLdap.error.url = true;
|
2019-08-29 09:59:57 +02:00
|
|
|
} else if (error.statusCode === 400 && error.message === 'invalid baseDn') {
|
|
|
|
|
$scope.externalLdap.error.baseDn = true;
|
|
|
|
|
} else if (error.statusCode === 400 && error.message === 'invalid filter') {
|
|
|
|
|
$scope.externalLdap.error.filter = true;
|
2020-06-03 21:24:04 +02:00
|
|
|
} else if (error.statusCode === 400 && error.message === 'invalid groupBaseDn') {
|
|
|
|
|
$scope.externalLdap.error.groupBaseDn = true;
|
|
|
|
|
} else if (error.statusCode === 400 && error.message === 'invalid groupFilter') {
|
|
|
|
|
$scope.externalLdap.error.groupFilter = true;
|
|
|
|
|
} else if (error.statusCode === 400 && error.message === 'invalid groupnameField') {
|
|
|
|
|
$scope.externalLdap.error.groupnameField = true;
|
2019-08-29 09:59:57 +02:00
|
|
|
} else if (error.statusCode === 400 && error.message === 'invalid bind credentials') {
|
|
|
|
|
$scope.externalLdap.error.credentials = true;
|
2019-10-25 16:38:59 -07:00
|
|
|
} else if (error.statusCode === 400 && error.message === 'invalid usernameField') {
|
|
|
|
|
$scope.externalLdap.error.usernameField = true;
|
2019-08-29 09:59:57 +02:00
|
|
|
} else {
|
|
|
|
|
$scope.externalLdap.error.generic = error.message;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2019-08-30 12:40:23 +02:00
|
|
|
$('#externalLdapModal').modal('hide');
|
2019-11-14 17:15:35 -08:00
|
|
|
|
|
|
|
|
loadExternalLdapConfig();
|
2019-08-29 09:59:57 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-25 16:14:14 -07:00
|
|
|
function getUsers(callback) {
|
2019-01-16 14:02:08 +01:00
|
|
|
var users = [];
|
2018-06-25 16:14:14 -07:00
|
|
|
|
2019-01-16 14:02:08 +01:00
|
|
|
Client.getUsers($scope.userSearchString, $scope.currentPage, $scope.pageItems.value, function (error, results) {
|
2018-06-25 16:14:14 -07:00
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
2020-09-16 16:03:14 -07:00
|
|
|
async.eachOfLimit(results, 20, function (result, index, iteratorDone) {
|
2018-06-25 16:14:14 -07:00
|
|
|
Client.getUser(result.id, function (error, user) {
|
|
|
|
|
if (error) return iteratorDone(error);
|
|
|
|
|
|
2020-09-16 16:03:14 -07:00
|
|
|
users[index] = user; // keep the sorting order
|
2018-06-25 16:14:14 -07:00
|
|
|
|
|
|
|
|
iteratorDone();
|
|
|
|
|
});
|
|
|
|
|
}, function (error) {
|
|
|
|
|
callback(error, users);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 13:59:44 -07:00
|
|
|
function refreshUsers(showBusy) { // loads users on current page only
|
2020-03-05 16:14:03 -08:00
|
|
|
if (showBusy) $scope.userRefreshBusy = true;
|
2019-01-15 13:30:37 +01:00
|
|
|
|
|
|
|
|
getUsers(function (error, result) {
|
|
|
|
|
if (error) return console.error('Unable to get user listing.', error);
|
|
|
|
|
|
|
|
|
|
angular.copy(result, $scope.users);
|
|
|
|
|
|
|
|
|
|
$scope.ready = true;
|
|
|
|
|
$scope.userRefreshBusy = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
function refresh() {
|
2020-08-10 13:59:44 -07:00
|
|
|
Client.getGroups(function (error, result) {
|
2018-01-22 13:01:38 -08:00
|
|
|
if (error) return console.error('Unable to get group listing.', error);
|
|
|
|
|
|
2018-07-24 22:20:00 -07:00
|
|
|
angular.copy(result, $scope.groups);
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.groupsById = { };
|
|
|
|
|
for (var i = 0; i < result.length; i++) {
|
|
|
|
|
$scope.groupsById[result[i].id] = result[i];
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-05 16:14:03 -08:00
|
|
|
refreshUsers(true);
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 09:59:57 +02:00
|
|
|
function loadExternalLdapConfig() {
|
|
|
|
|
Client.getExternalLdapConfig(function (error, result) {
|
|
|
|
|
if (error) return console.error('Unable to get external ldap config.', error);
|
|
|
|
|
|
2019-11-14 17:15:35 -08:00
|
|
|
$scope.externalLdap.currentConfig = result;
|
2020-02-24 17:49:36 +01:00
|
|
|
$scope.externalLdap.checkStatus();
|
2019-08-29 09:59:57 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-15 13:30:37 +01:00
|
|
|
$scope.showNextPage = function () {
|
|
|
|
|
$scope.currentPage++;
|
|
|
|
|
refreshUsers();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.showPrevPage = function () {
|
|
|
|
|
if ($scope.currentPage > 1) $scope.currentPage--;
|
|
|
|
|
else $scope.currentPage = 1;
|
|
|
|
|
refreshUsers();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.updateFilter = function (fresh) {
|
|
|
|
|
if (fresh) $scope.currentPage = 1;
|
|
|
|
|
refreshUsers();
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-10 13:59:44 -07:00
|
|
|
function refreshAllUsers() { // this loads all users on Cloudron, not just current page
|
2019-11-05 22:08:48 +01:00
|
|
|
Client.getUsers(function (error, results) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.allUsers = results;
|
2020-01-09 16:21:20 +01:00
|
|
|
|
|
|
|
|
$scope.allUsersById = {};
|
|
|
|
|
for (var i = 0; i < results.length; i++) {
|
|
|
|
|
$scope.allUsersById[results[i].id] = results[i];
|
|
|
|
|
}
|
2019-11-05 22:08:48 +01:00
|
|
|
});
|
2020-02-27 15:10:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Client.onReady(refresh);
|
|
|
|
|
Client.onReady(function () { if ($scope.user.isAtLeastAdmin) loadExternalLdapConfig(); });
|
2020-07-09 21:51:51 -07:00
|
|
|
Client.onReady(function () { if ($scope.user.isAtLeastAdmin) $scope.directoryConfig.loadDirectoryConfig(); });
|
2020-02-27 15:10:56 +01:00
|
|
|
Client.onReady(refreshAllUsers);
|
2020-02-26 16:48:51 +01:00
|
|
|
Client.onReady(function () {
|
2020-11-23 17:25:47 +01:00
|
|
|
// Order matters for permissions used in canEdit
|
2020-03-06 12:33:36 -08:00
|
|
|
$scope.roles = [
|
2020-11-23 17:25:47 +01:00
|
|
|
{ id: 'user', name: $translate.instant('users.role.user'), disabled: false },
|
|
|
|
|
{ id: 'usermanager', name: $translate.instant('users.role.usermanager'), disabled: false },
|
|
|
|
|
{ id: 'admin', name: $translate.instant('users.role.admin'), disabled: !$scope.user.isAtLeastAdmin },
|
|
|
|
|
{ id: 'owner', name: $translate.instant('users.role.owner'), disabled: !$scope.user.isAtLeastOwner }
|
2020-03-06 12:33:36 -08:00
|
|
|
];
|
2020-02-26 16:48:51 +01:00
|
|
|
});
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
// setup all the dialog focus handling
|
2018-06-18 17:45:09 -07:00
|
|
|
['userAddModal', 'userRemoveModal', 'userEditModal', 'groupAddModal', 'groupEditModal', 'groupRemoveModal'].forEach(function (id) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$('#' + id).on('shown.bs.modal', function () {
|
|
|
|
|
$(this).find("[autofocus]:first").focus();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-10-27 22:41:02 +02:00
|
|
|
new Clipboard('#passwordResetLinkClipboardButton').on('success', function(e) {
|
|
|
|
|
$('#passwordResetLinkClipboardButton').tooltip({
|
2018-01-22 13:01:38 -08:00
|
|
|
title: 'Copied!',
|
|
|
|
|
trigger: 'manual'
|
|
|
|
|
}).tooltip('show');
|
|
|
|
|
|
2021-10-27 22:41:02 +02:00
|
|
|
$timeout(function () { $('#passwordResetLinkClipboardButton').tooltip('hide'); }, 2000);
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
e.clearSelection();
|
2021-10-27 22:41:02 +02:00
|
|
|
}).on('error', function(/*e*/) {
|
|
|
|
|
$('#passwordResetLinkClipboardButton').tooltip({
|
|
|
|
|
title: 'Press Ctrl+C to copy',
|
|
|
|
|
trigger: 'manual'
|
|
|
|
|
}).tooltip('show');
|
|
|
|
|
|
|
|
|
|
$timeout(function () { $('#passwordResetLinkClipboardButton').tooltip('hide'); }, 2000);
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
|
2021-10-27 22:41:02 +02:00
|
|
|
new Clipboard('#invitationLinkClipboardButton').on('success', function(e) {
|
|
|
|
|
$('#invitationLinkClipboardButton').tooltip({
|
|
|
|
|
title: 'Copied!',
|
|
|
|
|
trigger: 'manual'
|
|
|
|
|
}).tooltip('show');
|
|
|
|
|
|
|
|
|
|
$timeout(function () { $('#invitationLinkClipboardButton').tooltip('hide'); }, 2000);
|
|
|
|
|
|
|
|
|
|
e.clearSelection();
|
|
|
|
|
}).on('error', function(/*e*/) {
|
|
|
|
|
$('#invitationLinkClipboardButton').tooltip({
|
2018-01-22 13:01:38 -08:00
|
|
|
title: 'Press Ctrl+C to copy',
|
|
|
|
|
trigger: 'manual'
|
|
|
|
|
}).tooltip('show');
|
|
|
|
|
|
2021-10-27 22:41:02 +02:00
|
|
|
$timeout(function () { $('#invitationLinkClipboardButton').tooltip('hide'); }, 2000);
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
|
2021-10-27 22:41:02 +02:00
|
|
|
new Clipboard('#setGhostClipboardButton').on('success', function(e) {
|
2021-09-17 15:53:11 +02:00
|
|
|
$('#setGhostClipboardButton').tooltip({
|
|
|
|
|
title: 'Copied!',
|
|
|
|
|
trigger: 'manual'
|
|
|
|
|
}).tooltip('show');
|
|
|
|
|
|
|
|
|
|
$timeout(function () { $('#setGhostClipboardButton').tooltip('hide'); }, 2000);
|
|
|
|
|
|
|
|
|
|
e.clearSelection();
|
2021-10-27 22:41:02 +02:00
|
|
|
}).on('error', function(/*e*/) {
|
2021-09-17 15:53:11 +02:00
|
|
|
$('#setGhostClipboardButton').tooltip({
|
|
|
|
|
title: 'Press Ctrl+C to copy',
|
|
|
|
|
trigger: 'manual'
|
|
|
|
|
}).tooltip('show');
|
|
|
|
|
|
|
|
|
|
$timeout(function () { $('#setGhostClipboardButton').tooltip('hide'); }, 2000);
|
|
|
|
|
});
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$('.modal-backdrop').remove();
|
|
|
|
|
}]);
|